]> Shamusworld >> Repos - architektonas/blob - src/forms/cadtoolbarselect.cpp
Successfully refactored CadToolBarLines to use predefined actions.
[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 "cadtoolbar.h"
18 #include "qg_actionhandler.h"
19 #include "rs_actioninterface.h"
20 #include "rs_debug.h"
21
22 CadToolBarSelect::CadToolBarSelect(QWidget * parent/*= 0*/, Qt::WindowFlags flags/*= 0*/):
23         QWidget(parent, flags), actionHandler(NULL), cadToolBar(NULL), selectAction(NULL),
24         nextAction(-1)
25 {
26         ui.setupUi(this);
27 }
28
29 CadToolBarSelect::~CadToolBarSelect()
30 {
31 }
32
33 void CadToolBarSelect::mousePressEvent(QMouseEvent * e)
34 {
35         if (e->button() == Qt::RightButton && cadToolBar != NULL)
36         {
37                 cadToolBar->back();
38                 e->accept();
39         }
40 }
41
42 void CadToolBarSelect::contextMenuEvent(QContextMenuEvent *e) {
43         e->accept();
44 }
45
46 void CadToolBarSelect::setCadToolBar(CadToolBar * tb)
47 {
48         cadToolBar = tb;
49
50         if (tb != NULL)
51                 actionHandler = tb->getActionHandler();
52                 //actionHandler->setCadToolBarSelect(this);
53         else
54                 RS_DEBUG->print(RS_Debug::D_ERROR, "CadToolBarSelect::setCadToolBar(): No valid toolbar set.");
55 }
56
57 void CadToolBarSelect::selectSingle()
58 {
59         if (actionHandler!=NULL) {
60                 actionHandler->slotSelectSingle();
61         }
62 }
63
64 void CadToolBarSelect::selectContour() {
65         if (actionHandler!=NULL) {
66                 actionHandler->slotSelectContour();
67         }
68 }
69
70 void CadToolBarSelect::deselectAll() {
71         if (actionHandler!=NULL) {
72                 actionHandler->slotDeselectAll();
73         }
74 }
75
76 void CadToolBarSelect::selectAll() {
77         if (actionHandler!=NULL) {
78                 actionHandler->slotSelectAll();
79         }
80 }
81
82 void CadToolBarSelect::selectWindow() {
83         if (actionHandler!=NULL) {
84                 actionHandler->slotSelectWindow();
85         }
86 }
87
88 void CadToolBarSelect::deselectWindow() {
89         if (actionHandler!=NULL) {
90                 actionHandler->slotDeselectWindow();
91         }
92 }
93
94 void CadToolBarSelect::selectIntersected() {
95         if (actionHandler!=NULL) {
96                 actionHandler->slotSelectIntersected();
97         }
98 }
99
100 void CadToolBarSelect::deselectIntersected() {
101         if (actionHandler!=NULL) {
102                 actionHandler->slotDeselectIntersected();
103         }
104 }
105
106 void CadToolBarSelect::selectInvert() {
107         if (actionHandler!=NULL) {
108                 actionHandler->slotSelectInvert();
109         }
110 }
111
112 void CadToolBarSelect::selectLayer()
113 {
114         if (actionHandler!=NULL)
115                 actionHandler->slotSelectLayer();
116 }
117
118 void CadToolBarSelect::setSelectAction(RS_ActionInterface * selectAction)
119 {
120         this->selectAction = selectAction;
121 }
122
123 void CadToolBarSelect::setNextAction(int nextAction)
124 {
125         this->nextAction = nextAction;
126
127         if (nextAction == -1)
128                 ui.bDoit->hide();
129         else
130                 ui.bDoit->show();
131 }
132
133 void CadToolBarSelect::runNextAction()
134 {
135         if (selectAction != NULL)
136         {
137                 selectAction->finish();
138                 selectAction = NULL;
139         }
140
141         if (nextAction != -1)
142         {
143                 actionHandler->killSelectActions();
144                 actionHandler->setCurrentAction((RS2::ActionType)nextAction);
145         }
146 }
147
148 void CadToolBarSelect::back()
149 {
150         if (cadToolBar != NULL)
151                 cadToolBar->back();
152 }