]> Shamusworld >> Repos - architektonas/blob - forms/cadtoolbarselect.cpp
Updated the TODO.
[architektonas] / 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), cadToolBar(parent), actionHandler(NULL),
24         selectAction(NULL), nextAction(-1)
25 {
26         actionHandler = cadToolBar->getActionHandler();
27
28         QGridLayout * gridLayout = new QGridLayout(this);
29         gridLayout->setSpacing(0);
30         gridLayout->setContentsMargins(0, 0, 0, 0);
31
32         QAction * actionBack = new QAction(QIcon(":/res/qg_back"), tr("Back"), this);
33         QToolButton * button = new QToolButton(this);
34         button->setDefaultAction(actionBack);
35         QSizePolicy policy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
36         button->setSizePolicy(policy);
37         gridLayout->addWidget(button, 0, 0, 1, 2);
38         connect(button, SIGNAL(clicked()), this, SLOT(back()));
39
40         gridLayout->addWidget(CreateToolButton(actionDeselectAll), 1, 0, 1, 1);
41         gridLayout->addWidget(CreateToolButton(actionSelectAll), 1, 1, 1, 1);
42         gridLayout->addWidget(CreateToolButton(actionSelectSingle), 2, 0, 1, 1);
43         gridLayout->addWidget(CreateToolButton(actionSelectContour), 2, 1, 1, 1);
44         gridLayout->addWidget(CreateToolButton(actionDeselectWindow), 3, 0, 1, 1);
45         gridLayout->addWidget(CreateToolButton(actionSelectWindow), 3, 1, 1, 1);
46         gridLayout->addWidget(CreateToolButton(actionDeselectIntersected), 4, 0, 1, 1);
47         gridLayout->addWidget(CreateToolButton(actionSelectIntersected), 4, 1, 1, 1);
48         gridLayout->addWidget(CreateToolButton(actionSelectInvert), 5, 0, 1, 1);
49         gridLayout->addWidget(CreateToolButton(actionSelectLayer), 5, 1, 1, 1);
50
51         QAction * actionDoit = new QAction(QIcon(":/res/qg_forward"), tr("Forward"), this);
52         doit = new QToolButton(this);
53         doit->setDefaultAction(actionDoit);
54         doit->setSizePolicy(policy);
55         gridLayout->addWidget(doit, 6, 0, 1, 2);
56         connect(doit, SIGNAL(clicked()), this, SLOT(runNextAction()));
57 }
58
59 CadToolBarSelect::~CadToolBarSelect()
60 {
61 }
62
63 //hmm, should these three funcs be here???
64 void CadToolBarSelect::setSelectAction(RS_ActionInterface * selectAction)
65 {
66         this->selectAction = selectAction;
67 }
68
69 void CadToolBarSelect::setNextAction(int nextAction)
70 {
71         this->nextAction = nextAction;
72
73         if (nextAction == -1)
74                 doit->hide();
75         else
76                 doit->show();
77 }
78
79 void CadToolBarSelect::runNextAction()
80 {
81 //printf("CadToolBarSelect::runNextAction(): Entered function...\n");
82         if (selectAction)
83         {
84 //printf("CadToolBarSelect::runNextAction(): About to do selectAction...\n");
85                 selectAction->finish();
86                 selectAction = NULL;
87         }
88
89         if (nextAction != -1)
90         {
91 //printf("CadToolBarSelect::runNextAction(): About to do nextAction...\n");
92                 actionHandler->killSelectActions();
93                 actionHandler->setCurrentAction((RS2::ActionType)nextAction);
94         }
95 }
96
97 void CadToolBarSelect::back()
98 {
99         cadToolBar->back();
100 }
101
102 QToolButton * CadToolBarSelect::CreateToolButton(QAction * action)
103 {
104         QToolButton * button = new QToolButton(this);
105         button->setDefaultAction(action);
106         button->setIconSize(QSize(18, 18));
107
108         return button;
109 }