Skip to content

Commit c25aab1

Browse files
committedJul 11, 2017
Port display of cursor location from composer
1 parent 6ca6423 commit c25aab1

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed
 

‎python/gui/layout/qgslayoutview.sip

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ class QgsLayoutView: QGraphicsView
142142
Is emitted whenever the zoom level of the view is changed.
143143
%End
144144

145+
void cursorPosChanged( QPointF layoutPoint );
146+
%Docstring
147+
Is emitted when the mouse cursor coordinates change within the view.
148+
The ``layoutPoint`` argument indicates the cursor position within
149+
the layout coordinate system.
150+
%End
151+
145152
protected:
146153
virtual void mousePressEvent( QMouseEvent *event );
147154

‎src/app/layout/qgslayoutdesignerdialog.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#include <QLineEdit>
3434
#include <QDesktopWidget>
3535
#include <QSlider>
36+
#include <QLabel>
37+
3638

3739
//add some nice zoom levels for zoom comboboxes
3840
QList<double> QgsLayoutDesignerDialog::sStatusZoomLevelsList { 0.125, 0.25, 0.5, 1.0, 2.0, 4.0, 8.0};
@@ -131,6 +133,19 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
131133
connect( mActionZoomAll, &QAction::triggered, mView, &QgsLayoutView::zoomFull );
132134
connect( mActionZoomActual, &QAction::triggered, mView, &QgsLayoutView::zoomActual );
133135

136+
//create status bar labels
137+
mStatusCursorXLabel = new QLabel( mStatusBar );
138+
mStatusCursorXLabel->setMinimumWidth( 100 );
139+
mStatusCursorYLabel = new QLabel( mStatusBar );
140+
mStatusCursorYLabel->setMinimumWidth( 100 );
141+
mStatusCursorPageLabel = new QLabel( mStatusBar );
142+
mStatusCursorPageLabel->setMinimumWidth( 100 );
143+
144+
mStatusBar->addPermanentWidget( mStatusCursorXLabel );
145+
mStatusBar->addPermanentWidget( mStatusCursorXLabel );
146+
mStatusBar->addPermanentWidget( mStatusCursorYLabel );
147+
mStatusBar->addPermanentWidget( mStatusCursorPageLabel );
148+
134149
mStatusZoomCombo = new QComboBox();
135150
mStatusZoomCombo->setEditable( true );
136151
mStatusZoomCombo->setInsertPolicy( QComboBox::NoInsert );
@@ -163,9 +178,13 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
163178
mStatusBar->addPermanentWidget( mStatusZoomCombo );
164179
mStatusBar->addPermanentWidget( mStatusZoomSlider );
165180

181+
//hide borders from child items in status bar under Windows
182+
mStatusBar->setStyleSheet( QStringLiteral( "QStatusBar::item {border: none;}" ) );
183+
166184
mView->setTool( mSelectTool );
167185
mView->setFocus();
168186
connect( mView, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutDesignerDialog::updateStatusZoom );
187+
connect( mView, &QgsLayoutView::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );
169188

170189
restoreWindowState();
171190
}
@@ -310,6 +329,26 @@ void QgsLayoutDesignerDialog::updateStatusZoom()
310329
whileBlocking( mStatusZoomSlider )->setValue( zoomLevel );
311330
}
312331

332+
void QgsLayoutDesignerDialog::updateStatusCursorPos( QPointF position )
333+
{
334+
if ( !mView->currentLayout() )
335+
{
336+
return;
337+
}
338+
339+
//convert cursor position to position on current page
340+
#if 0 // TODO
341+
QPointF pagePosition = mView->currentLayout()->positionOnPage( cursorPosition );
342+
int currentPage = mView->currentLayout()->pageNumberForPoint( cursorPosition );
343+
#endif
344+
QPointF pagePosition = position;
345+
int currentPage = 1;
346+
347+
mStatusCursorXLabel->setText( QString( tr( "x: %1 mm" ) ).arg( pagePosition.x() ) );
348+
mStatusCursorYLabel->setText( QString( tr( "y: %1 mm" ) ).arg( pagePosition.y() ) );
349+
mStatusCursorPageLabel->setText( QString( tr( "page: %1" ) ).arg( currentPage ) );
350+
}
351+
313352
QgsLayoutView *QgsLayoutDesignerDialog::view()
314353
{
315354
return mView;

‎src/app/layout/qgslayoutdesignerdialog.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class QgsLayoutViewToolZoom;
2828
class QgsLayoutViewToolSelect;
2929
class QComboBox;
3030
class QSlider;
31+
class QLabel;
3132

3233
class QgsAppLayoutDesignerInterface : public QgsLayoutDesignerInterface
3334
{
@@ -120,6 +121,9 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
120121
//! Updates zoom level in status bar
121122
void updateStatusZoom();
122123

124+
//! Updates cursor position in status bar
125+
void updateStatusCursorPos( QPointF position );
126+
123127
private:
124128

125129
QgsAppLayoutDesignerInterface *mInterface = nullptr;
@@ -134,6 +138,11 @@ class QgsLayoutDesignerDialog: public QMainWindow, private Ui::QgsLayoutDesigner
134138
QComboBox *mStatusZoomCombo = nullptr;
135139
QSlider *mStatusZoomSlider = nullptr;
136140

141+
//! Labels in status bar which shows current mouse position
142+
QLabel *mStatusCursorXLabel = nullptr;
143+
QLabel *mStatusCursorYLabel = nullptr;
144+
QLabel *mStatusCursorPageLabel = nullptr;
145+
137146
static QList<double> sStatusZoomLevelsList;
138147

139148
QgsLayoutViewToolAddItem *mAddItemTool = nullptr;

‎src/gui/layout/qgslayoutview.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
203203
{
204204
mMouseCurrentXY = event->pos();
205205

206+
//update cursor position in status bar
207+
emit cursorPosChanged( mapToScene( mMouseCurrentXY ) );
208+
206209
if ( mTool )
207210
{
208211
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event ) );

‎src/gui/layout/qgslayoutview.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
172172
*/
173173
void zoomLevelChanged();
174174

175+
/**
176+
* Is emitted when the mouse cursor coordinates change within the view.
177+
* The \a layoutPoint argument indicates the cursor position within
178+
* the layout coordinate system.
179+
*/
180+
void cursorPosChanged( QPointF layoutPoint );
181+
175182
protected:
176183
void mousePressEvent( QMouseEvent *event ) override;
177184
void mouseReleaseEvent( QMouseEvent *event ) override;

0 commit comments

Comments
 (0)
Please sign in to comment.