Skip to content
Permalink
Browse files

[FEATURE][composer] Add zoom actual size action to composer, zoom ind…

…icator and combobox to status bar
  • Loading branch information
nyalldawson committed Dec 29, 2013
1 parent ed3e04d commit c6d0bef4d551795e2e564176ed3a86094a303f0f
@@ -256,6 +256,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
viewMenu->addAction( mActionZoomIn );
viewMenu->addAction( mActionZoomOut );
viewMenu->addAction( mActionZoomAll );
viewMenu->addAction( mActionZoomActual );
viewMenu->addSeparator();
viewMenu->addAction( mActionRefreshView );
viewMenu->addSeparator();
@@ -331,6 +332,26 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
setMouseTracking( true );
mViewFrame->setMouseTracking( true );

mStatusZoomCombo = new QComboBox( mStatusBar );
mStatusZoomCombo->setEditable( true );
mStatusZoomCombo->setInsertPolicy( QComboBox::NoInsert );
mStatusZoomCombo->setCompleter( 0 );
mStatusZoomCombo->setMinimumWidth( 100 );
//zoom combo box accepts decimals in the range 1-9999, with an optional decimal point and "%" sign
QRegExp zoomRx( "\\s*\\d{1,4}(\\.\\d?)?\\s*%?" );
QValidator *zoomValidator = new QRegExpValidator( zoomRx, mStatusZoomCombo );
mStatusZoomCombo->lineEdit()->setValidator( zoomValidator );

//add some nice zoom levels to the zoom combobox
mStatusZoomLevelsList << 0.125 << 0.25 << 0.5 << 1.0 << 2.0 << 4.0 << 8.0;
QList<double>::iterator zoom_it;
for ( zoom_it = mStatusZoomLevelsList.begin(); zoom_it != mStatusZoomLevelsList.end(); ++zoom_it )
{
mStatusZoomCombo->insertItem( 0, QString( tr( "%1\%" ) ).arg(( *zoom_it ) * 100 ) );
}
connect( mStatusZoomCombo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( on_mStatusZoomCombo_currentIndexChanged( int ) ) );
connect( mStatusZoomCombo->lineEdit(), SIGNAL( returnPressed() ), this, SLOT( on_mStatusZoomCombo_zoomEntered() ) );

//create status bar labels
mStatusCursorXLabel = new QLabel( mStatusBar );
mStatusCursorXLabel->setMinimumWidth( 100 );
@@ -339,9 +360,11 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mStatusCursorPageLabel = new QLabel( mStatusBar );
mStatusCursorPageLabel->setMinimumWidth( 100 );
mStatusCompositionLabel = new QLabel( mStatusBar );

mStatusBar->addWidget( mStatusCursorXLabel );
mStatusBar->addWidget( mStatusCursorYLabel );
mStatusBar->addWidget( mStatusCursorPageLabel );
mStatusBar->addWidget( mStatusZoomCombo );
mStatusBar->addWidget( mStatusCompositionLabel );

//create composer view and layout with rulers
@@ -480,6 +503,7 @@ void QgsComposer::setupTheme()
mActionZoomAll->setIcon( QgsApplication::getThemeIcon( "/mActionZoomFullExtent.svg" ) );
mActionZoomIn->setIcon( QgsApplication::getThemeIcon( "/mActionZoomIn.svg" ) );
mActionZoomOut->setIcon( QgsApplication::getThemeIcon( "/mActionZoomOut.svg" ) );
mActionZoomActual->setIcon( QgsApplication::getThemeIcon( "/mActionZoomActual.svg" ) );
mActionMouseZoom->setIcon( QgsApplication::getThemeIcon( "/mActionZoomToSelected.svg" ) );
mActionRefreshView->setIcon( QgsApplication::getThemeIcon( "/mActionDraw.svg" ) );
mActionUndo->setIcon( QgsApplication::getThemeIcon( "/mActionUndo.png" ) );
@@ -547,6 +571,9 @@ void QgsComposer::connectSlots()
//also listen out for position updates from the horizontal/vertical rulers
connect( mHorizontalRuler, SIGNAL( cursorPosChanged( QPointF ) ), this, SLOT( updateStatusCursorPos( QPointF ) ) );
connect( mVerticalRuler, SIGNAL( cursorPosChanged( QPointF ) ), this, SLOT( updateStatusCursorPos( QPointF ) ) );
//listen out for zoom updates
connect( this, SIGNAL( zoomLevelChanged() ), this, SLOT( updateStatusZoom() ) );
connect( mView, SIGNAL( zoomLevelChanged() ), this, SLOT( updateStatusZoom() ) );
//listen out to status bar updates from the composition
connect( mComposition, SIGNAL( statusMsgChanged( QString ) ), this, SLOT( updateStatusCompositionMsg( QString ) ) );
}
@@ -631,6 +658,48 @@ void QgsComposer::updateStatusCursorPos( QPointF cursorPosition )
mStatusCursorPageLabel->setText( QString( tr( "page: %3" ) ).arg( currentPage ) );
}

void QgsComposer::updateStatusZoom()
{
double dpi = QgsApplication::desktop()->logicalDpiX();
//monitor dpi is not always correct - so make sure the value is sane
if (( dpi < 60 ) || ( dpi > 250 ) )
dpi = 72;

//pixel width for 1mm on screen
double scale100 = dpi / 25.4;
//current zoomLevel
double zoomLevel = mView->transform().m11() * 100 / scale100;

mStatusZoomCombo->blockSignals( true );
mStatusZoomCombo->lineEdit()->setText( QString( tr( "%1\%" ) ).arg( QString::number( zoomLevel, 'f', 1 ) ) );
mStatusZoomCombo->blockSignals( false );
}

void QgsComposer::on_mStatusZoomCombo_currentIndexChanged( int index )
{
double selectedZoom = mStatusZoomLevelsList[ mStatusZoomLevelsList.count() - index - 1 ];
if ( mView )
{
mView->setZoomLevel( selectedZoom );
//update zoom combobox text for correct format (one decimal place, trailing % sign)
mStatusZoomCombo->blockSignals( true );
mStatusZoomCombo->lineEdit()->setText( QString( tr( "%1\%" ) ).arg( QString::number( selectedZoom * 100, 'f', 1 ) ) );
mStatusZoomCombo->blockSignals( false );
}
}

void QgsComposer::on_mStatusZoomCombo_zoomEntered()
{
if ( !mView )
{
return;
}

//need to remove spaces and "%" characters from input text
QString zoom = mStatusZoomCombo->currentText().remove( QChar( '%' ) ).trimmed();
mView->setZoomLevel( zoom.toDouble() / 100 );
}

void QgsComposer::updateStatusCompositionMsg( QString message )
{
mStatusCompositionLabel->setText( message );
@@ -715,6 +784,11 @@ void QgsComposer::on_mActionZoomOut_triggered()
emit zoomLevelChanged();
}

void QgsComposer::on_mActionZoomActual_triggered()
{
mView->setZoomLevel( 1.0 );
}

void QgsComposer::on_mActionMouseZoom_triggered()
{
if ( mView )
@@ -126,6 +126,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Zoom out
void on_mActionZoomOut_triggered();

//! Zoom actual
void on_mActionZoomActual_triggered();

//! Refresh view
void on_mActionRefreshView_triggered();

@@ -365,6 +368,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Updates cursor position in status bar
void updateStatusCursorPos( QPointF position );

//! Updates zoom level in status bar
void updateStatusZoom();

void on_mStatusZoomCombo_currentIndexChanged( int index );

void on_mStatusZoomCombo_zoomEntered();

//! Updates status bar composition message
void updateStatusCompositionMsg( QString message );

@@ -414,6 +424,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QLabel* mStatusCursorXLabel;
QLabel* mStatusCursorYLabel;
QLabel* mStatusCursorPageLabel;
/**Combobox in status bar which shows/adjusts current zoom level*/
QComboBox* mStatusZoomCombo;
QList<double> mStatusZoomLevelsList;
/**Label in status bar which shows messages from the composition*/
QLabel* mStatusCompositionLabel;

@@ -23,6 +23,7 @@
#include <QMimeData>
#include <QGridLayout>

#include "qgsapplication.h"
#include "qgscomposerview.h"
#include "qgscomposerarrow.h"
#include "qgscomposerframe.h"
@@ -1313,6 +1314,7 @@ void QgsComposerView::wheelZoom( QWheelEvent * event )
}

//update composition for new zoom
emit zoomLevelChanged();
updateRulers();
update();
//redraw cached map items
@@ -1328,6 +1330,22 @@ void QgsComposerView::wheelZoom( QWheelEvent * event )
}
}

void QgsComposerView::setZoomLevel( double zoomLevel )
{
double dpi = QgsApplication::desktop()->logicalDpiX();
//monitor dpi is not always correct - so make sure the value is sane
if (( dpi < 60 ) || ( dpi > 250 ) )
dpi = 72;

//desired pixel width for 1mm on screen
double scale = zoomLevel * dpi / 25.4;
setTransform( QTransform::fromScale( scale , scale ) );

updateRulers();
update();
emit zoomLevelChanged();
}

void QgsComposerView::paintEvent( QPaintEvent* event )
{
if ( mPaintingEnabled )
@@ -1356,6 +1374,7 @@ void QgsComposerView::showEvent( QShowEvent* e )
void QgsComposerView::resizeEvent( QResizeEvent* event )
{
QGraphicsView::resizeEvent( event );
emit zoomLevelChanged();
updateRulers();
}

@@ -136,6 +136,9 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
void setHorizontalRuler( QgsComposerRuler* r ) { mHorizontalRuler = r; }
void setVerticalRuler( QgsComposerRuler* r ) { mVerticalRuler = r; }

/**Set zoom level, where a zoom level of 1.0 corresponds to 100%*/
void setZoomLevel( double zoomLevel );

protected:
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
@@ -220,6 +223,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
void actionFinished();
/**Is emitted when mouse cursor coordinates change*/
void cursorPosChanged( QPointF );
/**Is emitted when the view zoom changes*/
void zoomLevelChanged();

/**Emitted before composerview is shown*/
void composerViewShow( QgsComposerView* );
@@ -76,6 +76,7 @@
<bool>true</bool>
</attribute>
<addaction name="mActionZoomAll"/>
<addaction name="mActionZoomActual"/>
<addaction name="mActionZoomIn"/>
<addaction name="mActionZoomOut"/>
<addaction name="mActionRefreshView"/>
@@ -179,6 +180,21 @@
<string>Ctrl+-</string>
</property>
</action>
<action name="mActionZoomActual">
<property name="icon">
<iconset resource="../../images/images.qrc">
<normaloff>:/images/themes/default/mActionZoomActual.svg</normaloff>:/images/themes/default/mActionZoomActual.svg</iconset>
</property>
<property name="text">
<string>Zoom to 100%</string>
</property>
<property name="toolTip">
<string>Zoom to 100%</string>
</property>
<property name="shortcut">
<string>Ctrl+1</string>
</property>
</action>
<action name="mActionMouseZoom">
<property name="icon">
<iconset resource="../../images/images.qrc">

0 comments on commit c6d0bef

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