Skip to content

Commit

Permalink
Merge pull request #978 from nyalldawson/composer_statusbar
Browse files Browse the repository at this point in the history
Status bar for composer
  • Loading branch information
mhugent committed Oct 29, 2013
2 parents ac0c5d1 + d47e128 commit 9832ed9
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 9 deletions.
48 changes: 47 additions & 1 deletion src/app/composer/qgscomposer.cpp
Expand Up @@ -98,7 +98,6 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
setupUi( this );
setWindowTitle( mTitle );
setupTheme();
connect( mButtonBox, SIGNAL( rejected() ), this, SLOT( close() ) );

QSettings settings;
setStyleSheet( mQgis->styleSheet() );
Expand Down Expand Up @@ -328,6 +327,19 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
setMouseTracking( true );
mViewFrame->setMouseTracking( true );

//create status bar labels
mStatusCursorXLabel = new QLabel( mStatusBar );
mStatusCursorXLabel->setMinimumWidth( 100 );
mStatusCursorYLabel = new QLabel( mStatusBar );
mStatusCursorYLabel->setMinimumWidth( 100 );
mStatusCursorPageLabel = new QLabel( mStatusBar );
mStatusCursorPageLabel->setMinimumWidth( 100 );
mStatusCompositionLabel = new QLabel( mStatusBar );
mStatusBar->addWidget( mStatusCursorXLabel );
mStatusBar->addWidget( mStatusCursorYLabel );
mStatusBar->addWidget( mStatusCursorPageLabel );
mStatusBar->addWidget( mStatusCompositionLabel );

//create composer view and layout with rulers
mView = 0;
mViewLayout = new QGridLayout();
Expand Down Expand Up @@ -415,9 +427,12 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
mGeneralDock->raise();

// Create size grip (needed by Mac OS X for QMainWindow if QStatusBar is not visible)
//should not be needed now that composer has a status bar?
#if 0
mSizeGrip = new QSizeGrip( this );
mSizeGrip->resize( mSizeGrip->sizeHint() );
mSizeGrip->move( rect().bottomRight() - mSizeGrip->rect().bottomRight() );
#endif

restoreWindowState();
setSelectionTool();
Expand Down Expand Up @@ -521,6 +536,14 @@ void QgsComposer::connectSlots()
connect( mComposition, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
connect( mComposition, SIGNAL( composerTableAdded( QgsComposerAttributeTable* ) ), this, SLOT( addComposerTable( QgsComposerAttributeTable* ) ) );
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( deleteItem( QgsComposerItem* ) ) );

//listen out for position updates from the QgsComposerView
connect( mView, SIGNAL( cursorPosChanged( QPointF ) ), this, SLOT( updateStatusCursorPos( QPointF ) ) );
//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 to status bar updates from the composition
connect( mComposition, SIGNAL( statusMsgChanged( QString ) ), this, SLOT( updateStatusCompositionMsg( QString ) ) );
}

void QgsComposer::open( void )
Expand Down Expand Up @@ -587,6 +610,27 @@ void QgsComposer::setTitle( const QString& title )
}
}

void QgsComposer::updateStatusCursorPos( QPointF cursorPosition )
{
if ( !mComposition )
{
return;
}

//convert cursor position to position on current page
QPointF pagePosition = mComposition->positionOnPage( cursorPosition );
int currentPage = mComposition->pageNumberForPoint( cursorPosition );

mStatusCursorXLabel->setText( QString( tr( "x: %1 mm" ) ).arg( pagePosition.x() ) );
mStatusCursorYLabel->setText( QString( tr( "y: %1 mm" ) ).arg( pagePosition.y() ) );
mStatusCursorPageLabel->setText( QString( tr( "page: %3" ) ).arg( currentPage ) );
}

void QgsComposer::updateStatusCompositionMsg( QString message )
{
mStatusCompositionLabel->setText( message );
}

void QgsComposer::showItemOptions( QgsComposerItem* item )
{
QWidget* currentWidget = mItemDock->widget();
Expand Down Expand Up @@ -1991,7 +2035,9 @@ void QgsComposer::resizeEvent( QResizeEvent *e )
Q_UNUSED( e );

// Move size grip when window is resized
#if 0
mSizeGrip->move( rect().bottomRight() - mSizeGrip->rect().bottomRight() );
#endif

saveWindowState();
}
Expand Down
14 changes: 13 additions & 1 deletion src/app/composer/qgscomposer.h
Expand Up @@ -356,7 +356,11 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
//! Raise, unminimize and activate this window
void activate();

void on_mButtonBox_helpRequested() { QgsContextHelp::run( metaObject()->className() ); }
//! Updates cursor position in status bar
void updateStatusCursorPos( QPointF position );

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

private:

Expand Down Expand Up @@ -400,6 +404,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
/**Composer title*/
QString mTitle;

/**Labels in status bar which shows current mouse position*/
QLabel* mStatusCursorXLabel;
QLabel* mStatusCursorYLabel;
QLabel* mStatusCursorPageLabel;
/**Label in status bar which shows messages from the composition*/
QLabel* mStatusCompositionLabel;

//! Pointer to composer view
QgsComposerView *mView;
QGridLayout* mViewLayout;
Expand Down Expand Up @@ -487,3 +498,4 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
};

#endif

29 changes: 29 additions & 0 deletions src/core/composer/qgscomposermousehandles.cpp
Expand Up @@ -192,6 +192,7 @@ void QgsComposerMouseHandles::selectionChanged()
}
}

resetStatusBar();
updateHandles();
}

Expand Down Expand Up @@ -515,6 +516,29 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event
//redraw handles
resetTransform();
updateHandles();
//reset status bar message
resetStatusBar();
}

void QgsComposerMouseHandles::resetStatusBar()
{
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
int selectedCount = selectedItems.size();
if ( selectedCount > 1 )
{
//set status bar message to count of selected items
mComposition->setStatusMessage( QString( tr( "%1 items selected" ) ).arg( selectedCount ) );
}
else if ( selectedCount == 1 )
{
//set status bar message to count of selected items
mComposition->setStatusMessage( tr( "1 item selected" ) );
}
else
{
//clear status bar message
mComposition->setStatusMessage( QString( "" ) );
}
}

void QgsComposerMouseHandles::mousePressEvent( QGraphicsSceneMouseEvent* event )
Expand Down Expand Up @@ -594,6 +618,8 @@ void QgsComposerMouseHandles::dragMouseMove( const QPointF& currentPosition, boo
QTransform moveTransform;
moveTransform.translate( moveRectX, moveRectY );
setTransform( moveTransform );
//show current displacement of selection in status bar
mComposition->setStatusMessage( QString( tr( "dx: %1 mm dy: %2 mm" ) ).arg( moveRectX ).arg( moveRectY ) );
}

void QgsComposerMouseHandles::resizeMouseMove( const QPointF& currentPosition, bool lockRatio, bool fromCenter )
Expand Down Expand Up @@ -770,6 +796,9 @@ void QgsComposerMouseHandles::resizeMouseMove( const QPointF& currentPosition, b
setTransform( itemTransform );
mResizeRect = QRectF( mBeginHandlePos.x() + mx, mBeginHandlePos.y() + my, mBeginHandleWidth + rx, mBeginHandleHeight + ry );
setRect( 0, 0, fabs( mBeginHandleWidth + rx ), fabs( mBeginHandleHeight + ry ) );

//show current size of selection in status bar
mComposition->setStatusMessage( QString( tr( "width: %1 mm height: %2 mm" ) ).arg( rect().width() ).arg( rect().height() ) );
}

void QgsComposerMouseHandles::relativeResizeRect( QRectF& rectToResize, const QRectF& boundsBefore, const QRectF& boundsAfter )
Expand Down
3 changes: 3 additions & 0 deletions src/core/composer/qgscomposermousehandles.h
Expand Up @@ -179,6 +179,9 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI

//sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
void setViewportCursor( Qt::CursorShape cursor );

//resets the composer window status bar to the default message
void resetStatusBar();
};

#endif // QGSCOMPOSERMOUSEHANDLES_H
30 changes: 30 additions & 0 deletions src/core/composer/qgscomposition.cpp
Expand Up @@ -187,6 +187,36 @@ int QgsComposition::numPages() const
return mPages.size();
}

QPointF QgsComposition::positionOnPage( const QPointF & position ) const
{
double y;
if ( position.y() > ( mPages.size() - 1 ) * ( paperHeight() + spaceBetweenPages() ) )
{
//y coordinate is greater then the end of the last page, so return distance between
//top of last page and y coordinate
y = position.y() - ( mPages.size() - 1 ) * ( paperHeight() + spaceBetweenPages() );
}
else
{
//y coordinate is less then the end of the last page
y = fmod( position.y(), ( paperHeight() + spaceBetweenPages() ) );
}
return QPointF( position.x(), y );
}

int QgsComposition::pageNumberForPoint( const QPointF & position ) const
{
int pageNumber = qFloor( position.y() / ( paperHeight() + spaceBetweenPages() ) ) + 1;
pageNumber = pageNumber < 1 ? 1 : pageNumber;
pageNumber = pageNumber > mPages.size() ? mPages.size() : pageNumber;
return pageNumber;
}

void QgsComposition::setStatusMessage( const QString & message )
{
emit statusMsgChanged( message );
}

QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
{
return composerItemAt( position, 0 );
Expand Down
18 changes: 18 additions & 0 deletions src/core/composer/qgscomposition.h
Expand Up @@ -108,6 +108,21 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
/**Note: added in version 1.9*/
int numPages() const;

/**Returns the position within a page of a point in the composition
@note Added in QGIS 2.1
*/
QPointF positionOnPage( const QPointF & position ) const;

/**Returns the page number corresponding to a point in the composition
@note Added in QGIS 2.1
*/
int pageNumberForPoint( const QPointF & position ) const;

/**Sets the status bar message for the composer window
@note Added in QGIS 2.1
*/
void setStatusMessage( const QString & message );

void setSnapToGridEnabled( bool b );
bool snapToGridEnabled() const {return mSnapToGrid;}

Expand Down Expand Up @@ -512,6 +527,9 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
void composerTableAdded( QgsComposerAttributeTable* table );
/**Is emitted when a composer item has been removed from the scene*/
void itemRemoved( QgsComposerItem* );

/**Is emitted when the composition has an updated status bar message for the composer window*/
void statusMsgChanged( QString message );
};

template<class T> void QgsComposition::composerItems( QList<T*>& itemList )
Expand Down
1 change: 1 addition & 0 deletions src/gui/CMakeLists.txt
Expand Up @@ -212,6 +212,7 @@ qgsbusyindicatordialog.h
qgscharacterselectdialog.h
qgscollapsiblegroupbox.h
qgscolordialog.h
qgscomposerruler.h
qgscomposerview.h
qgscredentialdialog.h
qgsdatadefinedbutton.h
Expand Down
14 changes: 14 additions & 0 deletions src/gui/qgscomposerruler.cpp
Expand Up @@ -132,6 +132,20 @@ void QgsComposerRuler::mouseMoveEvent( QMouseEvent* event )
//qWarning( "QgsComposerRuler::mouseMoveEvent" );
updateMarker( event->posF() );
setSnapLinePosition( event->posF() );

//update cursor position in status bar
QPointF displayPos = mTransform.inverted().map( event->posF() );
if ( mDirection == Horizontal )
{
//mouse is over a horizontal ruler, so don't show a y coordinate
displayPos.setY( 0 );
}
else
{
//mouse is over a vertical ruler, so don't show an x coordinate
displayPos.setX( 0 );
}
emit cursorPosChanged( displayPos );
}

void QgsComposerRuler::mouseReleaseEvent( QMouseEvent* event )
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgscomposerruler.h
Expand Up @@ -9,6 +9,8 @@ class QGraphicsLineItem;
/**A class to show paper scale and the current cursor position*/
class GUI_EXPORT QgsComposerRuler: public QWidget
{
Q_OBJECT

public:
enum Direction
{
Expand Down Expand Up @@ -43,6 +45,11 @@ class GUI_EXPORT QgsComposerRuler: public QWidget
QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > > mSnappedItems;

void setSnapLinePosition( const QPointF& pos );

signals:
/**Is emitted when mouse cursor coordinates change*/
void cursorPosChanged( QPointF );

};

#endif // QGSCOMPOSERRULER_H
2 changes: 2 additions & 0 deletions src/gui/qgscomposerview.cpp
Expand Up @@ -603,6 +603,8 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
}

mMouseCurrentXY = e->pos();
//update cursor position in composer status bar
emit cursorPosChanged( mapToScene( e->pos() ) );

updateRulers();
if ( mHorizontalRuler )
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgscomposerview.h
Expand Up @@ -198,6 +198,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
/**Current action (e.g. adding composer map) has been finished. The purpose of this signal is that
QgsComposer may set the selection tool again*/
void actionFinished();
/**Is emitted when mouse cursor coordinates change*/
void cursorPosChanged( QPointF );

/**Emitted before composerview is shown*/
void composerViewShow( QgsComposerView* );
Expand Down
8 changes: 1 addition & 7 deletions src/ui/qgscomposerbase.ui
Expand Up @@ -37,15 +37,9 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Close|QDialogButtonBox::Help</set>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="mStatusBar"/>
<widget class="QToolBar" name="mComposerToolbar">
<property name="windowTitle">
<string>Composer</string>
Expand Down

0 comments on commit 9832ed9

Please sign in to comment.