]> Shamusworld >> Repos - architektonas/blob - src/forms/cadtoolbarselect.cpp
Bugfixes related to removing Snapper class.
[architektonas] / src / forms / cadtoolbarselect.cpp
1 // cadtoolbarselect.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/10/2010  Created this file. :-)
15 //
16
17 #include "cadtoolbarselect.h"
18
19 #include "actionhandler.h"
20 #include "actioninterface.h"
21 #include "cadtoolbar.h"
22 #include "createqtactions.h"
23
24 CadToolBarSelect::CadToolBarSelect(CadToolBar * parent, Qt::WindowFlags flags/*= 0*/):
25         QWidget((QWidget *)parent, flags), actionHandler(NULL), selectAction(NULL),
26         nextAction(-1)
27 {
28         actionHandler = parent->getActionHandler();
29
30         QGridLayout * gridLayout = new QGridLayout(this);
31         gridLayout->setSpacing(0);
32         gridLayout->setContentsMargins(0, 0, 0, 0);
33
34         gridLayout->addWidget(parent->CreateBackButton(this), 0, 0, 1, 2);
35
36         gridLayout->addWidget(parent->CreateToolButton(actionDeselectAll), 1, 0, 1, 1);
37         gridLayout->addWidget(parent->CreateToolButton(actionSelectAll), 1, 1, 1, 1);
38         gridLayout->addWidget(parent->CreateToolButton(actionSelectSingle), 2, 0, 1, 1);
39         gridLayout->addWidget(parent->CreateToolButton(actionSelectContour), 2, 1, 1, 1);
40         gridLayout->addWidget(parent->CreateToolButton(actionDeselectWindow), 3, 0, 1, 1);
41         gridLayout->addWidget(parent->CreateToolButton(actionSelectWindow), 3, 1, 1, 1);
42         gridLayout->addWidget(parent->CreateToolButton(actionDeselectIntersected), 4, 0, 1, 1);
43         gridLayout->addWidget(parent->CreateToolButton(actionSelectIntersected), 4, 1, 1, 1);
44         gridLayout->addWidget(parent->CreateToolButton(actionSelectInvert), 5, 0, 1, 1);
45         gridLayout->addWidget(parent->CreateToolButton(actionSelectLayer), 5, 1, 1, 1);
46
47         QAction * actionDoit = new QAction(QIcon(":/res/qg_forward"), tr("Forward"), this);
48         doit = new QToolButton(this);
49         doit->setDefaultAction(actionDoit);
50         QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
51         doit->setSizePolicy(policy);
52         gridLayout->addWidget(doit, 6, 0, 1, 2);
53         connect(doit, SIGNAL(clicked()), this, SLOT(runNextAction()));
54 }
55
56 CadToolBarSelect::~CadToolBarSelect()
57 {
58 }
59
60 //hmm, should these three funcs be here???
61 void CadToolBarSelect::setSelectAction(ActionInterface * selectAction)
62 {
63         this->selectAction = selectAction;
64 }
65
66 void CadToolBarSelect::setNextAction(int nextAction)
67 {
68         this->nextAction = nextAction;
69
70         if (nextAction == -1)
71                 doit->hide();
72         else
73                 doit->show();
74 }
75
76 void CadToolBarSelect::runNextAction()
77 {
78         if (selectAction)
79         {
80                 selectAction->finish();
81                 selectAction = NULL;
82         }
83
84         if (nextAction != -1)
85         {
86                 actionHandler->killSelectActions();
87                 actionHandler->setCurrentAction((RS2::ActionType)nextAction);
88         }
89 }