Isis 3 Programmer Reference
Tool.cpp
1#include "Tool.h"
2
3#include <QLayout>
4#include <QMenuBar>
5#include <QStackedWidget>
6#include <QVector>
7
8#include "CubeViewport.h"
9#include "MdiCubeViewport.h"
10#include "FileName.h"
11#include "IString.h"
12#include "RubberBandTool.h"
13#include "ToolPad.h"
14#include "ToolList.h"
15#include "Workspace.h"
16#include "ViewportMainWindow.h"
17
18
19namespace Isis {
20// QStackedWidget *Tool::m_activeToolBarStack = NULL;
21
27 Tool::Tool(QWidget *parent) : QObject(parent) {
28 m_cvp = NULL;
29 m_workspace = NULL;
30 m_active = false;
31 m_toolPadAction = NULL;
32 m_toolBarWidget = NULL;
33 m_toolList = NULL;
34
35 QString tempFileName = FileName("$ISISROOT/appdata/images/icons").expanded();
36 m_toolIconDir = tempFileName;
37 }
38
39
46 m_workspace = ws;
47
48 connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)),
49 this, SLOT(setCubeViewport(MdiCubeViewport *)));
50 connect(ws, SIGNAL(cubeViewportActivated(MdiCubeViewport *)),
51 this, SLOT(setCubeViewport(MdiCubeViewport *)));
52 connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)),
53 this, SLOT(registerTool(MdiCubeViewport *)));
54 }
55
56
57 RubberBandTool *Tool::rubberBandTool() {
58 RubberBandTool *result = NULL;
59
60 if (m_toolList) {
61 result = m_toolList->rubberBandTool();
62 }
63
64 return result;
65 }
66
67
68 void Tool::setList(ToolList *currentList) {
69 m_toolList = currentList;
70 }
71
72
78 void Tool::addTo(ViewportMainWindow *pViewPortMnWin) {
79 addTo(pViewPortMnWin->workspace());
80 addToPermanent(pViewPortMnWin->permanentToolBar());
81 addToActive(pViewPortMnWin->activeToolBar());
82 addTo(pViewPortMnWin->toolPad());
83 if(!menuName().isEmpty()) {
84 QMenu *menu = pViewPortMnWin->getMenu(menuName());
85// if (menu->actions().size() > 0) menu->addSeparator();
86 addTo(menu);
87 }
88
89 //connect(this, SIGNAL(clearWarningSignal ()), pViewPortMnWin, SLOT(resetWarning ()));
90 }
91
92
98 void Tool::addTo(ToolPad *toolpad) {
100 if(m_toolPadAction != NULL) {
101 toolpad->addAction(m_toolPadAction);
102 connect(m_toolPadAction, SIGNAL(toggled(bool)), this, SLOT(activate(bool)));
103 }
104 }
105
106
113 if (m_toolList) {
114 QStackedWidget *activeToolBarStack = m_toolList->toolBarStack(toolbar);
115
116 m_toolBarWidget = createToolBarWidget(activeToolBarStack);
117 if(m_toolBarWidget != NULL) {
118 activeToolBarStack->addWidget(m_toolBarWidget);
119 }
120
122 }
123 }
124
125
131 void Tool::activate(bool on) {
132 if(m_active) {
133 emit clearWarningSignal();
134 if(on)
135 return;
138 if(m_toolPadAction != NULL)
139 m_toolPadAction->setChecked(false);
140 m_active = false;
141 }
142 else {
143 if(!on)
144 return;
145 if(m_toolPadAction != NULL)
146 m_toolPadAction->setChecked(true);
149 emit toolActivated();
150 m_active = true;
151 }
152 }
153
154
161 if(cvp == m_cvp) {
162 updateTool();
163 return;
164 }
165
166 if(m_active)
168
169 m_cvp = cvp;
170
171 if(m_active) {
174 }
175 else {
176 updateTool();
177 }
178
179 emit viewportChanged();
180 }
181
182
188 if(m_cvp == NULL)
189 return;
190
191 connect(m_cvp, SIGNAL(scaleChanged()),
192 this, SLOT(scaleChanged()));
193
194 if (rubberBandTool()) {
195 connect(rubberBandTool(), SIGNAL(measureChange()),
196 this, SLOT(updateMeasure()));
197
198 connect(rubberBandTool(), SIGNAL(bandingComplete()),
199 this, SLOT(rubberBandComplete()));
200 }
201
202 connect(m_cvp, SIGNAL(mouseEnter()),
203 this, SLOT(mouseEnter()));
204
205 connect(m_cvp, SIGNAL(screenPixelsChanged()),
206 this, SLOT(screenPixelsChanged()));
207
208 connect(m_cvp, SIGNAL(mouseMove(QPoint)),
209 this, SLOT(mouseMove(QPoint)), Qt::DirectConnection);
210
211 connect(m_cvp, SIGNAL(mouseMove(QPoint, Qt::MouseButton)),
212 this, SLOT(mouseMove(QPoint, Qt::MouseButton)), Qt::DirectConnection);
213
214 connect(m_cvp, SIGNAL(mouseLeave()),
215 this, SLOT(mouseLeave()));
216
217 connect(m_cvp, SIGNAL(mouseDoubleClick(QPoint)),
218 this, SLOT(mouseDoubleClick(QPoint)));
219
220 connect(m_cvp, SIGNAL(mouseButtonPress(QPoint, Qt::MouseButton)),
221 this, SLOT(mouseButtonPress(QPoint, Qt::MouseButton)));
222
223 connect(m_cvp, SIGNAL(mouseButtonRelease(QPoint, Qt::MouseButton)),
224 this, SLOT(mouseButtonRelease(QPoint, Qt::MouseButton)));
225
227
228 if(m_toolPadAction != NULL) {
230 }
231 }
232
233
239 if(m_cvp == NULL)
240 return;
241
242 disconnect(m_cvp, SIGNAL(scaleChanged()),
243 this, SLOT(scaleChanged()));
244
245 if (rubberBandTool()) {
246 disconnect(rubberBandTool(), SIGNAL(measureChange()),
247 this, SLOT(updateMeasure()));
248
249 disconnect(rubberBandTool(), SIGNAL(bandingComplete()),
250 this, SLOT(rubberBandComplete()));
251 }
252
253 disconnect(m_cvp, SIGNAL(mouseEnter()),
254 this, SLOT(mouseEnter()));
255
256 disconnect(m_cvp, SIGNAL(screenPixelsChanged()),
257 this, SLOT(screenPixelsChanged()));
258
259 disconnect(m_cvp, SIGNAL(mouseMove(QPoint)),
260 this, SLOT(mouseMove(QPoint)));
261
262 disconnect(m_cvp, SIGNAL(mouseMove(QPoint, Qt::MouseButton)),
263 this, SLOT(mouseMove(QPoint, Qt::MouseButton)));
264
265 disconnect(m_cvp, SIGNAL(mouseLeave()),
266 this, SLOT(mouseLeave()));
267
268 disconnect(m_cvp, SIGNAL(mouseDoubleClick(QPoint)),
269 this, SLOT(mouseDoubleClick(QPoint)));
270
271 disconnect(m_cvp, SIGNAL(mouseButtonPress(QPoint, Qt::MouseButton)),
272 this, SLOT(mouseButtonPress(QPoint, Qt::MouseButton)));
273
274 disconnect(m_cvp, SIGNAL(mouseButtonRelease(QPoint, Qt::MouseButton)),
275 this, SLOT(mouseButtonRelease(QPoint, Qt::MouseButton)));
276
278 }
279
280
286 if(m_toolBarWidget == NULL)
287 return;
288// if (m_toolBarWidget->isVisible()) m_toolBarWidget->hide();
289 m_toolBarWidget->setEnabled(false);
290 }
291
292
298 updateTool();
299 if(m_toolBarWidget == NULL)
300 return;
301 if(cubeViewport() == NULL) {
302 m_toolBarWidget->setEnabled(false);
303 }
304 else {
305 m_toolBarWidget->setEnabled(true);
306 }
307
308 if (m_toolList && m_toolList->toolBarStack()) {
309 m_toolList->toolBarStack()->setCurrentWidget(m_toolBarWidget);
310 }
311 }
312
313
319 }
320
321
328 viewport->registerTool(this);
329
330 connect(m_cvp, SIGNAL(requestRestretch(MdiCubeViewport *, int)),
331 this, SLOT(stretchRequested(MdiCubeViewport *, int)));
332 }
333
334
340 rubberBandTool()->disable();
341 }
342
343
344 Workspace *Tool::workspace() {
345 return m_workspace;
346 }
347
348
352 void Tool::mouseMove(QPoint p) {};
353
354
358 void Tool::mouseDoubleClick(QPoint p) {
359 emit clearWarningSignal();
360 }
361
362
367 void Tool::mouseButtonPress(QPoint p, Qt::MouseButton s) {
368 emit clearWarningSignal();
369 }
370
371
380 void Tool::mouseButtonRelease(QPoint p, Qt::MouseButton s) {
381 emit clearWarningSignal();
382 }
383
384
391 return m_workspace->cubeViewportList();
392 }
393}
394
395
396
File name manipulation and expansion.
Definition FileName.h:100
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition FileName.cpp:196
Cube display widget for certain Isis MDI applications.
void registerTool(Tool *tool)
Registers the tool given tool.
Rubber banding tool.
void disable()
This is called when something is not using me, so turn off events, reset & repaint to clear the clear...
virtual void removeConnections(MdiCubeViewport *cvp)
Anytime a tool is created, you must be able to remove it's connections.
Definition Tool.h:247
Tool(QWidget *parent)
Tool constructor.
Definition Tool.cpp:27
virtual QAction * toolPadAction(ToolPad *toolpad)
Anytime a tool is created, you must setup a tool pad action with it.
Definition Tool.h:217
QString m_toolIconDir
The pathway to the icon directory.
Definition Tool.h:267
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition Tool.cpp:78
void removeViewportConnections()
Removes all the connections from the tool.
Definition Tool.cpp:238
QWidget * m_toolBarWidget
The tool bar on which this tool resides.
Definition Tool.h:265
virtual void enableRubberBandTool()
Anytime a tool is created, you may use the rubber band tool.
Definition Tool.cpp:339
QAction * m_toolPadAction
The tool pad on which this tool resides.
Definition Tool.h:266
virtual void screenPixelsChanged()
This is called when actions change which pixels from the cube are displayed.
Definition Tool.h:148
virtual QString menuName() const
Anytime a tool is created, you must give it a name for the menu.
Definition Tool.h:83
QVector< MdiCubeViewport * > CubeViewportList
A list of cubeviewports.
Definition Tool.h:205
MdiCubeViewport * m_cvp
current cubeviewport
Definition Tool.h:261
virtual void updateTool()
Updates the tool.
Definition Tool.cpp:318
virtual void mouseDoubleClick(QPoint p)
Definition Tool.cpp:358
void disableToolBar()
Disables entire tool bar.
Definition Tool.cpp:285
virtual QWidget * createToolBarWidget(QStackedWidget *parent)
Anytime a tool is created, you must add it to the tool bar.
Definition Tool.h:229
void addViewportConnections()
Makes all the connections for the tool.
Definition Tool.cpp:187
virtual void mouseButtonRelease(QPoint p, Qt::MouseButton s)
Resets the Warning to Nowarning when a different activity occurs on the application.
Definition Tool.cpp:380
void activate(bool)
Activates the tool.
Definition Tool.cpp:131
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition Tool.cpp:390
virtual void mouseMove(QPoint p)
Definition Tool.cpp:352
void setCubeViewport(MdiCubeViewport *cvp)
Sets the current viewport to the given cvp.
Definition Tool.cpp:160
void enableToolBar()
Enables entire tool bar.
Definition Tool.cpp:297
virtual void addConnections(MdiCubeViewport *cvp)
Anytime a tool is created, you must add the connections for it.
Definition Tool.h:239
virtual void addToPermanent(QToolBar *toolbar)
Definition Tool.h:97
void addToActive(QToolBar *toolbar)
Definition Tool.cpp:112
void registerTool(MdiCubeViewport *viewport)
Registers the tool to the viewport.
Definition Tool.cpp:327
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition Tool.h:197
virtual void mouseButtonPress(QPoint p, Qt::MouseButton s)
Definition Tool.cpp:367
bool m_active
Is the tool acitve?
Definition Tool.h:264
This was called the Qisis MainWindow.
QVector< MdiCubeViewport * > * cubeViewportList()
This method returns a Vector of MdiCubeViewports.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16