Skip to content
Permalink
Browse files

Merge pull request #978 from nyalldawson/composer_statusbar

Status bar for composer
  • Loading branch information
mhugent committed Oct 29, 2013
2 parents ac0c5d1 + d47e128 commit 9832ed99275df635d8528c3e48f1055a3b7312df
@@ -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() );
@@ -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();
@@ -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();
@@ -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 )
@@ -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();
@@ -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();
}
@@ -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:

@@ -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;
@@ -487,3 +498,4 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
};

#endif

@@ -192,6 +192,7 @@ void QgsComposerMouseHandles::selectionChanged()
}
}

resetStatusBar();
updateHandles();
}

@@ -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 )
@@ -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 )
@@ -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 )
@@ -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
@@ -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 );
@@ -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;}

@@ -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 )
@@ -212,6 +212,7 @@ qgsbusyindicatordialog.h
qgscharacterselectdialog.h
qgscollapsiblegroupbox.h
qgscolordialog.h
qgscomposerruler.h
qgscomposerview.h
qgscredentialdialog.h
qgsdatadefinedbutton.h
@@ -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 )
@@ -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
{
@@ -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
@@ -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 )
@@ -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* );
@@ -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>

0 comments on commit 9832ed9

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