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 
19 namespace 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("$base/icons").expanded();
36  m_toolIconDir = tempFileName;
37  }
38 
39 
45  void Tool::addTo(Workspace *ws) {
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) {
99  m_toolPadAction = toolPadAction(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 
112  void Tool::addToActive(QToolBar *toolbar) {
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 
121  disableToolBar();
122  }
123  }
124 
125 
131  void Tool::activate(bool on) {
132  if(m_active) {
133  emit clearWarningSignal();
134  if(on)
135  return;
137  disableToolBar();
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);
148  enableToolBar();
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) {
173  enableToolBar();
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 
Cube display widget for certain Isis MDI applications.
virtual void screenPixelsChanged()
This is called when actions change which pixels from the cube are displayed.
Definition: Tool.h:162
virtual void removeConnections(MdiCubeViewport *cvp)
Anytime a tool is created, you must be able to remove it&#39;s connections.
Definition: Tool.h:261
MdiCubeViewport * m_cvp
current cubeviewport
Definition: Tool.h:275
void registerTool(MdiCubeViewport *viewport)
Registers the tool to the viewport.
Definition: Tool.cpp:327
QToolBar * activeToolBar()
Returns the active toolbar.
virtual QAction * toolPadAction(ToolPad *toolpad)
Anytime a tool is created, you must setup a tool pad action with it.
Definition: Tool.h:231
void registerTool(Tool *tool)
Registers the tool given tool.
void addToActive(QToolBar *toolbar)
Definition: Tool.cpp:112
QAction * m_toolPadAction
The tool pad on which this tool resides.
Definition: Tool.h:280
File name manipulation and expansion.
Definition: FileName.h:116
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
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition: Tool.cpp:390
virtual void addToPermanent(QToolBar *toolbar)
Definition: Tool.h:111
bool m_active
Is the tool acitve?
Definition: Tool.h:278
void enableToolBar()
Enables entire tool bar.
Definition: Tool.cpp:297
void setCubeViewport(MdiCubeViewport *cvp)
Sets the current viewport to the given cvp.
Definition: Tool.cpp:160
QVector< MdiCubeViewport *> * cubeViewportList()
This method returns a Vector of MdiCubeViewports.
Definition: Workspace.cpp:238
void addAction(QAction *action)
Adds an action to the action group and tool bar.
Definition: ToolPad.h:38
QToolBar * permanentToolBar()
Returns the permanent toolbar.
This was called the Qisis MainWindow.
Tool(QWidget *parent)
Tool constructor.
Definition: Tool.cpp:27
void disableToolBar()
Disables entire tool bar.
Definition: Tool.cpp:285
QWidget * m_toolBarWidget
The tool bar on which this tool resides.
Definition: Tool.h:279
virtual void mouseDoubleClick(QPoint p)
Definition: Tool.cpp:358
QMenu * getMenu(const QString &name)
Returns the menu with menu name = name.
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:212
void addTo(ViewportMainWindow *mw)
Adds the tool to the application.
Definition: Tool.cpp:78
ToolPad * toolPad()
Returns the toolpad.
void addViewportConnections()
Makes all the connections for the tool.
Definition: Tool.cpp:187
Workspace * workspace()
Returns the current workspace.
Rubber banding tool.
virtual QWidget * createToolBarWidget(QStackedWidget *parent)
Anytime a tool is created, you must add it to the tool bar.
Definition: Tool.h:243
QString m_toolIconDir
The pathway to the icon directory.
Definition: Tool.h:281
virtual void mouseButtonPress(QPoint p, Qt::MouseButton s)
Definition: Tool.cpp:367
virtual void updateTool()
Updates the tool.
Definition: Tool.cpp:318
void disable()
This is called when something is not using me, so turn off events, reset & repaint to clear the clear...
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
virtual void enableRubberBandTool()
Anytime a tool is created, you may use the rubber band tool.
Definition: Tool.cpp:339
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:211
virtual QString menuName() const
Anytime a tool is created, you must give it a name for the menu.
Definition: Tool.h:97
void removeViewportConnections()
Removes all the connections from the tool.
Definition: Tool.cpp:238
void activate(bool)
Activates the tool.
Definition: Tool.cpp:131
virtual void addConnections(MdiCubeViewport *cvp)
Anytime a tool is created, you must add the connections for it.
Definition: Tool.h:253
virtual void mouseMove(QPoint p)
Definition: Tool.cpp:352