-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
867bdb6
commit 41b98aa
Showing
5 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/layout/qgslayoutviewtoolzoom.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ | ||
|
||
|
||
|
||
class QgsLayoutViewToolZoom : QgsLayoutViewTool | ||
{ | ||
%Docstring | ||
Layout view tool for zooming into and out of the layout. | ||
.. versionadded:: 3.0 | ||
%End | ||
|
||
%TypeHeaderCode | ||
#include "qgslayoutviewtoolzoom.h" | ||
%End | ||
public: | ||
|
||
QgsLayoutViewToolZoom( QgsLayoutView *view ); | ||
%Docstring | ||
Constructor for QgsLayoutViewToolZoom. | ||
%End | ||
|
||
virtual void layoutPressEvent( QgsLayoutViewMouseEvent *event ); | ||
|
||
virtual void layoutMoveEvent( QgsLayoutViewMouseEvent *event ); | ||
|
||
virtual void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ); | ||
|
||
virtual void deactivate(); | ||
|
||
|
||
}; | ||
|
||
/************************************************************************ | ||
* This file has been generated automatically from * | ||
* * | ||
* src/gui/layout/qgslayoutviewtoolzoom.h * | ||
* * | ||
* Do not edit manually ! Edit header and run scripts/sipify.pl again * | ||
************************************************************************/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/*************************************************************************** | ||
qgslayoutviewtoolzoom.cpp | ||
------------------------- | ||
Date : July 2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgslayoutviewtoolzoom.h" | ||
#include "qgslayoutviewmouseevent.h" | ||
#include "qgslayoutview.h" | ||
#include "qgslayoutviewrubberband.h" | ||
#include "qgsrectangle.h" | ||
#include "qgscursors.h" | ||
#include <QScrollBar> | ||
|
||
QgsLayoutViewToolZoom::QgsLayoutViewToolZoom( QgsLayoutView *view ) | ||
: QgsLayoutViewTool( view, tr( "Pan" ) ) | ||
{ | ||
QPixmap zoomQPixmap = QPixmap( ( const char ** )( zoom_in ) ); | ||
setCursor( QCursor( zoomQPixmap, 7, 7 ) ); | ||
|
||
mRubberBand.reset( new QgsLayoutViewRectangularRubberBand( view ) ); | ||
mRubberBand->setBrush( QBrush( QColor( 70, 50, 255, 25 ) ) ); | ||
mRubberBand->setPen( QPen( QBrush( QColor( 70, 50, 255, 100 ) ), 0 ) ); | ||
} | ||
|
||
void QgsLayoutViewToolZoom::layoutPressEvent( QgsLayoutViewMouseEvent *event ) | ||
{ | ||
if ( event->button() != Qt::LeftButton ) | ||
{ | ||
return; | ||
} | ||
|
||
mMousePressStartPos = event->pos(); | ||
if ( event->modifiers() & Qt::AltModifier ) | ||
{ | ||
//zoom out action, so zoom out and recenter on clicked point | ||
double scaleFactor = 2; | ||
//get current visible part of scene | ||
QRect viewportRect( 0, 0, view()->viewport()->width(), view()->viewport()->height() ); | ||
QgsRectangle visibleRect = QgsRectangle( view()->mapToScene( viewportRect ).boundingRect() ); | ||
|
||
visibleRect.scale( scaleFactor, event->layoutPoint().x(), event->layoutPoint().y() ); | ||
QRectF boundsRect = visibleRect.toRectF(); | ||
|
||
//zoom view to fit desired bounds | ||
view()->fitInView( boundsRect, Qt::KeepAspectRatio ); | ||
} | ||
else | ||
{ | ||
//zoom in action | ||
startMarqueeZoom( event->layoutPoint() ); | ||
} | ||
} | ||
|
||
void QgsLayoutViewToolZoom::layoutMoveEvent( QgsLayoutViewMouseEvent *event ) | ||
{ | ||
if ( !mMarqueeZoom ) | ||
return; | ||
|
||
mRubberBand->update( event->layoutPoint(), 0 ); | ||
} | ||
|
||
void QgsLayoutViewToolZoom::layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) | ||
{ | ||
if ( !mMarqueeZoom || event->button() != Qt::LeftButton ) | ||
{ | ||
return; | ||
} | ||
|
||
mMarqueeZoom = false; | ||
QRectF newBoundsRect = mRubberBand->finish( event->layoutPoint() ); | ||
|
||
// click? or click-and-drag? | ||
if ( !isClickAndDrag( mMousePressStartPos, event->pos() ) ) | ||
{ | ||
//just a click, so zoom to clicked point and recenter | ||
double scaleFactor = 0.5; | ||
//get current visible part of scene | ||
QRect viewportRect( 0, 0, view()->viewport()->width(), view()->viewport()->height() ); | ||
QgsRectangle visibleRect = QgsRectangle( view()->mapToScene( viewportRect ).boundingRect() ); | ||
|
||
visibleRect.scale( scaleFactor, event->layoutPoint().x(), event->layoutPoint().y() ); | ||
newBoundsRect = visibleRect.toRectF(); | ||
} | ||
|
||
//zoom view to fit desired bounds | ||
view()->fitInView( newBoundsRect, Qt::KeepAspectRatio ); | ||
} | ||
|
||
void QgsLayoutViewToolZoom::deactivate() | ||
{ | ||
if ( mMarqueeZoom ) | ||
{ | ||
mMarqueeZoom = false; | ||
mRubberBand->finish(); | ||
} | ||
QgsLayoutViewTool::deactivate(); | ||
} | ||
|
||
void QgsLayoutViewToolZoom::startMarqueeZoom( QPointF scenePoint ) | ||
{ | ||
mMarqueeZoom = true; | ||
|
||
mRubberBandStartPos = scenePoint; | ||
mRubberBand->start( scenePoint, 0 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/*************************************************************************** | ||
qgslayoutviewtoolzoom.h | ||
----------------------- | ||
Date : July 2017 | ||
Copyright : (C) 2017 Nyall Dawson | ||
Email : nyall dot dawson at gmail dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSLAYOUTVIEWTOOLZOOM_H | ||
#define QGSLAYOUTVIEWTOOLZOOM_H | ||
|
||
#include "qgis.h" | ||
#include "qgis_gui.h" | ||
#include "qgslayoutviewtool.h" | ||
#include "qgslayoutviewrubberband.h" | ||
#include <memory> | ||
|
||
/** | ||
* \ingroup gui | ||
* Layout view tool for zooming into and out of the layout. | ||
* \since QGIS 3.0 | ||
*/ | ||
class GUI_EXPORT QgsLayoutViewToolZoom : public QgsLayoutViewTool | ||
{ | ||
|
||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** | ||
* Constructor for QgsLayoutViewToolZoom. | ||
*/ | ||
QgsLayoutViewToolZoom( QgsLayoutView *view ); | ||
|
||
void layoutPressEvent( QgsLayoutViewMouseEvent *event ) override; | ||
void layoutMoveEvent( QgsLayoutViewMouseEvent *event ) override; | ||
void layoutReleaseEvent( QgsLayoutViewMouseEvent *event ) override; | ||
void deactivate() override; | ||
|
||
private: | ||
|
||
//! Start position for mouse press | ||
QPoint mMousePressStartPos; | ||
|
||
bool mMarqueeZoom = false; | ||
|
||
QPointF mRubberBandStartPos; | ||
|
||
//! Rubber band item | ||
std::unique_ptr< QgsLayoutViewRectangularRubberBand > mRubberBand; | ||
|
||
void startMarqueeZoom( QPointF scenePoint ); | ||
|
||
}; | ||
|
||
#endif // QGSLAYOUTVIEWTOOLZOOM_H |