USGS

Isis 3.0 Object Programmers' Reference

Home

Tool.cpp
1 #include "Tool.h"
2 
3 #include <QLayout>
4 #include <QMenuBar>
5 #include <QVector>
6 
7 #include "CubeViewport.h"
8 #include "MdiCubeViewport.h"
9 #include "FileName.h"
10 #include "IString.h"
11 #include "RubberBandTool.h"
12 #include "ToolPad.h"
13 #include "ToolList.h"
14 #include "Workspace.h"
15 #include "ViewportMainWindow.h"
16 
17 
18 namespace Isis {
19 // QStackedWidget *Tool::m_activeToolBarStack = NULL;
20 
26  Tool::Tool(QWidget *parent) : QObject(parent) {
27  m_cvp = NULL;
28  m_workspace = NULL;
29  m_active = false;
30  m_toolPadAction = NULL;
31  m_toolBarWidget = NULL;
32  m_toolList = NULL;
33 
34  QString tempFileName = FileName("$base/icons").expanded();
35  m_toolIconDir = tempFileName;
36  }
37 
38 
44  void Tool::addTo(Workspace *ws) {
45  m_workspace = ws;
46 
47  connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)),
48  this, SLOT(setCubeViewport(MdiCubeViewport *)));
49  connect(ws, SIGNAL(cubeViewportActivated(MdiCubeViewport *)),
50  this, SLOT(setCubeViewport(MdiCubeViewport *)));
51  connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)),
52  this, SLOT(registerTool(MdiCubeViewport *)));
53  }
54 
55 
56  RubberBandTool *Tool::rubberBandTool() {
57  RubberBandTool *result = NULL;
58 
59  if (m_toolList) {
60  result = m_toolList->rubberBandTool();
61  }
62 
63  return result;
64  }
65 
66 
67  void Tool::setList(ToolList *currentList) {
68  m_toolList = currentList;
69  }
70 
71 
77  void Tool::addTo(ViewportMainWindow *pViewPortMnWin) {
78  addTo(pViewPortMnWin->workspace());
79  addToPermanent(pViewPortMnWin->permanentToolBar());
80  addToActive(pViewPortMnWin->activeToolBar());
81  addTo(pViewPortMnWin->toolPad());
82  if(!menuName().isEmpty()) {
83  QMenu *menu = pViewPortMnWin->getMenu(menuName());
84 // if (menu->actions().size() > 0) menu->addSeparator();
85  addTo(menu);
86  }
87 
88  //connect(this, SIGNAL(clearWarningSignal ()), pViewPortMnWin, SLOT(resetWarning ()));
89  }
90 
91 
97  void Tool::addTo(ToolPad *toolpad) {
98  m_toolPadAction = toolPadAction(toolpad);
99  if(m_toolPadAction != NULL) {
100  toolpad->addAction(m_toolPadAction);
101  connect(m_toolPadAction, SIGNAL(toggled(bool)), this, SLOT(activate(bool)));
102  }
103  }
104 
105 
111  void Tool::addToActive(QToolBar *toolbar) {
112  if (m_toolList) {
113  QStackedWidget *activeToolBarStack = m_toolList->toolBarStack(toolbar);
114 
115  m_toolBarWidget = createToolBarWidget(activeToolBarStack);
116  if(m_toolBarWidget != NULL) {
117  activeToolBarStack->addWidget(m_toolBarWidget);
118  }
119 
120  disableToolBar();
121  }
122  }
123 
124 
130  void Tool::activate(bool on) {
131  if(m_active) {
132  emit clearWarningSignal();
133  if(on)
134  return;
136  disableToolBar();
137  if(m_toolPadAction != NULL)
138  m_toolPadAction->setChecked(false);
139  m_active = false;
140  }
141  else {
142  if(!on)
143  return;
144  if(m_toolPadAction != NULL)
145  m_toolPadAction->setChecked(true);
147  enableToolBar();
148  emit toolActivated();
149  m_active = true;
150  }
151  }
152 
153 
160  if(cvp == m_cvp) {
161  updateTool();
162  return;
163  }
164 
165  if(m_active)
167 
168  m_cvp = cvp;
169 
170  if(m_active) {
172  enableToolBar();
173  }
174  else {
175  updateTool();
176  }
177 
178  emit viewportChanged();
179  }
180 
181 
187  if(m_cvp == NULL)
188  return;
189 
190  connect(m_cvp, SIGNAL(scaleChanged()),
191  this, SLOT(scaleChanged()));
192 
193  if (rubberBandTool()) {
194  connect(rubberBandTool(), SIGNAL(measureChange()),
195  this, SLOT(updateMeasure()));
196 
197  connect(rubberBandTool(), SIGNAL(bandingComplete()),
198  this, SLOT(rubberBandComplete()));
199  }
200 
201  connect(m_cvp, SIGNAL(mouseEnter()),
202  this, SLOT(mouseEnter()));
203 
204  connect(m_cvp, SIGNAL(screenPixelsChanged()),
205  this, SLOT(screenPixelsChanged()));
206 
207  connect(m_cvp, SIGNAL(mouseMove(QPoint)),
208  this, SLOT(mouseMove(QPoint)), Qt::DirectConnection);
209 
210  connect(m_cvp, SIGNAL(mouseMove(QPoint, Qt::MouseButton)),
211  this, SLOT(mouseMove(QPoint, Qt::MouseButton)), Qt::DirectConnection);
212 
213  connect(m_cvp, SIGNAL(mouseLeave()),
214  this, SLOT(mouseLeave()));
215 
216  connect(m_cvp, SIGNAL(mouseDoubleClick(QPoint)),
217  this, SLOT(mouseDoubleClick(QPoint)));
218 
219  connect(m_cvp, SIGNAL(mouseButtonPress(QPoint, Qt::MouseButton)),
220  this, SLOT(mouseButtonPress(QPoint, Qt::MouseButton)));
221 
222  connect(m_cvp, SIGNAL(mouseButtonRelease(QPoint, Qt::MouseButton)),
223  this, SLOT(mouseButtonRelease(QPoint, Qt::MouseButton)));
224 
226 
227  if(m_toolPadAction != NULL) {
229  }
230  }
231 
232 
238  if(m_cvp == NULL)
239  return;
240 
241  disconnect(m_cvp, SIGNAL(scaleChanged()),
242  this, SLOT(scaleChanged()));
243 
244  if (rubberBandTool()) {
245  disconnect(rubberBandTool(), SIGNAL(measureChange()),
246  this, SLOT(updateMeasure()));
247 
248  disconnect(rubberBandTool(), SIGNAL(bandingComplete()),
249  this, SLOT(rubberBandComplete()));
250  }
251 
252  disconnect(m_cvp, SIGNAL(mouseEnter()),
253  this, SLOT(mouseEnter()));
254 
255  disconnect(m_cvp, SIGNAL(screenPixelsChanged()),
256  this, SLOT(screenPixelsChanged()));
257 
258  disconnect(m_cvp, SIGNAL(mouseMove(QPoint)),
259  this, SLOT(mouseMove(QPoint)));
260 
261  disconnect(m_cvp, SIGNAL(mouseMove(QPoint, Qt::MouseButton)),
262  this, SLOT(mouseMove(QPoint, Qt::MouseButton)));
263 
264  disconnect(m_cvp, SIGNAL(mouseLeave()),
265  this, SLOT(mouseLeave()));
266 
267  disconnect(m_cvp, SIGNAL(mouseDoubleClick(QPoint)),
268  this, SLOT(mouseDoubleClick(QPoint)));
269 
270  disconnect(m_cvp, SIGNAL(mouseButtonPress(QPoint, Qt::MouseButton)),
271  this, SLOT(mouseButtonPress(QPoint, Qt::MouseButton)));
272 
273  disconnect(m_cvp, SIGNAL(mouseButtonRelease(QPoint, Qt::MouseButton)),
274  this, SLOT(mouseButtonRelease(QPoint, Qt::MouseButton)));
275 
277  }
278 
279 
285  if(m_toolBarWidget == NULL)
286  return;
287 // if (m_toolBarWidget->isVisible()) m_toolBarWidget->hide();
288  m_toolBarWidget->setEnabled(false);
289  }
290 
291 
297  updateTool();
298  if(m_toolBarWidget == NULL)
299  return;
300  if(cubeViewport() == NULL) {
301  m_toolBarWidget->setEnabled(false);
302  }
303  else {
304  m_toolBarWidget->setEnabled(true);
305  }
306 
307  if (m_toolList && m_toolList->toolBarStack()) {
308  m_toolList->toolBarStack()->setCurrentWidget(m_toolBarWidget);
309  }
310  }
311 
312 
318  }
319 
320 
327  viewport->registerTool(this);
328 
329  connect(m_cvp, SIGNAL(requestRestretch(MdiCubeViewport *, int)),
330  this, SLOT(stretchRequested(MdiCubeViewport *, int)));
331  }
332 
333 
339  rubberBandTool()->disable();
340  }
341 
342 
343  Workspace *Tool::workspace() {
344  return m_workspace;
345  }
346 
347 
351  void Tool::mouseMove(QPoint p) {};
352 
353 
357  void Tool::mouseDoubleClick(QPoint p) {
358  emit clearWarningSignal();
359  }
360 
361 
366  void Tool::mouseButtonPress(QPoint p, Qt::MouseButton s) {
367  emit clearWarningSignal();
368  }
369 
370 
379  void Tool::mouseButtonRelease(QPoint p, Qt::MouseButton s) {
380  emit clearWarningSignal();
381  }
382 
383 
390  return m_workspace->cubeViewportList();
391  }
392 }
393 
394 
395