Skip to content
Permalink
Browse files

[composer] Add action for showing/hiding rulers

  • Loading branch information
nyalldawson committed Dec 29, 2013
1 parent 37b48bd commit 7d712aca749de648c6e36b98c11d5a2d41c4081a
Showing with 59 additions and 8 deletions.
  1. +30 −5 src/app/composer/qgscomposer.cpp
  2. +4 −0 src/app/composer/qgscomposer.h
  3. +2 −0 src/gui/qgscomposerruler.h
  4. +23 −3 src/ui/qgscomposerbase.ui
@@ -175,6 +175,7 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mActionShowGuides->setCheckable( true );
mActionSnapGuides->setCheckable( true );
mActionSmartGuides->setCheckable( true );
mActionShowRulers->setCheckable( true );

#ifdef Q_WS_MAC
mActionQuit->setText( tr( "Close" ) );
@@ -267,6 +268,8 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
viewMenu->addAction( mActionSnapGuides );
viewMenu->addAction( mActionSmartGuides );
viewMenu->addAction( mActionClearGuides );
viewMenu->addSeparator();
viewMenu->addAction( mActionShowRulers );

// Panel and toolbar submenus
mPanelMenu = new QMenu( tr( "Panels" ), this );
@@ -374,16 +377,27 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mViewLayout->setMargin( 0 );
mHorizontalRuler = new QgsComposerRuler( QgsComposerRuler::Horizontal );
mVerticalRuler = new QgsComposerRuler( QgsComposerRuler::Vertical );
QWidget* fake = new QWidget();
fake->setAttribute( Qt::WA_NoMousePropagation );
fake->setBackgroundRole( QPalette::Window );
fake->setFixedSize( 20, 20 );
mViewLayout->addWidget( fake, 0, 0 );
mRulerLayoutFix = new QWidget();
mRulerLayoutFix->setAttribute( Qt::WA_NoMousePropagation );
mRulerLayoutFix->setBackgroundRole( QPalette::Window );
mRulerLayoutFix->setFixedSize( mVerticalRuler->rulerSize(), mHorizontalRuler->rulerSize() );
mViewLayout->addWidget( mRulerLayoutFix, 0, 0 );
mViewLayout->addWidget( mHorizontalRuler, 0, 1 );
mViewLayout->addWidget( mVerticalRuler, 1, 0 );
createComposerView();
mViewFrame->setLayout( mViewLayout );

//initial state of rulers
QSettings myQSettings;
bool showRulers = myQSettings.value( "/Composer/showRulers", true ).toBool();
mActionShowRulers->blockSignals( true );
mActionShowRulers->setChecked( showRulers );
mHorizontalRuler->setVisible( showRulers );
mVerticalRuler->setVisible( showRulers );
mRulerLayoutFix->setVisible( showRulers );
mActionShowRulers->blockSignals( false );
connect( mActionShowRulers, SIGNAL( triggered( bool ) ), this, SLOT( toggleRulers( bool ) ) );

//init undo/redo buttons
mComposition = new QgsComposition( mQgis->mapCanvas()->mapRenderer() );

@@ -878,6 +892,17 @@ void QgsComposer::on_mActionClearGuides_triggered()
}
}

void QgsComposer::toggleRulers( bool checked )
{
//show or hide rulers
mHorizontalRuler->setVisible( checked );
mVerticalRuler->setVisible( checked );
mRulerLayoutFix->setVisible( checked );

QSettings myQSettings;
myQSettings.setValue( "/Composer/showRulers", checked );
}

void QgsComposer::on_mActionExportAsPDF_triggered()
{
if ( !mComposition || !mView )
@@ -306,6 +306,9 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//!Enable or disable smart guides
void on_mActionSmartGuides_triggered( bool checked );

//!Show/hide rulers
void toggleRulers( bool checked );

//!Clear guides
void on_mActionClearGuides_triggered();

@@ -435,6 +438,7 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
QGridLayout* mViewLayout;
QgsComposerRuler* mHorizontalRuler;
QgsComposerRuler* mVerticalRuler;
QWidget* mRulerLayoutFix;

//! Current composition
QgsComposition *mComposition;
@@ -29,6 +29,8 @@ class GUI_EXPORT QgsComposerRuler: public QWidget
void setComposition( QgsComposition* c ) { mComposition = c; }
QgsComposition* composition() { return mComposition; }

int rulerSize() { return mRulerMinSize; }

protected:
void paintEvent( QPaintEvent* event );
void mouseMoveEvent( QMouseEvent* event );
@@ -21,7 +21,16 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item row="0" column="0">
@@ -796,7 +805,7 @@
<property name="text">
<string>Pan Composer</string>
</property>
</action>
</action>
<action name="mActionOptions">
<property name="icon">
<iconset resource="../../images/images.qrc">
@@ -808,7 +817,18 @@
<property name="menuRole">
<enum>QAction::PreferencesRole</enum>
</property>
</action>
</action>
<action name="mActionShowRulers">
<property name="text">
<string>Show Rulers</string>
</property>
<property name="toolTip">
<string>Show rulers</string>
</property>
<property name="shortcut">
<string>Ctrl+R</string>
</property>
</action>
</widget>
<resources>
<include location="../../images/images.qrc"/>

0 comments on commit 7d712ac

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