diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-02-28 15:47:23 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2018-03-01 10:36:15 +0000 |
commit | 1787f95f5727a20a4f0871736ad987fcfdf0f3c6 (patch) | |
tree | a1a4f2655416104d6c18b7a5398d4d574552cb3e /examples/svg/svgviewer/mainwindow.cpp | |
parent | d4addd30de02c1afd5f93cbc2319bd3bdaed9588 (diff) |
SVG viewer example: Improve zoom facilityv5.11.0-beta3v5.11.0-beta2
Add a label displaying the current zoom with
a tooltip.
Add menu actions for ZoomIn/ZoomOut and Reset.
Task-number: QTBUG-60653
Change-Id: I7569427345737024b7a3191677e54c83673bb40e
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'examples/svg/svgviewer/mainwindow.cpp')
-rw-r--r-- | examples/svg/svgviewer/mainwindow.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/svg/svgviewer/mainwindow.cpp b/examples/svg/svgviewer/mainwindow.cpp index 8cb94d2..7dd240a 100644 --- a/examples/svg/svgviewer/mainwindow.cpp +++ b/examples/svg/svgviewer/mainwindow.cpp @@ -64,6 +64,7 @@ static inline QString picturesLocation() MainWindow::MainWindow() : QMainWindow() , m_view(new SvgView) + , m_zoomLabel(new QLabel) { QToolBar *toolBar = new QToolBar(this); addToolBar(Qt::TopToolBarArea, toolBar); @@ -94,6 +95,14 @@ MainWindow::MainWindow() m_outlineAction->setChecked(true); connect(m_outlineAction, &QAction::toggled, m_view, &SvgView::setViewOutline); + viewMenu->addSeparator(); + QAction *zoomAction = viewMenu->addAction(tr("Zoom &In"), m_view, &SvgView::zoomIn); + zoomAction->setShortcut(QKeySequence::ZoomIn); + zoomAction = viewMenu->addAction(tr("Zoom &Out"), m_view, &SvgView::zoomOut); + zoomAction->setShortcut(QKeySequence::ZoomOut); + zoomAction = viewMenu->addAction(tr("Reset Zoom"), m_view, &SvgView::resetZoom); + zoomAction->setShortcut(Qt::CTRL + Qt::Key_0); + QMenu *rendererMenu = menuBar()->addMenu(tr("&Renderer")); m_nativeAction = rendererMenu->addAction(tr("&Native")); m_nativeAction->setCheckable(true); @@ -134,6 +143,11 @@ MainWindow::MainWindow() help->addAction(tr("About Qt"), qApp, &QApplication::aboutQt); setCentralWidget(m_view); + + m_zoomLabel->setToolTip(tr("Use the mouse wheel to zoom")); + statusBar()->addPermanentWidget(m_zoomLabel); + updateZoomLabel(); + connect(m_view, &SvgView::zoomChanged, this, &MainWindow::updateZoomLabel); } void MainWindow::openFile() @@ -221,3 +235,9 @@ void MainWindow::exportImage() } } } + +void MainWindow::updateZoomLabel() +{ + const int percent = qRound(m_view->zoomFactor() * qreal(100)); + m_zoomLabel->setText(QString::number(percent) + QLatin1Char('%')); +} |