|
Isis 3.0 Object Programmers' Reference |
Home |
00001 #include "Tool.h" 00002 00003 #include <QLayout> 00004 #include <QMenuBar> 00005 #include <QVector> 00006 00007 #include "CubeViewport.h" 00008 #include "MdiCubeViewport.h" 00009 #include "FileName.h" 00010 #include "IString.h" 00011 #include "RubberBandTool.h" 00012 #include "ToolPad.h" 00013 #include "Workspace.h" 00014 #include "ViewportMainWindow.h" 00015 00016 00017 namespace Isis { 00018 QStackedWidget *Tool::p_activeToolBarStack = NULL; 00019 00025 Tool::Tool(QWidget *parent) : QObject(parent) { 00026 p_cvp = NULL; 00027 p_workspace = NULL; 00028 p_active = false; 00029 p_toolPadAction = NULL; 00030 p_toolBarWidget = NULL; 00031 QString tempFileName = FileName("$base/icons").expanded(); 00032 p_toolIconDir = tempFileName; 00033 } 00034 00035 00041 void Tool::addTo(Workspace *ws) { 00042 p_workspace = ws; 00043 00044 connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)), 00045 this, SLOT(setCubeViewport(MdiCubeViewport *))); 00046 connect(ws, SIGNAL(cubeViewportActivated(MdiCubeViewport *)), 00047 this, SLOT(setCubeViewport(MdiCubeViewport *))); 00048 connect(ws, SIGNAL(cubeViewportAdded(MdiCubeViewport *)), 00049 this, SLOT(registerTool(MdiCubeViewport *))); 00050 } 00051 00057 void Tool::addTo(ViewportMainWindow *pViewPortMnWin) { 00058 addTo(pViewPortMnWin->workspace()); 00059 addToPermanent(pViewPortMnWin->permanentToolBar()); 00060 addToActive(pViewPortMnWin->activeToolBar()); 00061 addTo(pViewPortMnWin->toolPad()); 00062 if(!menuName().isEmpty()) { 00063 QMenu *menu = pViewPortMnWin->getMenu(menuName()); 00064 // if (menu->actions().size() > 0) menu->addSeparator(); 00065 addTo(menu); 00066 } 00067 00068 //connect(this, SIGNAL(clearWarningSignal ()), pViewPortMnWin, SLOT(resetWarning ())); 00069 } 00070 00071 00077 void Tool::addTo(ToolPad *toolpad) { 00078 p_toolPadAction = toolPadAction(toolpad); 00079 if(p_toolPadAction != NULL) { 00080 toolpad->addAction(p_toolPadAction); 00081 connect(p_toolPadAction, SIGNAL(toggled(bool)), this, SLOT(activate(bool))); 00082 } 00083 } 00084 00085 00091 void Tool::addToActive(QToolBar *toolbar) { 00092 if(p_activeToolBarStack == NULL) { 00093 p_activeToolBarStack = new QStackedWidget(toolbar); 00094 toolbar->addWidget(p_activeToolBarStack); 00095 } 00096 00097 p_toolBarWidget = createToolBarWidget(p_activeToolBarStack); 00098 if(p_toolBarWidget != NULL) { 00099 p_activeToolBarStack->addWidget(p_toolBarWidget); 00100 } 00101 disableToolBar(); 00102 } 00103 00104 00110 void Tool::activate(bool on) { 00111 if(p_active) { 00112 emit clearWarningSignal(); 00113 if(on) 00114 return; 00115 removeViewportConnections(); 00116 disableToolBar(); 00117 if(p_toolPadAction != NULL) 00118 p_toolPadAction->setChecked(false); 00119 p_active = false; 00120 } 00121 else { 00122 if(!on) 00123 return; 00124 if(p_toolPadAction != NULL) 00125 p_toolPadAction->setChecked(true); 00126 addViewportConnections(); 00127 enableToolBar(); 00128 emit toolActivated(); 00129 p_active = true; 00130 } 00131 } 00132 00133 00139 void Tool::setCubeViewport(MdiCubeViewport *cvp) { 00140 if(cvp == p_cvp) { 00141 updateTool(); 00142 return; 00143 } 00144 00145 if(p_active) 00146 removeViewportConnections(); 00147 00148 p_cvp = cvp; 00149 00150 if(p_active) { 00151 addViewportConnections(); 00152 enableToolBar(); 00153 } 00154 else { 00155 updateTool(); 00156 } 00157 00158 emit viewportChanged(); 00159 } 00160 00161 00166 void Tool::addViewportConnections() { 00167 if(p_cvp == NULL) 00168 return; 00169 00170 connect(p_cvp, SIGNAL(scaleChanged()), 00171 this, SLOT(scaleChanged())); 00172 00173 connect(RubberBandTool::getInstance(), SIGNAL(measureChange()), 00174 this, SLOT(updateMeasure())); 00175 00176 connect(RubberBandTool::getInstance(), SIGNAL(bandingComplete()), 00177 this, SLOT(rubberBandComplete())); 00178 00179 connect(p_cvp, SIGNAL(mouseEnter()), 00180 this, SLOT(mouseEnter())); 00181 00182 connect(p_cvp, SIGNAL(screenPixelsChanged()), 00183 this, SLOT(screenPixelsChanged())); 00184 00185 connect(p_cvp, SIGNAL(mouseMove(QPoint)), 00186 this, SLOT(mouseMove(QPoint)), Qt::DirectConnection); 00187 00188 connect(p_cvp, SIGNAL(mouseMove(QPoint, Qt::MouseButton)), 00189 this, SLOT(mouseMove(QPoint, Qt::MouseButton)), Qt::DirectConnection); 00190 00191 connect(p_cvp, SIGNAL(mouseLeave()), 00192 this, SLOT(mouseLeave())); 00193 00194 connect(p_cvp, SIGNAL(mouseDoubleClick(QPoint)), 00195 this, SLOT(mouseDoubleClick(QPoint))); 00196 00197 connect(p_cvp, SIGNAL(mouseButtonPress(QPoint, Qt::MouseButton)), 00198 this, SLOT(mouseButtonPress(QPoint, Qt::MouseButton))); 00199 00200 connect(p_cvp, SIGNAL(mouseButtonRelease(QPoint, Qt::MouseButton)), 00201 this, SLOT(mouseButtonRelease(QPoint, Qt::MouseButton))); 00202 00203 addConnections(p_cvp); 00204 00205 if(p_toolPadAction != NULL) { 00206 enableRubberBandTool(); 00207 } 00208 } 00209 00210 00215 void Tool::removeViewportConnections() { 00216 if(p_cvp == NULL) 00217 return; 00218 00219 disconnect(p_cvp, SIGNAL(scaleChanged()), 00220 this, SLOT(scaleChanged())); 00221 00222 disconnect(RubberBandTool::getInstance(), SIGNAL(measureChange()), 00223 this, SLOT(updateMeasure())); 00224 00225 disconnect(RubberBandTool::getInstance(), SIGNAL(bandingComplete()), 00226 this, SLOT(rubberBandComplete())); 00227 00228 disconnect(p_cvp, SIGNAL(mouseEnter()), 00229 this, SLOT(mouseEnter())); 00230 00231 disconnect(p_cvp, SIGNAL(screenPixelsChanged()), 00232 this, SLOT(screenPixelsChanged())); 00233 00234 disconnect(p_cvp, SIGNAL(mouseMove(QPoint)), 00235 this, SLOT(mouseMove(QPoint))); 00236 00237 disconnect(p_cvp, SIGNAL(mouseMove(QPoint, Qt::MouseButton)), 00238 this, SLOT(mouseMove(QPoint, Qt::MouseButton))); 00239 00240 disconnect(p_cvp, SIGNAL(mouseLeave()), 00241 this, SLOT(mouseLeave())); 00242 00243 disconnect(p_cvp, SIGNAL(mouseDoubleClick(QPoint)), 00244 this, SLOT(mouseDoubleClick(QPoint))); 00245 00246 disconnect(p_cvp, SIGNAL(mouseButtonPress(QPoint, Qt::MouseButton)), 00247 this, SLOT(mouseButtonPress(QPoint, Qt::MouseButton))); 00248 00249 disconnect(p_cvp, SIGNAL(mouseButtonRelease(QPoint, Qt::MouseButton)), 00250 this, SLOT(mouseButtonRelease(QPoint, Qt::MouseButton))); 00251 00252 removeConnections(p_cvp); 00253 } 00254 00255 00260 void Tool::disableToolBar() { 00261 if(p_toolBarWidget == NULL) 00262 return; 00263 // if (p_toolBarWidget->isVisible()) p_toolBarWidget->hide(); 00264 p_toolBarWidget->setEnabled(false); 00265 } 00266 00267 00272 void Tool::enableToolBar() { 00273 updateTool(); 00274 if(p_toolBarWidget == NULL) 00275 return; 00276 if(cubeViewport() == NULL) { 00277 p_toolBarWidget->setEnabled(false); 00278 } 00279 else { 00280 p_toolBarWidget->setEnabled(true); 00281 } 00282 p_activeToolBarStack->setCurrentWidget(p_toolBarWidget); 00283 } 00284 00285 00290 void Tool::updateTool() { 00291 } 00292 00293 00299 void Tool::registerTool(MdiCubeViewport *viewport) { 00300 viewport->registerTool(this); 00301 00302 connect(p_cvp, SIGNAL(requestRestretch(MdiCubeViewport *, int)), 00303 this, SLOT(stretchRequested(MdiCubeViewport *, int))); 00304 } 00305 00306 00311 void Tool::enableRubberBandTool() { 00312 RubberBandTool::disable(); 00313 } 00314 00315 00319 void Tool::mouseMove(QPoint p) {}; 00320 00321 00325 void Tool::mouseDoubleClick(QPoint p) { 00326 emit clearWarningSignal(); 00327 } 00328 00329 00334 void Tool::mouseButtonPress(QPoint p, Qt::MouseButton s) { 00335 emit clearWarningSignal(); 00336 } 00337 00338 00347 void Tool::mouseButtonRelease(QPoint p, Qt::MouseButton s) { 00348 emit clearWarningSignal(); 00349 } 00350 00351 00357 Tool::CubeViewportList *Tool::cubeViewportList() const { 00358 return p_workspace->cubeViewportList(); 00359 } 00360 } 00361 00362 00363