Skip to content

Commit 6ca6423

Browse files
committed
Also add a slider for easier zoom changing to status bar
1 parent 02d0a04 commit 6ca6423

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <QComboBox>
3333
#include <QLineEdit>
3434
#include <QDesktopWidget>
35+
#include <QSlider>
3536

3637
//add some nice zoom levels for zoom comboboxes
3738
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
149150
connect( mStatusZoomCombo, static_cast<void ( QComboBox::* )( int )>( &QComboBox::activated ), this, &QgsLayoutDesignerDialog::statusZoomCombo_currentIndexChanged );
150151
connect( mStatusZoomCombo->lineEdit(), &QLineEdit::returnPressed, this, &QgsLayoutDesignerDialog::statusZoomCombo_zoomEntered );
151152

153+
mStatusZoomSlider = new QSlider();
154+
mStatusZoomSlider->setFixedWidth( mStatusZoomCombo->width() );
155+
mStatusZoomSlider->setOrientation( Qt::Horizontal );
156+
mStatusZoomSlider->setMinimum( 20 );
157+
mStatusZoomSlider->setMaximum( 800 );
158+
connect( mStatusZoomSlider, &QSlider::valueChanged, this, &QgsLayoutDesignerDialog::sliderZoomChanged );
159+
160+
mStatusZoomCombo->setToolTip( tr( "Zoom level" ) );
161+
mStatusZoomSlider->setToolTip( tr( "Zoom level" ) );
162+
152163
mStatusBar->addPermanentWidget( mStatusZoomCombo );
164+
mStatusBar->addPermanentWidget( mStatusZoomSlider );
153165

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

292+
void QgsLayoutDesignerDialog::sliderZoomChanged( int value )
293+
{
294+
mView->setZoomLevel( value / 100.0 );
295+
}
296+
280297
void QgsLayoutDesignerDialog::updateStatusZoom()
281298
{
282299
double dpi = QgsApplication::desktop()->logicalDpiX();
@@ -290,6 +307,7 @@ void QgsLayoutDesignerDialog::updateStatusZoom()
290307
double zoomLevel = mView->transform().m11() * 100 / scale100;
291308

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

295313
QgsLayoutView *QgsLayoutDesignerDialog::view()

src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class QgsLayoutViewToolPan;
2727
class QgsLayoutViewToolZoom;
2828
class QgsLayoutViewToolSelect;
2929
class QComboBox;
30+
class QSlider;
3031

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

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

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

134137
static QList<double> sStatusZoomLevelsList;
135138

0 commit comments

Comments
 (0)