1#include "MosaicZoomTool.h" 
    7#include <QDoubleSpinBox> 
    8#include <QGraphicsSceneMouseEvent> 
   16#include "MosaicGraphicsView.h" 
   17#include "MosaicSceneWidget.h" 
   18#include "Projection.h" 
   30    m_zoomInAction = 
new QAction(
this);
 
   31    m_zoomInAction->setIcon(
getIcon(
"viewmag+.png"));
 
   32    m_zoomInAction->setText(
"Zoom In");
 
   33    m_zoomInAction->setToolTip(
"Zoom in on the mosaic scene");
 
   34    m_zoomInAction->setShortcut(Qt::Key_Plus);
 
   36      "<b>Function:</b> Zoom in 2X at the center of the active viewport \ 
   37      <p><b>Shortcut:</b>  +</p> \ 
   38      <p><b>Mouse:</b>  LeftButton zooms in 2X under pointer</p> \ 
   39      <p><b>Modifiers:</b>  Shortcuts and mouse clicks can be augmented \ 
   40      using the Ctrl or Alt key for 4X and 8X zooms, respectively</p> \ 
   41      <p><b>Hint:</b>  Left click and drag for a local zoom which scales data \ 
   42      in the marquee to the view</p>";
 
   43    m_zoomInAction->setWhatsThis(text);
 
   44    connect(m_zoomInAction, SIGNAL(triggered()), 
this, SLOT(
zoomIn2X()));
 
   46    m_zoomOutAction = 
new QAction(
this);
 
   47    m_zoomOutAction->setIcon(
getIcon(
"viewmag-.png"));
 
   48    m_zoomOutAction->setText(
"Zoom Out");
 
   49    m_zoomOutAction->setToolTip(
"Zoom out on the mosaic scene");
 
   50    m_zoomOutAction->setShortcut(Qt::Key_Minus);
 
   52      "<b>Function:</b> Zoom out 2X at the center of the view \ 
   53      <p><b>Shortcut:</b>  +</p> \ 
   54      <p><b>Mouse:</b>  RightButton zooms out 2X under pointer</p> \ 
   55      <p><b>Modifiers:</b>  Shortcuts and mouse clicks can be augmented \ 
   56      using the Ctrl or Alt key for 4X and 8X zooms, respectively</p> \ 
   57      <p><b>Hint:</b>  Left click and drag for a local zoom which scales data \ 
   58      in the marquee to the view</p>";
 
   59    m_zoomOutAction->setWhatsThis(text);
 
   60    connect(m_zoomOutAction, SIGNAL(triggered()), 
this, SLOT(
zoomOut2X()));
 
   62    m_zoomFitAction = 
new QAction(
this);
 
   63    m_zoomFitAction->setIcon(
getIcon(
"viewmagfit.png"));
 
   64    m_zoomFitAction->setText(
"Fit in View");
 
   65    m_zoomFitAction->setToolTip(
"Zoom to where all of the cubes are visible in " 
   67    m_zoomFitAction->setShortcut(Qt::Key_Asterisk);
 
   69      "<b>Function:</b> Fit the entire mosaic inside the view. \ 
   70      <p><b>Shortcut:</b> *</p> \ 
   71      <p><b>Hint:</b>  Many shortcuts for the zoom tool and other tools \ 
   72      are easily available on the numeric keypad </p>";
 
   73    m_zoomFitAction->setWhatsThis(text);
 
   74    connect(m_zoomFitAction, SIGNAL(triggered()), 
this, SLOT(
zoomFit()));
 
 
   86      QPointF point1 = getWidget()->getView()->mapToScene(0, 0);
 
   87      QPointF point2 = getWidget()->getView()->mapToScene(
 
   88          (
int)getWidget()->getView()->width(), 0);
 
   89      double newWidth = point2.x() - point1.x();
 
   92      p_screenResolution = newWidth / getWidget()->getView()->viewport()->width();
 
   95      p_scaleBox->setValue(p_screenResolution);
 
  100      p_scaleBox->setSingleStep(p_screenResolution * .05);
 
 
  105  QList<QAction *> MosaicZoomTool::getViewActions() {
 
  106    QList<QAction *> viewActs;
 
  108    viewActs.append(m_zoomInAction);
 
  109    viewActs.append(m_zoomOutAction);
 
  110    viewActs.append(m_zoomFitAction);
 
  118    action->setIcon(
getIcon(
"viewmag.png"));
 
  119    action->setToolTip(
"Zoom (z)");
 
  120    action->setShortcut(Qt::Key_Z);
 
  122      "<b>Function:</b>  Zoom in or out of the current cube.<br><br>" 
  123      "This tool gives you a <b>click</b> to zoom by 2X and center on the " 
  124      "point you clicked on, a <b>right-click</b> to zoom out by 2X and center " 
  125      "on the point you clicked on, a <b>click and drag</b> box to best fit " 
  126      "the given area into the visible screen, a <b>right-click and drag</b> " 
  127      "box to zoom out and center on the center (smaller box means zoom out " 
  128      "more), and disables context menus on the mosaic scene." 
  129      "<p><b>Shortcut:</b>  z</p> ";
 
  130    action->setWhatsThis(text);
 
 
  146    QToolButton *zoomInButton = 
new QToolButton(hbox);
 
  147    zoomInButton->setAutoRaise(
true);
 
  148    zoomInButton->setDefaultAction(m_zoomInAction);
 
  149    zoomInButton->setIconSize(QSize(22, 22));
 
  151    QToolButton *zoomOutButton = 
new QToolButton(hbox);
 
  152    zoomOutButton->setAutoRaise(
true);
 
  153    zoomOutButton->setDefaultAction(m_zoomOutAction);
 
  154    zoomOutButton->setIconSize(QSize(22, 22));
 
  156    QToolButton *zoomFitButton = 
new QToolButton(hbox);
 
  157    zoomFitButton->setAutoRaise(
true);
 
  158    zoomFitButton->setDefaultAction(m_zoomFitAction);
 
  159    zoomFitButton->setIconSize(QSize(22, 22));
 
  161    p_scaleBox = 
new QDoubleSpinBox();
 
  162    p_scaleBox->setRange(DBL_MIN, DBL_MAX);
 
  163    p_scaleBox->setDecimals(8);
 
  164    connect(p_scaleBox, SIGNAL(editingFinished()), 
this, SLOT(
zoomManual()));
 
  166    QLabel *resolutionLabel = 
new QLabel(
"Meters per pixel");
 
  168    QHBoxLayout *layout = 
new QHBoxLayout(hbox);
 
  169    layout->setMargin(0);
 
  170    layout->addWidget(zoomInButton);
 
  171    layout->addWidget(zoomOutButton);
 
  177    layout->addWidget(zoomFitButton);
 
  178    layout->addWidget(p_scaleBox);
 
  179    layout->addWidget(resolutionLabel);
 
  180    layout->addStretch(1);
 
  181    hbox->setLayout(layout);
 
 
  186  void MosaicZoomTool::mouseButtonRelease(QPointF mouseLoc, Qt::MouseButton s) {
 
  190    if(s == Qt::LeftButton)
 
  192    else if(s == Qt::RightButton)
 
  197  void MosaicZoomTool::mouseWheel(QPointF mouseLoc, 
int delta) {
 
  198    static const double sensitivity = 60.0; 
 
  199    double scale = delta / sensitivity;
 
  202      scale = 1.0 / (-delta / sensitivity);
 
  204    scale = limitZoomBy(scale);
 
  206    QPoint screenMouseLoc(getWidget()->getView()->mapFromScene(mouseLoc));
 
  208        getWidget()->getView()->viewport()->size().width() / 2,
 
  209        getWidget()->getView()->viewport()->size().height() / 2);
 
  217    QPoint desiredScreenCenter =
 
  218        screenCenter + (screenCenter - screenMouseLoc);
 
  219    QPointF newCenterPoint =
 
  220        getWidget()->getView()->mapToScene(desiredScreenCenter);
 
  221    getWidget()->getView()->centerOn(newCenterPoint);
 
  239    zoomBy(1.0 / 2.0, center);
 
 
  252  double MosaicZoomTool::limitZoomBy(
double factor) {
 
  253    QTransform matrix = getWidget()->getView()->viewportTransform();
 
  254    matrix = matrix.scale(factor, factor).inverted();
 
  256    int smallerDimension = getWidget()->getView()->width();
 
  257    int largerDimension = getWidget()->getView()->height();
 
  259    if(smallerDimension > largerDimension) {
 
  260      int tmp = smallerDimension;
 
  261      smallerDimension = largerDimension;
 
  262      largerDimension = tmp;
 
  265    QPointF point1 = matrix.map(QPointF(0, 0));
 
  266    QPointF point2 = matrix.map(QPointF(smallerDimension, 0));
 
  272    if((point2.x() - point1.x()) < 1) {
 
  273      QTransform origMatrix = getWidget()->getView()->viewportTransform();
 
  274      factor = smallerDimension / (origMatrix.m11() * 1.0);
 
  277    point1 = matrix.map(QPointF(0, 0));
 
  278    point2 = matrix.map(QPointF(largerDimension, 0));
 
  280    if((point2.x() - point1.x()) > 1E10) {
 
  281      QTransform origMatrix = getWidget()->getView()->viewportTransform();
 
  282      factor = largerDimension / (origMatrix.m11() * 1E10);
 
  296    factor = limitZoomBy(factor);
 
  298    getWidget()->getView()->scale(factor, factor);
 
  300    if(!center.isNull()) {
 
  301      getWidget()->getView()->centerOn(center);
 
 
  313    getWidget()->
refit();
 
 
  348      double x = p_screenResolution / p_scaleBox->value();
 
 
  361      getWidget()->setCubesSelectable(
false);
 
  362      getWidget()->getView()->setContextMenuPolicy(Qt::NoContextMenu);
 
  363      getWidget()->enableRubberBand(
true);
 
  366      getWidget()->setCubesSelectable(
true);
 
  367      getWidget()->getView()->setContextMenuPolicy(Qt::DefaultContextMenu);
 
  368      getWidget()->enableRubberBand(
false);
 
 
  386    double meters_pixel = 0.0;
 
  392    if(r.width() > r.height()) {
 
  393      meters_pixel = r.width() / getWidget()->getView()->viewport()->width();
 
  396      meters_pixel = r.height() / getWidget()->getView()->viewport()->height();
 
  400    double scale = p_screenResolution / meters_pixel;
 
  403    if(s == Qt::LeftButton) {
 
  404      zoomBy(scale, r.center());
 
  408    if(s == Qt::RightButton) {
 
  409      zoomBy(1 / scale, r.center());
 
 
This is free and unencumbered software released into the public domain.