Skip to content
Permalink
Browse files

Fix for ticket #415.

Mouse wheel action made configurable: zoom (default), zoom and recenter, do nothing.
Also made zoom factor configurable.


git-svn-id: http://svn.osgeo.org/qgis/trunk@6177 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Dec 3, 2006
1 parent 3486d4b commit fbc787fc71807a6905f37694d9cfa97a14cf46fd
Showing with 147 additions and 44 deletions.
  1. +8 −0 src/gui/qgisapp.cpp
  2. +42 −22 src/gui/qgsmapcanvas.cpp
  3. +15 −7 src/gui/qgsmapcanvas.h
  4. +6 −0 src/gui/qgsoptions.cpp
  5. +76 −15 src/ui/qgsoptionsbase.ui
@@ -1126,6 +1126,10 @@ void QgisApp::createOverview()
QSettings mySettings;
mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing",false).toBool());
mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render",false).toBool());

int action = mySettings.value("/qgis/wheel_action", 0).toInt();
double zoomFactor = mySettings.value("/qgis/zoom_factor", 2).toDouble();
mMapCanvas->setWheelAction((QgsMapCanvas::WheelAction) action, zoomFactor);
}


@@ -4127,6 +4131,10 @@ void QgisApp::options()
QSettings mySettings;
mMapCanvas->enableAntiAliasing(mySettings.value("/qgis/enable_anti_aliasing").toBool());
mMapCanvas->useQImageToRender(mySettings.value("/qgis/use_qimage_to_render").toBool());

int action = mySettings.value("/qgis/wheel_action", 0).toInt();
double zoomFactor = mySettings.value("/qgis/zoom_factor", 2).toDouble();
mMapCanvas->setWheelAction((QgsMapCanvas::WheelAction) action, zoomFactor);
}
}

@@ -76,10 +76,6 @@ class QgsMapCanvas::CanvasProperties



// But the static members must be initialised outside the class! (or GCC 4 dies)
const double QgsMapCanvas::scaleDefaultMultiple = 2.0;


/** note this is private and so shouldn't be accessible */
QgsMapCanvas::QgsMapCanvas()
{}
@@ -102,6 +98,8 @@ QgsMapCanvas::QgsMapCanvas()
mFrozen = false;
mDirty = true;

setWheelAction(WheelZoom);

// by default, the canvas is rendered
mRenderFlag = true;

@@ -740,20 +738,55 @@ void QgsMapCanvas::updateCanvasItemsPositions()
void QgsMapCanvas::wheelEvent(QWheelEvent *e)
{
// Zoom the map canvas in response to a mouse wheel event. Moving the
// wheel forward (away) from the user zooms in by a factor of 2.
// TODO The scale factor needs to be customizable by the user.
// wheel forward (away) from the user zooms in
#ifdef QGISDEBUG
std::cout << "Wheel event delta " << e->delta() << std::endl;
#endif

// change extent
zoomWithCenter(e->x(), e->y(), e->delta() > 0);
switch (mWheelAction)
{
case WheelZoom:
// zoom without changing extent
zoom(e->delta() > 0);
break;

case WheelZoomAndRecenter:
// zoom and don't change extent
zoomWithCenter(e->x(), e->y(), e->delta() > 0);
break;

case WheelNothing:
// well, nothing!
break;
}
}

void QgsMapCanvas::setWheelAction(WheelAction action, double factor)
{
mWheelAction = action;
mWheelZoomFactor = factor;
}

void QgsMapCanvas::zoom(bool zoomIn)
{
double scaleFactor = (zoomIn ? 1/mWheelZoomFactor : mWheelZoomFactor);

QgsRect r = mMapRender->extent();
r.scale(scaleFactor);
setExtent(r);
refresh();
}

void QgsMapCanvas::zoomWithCenter(int x, int y, bool zoomIn)
{
zoomByScale(x, y, (zoomIn ? 1/scaleDefaultMultiple : scaleDefaultMultiple));
double scaleFactor = (zoomIn ? 1/mWheelZoomFactor : mWheelZoomFactor);

// transform the mouse pos to map coordinates
QgsPoint center = getCoordinateTransform()->toMapPoint(x, y);
QgsRect r = mMapRender->extent();
r.scale(scaleFactor, &center);
setExtent(r);
refresh();
}


@@ -777,19 +810,6 @@ void QgsMapCanvas::contentsMouseMoveEvent(QMouseEvent * e)
} // mouseMoveEvent


/**
* Zooms at the given screen x and y by the given scale (< 1, zoom out, > 1, zoom in)
*/
void QgsMapCanvas::zoomByScale(int x, int y, double scaleFactor)
{
// transform the mouse pos to map coordinates
QgsPoint center = getCoordinateTransform()->toMapPoint(x, y);
QgsRect r = mMapRender->extent();
r.scale(scaleFactor, &center);
setExtent(r);
refresh();
}


/** Sets the map tool currently being used on the canvas */
void QgsMapCanvas::setMapTool(QgsMapTool* tool)
@@ -64,7 +64,10 @@ class QgsMapCanvas : public Q3CanvasView
{
Q_OBJECT;

public:
public:

enum WheelAction { WheelZoom, WheelZoomAndRecenter, WheelNothing };

//! Constructor
QgsMapCanvas(QWidget * parent = 0, const char *name = 0);

@@ -186,8 +189,14 @@ class QgsMapCanvas : public Q3CanvasView

//! returns current layer (set by legend widget)
QgsMapLayer* currentLayer();

//! set wheel action and zoom factor (should be greater than 1)
void setWheelAction(WheelAction action, double factor = 2);

//! Zooms in/out with a given center (uses zoomByScale)
//! Zooms in/out preserving
void zoom(bool zoomIn);

//! Zooms in/out with a given center
void zoomWithCenter(int x, int y, bool zoomIn);

//! used to determine if anti-aliasing is enabled or not
@@ -340,9 +349,6 @@ class QgsMapCanvas : public Q3CanvasView
//! Overridden draw contents from canvas view
void drawContents(QPainter * p, int cx, int cy, int cw, int ch);

//! Zooms to a given center and scale
void zoomByScale(int x, int y, double scaleFactor);

//! called when panning is in action, reset indicates end of panning
void moveCanvasContents(bool reset = FALSE);

@@ -372,8 +378,10 @@ class QgsMapCanvas : public Q3CanvasView
QgsRect mLastExtent;

//! Scale factor multiple for default zoom in/out
// TODO Make this customisable by the user
static const double scaleDefaultMultiple;
double mWheelZoomFactor;

//! Mouse wheel action
WheelAction mWheelAction;

}; // class QgsMapCanvas

@@ -138,6 +138,9 @@ QgsOptions::QgsOptions(QWidget *parent, Qt::WFlags fl) :
pbnCanvasColor->setPalette( QColor(myRed,myGreen,myBlue) );

capitaliseCheckBox->setChecked(settings.value("qgis/capitaliseLayerName", QVariant(false)).toBool());

cmbWheelAction->setCurrentIndex(settings.value("/qgis/wheel_action", 0).toInt());
spinZoomFactor->setValue(settings.value("/qgis/zoom_factor", 2).toDouble());
}

//! Destructor
@@ -243,6 +246,9 @@ void QgsOptions::saveOptions()
myGreen = settings.writeEntry("/qgis/default_canvas_color_green",myColor.green());
myBlue = settings.writeEntry("/qgis/default_canvas_color_blue",myColor.blue());

settings.writeEntry("/qgis/wheel_action", cmbWheelAction->currentIndex());
settings.writeEntry("/qgis/zoom_factor", spinZoomFactor->value());

//all done
accept();
}
@@ -18,17 +18,17 @@
<property name="sizeGripEnabled" >
<bool>true</bool>
</property>
<layout class="QGridLayout" >
<layout class="QVBoxLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="0" >
<item>
<widget class="QTabWidget" name="tabWidget" >
<property name="currentIndex" >
<number>0</number>
<number>2</number>
</property>
<widget class="QWidget" name="tabAppearance" >
<attribute name="title" >
@@ -389,7 +389,7 @@
</widget>
<widget class="QWidget" name="tabMap" >
<attribute name="title" >
<string>&amp;Selection &amp;&amp; Measuring</string>
<string>&amp;Map tools</string>
</attribute>
<layout class="QGridLayout" >
<property name="margin" >
@@ -398,6 +398,19 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="3" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="0" >
<widget class="QGroupBox" name="groupBox_7" >
<property name="title" >
@@ -482,17 +495,65 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item row="2" column="0" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
<widget class="QGroupBox" name="groupBox_10" >
<property name="title" >
<string>Panning and zooming</string>
</property>
</spacer>
<layout class="QGridLayout" >
<property name="margin" >
<number>9</number>
</property>
<property name="spacing" >
<number>6</number>
</property>
<item row="0" column="1" >
<widget class="QComboBox" name="cmbWheelAction" >
<item>
<property name="text" >
<string>Zoom</string>
</property>
</item>
<item>
<property name="text" >
<string>Zoom and recenter</string>
</property>
</item>
<item>
<property name="text" >
<string>Nothing</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0" >
<widget class="QLabel" name="label_3" >
<property name="text" >
<string>Zoom factor:</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="label_2" >
<property name="text" >
<string>Mouse wheel action:</string>
</property>
</widget>
</item>
<item row="1" column="1" >
<widget class="QDoubleSpinBox" name="spinZoomFactor" >
<property name="decimals" >
<number>1</number>
</property>
<property name="minimum" >
<double>1.100000000000000</double>
</property>
<property name="value" >
<double>2.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@@ -671,7 +732,7 @@ p, li { white-space: pre-wrap; }
</widget>
</widget>
</item>
<item row="1" column="0" >
<item>
<layout class="QHBoxLayout" >
<property name="margin" >
<number>0</number>

0 comments on commit fbc787f

Please sign in to comment.
You can’t perform that action at this time.