@@ -256,6 +256,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
256
256
viewMenu->addAction ( mActionZoomIn );
257
257
viewMenu->addAction ( mActionZoomOut );
258
258
viewMenu->addAction ( mActionZoomAll );
259
+ viewMenu->addAction ( mActionZoomActual );
259
260
viewMenu->addSeparator ();
260
261
viewMenu->addAction ( mActionRefreshView );
261
262
viewMenu->addSeparator ();
@@ -331,6 +332,26 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
331
332
setMouseTracking ( true );
332
333
mViewFrame ->setMouseTracking ( true );
333
334
335
+ mStatusZoomCombo = new QComboBox ( mStatusBar );
336
+ mStatusZoomCombo ->setEditable ( true );
337
+ mStatusZoomCombo ->setInsertPolicy ( QComboBox::NoInsert );
338
+ mStatusZoomCombo ->setCompleter ( 0 );
339
+ mStatusZoomCombo ->setMinimumWidth ( 100 );
340
+ // zoom combo box accepts decimals in the range 1-9999, with an optional decimal point and "%" sign
341
+ QRegExp zoomRx ( " \\ s*\\ d{1,4}(\\ .\\ d?)?\\ s*%?" );
342
+ QValidator *zoomValidator = new QRegExpValidator ( zoomRx, mStatusZoomCombo );
343
+ mStatusZoomCombo ->lineEdit ()->setValidator ( zoomValidator );
344
+
345
+ // add some nice zoom levels to the zoom combobox
346
+ mStatusZoomLevelsList << 0.125 << 0.25 << 0.5 << 1.0 << 2.0 << 4.0 << 8.0 ;
347
+ QList<double >::iterator zoom_it;
348
+ for ( zoom_it = mStatusZoomLevelsList .begin (); zoom_it != mStatusZoomLevelsList .end (); ++zoom_it )
349
+ {
350
+ mStatusZoomCombo ->insertItem ( 0 , QString ( tr ( " %1\%" ) ).arg (( *zoom_it ) * 100 ) );
351
+ }
352
+ connect ( mStatusZoomCombo , SIGNAL ( currentIndexChanged ( int ) ), this , SLOT ( on_mStatusZoomCombo_currentIndexChanged ( int ) ) );
353
+ connect ( mStatusZoomCombo ->lineEdit (), SIGNAL ( returnPressed () ), this , SLOT ( on_mStatusZoomCombo_zoomEntered () ) );
354
+
334
355
// create status bar labels
335
356
mStatusCursorXLabel = new QLabel ( mStatusBar );
336
357
mStatusCursorXLabel ->setMinimumWidth ( 100 );
@@ -339,9 +360,11 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
339
360
mStatusCursorPageLabel = new QLabel ( mStatusBar );
340
361
mStatusCursorPageLabel ->setMinimumWidth ( 100 );
341
362
mStatusCompositionLabel = new QLabel ( mStatusBar );
363
+
342
364
mStatusBar ->addWidget ( mStatusCursorXLabel );
343
365
mStatusBar ->addWidget ( mStatusCursorYLabel );
344
366
mStatusBar ->addWidget ( mStatusCursorPageLabel );
367
+ mStatusBar ->addWidget ( mStatusZoomCombo );
345
368
mStatusBar ->addWidget ( mStatusCompositionLabel );
346
369
347
370
// create composer view and layout with rulers
@@ -480,6 +503,7 @@ void QgsComposer::setupTheme()
480
503
mActionZoomAll ->setIcon ( QgsApplication::getThemeIcon ( " /mActionZoomFullExtent.svg" ) );
481
504
mActionZoomIn ->setIcon ( QgsApplication::getThemeIcon ( " /mActionZoomIn.svg" ) );
482
505
mActionZoomOut ->setIcon ( QgsApplication::getThemeIcon ( " /mActionZoomOut.svg" ) );
506
+ mActionZoomActual ->setIcon ( QgsApplication::getThemeIcon ( " /mActionZoomActual.svg" ) );
483
507
mActionMouseZoom ->setIcon ( QgsApplication::getThemeIcon ( " /mActionZoomToSelected.svg" ) );
484
508
mActionRefreshView ->setIcon ( QgsApplication::getThemeIcon ( " /mActionDraw.svg" ) );
485
509
mActionUndo ->setIcon ( QgsApplication::getThemeIcon ( " /mActionUndo.png" ) );
@@ -547,6 +571,9 @@ void QgsComposer::connectSlots()
547
571
// also listen out for position updates from the horizontal/vertical rulers
548
572
connect ( mHorizontalRuler , SIGNAL ( cursorPosChanged ( QPointF ) ), this , SLOT ( updateStatusCursorPos ( QPointF ) ) );
549
573
connect ( mVerticalRuler , SIGNAL ( cursorPosChanged ( QPointF ) ), this , SLOT ( updateStatusCursorPos ( QPointF ) ) );
574
+ // listen out for zoom updates
575
+ connect ( this , SIGNAL ( zoomLevelChanged () ), this , SLOT ( updateStatusZoom () ) );
576
+ connect ( mView , SIGNAL ( zoomLevelChanged () ), this , SLOT ( updateStatusZoom () ) );
550
577
// listen out to status bar updates from the composition
551
578
connect ( mComposition , SIGNAL ( statusMsgChanged ( QString ) ), this , SLOT ( updateStatusCompositionMsg ( QString ) ) );
552
579
}
@@ -631,6 +658,48 @@ void QgsComposer::updateStatusCursorPos( QPointF cursorPosition )
631
658
mStatusCursorPageLabel ->setText ( QString ( tr ( " page: %3" ) ).arg ( currentPage ) );
632
659
}
633
660
661
+ void QgsComposer::updateStatusZoom ()
662
+ {
663
+ double dpi = QgsApplication::desktop ()->logicalDpiX ();
664
+ // monitor dpi is not always correct - so make sure the value is sane
665
+ if (( dpi < 60 ) || ( dpi > 250 ) )
666
+ dpi = 72 ;
667
+
668
+ // pixel width for 1mm on screen
669
+ double scale100 = dpi / 25.4 ;
670
+ // current zoomLevel
671
+ double zoomLevel = mView ->transform ().m11 () * 100 / scale100;
672
+
673
+ mStatusZoomCombo ->blockSignals ( true );
674
+ mStatusZoomCombo ->lineEdit ()->setText ( QString ( tr ( " %1\%" ) ).arg ( QString::number ( zoomLevel, ' f' , 1 ) ) );
675
+ mStatusZoomCombo ->blockSignals ( false );
676
+ }
677
+
678
+ void QgsComposer::on_mStatusZoomCombo_currentIndexChanged ( int index )
679
+ {
680
+ double selectedZoom = mStatusZoomLevelsList [ mStatusZoomLevelsList .count () - index - 1 ];
681
+ if ( mView )
682
+ {
683
+ mView ->setZoomLevel ( selectedZoom );
684
+ // update zoom combobox text for correct format (one decimal place, trailing % sign)
685
+ mStatusZoomCombo ->blockSignals ( true );
686
+ mStatusZoomCombo ->lineEdit ()->setText ( QString ( tr ( " %1\%" ) ).arg ( QString::number ( selectedZoom * 100 , ' f' , 1 ) ) );
687
+ mStatusZoomCombo ->blockSignals ( false );
688
+ }
689
+ }
690
+
691
+ void QgsComposer::on_mStatusZoomCombo_zoomEntered ()
692
+ {
693
+ if ( !mView )
694
+ {
695
+ return ;
696
+ }
697
+
698
+ // need to remove spaces and "%" characters from input text
699
+ QString zoom = mStatusZoomCombo ->currentText ().remove ( QChar ( ' %' ) ).trimmed ();
700
+ mView ->setZoomLevel ( zoom.toDouble () / 100 );
701
+ }
702
+
634
703
void QgsComposer::updateStatusCompositionMsg ( QString message )
635
704
{
636
705
mStatusCompositionLabel ->setText ( message );
@@ -715,6 +784,11 @@ void QgsComposer::on_mActionZoomOut_triggered()
715
784
emit zoomLevelChanged ();
716
785
}
717
786
787
+ void QgsComposer::on_mActionZoomActual_triggered ()
788
+ {
789
+ mView ->setZoomLevel ( 1.0 );
790
+ }
791
+
718
792
void QgsComposer::on_mActionMouseZoom_triggered ()
719
793
{
720
794
if ( mView )
0 commit comments