|
| 1 | +/*************************************************************************** |
| 2 | + qgsstatusbarmagnifierwidget.cpp |
| 3 | + begin : April 2016 |
| 4 | + copyright : (C) 2016 Paul Blottiere, Oslandia |
| 5 | + email : paul dot blottiere at oslandia dot com |
| 6 | + ***************************************************************************/ |
| 7 | + |
| 8 | +/*************************************************************************** |
| 9 | + * * |
| 10 | + * This program is free software; you can redistribute it and/or modify * |
| 11 | + * it under the terms of the GNU General Public License as published by * |
| 12 | + * the Free Software Foundation; either version 2 of the License, or * |
| 13 | + * (at your option) any later version. * |
| 14 | + * * |
| 15 | + ***************************************************************************/ |
| 16 | + |
| 17 | +#include <QFont> |
| 18 | +#include <QHBoxLayout> |
| 19 | +#include <QLabel> |
| 20 | + |
| 21 | +#include <qgsapplication.h> |
| 22 | +#include "qgsstatusbarmagnifierwidget.h" |
| 23 | +#include "qgsmapcanvas.h" |
| 24 | +#include "qgsdoublespinbox.h" |
| 25 | + |
| 26 | +QgsStatusBarMagnifierWidget::QgsStatusBarMagnifierWidget( QWidget* parent, |
| 27 | + QgsMapCanvas *canvas ) : |
| 28 | + QWidget( parent ), |
| 29 | + mCanvas( canvas ), |
| 30 | + mMagnifier( 100 ), |
| 31 | + mMagnifierMin( 100 ), |
| 32 | + mMagnifierMax( 1000 ) |
| 33 | +{ |
| 34 | + // label |
| 35 | + mLabel = new QLabel( this ); |
| 36 | + mLabel->setMinimumWidth( 10 ); |
| 37 | + mLabel->setMargin( 3 ); |
| 38 | + mLabel->setAlignment( Qt::AlignCenter ); |
| 39 | + mLabel->setFrameStyle( QFrame::NoFrame ); |
| 40 | + mLabel->setText( tr( "Magnifier" ) ); |
| 41 | + mLabel->setToolTip( tr( "Magnifier" ) ); |
| 42 | + |
| 43 | + mSpinBox = new QgsDoubleSpinBox( this ); |
| 44 | + mSpinBox->setSuffix( "%" ); |
| 45 | + mSpinBox->setClearValue( mMagnifierMin ); |
| 46 | + mSpinBox->setKeyboardTracking( false ); |
| 47 | + mSpinBox->setMaximumWidth( 120 ); |
| 48 | + mSpinBox->setDecimals( 0 ); |
| 49 | + mSpinBox->setRange( mMagnifierMin, mMagnifierMax ); |
| 50 | + mSpinBox->setWrapping( false ); |
| 51 | + mSpinBox->setSingleStep( 50 ); |
| 52 | + mSpinBox->setToolTip( tr( "Magnifier level" ) ); |
| 53 | + |
| 54 | + connect( mSpinBox, SIGNAL( valueChanged( double ) ), this, |
| 55 | + SLOT( updateMagnifier() ) ); |
| 56 | + |
| 57 | + // layout |
| 58 | + mLayout = new QHBoxLayout( this ); |
| 59 | + mLayout->addWidget( mLabel ); |
| 60 | + mLayout->addWidget( mSpinBox ); |
| 61 | + mLayout->setContentsMargins( 0, 0, 0, 0 ); |
| 62 | + mLayout->setAlignment( Qt::AlignRight ); |
| 63 | + mLayout->setSpacing( 0 ); |
| 64 | + |
| 65 | + setLayout( mLayout ); |
| 66 | + |
| 67 | + updateMagnifier(); |
| 68 | +} |
| 69 | + |
| 70 | +QgsStatusBarMagnifierWidget::~QgsStatusBarMagnifierWidget() |
| 71 | +{ |
| 72 | +} |
| 73 | + |
| 74 | +double QgsStatusBarMagnifierWidget::magnificationLevel() |
| 75 | +{ |
| 76 | + return mMagnifier; |
| 77 | +} |
| 78 | + |
| 79 | +void QgsStatusBarMagnifierWidget::setFont( const QFont& myFont ) |
| 80 | +{ |
| 81 | + mLabel->setFont( myFont ); |
| 82 | + mSpinBox->setFont( myFont ); |
| 83 | +} |
| 84 | + |
| 85 | +bool QgsStatusBarMagnifierWidget::setMagnificationLevel( int level ) |
| 86 | +{ |
| 87 | + bool rc = false; |
| 88 | + |
| 89 | + if ( level >= mMagnifierMin && level <= mMagnifierMax ) |
| 90 | + { |
| 91 | + mSpinBox->setValue( level ); |
| 92 | + rc = true; |
| 93 | + } |
| 94 | + |
| 95 | + return rc; |
| 96 | +} |
| 97 | + |
| 98 | +void QgsStatusBarMagnifierWidget::updateMagnifier() |
| 99 | +{ |
| 100 | + // get current data |
| 101 | + mMagnifier = mSpinBox->value(); |
| 102 | + |
| 103 | + // update map canvas |
| 104 | + mCanvas->setMagnificationFactor( mMagnifier / double( mMagnifierMin ) ); |
| 105 | +} |
0 commit comments