22 #include <QApplication>
23 #include <QHBoxLayout>
28 #include <QMessageBox>
29 #include <QPushButton>
30 #include <QStackedWidget>
31 #include <QToolButton>
36 #include "MainWindow.h"
38 #include "RubberBandTool.h"
59 p_zoomIn4X->setShortcut(Qt::CTRL + Qt::Key_Plus);
63 p_zoomIn8X->setShortcut(Qt::ALT + Qt::Key_Plus);
108 action->setIcon(QPixmap(
toolIconDir() +
"/viewmag.png"));
109 action->setToolTip(
"Zoom (Z)");
110 action->setShortcut(Qt::Key_Z);
112 "<b>Function:</b> Zoom in or out of the current cube. \
113 <p><b>Shortcut:</b> Z</p> ";
114 action->setWhatsThis(text);
156 QToolButton *zoomInButton =
new QToolButton(hbox);
157 zoomInButton->setIcon(QPixmap(
toolIconDir() +
"/viewmag+.png"));
158 zoomInButton->setToolTip(
"Zoom In");
160 "<b>Function:</b> Zoom in 2X at the center of the active viewport \
161 <p><b>Shortcut:</b> +</p> \
162 <p><b>Mouse:</b> LeftButton zooms in 2X under pointer</p> \
163 <p><b>Modifiers:</b> Shortcuts and mouse clicks can be augmented \
164 using the Ctrl or Alt key for 4X and 8X zooms, respectively</p> \
165 <p><b>Hint:</b> Left click and drag for a local zoom which scales data \
166 in the red marquee to the viewport</p>";
167 zoomInButton->setWhatsThis(text);
168 connect(zoomInButton, SIGNAL(clicked()),
this, SLOT(
zoomIn2X()));
169 zoomInButton->setAutoRaise(
true);
170 zoomInButton->setIconSize(QSize(22, 22));
172 QToolButton *zoomOutButton =
new QToolButton(hbox);
173 zoomOutButton->setIcon(QPixmap(
toolIconDir() +
"/viewmag-.png"));
174 zoomOutButton->setToolTip(
"Zoom Out");
176 "<b>Function:</b> Zoom out 2X at the center of the active viewport \
177 <p><b>Shortcut:</b> +</p> \
178 <p><b>Mouse:</b> RightButton zooms out 2X under pointer</p> \
179 <p><b>Modifiers:</b> Shortcuts and mouse clicks can be augmented \
180 using the Ctrl or Alt key for 4X and 8X zooms, respectively</p> \
181 <p><b>Hint:</b> Left click and drag for a local zoom which scales data \
182 in the red marquee to the viewport</p>";
183 zoomOutButton->setWhatsThis(text);
184 connect(zoomOutButton, SIGNAL(clicked()),
this, SLOT(
zoomOut2X()));
185 zoomOutButton->setAutoRaise(
true);
186 zoomOutButton->setIconSize(QSize(22, 22));
188 QToolButton *zoomActButton =
new QToolButton(hbox);
189 zoomActButton->setIcon(QPixmap(
toolIconDir() +
"/viewmag1.png"));
190 zoomActButton->setToolTip(
"Zoom 1:1");
192 "<b>Function:</b> Zoom the active viewport to 1:1 such that one \
193 viewport pixel represents one cube pixel. That is, 100% scale. \
194 <p><b>Shortcut:</b> /</p> \
195 <p><b>Mouse:</b> Ctrl+MiddleButton zooms 1:1 under pointer</p> \
196 <p><b>Hint:</b> MiddleButton (without Ctrl) retains current \
197 scale but moves the pixel under the pointer to the center of the \
199 zoomActButton->setWhatsThis(text);
200 connect(zoomActButton, SIGNAL(clicked()),
this, SLOT(
zoomActual()));
201 zoomActButton->setAutoRaise(
true);
202 zoomActButton->setIconSize(QSize(22, 22));
206 QMenu *zoomFitMenu =
new QMenu();
208 fitWidth->setText(
"Fit Width");
209 connect(fitWidth, SIGNAL(triggered(
bool)),
this, SLOT(
zoomFitWidth()));
210 zoomFitMenu->addAction(fitWidth);
213 fitHeight->setText(
"Fit Height");
214 connect(fitHeight, SIGNAL(triggered(
bool)),
this, SLOT(
zoomFitHeight()));
215 zoomFitMenu->addAction(fitHeight);
217 QToolButton *zoomFitButton =
new QToolButton(hbox);
218 zoomFitButton->setIcon(QPixmap(
toolIconDir() +
"/viewmagfit.png"));
219 zoomFitButton->setMenu(zoomFitMenu);
220 zoomFitButton->setPopupMode(QToolButton::MenuButtonPopup);
221 zoomFitButton->setToolTip(
"Fit in viewport");
223 "<b>Function:</b> Fit the entire cube inside the active viewport. For \
224 extremely large cubes, this may not be possible. \
225 <p><b>Shortcut:</b> *</p> \
226 <p><b>Hint:</b> Many shortcuts for the zoom tool and other tools \
227 are easily available on the numeric keypad </p>";
228 zoomFitButton->setWhatsThis(text);
229 connect(zoomFitButton, SIGNAL(clicked()),
this, SLOT(
zoomFit()));
230 zoomFitButton->setAutoRaise(
true);
231 zoomFitButton->setIconSize(QSize(22, 22));
238 QDoubleValidator *dval =
new QDoubleValidator(hbox);
242 policy.setHorizontalPolicy(QSizePolicy::Fixed);
247 "<b>Function:</b> Shows the scale of the active viewport. Additionally, \
248 you can manually enter the scale.";
252 QHBoxLayout *layout =
new QHBoxLayout(hbox);
253 layout->setMargin(0);
254 layout->addWidget(zoomInButton);
255 layout->addWidget(zoomOutButton);
256 layout->addWidget(zoomActButton);
257 layout->addWidget(zoomFitButton);
259 layout->addStretch(1);
260 hbox->setLayout(layout);
342 if(d == NULL)
return;
343 double newScale = d->
scale() * factor;
344 if(newScale == 0.0) {
357 newScale = d->
scale() * factor;
358 if(newScale == 0.0) {
378 if(d == NULL)
return;
404 if(d == NULL)
return;
430 if(d == NULL)
return;
456 if(d == NULL)
return;
458 double newScale = strScale.toDouble() / 100.;
485 strScale.setNum(scale);
504 QApplication::processEvents();
506 if(!rubberBandTool()->isValid())
return;
509 if(!rubberBandTool()->figureIsPoint()) {
511 if((r.width() >= 5) && (r.height() >= 5)) {
512 int x = r.x() + r.width() / 2;
513 int y = r.y() + r.height() / 2;
514 double xscale = (double) d->viewport()->width() / r.width();
515 double yscale = (double) d->viewport()->height() / r.height();
516 double newScale = xscale < yscale ? xscale : yscale;
517 if(rubberBandTool()->mouseButton() & Qt::RightButton) {
518 newScale = 1.0 / newScale;
520 newScale *= d->
scale();
528 int x = r.x() + r.width() / 2;
529 int y = r.y() + r.height() / 2;
530 double xscale = (double) d->viewport()->width() / r.width();
531 double yscale = (double) d->viewport()->height() / r.height();
532 double newScale = xscale < yscale ? xscale : yscale;
533 if(rubberBandTool()->mouseButton() & Qt::RightButton) {
534 newScale = 1.0 / newScale;
536 newScale *= d->
scale();
546 if(rubberBandTool()->mouseButton() & Qt::ControlModifier) {
549 if(rubberBandTool()->mouseButton() & Qt::ShiftModifier) {
552 if(rubberBandTool()->mouseButton() & Qt::RightButton) {
553 factor = 1.0 / factor;
555 if(rubberBandTool()->mouseButton() & Qt::MidButton) {
558 if(rubberBandTool()->mouseButton() == Qt::MidButton + Qt::ControlModifier) {
562 double newScale = d->
scale() * factor;
563 if(newScale == 0.0) {
568 QPoint p = rubberBandTool()->
vertices()[0];
569 setScale(d, newScale, p.x(), p.y());
577 newScale = d->
scale() * factor;
578 if(newScale == 0.0) {
583 newScale =
setScale(d, newScale, p.x(), p.y());
587 p_lastScale = newScale;
598 rubberBandTool()->
enable(RubberBandTool::RectangleMode);
599 rubberBandTool()->enablePoints();
600 rubberBandTool()->enableAllClicks();
623 double oldScale = d->
scale();
625 if (newScale <= 0.0) {
627 "Scale value must be greater than 0.",
635 "Unable to rescale image to ["
638 QString message = fullError.
toString();
639 QMessageBox::warning((
QWidget *)parent(),
"Warning", message);
668 double oldScale = d->
scale();
670 if (newScale <= 0.0) {
672 "Scale value must be greater than 0.",
_FILEINFO_);
678 "Unable to rescale image to ["
679 +
IString(newScale * 100) +
"]",
681 QString message = fullError.
toString();
682 QMessageBox::warning((
QWidget *)parent(),
"Warning", message);
710 double oldScale = d->
scale();
712 if (newScale <= 0.0) {
714 "Scale value must be greater than 0.",
_FILEINFO_);
721 "Unable to rescale image to ["
724 QString message = fullError.
toString();
725 QMessageBox::warning((
QWidget *)parent(),
"Warning", message);
Cube display widget for certain Isis MDI applications.
double fitScaleWidth() const
Determine the scale of cube in the width to fit in the viewport.
int cubeSamples() const
Return the number of samples in the cube.
void setScale(double scale)
Change the scale of the cube to the given parameter value.
#define _FILEINFO_
Macro for the filename and line number.
double fitScaleHeight() const
Determine the scale of cube in heighth to fit in the viewport.
A type of error that could only have occurred due to a mistake on the user's part (e...
bool isLinked() const
Is the viewport linked with other viewports.
QString toString() const
Returns a string representation of this exception.
Adds specific functionality to C++ strings.
double scale() const
Return the scale.
int cubeLines() const
Return the number of lines in the cube.
double fitScale() const
Determine the scale that causes the full cube to fit in the viewport.