Isis 3 Programmer Reference
PanTool.cpp
1 #include "PanTool.h"
2 
3 #include <QAction>
4 #include <QComboBox>
5 #include <QHBoxLayout>
6 #include <QLineEdit>
7 #include <QLabel>
8 #include <QMenu>
9 #include <QMenuBar>
10 #include <QMessageBox>
11 #include <QStackedWidget>
12 #include <QToolButton>
13 
14 #include "IString.h"
15 #include "MainWindow.h"
16 #include "MdiCubeViewport.h"
17 #include "ToolPad.h"
18 
19 namespace Isis {
20  PanTool::PanTool(QWidget *parent) : Tool(parent) {
21  p_panRight = new QAction(parent);
22  p_panRight->setShortcut(Qt::CTRL + Qt::Key_Right);
23  p_panRight->setText("&Pan Right");
24  p_panRight->setIcon(QPixmap(toolIconDir() + "/forward.png"));
25  connect(p_panRight, SIGNAL(triggered()), this, SLOT(panRight()));
26 
27  p_panLeft = new QAction(parent);
28  p_panLeft->setShortcut(Qt::CTRL + Qt::Key_Left);
29  p_panLeft->setText("&Pan Left");
30  p_panLeft->setIcon(QPixmap(toolIconDir() + "/back.png"));
31  connect(p_panLeft, SIGNAL(triggered()), this, SLOT(panLeft()));
32 
33  p_panUp = new QAction(parent);
34  p_panUp->setShortcut(Qt::CTRL + Qt::Key_Up);
35  p_panUp->setText("&Pan Up");
36  p_panUp->setIcon(QPixmap(toolIconDir() + "/up.png"));
37  connect(p_panUp, SIGNAL(triggered()), this, SLOT(panUp()));
38 
39  p_panDown = new QAction(parent);
40  p_panDown->setShortcut(Qt::CTRL + Qt::Key_Down);
41  p_panDown->setText("&Pan Down");
42  p_panDown->setIcon(QPixmap(toolIconDir() + "/down.png"));
43  connect(p_panDown, SIGNAL(triggered()), this, SLOT(panDown()));
44 
45  p_dragPan = false;
46  }
47 
49  QAction *action = new QAction(pad);
50  action->setIcon(QPixmap(toolIconDir() + "/move.png"));
51  action->setToolTip("Pan (P)");
52  action->setShortcut(Qt::Key_P);
53  QString text =
54  "<b>Function:</b> View different areas of the cube. \
55  <p><b>Shortcut:</b> P</p> ";
56  action->setWhatsThis(text);
57  return action;
58  }
59 
60  void PanTool::addTo(QMenu *menu) {
61  menu->addAction(p_panLeft);
62  menu->addAction(p_panRight);
63  menu->addAction(p_panUp);
64  menu->addAction(p_panDown);
65  }
66 
67  QWidget *PanTool::createToolBarWidget(QStackedWidget *parent) {
68  QWidget *hbox = new QWidget(parent);
69 
70  QToolButton *leftButton = new QToolButton(hbox);
71  leftButton->setIcon(QPixmap(toolIconDir() + "/back.png"));
72  leftButton->setToolTip("Pan Left");
73  QString text =
74  "<b>Function: </b>Pan cube in the active viewport to the left \
75  <p><b>Shortcut:</b> Ctrl+LeftArrow</p> \
76  <p><b>Mouse:</b> Hold LeftButton and drag pointer to the right</p> \
77  <p><b>Hint:</b> Arrow keys without Ctrl modifier moves \
78  the mouse pointer</p>";
79 
80  leftButton->setWhatsThis(text);
81  leftButton->setAutoRaise(true);
82  leftButton->setIconSize(QSize(22, 22));
83  connect(leftButton, SIGNAL(clicked()), this, SLOT(panLeft()));
84 
85  QToolButton *rightButton = new QToolButton(hbox);
86  rightButton->setIcon(QPixmap(toolIconDir() + "/forward.png"));
87  rightButton->setToolTip("Pan Right");
88  text =
89  "<b>Function: </b>Pan cube in the active viewport to the right \
90  <p><b>Shortcut:</b> Ctrl+RightArrow</p> \
91  <p><b>Mouse:</b> Hold LeftButton and drag pointer to the left</p>\
92  <p><b>Hint:</b> Arrow keys without Ctrl modifier moves \
93  the mouse pointer</p>";
94  rightButton->setWhatsThis(text);
95  rightButton->setAutoRaise(true);
96  rightButton->setIconSize(QSize(22, 22));
97  connect(rightButton, SIGNAL(clicked()), this, SLOT(panRight()));
98 
99  QToolButton *upButton = new QToolButton(hbox);
100  upButton->setIcon(QPixmap(toolIconDir() + "/up.png"));
101  upButton->setToolTip("Pan Up");
102  text =
103  "<b>Function: </b>Pan cube in the active viewport up \
104  <p><b>Shortcut:</b> Ctrl+UpArrow</p> \
105  <p><b>Mouse:</b> Hold LeftButton and drag pointer down</p> \
106  <p><b>Hint:</b> Arrow keys without Ctrl modifier moves \
107  the mouse pointer</p>";
108  upButton->setWhatsThis(text);
109  upButton->setAutoRaise(true);
110  upButton->setIconSize(QSize(22, 22));
111  connect(upButton, SIGNAL(clicked()), this, SLOT(panUp()));
112 
113  QToolButton *downButton = new QToolButton(hbox);
114  downButton->setIcon(QPixmap(toolIconDir() + "/down.png"));
115  downButton->setToolTip("Pan Down");
116  text =
117  "<b>Function: </b>Pan cube in the active viewport down \
118  <p><b>Shortcut:</b> Ctrl+DownArrow</p> \
119  <p><b>Mouse:</b> Hold LeftButton and drag pointer up</p> \
120  <p><b>Hint:</b> Arrow keys without Ctrl modifier moves \
121  the mouse pointer</p>";
122  downButton->setWhatsThis(text);
123  downButton->setAutoRaise(true);
124  downButton->setIconSize(QSize(22, 22));
125  connect(downButton, SIGNAL(clicked()), this, SLOT(panDown()));
126 
127  p_panRateBox = new QComboBox(hbox);
128  p_panRateBox->addItem("1/4 Screen");
129  p_panRateBox->addItem("1/2 Screen");
130  p_panRateBox->addItem("3/4 Screen");
131  p_panRateBox->addItem("Full Screen");
132  p_panRateBox->addItem("Custom");
133  p_panRateBox->setToolTip("Pan Rate");
134  text =
135  "<b>Function: </b>Change the rate of panning when using the pan buttons \
136  or Ctrl+ArrowKeys";
137  p_panRateBox->setWhatsThis(text);
138  //p_panRateBox->setCurrentIndex(4);
139  connect(p_panRateBox, SIGNAL(activated(int)),
140  this, SLOT(updateLineEdit()));
141 
142  p_lineEdit = new QLineEdit();
143  p_lineEdit->setFixedWidth(50);
144  p_lineEdit->setToolTip("Custom Pan Rate");
145  text = "<b>Function: </b>Enter a custom percentage pan rate";
146  p_lineEdit->setWhatsThis(text);
147  //p_lineEdit->setText("75");
148  connect(p_lineEdit, SIGNAL(returnPressed()),
149  this, SLOT(writeSettings()));
150 
151  QIntValidator *ival = new QIntValidator(hbox);
152  ival->setRange(1, 100);
153  p_lineEdit->setValidator(ival);
154  QLabel *percent = new QLabel("%");
155 
156  QHBoxLayout *layout = new QHBoxLayout(hbox);
157  layout->setMargin(0);
158  layout->addWidget(leftButton);
159  layout->addWidget(rightButton);
160  layout->addWidget(upButton);
161  layout->addWidget(downButton);
162  layout->addWidget(p_panRateBox);
163  layout->addWidget(p_lineEdit);
164  layout->addWidget(percent);
165  layout->addStretch(1);
166  hbox->setLayout(layout);
167 
168  readSettings();
169 
170  return hbox;
171  }
172 
173  int PanTool::panRate(bool horz) {
175  if(d == NULL) return 0;
176  if(p_lineEdit->text() == "") {
177  QString text = "You must enter a value in the text box \n "
178  "to use the Custom pan percentage option";
179  QMessageBox::information(p_panRateBox, "Invalid Value",
180  text, QMessageBox::Ok);
181  return -1;
182  }
183  else {
184  int percent = p_lineEdit->text().toInt();
185  if(horz) {
186  return(int)(d->viewport()->width() * (percent * 0.01));
187  }
188  else {
189  return(int)(d->viewport()->height() * (percent * 0.01));
190  }
191  }
192  }
193 
194  void PanTool::pan(int x, int y) {
195  MdiCubeViewport *d = cubeViewport();
196  if(d == NULL) return;
197  if(x == -1 || y == -1) return;
198  d->scrollBy(x, y);
199 
200  if(d->isLinked()) {
201  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
202  d = (*(cubeViewportList()))[i];
203  if(d == cubeViewport()) continue;
204  if(d->isLinked()) d->scrollBy(x, y);
205  }
206  }
207  }
208 
209  void PanTool::mouseButtonPress(QPoint p, Qt::MouseButton s) {
210  if(s == Qt::LeftButton) {
211  p_dragPan = true;
212  p_lastPoint = p;
213  }
214  }
215 
216  void PanTool::mouseMove(QPoint p) {
217  if(p_dragPan) {
218  QPoint diff = p_lastPoint - p;
219  pan(diff.x(), diff.y());
220  p_lastPoint = p;
221  }
222  }
223 
224  void PanTool::mouseButtonRelease(QPoint p, Qt::MouseButton s) {
225  p_dragPan = false;
226  if(s != Qt::RightButton) return;
227 
228  MdiCubeViewport *d = cubeViewport();
229  if(d == NULL) return;
230  double cx, cy;
231  d->viewportToCube(p.x(), p.y(), cx, cy);
232  d->center(cx, cy);
233 
234  if(d->isLinked()) {
235  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
236  d = (*(cubeViewportList()))[i];
237  if(d == cubeViewport()) continue;
238  if(d->isLinked()) {
239  d->viewportToCube(p.x(), p.y(), cx, cy);
240  d->center(cx, cy);
241  }
242  }
243  }
244  }
245 
246 
247  void PanTool::setCustom() {
248  p_panRateBox->setCurrentIndex(4);
249  }
250 
251 
252  void PanTool::updateLineEdit() {
253  if(p_panRateBox->currentIndex() == 0) p_lineEdit->setText("25");
254  else if(p_panRateBox->currentIndex() == 1) p_lineEdit->setText("50");
255  else if(p_panRateBox->currentIndex() == 2) p_lineEdit->setText("75");
256  else if(p_panRateBox->currentIndex() == 3) p_lineEdit->setText("100");
257  else if(p_panRateBox->currentIndex() == 4) p_lineEdit->setText("");
258  }
259 
260  void PanTool::writeSettings() {
261  FileName config("$HOME/.Isis/qview/Pan Tool.config");
262  QSettings settings(config.expanded(),
263  QSettings::NativeFormat);
264  settings.setValue("rate", p_lineEdit->text());
265  }
266 
267  void PanTool::readSettings() {
268  FileName config("$HOME/.Isis/qview/Pan Tool.config");
269  QSettings settings(config.expanded(),
270  QSettings::NativeFormat);
271  QString rate = settings.value("rate", "75").toString();
272 
273  p_lineEdit->setText(rate);
274  if(rate == "100") p_panRateBox->setCurrentIndex(3);
275  else if(rate == "75") p_panRateBox->setCurrentIndex(2);
276  else if(rate == "50") p_panRateBox->setCurrentIndex(1);
277  else if(rate == "25") p_panRateBox->setCurrentIndex(0);
278  else p_panRateBox->setCurrentIndex(4);
279  }
280 
281 }
Cube display widget for certain Isis MDI applications.
QString toolIconDir() const
returns the path to the icon directory.
Definition: Tool.h:127
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition: Tool.cpp:390
QWidget * createToolBarWidget(QStackedWidget *parent)
Anytime a tool is created, you must add it to the tool bar.
Definition: PanTool.cpp:67
void addTo(QMenu *)
Definition: PanTool.cpp:60
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:211
QAction * toolPadAction(ToolPad *pad)
Anytime a tool is created, you must setup a tool pad action with it.
Definition: PanTool.cpp:48