Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Also add a slider for easier zoom changing to status bar
  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 02d0a04 commit 6ca6423
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.cpp
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout/qgslayoutdesignerdialog.h
Expand Up @@ -27,6 +27,7 @@ class QgsLayoutViewToolPan;
class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QComboBox;
class QSlider;

class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
{
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down

0 comments on commit 6ca6423

Please sign in to comment.