Skip to content

Commit d47e128

Browse files
committedOct 24, 2013
[FEATURE] Add status bar to composer window which shows current cursor position, details about selection resize/move
1 parent 79ce937 commit d47e128

12 files changed

+168
-1
lines changed
 

‎src/app/composer/qgscomposer.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
313313
setMouseTracking( true );
314314
mViewFrame->setMouseTracking( true );
315315

316+
//create status bar labels
317+
mStatusCursorXLabel = new QLabel( mStatusBar );
318+
mStatusCursorXLabel->setMinimumWidth( 100 );
319+
mStatusCursorYLabel = new QLabel( mStatusBar );
320+
mStatusCursorYLabel->setMinimumWidth( 100 );
321+
mStatusCursorPageLabel = new QLabel( mStatusBar );
322+
mStatusCursorPageLabel->setMinimumWidth( 100 );
323+
mStatusCompositionLabel = new QLabel( mStatusBar );
324+
mStatusBar->addWidget( mStatusCursorXLabel );
325+
mStatusBar->addWidget( mStatusCursorYLabel );
326+
mStatusBar->addWidget( mStatusCursorPageLabel );
327+
mStatusBar->addWidget( mStatusCompositionLabel );
328+
316329
//create composer view and layout with rulers
317330
mView = 0;
318331
mViewLayout = new QGridLayout();
@@ -343,7 +356,6 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
343356

344357
connectSlots();
345358

346-
347359
mComposition->setParent( mView );
348360
mView->setComposition( mComposition );
349361

@@ -400,9 +412,12 @@ QgsComposer::QgsComposer( QgisApp *qgis, const QString& title )
400412
mGeneralDock->raise();
401413

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

407422
restoreWindowState();
408423
setSelectionTool();
@@ -506,6 +521,14 @@ void QgsComposer::connectSlots()
506521
connect( mComposition, SIGNAL( composerShapeAdded( QgsComposerShape* ) ), this, SLOT( addComposerShape( QgsComposerShape* ) ) );
507522
connect( mComposition, SIGNAL( composerTableAdded( QgsComposerAttributeTable* ) ), this, SLOT( addComposerTable( QgsComposerAttributeTable* ) ) );
508523
connect( mComposition, SIGNAL( itemRemoved( QgsComposerItem* ) ), this, SLOT( deleteItem( QgsComposerItem* ) ) );
524+
525+
//listen out for position updates from the QgsComposerView
526+
connect( mView, SIGNAL( cursorPosChanged( QPointF ) ), this, SLOT( updateStatusCursorPos( QPointF ) ) );
527+
//also listen out for position updates from the horizontal/vertical rulers
528+
connect( mHorizontalRuler, SIGNAL( cursorPosChanged( QPointF ) ), this, SLOT( updateStatusCursorPos( QPointF ) ) );
529+
connect( mVerticalRuler, SIGNAL( cursorPosChanged( QPointF ) ), this, SLOT( updateStatusCursorPos( QPointF ) ) );
530+
//listen out to status bar updates from the composition
531+
connect( mComposition, SIGNAL( statusMsgChanged( QString ) ), this, SLOT( updateStatusCompositionMsg( QString ) ) );
509532
}
510533

511534
void QgsComposer::open( void )
@@ -572,6 +595,27 @@ void QgsComposer::setTitle( const QString& title )
572595
}
573596
}
574597

598+
void QgsComposer::updateStatusCursorPos( QPointF cursorPosition )
599+
{
600+
if ( !mComposition )
601+
{
602+
return;
603+
}
604+
605+
//convert cursor position to position on current page
606+
QPointF pagePosition = mComposition->positionOnPage( cursorPosition );
607+
int currentPage = mComposition->pageNumberForPoint( cursorPosition );
608+
609+
mStatusCursorXLabel->setText( QString( tr( "x: %1 mm" ) ).arg( pagePosition.x() ) );
610+
mStatusCursorYLabel->setText( QString( tr( "y: %1 mm" ) ).arg( pagePosition.y() ) );
611+
mStatusCursorPageLabel->setText( QString( tr( "page: %3" ) ).arg( currentPage ) );
612+
}
613+
614+
void QgsComposer::updateStatusCompositionMsg( QString message )
615+
{
616+
mStatusCompositionLabel->setText( message );
617+
}
618+
575619
void QgsComposer::showItemOptions( QgsComposerItem* item )
576620
{
577621
QWidget* currentWidget = mItemDock->widget();
@@ -1922,7 +1966,9 @@ void QgsComposer::resizeEvent( QResizeEvent *e )
19221966
Q_UNUSED( e );
19231967

19241968
// Move size grip when window is resized
1969+
#if 0
19251970
mSizeGrip->move( rect().bottomRight() - mSizeGrip->rect().bottomRight() );
1971+
#endif
19261972

19271973
saveWindowState();
19281974
}

‎src/app/composer/qgscomposer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,12 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
338338
//! Raise, unminimize and activate this window
339339
void activate();
340340

341+
//! Updates cursor position in status bar
342+
void updateStatusCursorPos( QPointF position );
343+
344+
//! Updates status bar composition message
345+
void updateStatusCompositionMsg( QString message );
346+
341347
private:
342348

343349
/**Establishes the signal slot connection for the class*/
@@ -377,6 +383,13 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
377383
/**Composer title*/
378384
QString mTitle;
379385

386+
/**Labels in status bar which shows current mouse position*/
387+
QLabel* mStatusCursorXLabel;
388+
QLabel* mStatusCursorYLabel;
389+
QLabel* mStatusCursorPageLabel;
390+
/**Label in status bar which shows messages from the composition*/
391+
QLabel* mStatusCompositionLabel;
392+
380393
//! Pointer to composer view
381394
QgsComposerView *mView;
382395
QGridLayout* mViewLayout;
@@ -464,3 +477,4 @@ class QgsComposer: public QMainWindow, private Ui::QgsComposerBase
464477
};
465478

466479
#endif
480+

‎src/core/composer/qgscomposermousehandles.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ void QgsComposerMouseHandles::selectionChanged()
192192
}
193193
}
194194

195+
resetStatusBar();
195196
updateHandles();
196197
}
197198

@@ -515,6 +516,29 @@ void QgsComposerMouseHandles::mouseReleaseEvent( QGraphicsSceneMouseEvent* event
515516
//redraw handles
516517
resetTransform();
517518
updateHandles();
519+
//reset status bar message
520+
resetStatusBar();
521+
}
522+
523+
void QgsComposerMouseHandles::resetStatusBar()
524+
{
525+
QList<QgsComposerItem*> selectedItems = mComposition->selectedComposerItems();
526+
int selectedCount = selectedItems.size();
527+
if ( selectedCount > 1 )
528+
{
529+
//set status bar message to count of selected items
530+
mComposition->setStatusMessage( QString( tr( "%1 items selected" ) ).arg( selectedCount ) );
531+
}
532+
else if ( selectedCount == 1 )
533+
{
534+
//set status bar message to count of selected items
535+
mComposition->setStatusMessage( tr( "1 item selected" ) );
536+
}
537+
else
538+
{
539+
//clear status bar message
540+
mComposition->setStatusMessage( QString( "" ) );
541+
}
518542
}
519543

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

599625
void QgsComposerMouseHandles::resizeMouseMove( const QPointF& currentPosition, bool lockRatio, bool fromCenter )
@@ -770,6 +796,9 @@ void QgsComposerMouseHandles::resizeMouseMove( const QPointF& currentPosition, b
770796
setTransform( itemTransform );
771797
mResizeRect = QRectF( mBeginHandlePos.x() + mx, mBeginHandlePos.y() + my, mBeginHandleWidth + rx, mBeginHandleHeight + ry );
772798
setRect( 0, 0, fabs( mBeginHandleWidth + rx ), fabs( mBeginHandleHeight + ry ) );
799+
800+
//show current size of selection in status bar
801+
mComposition->setStatusMessage( QString( tr( "width: %1 mm height: %2 mm" ) ).arg( rect().width() ).arg( rect().height() ) );
773802
}
774803

775804
void QgsComposerMouseHandles::relativeResizeRect( QRectF& rectToResize, const QRectF& boundsBefore, const QRectF& boundsAfter )

‎src/core/composer/qgscomposermousehandles.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ class CORE_EXPORT QgsComposerMouseHandles: public QObject, public QGraphicsRectI
179179

180180
//sets the mouse cursor for the QGraphicsView attached to the composition (workaround qt bug #3732)
181181
void setViewportCursor( Qt::CursorShape cursor );
182+
183+
//resets the composer window status bar to the default message
184+
void resetStatusBar();
182185
};
183186

184187
#endif // QGSCOMPOSERMOUSEHANDLES_H

‎src/core/composer/qgscomposition.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,36 @@ int QgsComposition::numPages() const
181181
return mPages.size();
182182
}
183183

184+
QPointF QgsComposition::positionOnPage( const QPointF & position ) const
185+
{
186+
double y;
187+
if ( position.y() > ( mPages.size() - 1 ) * ( paperHeight() + spaceBetweenPages() ) )
188+
{
189+
//y coordinate is greater then the end of the last page, so return distance between
190+
//top of last page and y coordinate
191+
y = position.y() - ( mPages.size() - 1 ) * ( paperHeight() + spaceBetweenPages() );
192+
}
193+
else
194+
{
195+
//y coordinate is less then the end of the last page
196+
y = fmod( position.y(), ( paperHeight() + spaceBetweenPages() ) );
197+
}
198+
return QPointF( position.x(), y );
199+
}
200+
201+
int QgsComposition::pageNumberForPoint( const QPointF & position ) const
202+
{
203+
int pageNumber = qFloor( position.y() / ( paperHeight() + spaceBetweenPages() ) ) + 1;
204+
pageNumber = pageNumber < 1 ? 1 : pageNumber;
205+
pageNumber = pageNumber > mPages.size() ? mPages.size() : pageNumber;
206+
return pageNumber;
207+
}
208+
209+
void QgsComposition::setStatusMessage( const QString & message )
210+
{
211+
emit statusMsgChanged( message );
212+
}
213+
184214
QgsComposerItem* QgsComposition::composerItemAt( const QPointF & position )
185215
{
186216
return composerItemAt( position, 0 );

‎src/core/composer/qgscomposition.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
108108
/**Note: added in version 1.9*/
109109
int numPages() const;
110110

111+
/**Returns the position within a page of a point in the composition
112+
@note Added in QGIS 2.1
113+
*/
114+
QPointF positionOnPage( const QPointF & position ) const;
115+
116+
/**Returns the page number corresponding to a point in the composition
117+
@note Added in QGIS 2.1
118+
*/
119+
int pageNumberForPoint( const QPointF & position ) const;
120+
121+
/**Sets the status bar message for the composer window
122+
@note Added in QGIS 2.1
123+
*/
124+
void setStatusMessage( const QString & message );
125+
111126
void setSnapToGridEnabled( bool b );
112127
bool snapToGridEnabled() const {return mSnapToGrid;}
113128

@@ -498,6 +513,9 @@ class CORE_EXPORT QgsComposition : public QGraphicsScene
498513
void composerTableAdded( QgsComposerAttributeTable* table );
499514
/**Is emitted when a composer item has been removed from the scene*/
500515
void itemRemoved( QgsComposerItem* );
516+
517+
/**Is emitted when the composition has an updated status bar message for the composer window*/
518+
void statusMsgChanged( QString message );
501519
};
502520

503521
template<class T> void QgsComposition::composerItems( QList<T*>& itemList )

‎src/gui/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ qgsbusyindicatordialog.h
212212
qgscharacterselectdialog.h
213213
qgscollapsiblegroupbox.h
214214
qgscolordialog.h
215+
qgscomposerruler.h
215216
qgscomposerview.h
216217
qgscredentialdialog.h
217218
qgsdatadefinedbutton.h

‎src/gui/qgscomposerruler.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ void QgsComposerRuler::mouseMoveEvent( QMouseEvent* event )
132132
//qWarning( "QgsComposerRuler::mouseMoveEvent" );
133133
updateMarker( event->posF() );
134134
setSnapLinePosition( event->posF() );
135+
136+
//update cursor position in status bar
137+
QPointF displayPos = mTransform.inverted().map( event->posF() );
138+
if ( mDirection == Horizontal )
139+
{
140+
//mouse is over a horizontal ruler, so don't show a y coordinate
141+
displayPos.setY( 0 );
142+
}
143+
else
144+
{
145+
//mouse is over a vertical ruler, so don't show an x coordinate
146+
displayPos.setX( 0 );
147+
}
148+
emit cursorPosChanged( displayPos );
135149
}
136150

137151
void QgsComposerRuler::mouseReleaseEvent( QMouseEvent* event )

‎src/gui/qgscomposerruler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class QGraphicsLineItem;
99
/**A class to show paper scale and the current cursor position*/
1010
class GUI_EXPORT QgsComposerRuler: public QWidget
1111
{
12+
Q_OBJECT
13+
1214
public:
1315
enum Direction
1416
{
@@ -43,6 +45,11 @@ class GUI_EXPORT QgsComposerRuler: public QWidget
4345
QList< QPair< QgsComposerItem*, QgsComposerItem::ItemPositionMode > > mSnappedItems;
4446

4547
void setSnapLinePosition( const QPointF& pos );
48+
49+
signals:
50+
/**Is emitted when mouse cursor coordinates change*/
51+
void cursorPosChanged( QPointF );
52+
4653
};
4754

4855
#endif // QGSCOMPOSERRULER_H

‎src/gui/qgscomposerview.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,8 @@ void QgsComposerView::mouseMoveEvent( QMouseEvent* e )
603603
}
604604

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

607609
updateRulers();
608610
if ( mHorizontalRuler )

‎src/gui/qgscomposerview.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ class GUI_EXPORT QgsComposerView: public QGraphicsView
198198
/**Current action (e.g. adding composer map) has been finished. The purpose of this signal is that
199199
QgsComposer may set the selection tool again*/
200200
void actionFinished();
201+
/**Is emitted when mouse cursor coordinates change*/
202+
void cursorPosChanged( QPointF );
201203

202204
/**Emitted before composerview is shown*/
203205
void composerViewShow( QgsComposerView* );

‎src/ui/qgscomposerbase.ui

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
</item>
4040
</layout>
4141
</widget>
42+
<widget class="QStatusBar" name="mStatusBar"/>
4243
<widget class="QToolBar" name="mComposerToolbar">
4344
<property name="windowTitle">
4445
<string>Composer</string>

0 commit comments

Comments
 (0)
Please sign in to comment.