Skip to content
Permalink
Browse files

Port display of cursor location from composer

  • Loading branch information
nyalldawson committed Jul 11, 2017
1 parent 6ca6423 commit c25aab16b0e7a823baf57e4093527d4c0e3485bc
@@ -142,6 +142,13 @@ class QgsLayoutView: QGraphicsView
Is emitted whenever the zoom level of the view is changed.
%End

void cursorPosChanged( QPointF layoutPoint );
%Docstring
Is emitted when the mouse cursor coordinates change within the view.
The ``layoutPoint`` argument indicates the cursor position within
the layout coordinate system.
%End

protected:
virtual void mousePressEvent( QMouseEvent *event );

@@ -33,6 +33,8 @@
#include <QLineEdit>
#include <QDesktopWidget>
#include <QSlider>
#include <QLabel>


//add some nice zoom levels for zoom comboboxes
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
connect( mActionZoomAll, &QAction::triggered, mView, &QgsLayoutView::zoomFull );
connect( mActionZoomActual, &QAction::triggered, mView, &QgsLayoutView::zoomActual );

//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 );

mStatusBar->addPermanentWidget( mStatusCursorXLabel );
mStatusBar->addPermanentWidget( mStatusCursorXLabel );
mStatusBar->addPermanentWidget( mStatusCursorYLabel );
mStatusBar->addPermanentWidget( mStatusCursorPageLabel );

mStatusZoomCombo = new QComboBox();
mStatusZoomCombo->setEditable( true );
mStatusZoomCombo->setInsertPolicy( QComboBox::NoInsert );
@@ -163,9 +178,13 @@ QgsLayoutDesignerDialog::QgsLayoutDesignerDialog( QWidget *parent, Qt::WindowFla
mStatusBar->addPermanentWidget( mStatusZoomCombo );
mStatusBar->addPermanentWidget( mStatusZoomSlider );

//hide borders from child items in status bar under Windows
mStatusBar->setStyleSheet( QStringLiteral( "QStatusBar::item {border: none;}" ) );

mView->setTool( mSelectTool );
mView->setFocus();
connect( mView, &QgsLayoutView::zoomLevelChanged, this, &QgsLayoutDesignerDialog::updateStatusZoom );
connect( mView, &QgsLayoutView::cursorPosChanged, this, &QgsLayoutDesignerDialog::updateStatusCursorPos );

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

void QgsLayoutDesignerDialog::updateStatusCursorPos( QPointF position )
{
if ( !mView->currentLayout() )
{
return;
}

//convert cursor position to position on current page
#if 0 // TODO
QPointF pagePosition = mView->currentLayout()->positionOnPage( cursorPosition );
int currentPage = mView->currentLayout()->pageNumberForPoint( cursorPosition );
#endif
QPointF pagePosition = position;
int currentPage = 1;

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: %1" ) ).arg( currentPage ) );
}

QgsLayoutView *QgsLayoutDesignerDialog::view()
{
return mView;
@@ -28,6 +28,7 @@ class QgsLayoutViewToolZoom;
class QgsLayoutViewToolSelect;
class QComboBox;
class QSlider;
class QLabel;

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

//! Updates cursor position in status bar
void updateStatusCursorPos( QPointF position );

private:

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

//! Labels in status bar which shows current mouse position
QLabel *mStatusCursorXLabel = nullptr;
QLabel *mStatusCursorYLabel = nullptr;
QLabel *mStatusCursorPageLabel = nullptr;

static QList<double> sStatusZoomLevelsList;

QgsLayoutViewToolAddItem *mAddItemTool = nullptr;
@@ -203,6 +203,9 @@ void QgsLayoutView::mouseMoveEvent( QMouseEvent *event )
{
mMouseCurrentXY = event->pos();

//update cursor position in status bar
emit cursorPosChanged( mapToScene( mMouseCurrentXY ) );

if ( mTool )
{
std::unique_ptr<QgsLayoutViewMouseEvent> me( new QgsLayoutViewMouseEvent( this, event ) );
@@ -172,6 +172,13 @@ class GUI_EXPORT QgsLayoutView: public QGraphicsView
*/
void zoomLevelChanged();

/**
* Is emitted when the mouse cursor coordinates change within the view.
* The \a layoutPoint argument indicates the cursor position within
* the layout coordinate system.
*/
void cursorPosChanged( QPointF layoutPoint );

protected:
void mousePressEvent( QMouseEvent *event ) override;
void mouseReleaseEvent( QMouseEvent *event ) override;

0 comments on commit c25aab1

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