Skip to content
Permalink
Browse files

Also add a slider for easier zoom changing to status bar

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 02d0a04 commit 6ca6423005114b26eec41717b303b7ab0d2b8904
Showing with 21 additions and 0 deletions.
  1. +18 −0 src/app/layout/qgslayoutdesignerdialog.cpp
  2. +3 −0 src/app/layout/qgslayoutdesignerdialog.h
@@ -32,6 +32,7 @@
#include <QComboBox>
#include <QLineEdit>
#include <QDesktopWidget>
#include <QSlider>

//add some nice zoom levels for zoom comboboxes
QList<double> QgsLayoutDesignerDialog::sStatusZoomLevelsList { 0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0};
@@ -149,7 +150,18 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
connect( mStatusZoomCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ), this, &QgsLayoutDesignerDialog::statusZoomCombo_currentIndexChanged );
connect( mStatusZoomCombo->lineEdit(), &QLineEdit::returnPressed, this, &QgsLayoutDesignerDialog::statusZoomCombo_zoomEntered );

mStatusZoomSlider = new QSlider();
mStatusZoomSlider->setFixedWidth( mStatusZoomCombo->width() );
mStatusZoomSlider->setOrientation( Qt::Horizontal );
mStatusZoomSlider->setMinimum( 20 );
mStatusZoomSlider->setMaximum( 800 );
connect( mStatusZoomSlider, &QSlider::valueChanged, this, &QgsLayoutDesignerDialog::sliderZoomChanged );

mStatusZoomCombo->setToolTip( tr( "Zoom level" ) );
mStatusZoomSlider->setToolTip( tr( "Zoom level" ) );

mStatusBar->addPermanentWidget( mStatusZoomCombo );
mStatusBar->addPermanentWidget( mStatusZoomSlider );

mView->setTool( mSelectTool );
mView->setFocus();
@@ -277,6 +289,11 @@ void QgsLayoutDesignerDialog::statusZoomCombo_zoomEntered()
mView->setZoomLevel( zoom.toDouble() / 100 );
}

void QgsLayoutDesignerDialog::sliderZoomChanged( int value )
{
mView->setZoomLevel( value / 100.0 );
}

void QgsLayoutDesignerDialog::updateStatusZoom()
{
double dpi = QgsApplication::desktop()->logicalDpiX();
@@ -290,6 +307,7 @@ void QgsLayoutDesignerDialog::updateStatusZoom()
double zoomLevel = mView->transform().m11() * 100 / scale100;

whileBlocking( mStatusZoomCombo )->lineEdit()->setText( tr( "%1%" ).arg( zoomLevel, 0, 'f', 1 ) );
whileBlocking( mStatusZoomSlider )->setValue( zoomLevel );
}

QgsLayoutView *QgsLayoutDesignerDialog::view()
@@ -27,6 +27,7 @@ class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QComboBox;
class QSlider;

class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
@@ -114,6 +115,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
void itemTypeAdded( int type );
void statusZoomCombo_currentIndexChanged( int index );
void statusZoomCombo_zoomEntered();
void sliderZoomChanged( int value );

//! Updates zoom level in status bar
void updateStatusZoom();
@@ -130,6 +132,7 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner

//! Combobox in status bar which shows/adjusts current zoom level
QComboBox *mStatusZoomCombo = nullptr;
QSlider *mStatusZoomSlider = nullptr;

static QList<double> sStatusZoomLevelsList;

0 comments on commit 6ca6423

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