Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[FEATURE] add a map canvas magnifier
- Loading branch information
1 parent
948c1f0
commit 9a62613
Showing
19 changed files
with
400 additions
and
6 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
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
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
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,114 @@ | ||
/*************************************************************************** | ||
qgsstatusbarmagnifierwidget.cpp | ||
begin : April 2016 | ||
copyright : (C) 2016 Paul Blottiere, Oslandia | ||
email : paul dot blottiere at oslandia 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 <QFont> | ||
#include <QHBoxLayout> | ||
#include <QLabel> | ||
|
||
#include <qgsapplication.h> | ||
#include "qgsstatusbarmagnifierwidget.h" | ||
#include "qgsmapcanvas.h" | ||
#include "qgsdoublespinbox.h" | ||
|
||
QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget* parent, | ||
QgsMapCanvas *canvas ) : | ||
QWidget( parent ), | ||
mCanvas( canvas ), | ||
mMagnifier( 100 ), | ||
mMagnifierMin( 100 ), | ||
mMagnifierMax( 1000 ) | ||
{ | ||
// label | ||
mLabel = new QLabel( this ); | ||
mLabel->setMinimumWidth( 10 ); | ||
mLabel->setMargin( 3 ); | ||
mLabel->setAlignment( Qt::AlignCenter ); | ||
mLabel->setFrameStyle( QFrame::NoFrame ); | ||
mLabel->setText( tr( "Magnifier" ) ); | ||
mLabel->setToolTip( tr( "Magnifier" ) ); | ||
|
||
mSpinBox = new QgsDoubleSpinBox( this ); | ||
mSpinBox->setSuffix( "%" ); | ||
mSpinBox->setClearValue( mMagnifierMin ); | ||
mSpinBox->setKeyboardTracking( false ); | ||
mSpinBox->setMaximumWidth( 120 ); | ||
mSpinBox->setDecimals( 0 ); | ||
mSpinBox->setRange( mMagnifierMin, mMagnifierMax ); | ||
mSpinBox->setWrapping( false ); | ||
mSpinBox->setSingleStep( 50 ); | ||
mSpinBox->setToolTip( tr( "Magnifier level" ) ); | ||
|
||
connect( mSpinBox, SIGNAL( valueChanged( double ) ), this, | ||
SLOT( updateMagnifier() ) ); | ||
|
||
// layout | ||
mLayout = new QHBoxLayout( this ); | ||
mLayout->addWidget( mLabel ); | ||
mLayout->addWidget( mSpinBox ); | ||
mLayout->setContentsMargins( 0, 0, 0, 0 ); | ||
mLayout->setAlignment( Qt::AlignRight ); | ||
mLayout->setSpacing( 0 ); | ||
|
||
setLayout( mLayout ); | ||
|
||
updateMagnifier(); | ||
} | ||
|
||
QgsStatusBarMagnifierWidget::~QgsStatusBarMagnifierWidget() | ||
{ | ||
} | ||
|
||
double QgsStatusBarMagnifierWidget::magnificationLevel() | ||
{ | ||
return mMagnifier; | ||
} | ||
|
||
void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont ) | ||
{ | ||
mLabel->setFont( myFont ); | ||
mSpinBox->setFont( myFont ); | ||
} | ||
|
||
bool QgsStatusBarMagnifierWidget::setMagnificationLevel( int level ) | ||
{ | ||
bool rc = false; | ||
|
||
if ( level >= mMagnifierMin && level <= mMagnifierMax ) | ||
{ | ||
mSpinBox->setValue( level ); | ||
rc = true; | ||
} | ||
|
||
return rc; | ||
} | ||
|
||
void QgsStatusBarMagnifierWidget::updateMagnifier() | ||
{ | ||
// get current data | ||
mMagnifier = mSpinBox->value(); | ||
|
||
// update background color | ||
QSettings mySettings; | ||
int value = mySettings.value( "/qgis/magnifier_level", 100 ).toInt(); | ||
|
||
if ( mMagnifier == value ) | ||
mSpinBox->setBackgroundColor(); | ||
else | ||
mSpinBox->setBackgroundColor( new QColor( 200, 200, 255 ) ); | ||
|
||
// update map canvas | ||
mCanvas->setMagnificationFactor( mMagnifier / double( mMagnifierMin ) ); | ||
} |
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,78 @@ | ||
/*************************************************************************** | ||
qgsstatusbarmagnifierwidget.h | ||
begin : April 2016 | ||
copyright : (C) 2016 Paul Blottiere, Oslandia | ||
email : paul dot blottiere at oslandia 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 QGSSTATUSBARMAGNIFIERWIDGET_H | ||
#define QGSSTATUSBARMAGNIFIERWIDGET_H | ||
|
||
class QLabel; | ||
class QFont; | ||
class QHBoxLayout; | ||
class QgsMapCanvas; | ||
class QgsDoubleSpinBox; | ||
|
||
#include <QWidget> | ||
|
||
/** | ||
* A widget which lets the user select the current level of magnification to | ||
* apply to the canvas. | ||
* @note added in 2.16 | ||
*/ | ||
class APP_EXPORT QgsStatusBarMagnifierWidget : public QWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** Constructor | ||
* @param parent is the parent widget | ||
* @param canvas the map canvas | ||
*/ | ||
QgsStatusBarMagnifierWidget( QWidget* parent, QgsMapCanvas *canvas ); | ||
|
||
/** Destructor */ | ||
virtual ~QgsStatusBarMagnifierWidget(); | ||
|
||
/** Set the font of the text | ||
* @param font the font to use | ||
*/ | ||
void setFont( const QFont& font ); | ||
|
||
/** Returns the current magnification level | ||
* @return magnification level | ||
*/ | ||
double magnificationLevel(); | ||
|
||
/** Set the magnification level | ||
* @param level the magnification level | ||
* @return true if the level is valid, false otherwise | ||
*/ | ||
bool setMagnificationLevel( int level ); | ||
|
||
private slots: | ||
|
||
void updateMagnifier(); | ||
|
||
private: | ||
QgsMapCanvas *mCanvas; | ||
QHBoxLayout *mLayout; | ||
QLabel *mLabel; | ||
QgsDoubleSpinBox *mSpinBox; | ||
int mMagnifier; | ||
int mMagnifierMin; | ||
int mMagnifierMax; | ||
}; | ||
|
||
#endif |
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
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
Oops, something went wrong.