From 1787f95f5727a20a4f0871736ad987fcfdf0f3c6 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 28 Feb 2018 15:47:23 +0100 Subject: SVG viewer example: Improve zoom facility 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 --- examples/svg/svgviewer/mainwindow.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'examples/svg/svgviewer/mainwindow.cpp') 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('%')); +} -- cgit v1.2.1