Isis 3 Programmer Reference
BlinkTool.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "BlinkTool.h"
10 
11 #include "FileName.h"
12 #include "IString.h"
13 #include "MainWindow.h"
14 #include "MdiCubeViewport.h"
15 
16 #include <QDialog>
17 #include <QDoubleSpinBox>
18 #include <QEvent>
19 #include <QHBoxLayout>
20 #include <QListWidgetItem>
21 #include <QMenu>
22 #include <QPainter>
23 #include <QPushButton>
24 #include <QSettings>
25 #include <QSplitter>
26 #include <QTimer>
27 #include <QToolBar>
28 #include <QToolButton>
29 #include <QVBoxLayout>
30 
31 namespace Isis {
32 
39  BlinkTool::BlinkTool(QWidget *parent) : Tool(parent) {
40  // Create the blink window
41  p_dialog = new QDialog(parent);
42  p_dialog->setWindowTitle("Blink Comparator");
43  p_dialog->setSizeGripEnabled(true);
45  p_blinkWindow->setMinimumSize(492, 492);
46  p_blinkWindow->setBackgroundRole(QPalette::Shadow);
47  //p_blinkWindow->installEventFilter(this);
48 
49  p_listWidget = new QListWidget(p_dialog);
50  p_listWidget->setMinimumHeight(100);
51  connect(p_listWidget, SIGNAL(itemActivated(QListWidgetItem *)),
52  this, SLOT(toggleLink(QListWidgetItem *)));
53  connect(p_listWidget, SIGNAL(currentRowChanged(int)),
54  this, SLOT(updateWindow()));
55 
56  p_splitter = new QSplitter(Qt::Vertical, p_dialog);
57  p_splitter->addWidget(p_blinkWindow);
58  p_splitter->addWidget(p_listWidget);
59  p_splitter->setCollapsible(0, false);
60  p_splitter->setCollapsible(1, false);
61  p_splitter->setStretchFactor(0, 0);
62  p_splitter->setStretchFactor(1, 1);
63 
64  QWidget *buttons = new QWidget(p_dialog);
65 
66  QVBoxLayout *layout = new QVBoxLayout();
67 // layout->addWidget(p_blinkWindow,2);
68 // layout->addWidget(p_listWidget,1);
69  layout->addWidget(p_splitter, 1);
70  layout->addWidget(buttons, 0);
71  p_dialog->setLayout(layout);
72 
73  QToolButton *reverse = new QToolButton(buttons);
74  reverse->setIcon(QPixmap(toolIconDir() + "/blinkReverse.png"));
75  reverse->setIconSize(QSize(22, 22));
76  reverse->setShortcut(Qt::CTRL + Qt::Key_Delete);
77  reverse->setToolTip("Previous");
78  QString text = "<b>Function:</b> Show previous linked viewport and \
79  stop automatic timed blinking \
80  <p><b>Shortcut:</b> Ctrl+Delete</p>";
81  reverse->setWhatsThis(text);
82  connect(reverse, SIGNAL(released()), this, SLOT(reverse()));
83 
84  QToolButton *stop = new QToolButton(buttons);
85  stop->setIcon(QPixmap(toolIconDir() + "/blinkStop.png"));
86  stop->setIconSize(QSize(22, 22));
87  stop->setToolTip("Stop");
88  text = "<b>Function:</b> Stop automatic timed blinking";
89  stop->setWhatsThis(text);
90  connect(stop, SIGNAL(released()), this, SLOT(stop()));
91 
92  QToolButton *start = new QToolButton(buttons);
93  start->setIcon(QPixmap(toolIconDir() + "/blinkStart.png"));
94  start->setIconSize(QSize(22, 22));
95  start->setToolTip("Start");
96  text = "<b>Function:</b> Start automatic timed blinking. Cycles \
97  through linked viewports at variable rate";
98  start->setWhatsThis(text);
99  connect(start, SIGNAL(released()), this, SLOT(start()));
100 
101  QToolButton *forward = new QToolButton(buttons);
102  forward->setIcon(QPixmap(toolIconDir() + "/blinkAdvance.png"));
103  forward->setIconSize(QSize(22, 22));
104  forward->setToolTip("Next");
105  forward->setShortcut(Qt::Key_Delete);
106  text = "<b>Function:</b> Show next linked viewport and stop \
107  automatic timed blinking \
108  <p><b>Shortcut:</b> Delete</p>";
109  forward->setWhatsThis(text);
110  connect(forward, SIGNAL(released()), this, SLOT(advance()));
111 
112  p_timeBox = new QDoubleSpinBox(buttons);
113  p_timeBox->setMinimum(0.1);
114  p_timeBox->setMaximum(5.0);
115  p_timeBox->setDecimals(1);
116  p_timeBox->setSingleStep(0.1);
117  p_timeBox->setValue(0.5);
118  p_timeBox->setToolTip("iTime Delay");
119  text = "<b>Function:</b> Change automatic blink rate between " +
120  QString::number(p_timeBox->minimum()) + " and " +
121  QString::number(p_timeBox->maximum()) + " seconds";
122  p_timeBox->setWhatsThis(text);
123 
124  QPushButton *close = new QPushButton("Close", buttons);
125  close->setDefault(false);
126  close->setAutoDefault(false);
127  connect(close, SIGNAL(released()), p_dialog, SLOT(hide()));
128  connect(close, SIGNAL(released()), this, SLOT(stop()));
129 
130  QHBoxLayout *hlayout = new QHBoxLayout();
131  hlayout->addWidget(reverse);
132  hlayout->addWidget(stop);
133  hlayout->addWidget(start);
134  hlayout->addWidget(forward);
135  hlayout->addWidget(p_timeBox);
136  hlayout->addStretch(1);
137  hlayout->addWidget(close);
138  buttons->setLayout(hlayout);
139 
140  // Create the action to bring up the blink window
141  p_action = new QAction(parent);
142  p_action->setShortcut(Qt::Key_K);
143  p_action->setText("&Blink ...");
144  p_action->setIcon(QPixmap(toolIconDir() + "/blink.png"));
145  p_action->setToolTip("Blink");
146  text =
147  "<b>Function:</b> Opens a blink comparator for linked viewports. \
148  <p><b>Shortcut:</b>K</p>";
149  p_action->setWhatsThis(text);
150  p_action->setEnabled(false);
151  connect(p_action, SIGNAL(triggered()), p_dialog, SLOT(show()));
152 
153  p_timerOn = false;
154  readSettings();
155  p_blinkWindow->installEventFilter(this);
156  }
157 
158 
165  void BlinkTool::addTo(QMenu *menu) {
166  menu->addAction(p_action);
167  }
168 
169 
177  perm->addAction(p_action);
178  }
179 
180 
186  QString unlinkedIcon = FileName("$ISISROOT/appdata/images/icons/unlinked.png").expanded();
187  static QIcon unlinked(unlinkedIcon);
188  QString linkedIcon = FileName("$ISISROOT/appdata/images/icons/linked.png").expanded();
189  static QIcon linked(linkedIcon);
190  p_listWidget->clear();
191  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
192  MdiCubeViewport *d = (*(cubeViewportList()))[i];
193  disconnect(d, SIGNAL(linkChanging(bool)), this, 0);
194  disconnect(d, SIGNAL(windowTitleChanged()), this, 0);
195  QListWidgetItem *item = new QListWidgetItem(p_listWidget);
196  item->setText(d->parentWidget()->windowTitle());
197  if(d->isLinked()) {
198  item->setIcon(linked);
199  }
200  else {
201  item->setIcon(unlinked);
202  }
203  connect(d, SIGNAL(linkChanging(bool)), this, SLOT(updateTool()));
204  connect(d, SIGNAL(windowTitleChanged()), this, SLOT(updateTool()));
205  }
206 
207  if(cubeViewport() == NULL) {
208  p_action->setEnabled(false);
209  }
210  else if(cubeViewportList()->size() <= 1) {
211  p_action->setEnabled(false);
212  }
213  else {
214  p_action->setEnabled(true);
215  }
216  }
217 
218 
225  void BlinkTool::toggleLink(QListWidgetItem *item) {
226  for(int i = 0; i < p_listWidget->count(); i++) {
227  if(p_listWidget->item(i) == item) {
228  MdiCubeViewport *d = (*(cubeViewportList()))[i];
229  d->setLinked(!d->isLinked());
230  return;
231  }
232  }
233  }
234 
235 
241  p_timerOn = false;
242 
243  int row = p_listWidget->currentRow() - 1;
244  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
245  if(row < 0) row = (int)cubeViewportList()->size() - 1;
246  MdiCubeViewport *d = (*(cubeViewportList()))[row];
247  if(d->isLinked()) {
248  p_listWidget->setCurrentRow(row);
249  p_listWidget->scrollToItem(p_listWidget->currentItem());
250  break;
251  }
252  row--;
253  }
254  }
255 
256 
262  p_timerOn = false;
263  }
264 
265 
271  if(p_timerOn) return;
272  p_timerOn = true;
273  int msec = (int)(p_timeBox->value() * 1000.0);
274  QTimer::singleShot(msec, this, SLOT(timeout()));
275  }
276 
282  p_timerOn = false;
283 
284  int row = p_listWidget->currentRow() + 1;
285  for(int i = 0; i < (int)cubeViewportList()->size(); i++) {
286  if(row >= (int) cubeViewportList()->size()) row = 0;
287  MdiCubeViewport *d = (*(cubeViewportList()))[row];
288  if(d->isLinked()) {
289  p_listWidget->setCurrentRow(row);
290  p_listWidget->scrollToItem(p_listWidget->currentItem());
291  break;
292  }
293  row++;
294  }
295  }
296 
297 
303  if(p_timerOn) {
304  advance();
305  start();
306  }
307  }
308 
309 
315  p_blinkWindow->repaint();
316  }
317 
318 
325  QSettings settings(MainWindow::settingsFileName("BlinkTool"), QSettings::NativeFormat);
326  settings.setValue("rate", p_timeBox->value());
327  settings.setValue("size", p_dialog->size());
328  settings.setValue("pos", p_dialog->pos());
329  settings.setValue("geom", p_dialog->saveGeometry());
330  settings.setValue("splitterState", p_splitter->saveState());
331  }
332 
333 
340  QSettings settings(MainWindow::settingsFileName("BlinkTool"), QSettings::NativeFormat);
341  double rate = settings.value("rate", 0.5).toDouble();
342 
343  p_dialog->restoreGeometry(settings.value("geom").toByteArray());
344  p_splitter->restoreState(settings.value("splitterState").toByteArray());
345 
346  if (!settings.value("pos").toPoint().isNull())
347  p_dialog->move(settings.value("pos").toPoint());
348 
349  p_dialog->resize(settings.value("size", QSize(492, 492)).toSize());
350 
351  p_timeBox->setValue(rate);
352  }
353 
354 
365  bool BlinkTool::eventFilter(QObject *o, QEvent *e) {
366  if(o != p_blinkWindow) return false;
367  if(e->type() == QEvent::Hide) writeSettings();
368  if(e->type() != QEvent::Paint) return false;
369 
370  static QPixmap lastPixmap;
371  int row = p_listWidget->currentRow();
372  if(row != -1) {
373  MdiCubeViewport *d = (*(cubeViewportList()))[row];
374  lastPixmap = d->pixmap();
375  }
376 
377  int dx = lastPixmap.width() - p_blinkWindow->width();
378  int x = 0;
379  int sx = dx / 2;
380  if(dx < 0) {
381  x = -dx / 2;
382  sx = 0;
383  }
384  int dy = lastPixmap.height() - p_blinkWindow->height();
385  int y = 0;
386  int sy = dy / 2;
387  if(dy < 0) {
388  y = -dy / 2;
389  sy = 0;
390  }
391 
392  QPainter p(p_blinkWindow);
393  p.drawPixmap(x, y, lastPixmap, sx, sy, -1, -1);
394 
395  return true;
396  }
397 }
Isis::MdiCubeViewport
Cube display widget for certain Isis MDI applications.
Definition: MdiCubeViewport.h:39
QWidget
Isis::Tool::cubeViewportList
CubeViewportList * cubeViewportList() const
Return the list of cubeviewports.
Definition: Tool.cpp:390
Isis::Tool
Base class for the Qisis tools.
Definition: Tool.h:67
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
QMenu
Isis::Tool::toolIconDir
QString toolIconDir() const
returns the path to the icon directory.
Definition: Tool.h:113
Isis::CubeViewport::pixmap
QPixmap pixmap()
Returns the pixmap.
Definition: CubeViewport.h:401
QToolBar
Isis::MdiCubeViewport::setLinked
void setLinked(bool b)
Change the linked state of the viewport.
Definition: MdiCubeViewport.cpp:58
Isis::FileName::expanded
QString expanded() const
Returns a QString of the full file name including the file path, excluding the attributes.
Definition: FileName.cpp:196
Isis::MdiCubeViewport::isLinked
bool isLinked() const
Is the viewport linked with other viewports.
Definition: MdiCubeViewport.h:50
QDialog
QObject
QAction
Isis::Tool::cubeViewport
MdiCubeViewport * cubeViewport() const
Return the current cubeviewport.
Definition: Tool.h:197
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16