]> Shamusworld >> Repos - architektonas/blob - src/forms/cadtoolbarselect.cpp
Refactored CAD tool bars once more...
[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 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Created this file. :-)
13 //
14
15 #include "cadtoolbarselect.h"
16
17 #include "qg_actionhandler.h"
18 #include "rs_actioninterface.h"
19 #include "cadtoolbar.h"
20 #include "createqtactions.h"
21
22 CadToolBarSelect::CadToolBarSelect(CadToolBar * parent, Qt::WindowFlags flags/*= 0*/):
23         QWidget((QWidget *)parent, flags), actionHandler(NULL), selectAction(NULL),
24         nextAction(-1)
25 {
26         actionHandler = parent->getActionHandler();
27
28         QGridLayout * gridLayout = new QGridLayout(this);
29         gridLayout->setSpacing(0);
30         gridLayout->setContentsMargins(0, 0, 0, 0);
31
32         gridLayout->addWidget(parent->CreateBackButton(this), 0, 0, 1, 2);
33
34         gridLayout->addWidget(parent->CreateToolButton(actionDeselectAll), 1, 0, 1, 1);
35         gridLayout->addWidget(parent->CreateToolButton(actionSelectAll), 1, 1, 1, 1);
36         gridLayout->addWidget(parent->CreateToolButton(actionSelectSingle), 2, 0, 1, 1);
37         gridLayout->addWidget(parent->CreateToolButton(actionSelectContour), 2, 1, 1, 1);
38         gridLayout->addWidget(parent->CreateToolButton(actionDeselectWindow), 3, 0, 1, 1);
39         gridLayout->addWidget(parent->CreateToolButton(actionSelectWindow), 3, 1, 1, 1);
40         gridLayout->addWidget(parent->CreateToolButton(actionDeselectIntersected), 4, 0, 1, 1);
41         gridLayout->addWidget(parent->CreateToolButton(actionSelectIntersected), 4, 1, 1, 1);
42         gridLayout->addWidget(parent->CreateToolButton(actionSelectInvert), 5, 0, 1, 1);
43         gridLayout->addWidget(parent->CreateToolButton(actionSelectLayer), 5, 1, 1, 1);
44
45         QAction * actionDoit = new QAction(QIcon(":/res/qg_forward"), tr("Forward"), this);
46         doit = new QToolButton(this);
47         doit->setDefaultAction(actionDoit);
48         QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
49         doit->setSizePolicy(policy);
50         gridLayout->addWidget(doit, 6, 0, 1, 2);
51         connect(doit, SIGNAL(clicked()), this, SLOT(runNextAction()));
52 }
53
54 CadToolBarSelect::~CadToolBarSelect()
55 {
56 }
57
58 //hmm, should these three funcs be here???
59 void CadToolBarSelect::setSelectAction(RS_ActionInterface * selectAction)
60 {
61         this->selectAction = selectAction;
62 }
63
64 void CadToolBarSelect::setNextAction(int nextAction)
65 {
66         this->nextAction = nextAction;
67
68         if (nextAction == -1)
69                 doit->hide();
70         else
71                 doit->show();
72 }
73
74 void CadToolBarSelect::runNextAction()
75 {
76         if (selectAction)
77         {
78                 selectAction->finish();
79                 selectAction = NULL;
80         }
81
82         if (nextAction != -1)
83         {
84                 actionHandler->killSelectActions();
85                 actionHandler->setCurrentAction((RS2::ActionType)nextAction);
86         }
87 }