|
82 | 82 | #include <QDesktopServices> |
83 | 83 | #include <QFileDialog> |
84 | 84 | #include <QLabel> |
| 85 | +#include <QLineEdit> |
85 | 86 | #include <QMessageBox> |
86 | 87 | #include <QMimeData> |
87 | 88 | #include <QRegularExpression> |
88 | 89 | #include <QShortcut> |
| 90 | +#include <QSlider> |
89 | 91 | #include <QStandardPaths> |
90 | 92 | #include <QStatusBar> |
91 | 93 | #include <QTextStream> |
@@ -754,6 +756,47 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) |
754 | 756 | myStatusBar->addPermanentWidget(mNewsButton); |
755 | 757 | myStatusBar->addPermanentWidget(new NewVersionButton(NewVersionButton::AutoVisible, myStatusBar)); |
756 | 758 |
|
| 759 | + // Zoom controls in the status bar (slider + percentage, with +/- buttons) |
| 760 | + mZoomOutButton = new QToolButton(myStatusBar); |
| 761 | + mZoomOutButton->setText(QStringLiteral("-")); |
| 762 | + mZoomOutButton->setAutoRaise(true); |
| 763 | + |
| 764 | + mZoomInButton = new QToolButton(myStatusBar); |
| 765 | + mZoomInButton->setText(QStringLiteral("+")); |
| 766 | + mZoomInButton->setAutoRaise(true); |
| 767 | + |
| 768 | + mZoomSlider = new QSlider(Qt::Horizontal); |
| 769 | + mZoomSlider->setRange(10, 3200); // 10% to 3200% zoom |
| 770 | + mZoomSlider->setFixedWidth(Utils::dpiScaled(100)); |
| 771 | + mZoomSlider->setToolTip(tr("Zoom Level")); |
| 772 | + |
| 773 | + mZoomEdit = new QLineEdit; |
| 774 | + mZoomEdit->setFixedWidth(Utils::dpiScaled(50)); |
| 775 | + mZoomEdit->setAlignment(Qt::AlignCenter); |
| 776 | + mZoomEdit->setToolTip(tr("Current Zoom Percentage")); |
| 777 | + |
| 778 | + connect(mZoomSlider, &QSlider::valueChanged, this, [this](int value) { |
| 779 | + if (mZoomable) |
| 780 | + mZoomable->setScale(value / 100.0); |
| 781 | + }); |
| 782 | + |
| 783 | + connect(mZoomEdit, &QLineEdit::returnPressed, this, [this]() { |
| 784 | + QString text = mZoomEdit->text().remove(QLatin1Char('%')).trimmed(); |
| 785 | + bool ok; |
| 786 | + int value = text.toInt(&ok); |
| 787 | + if (ok) { |
| 788 | + if (mZoomable) |
| 789 | + mZoomable->setScale(value / 100.0); |
| 790 | + else if (mZoomSlider) |
| 791 | + mZoomSlider->setValue(value); |
| 792 | + } |
| 793 | + }); |
| 794 | + |
| 795 | + statusBar()->addPermanentWidget(mZoomOutButton); |
| 796 | + statusBar()->addPermanentWidget(mZoomSlider); |
| 797 | + statusBar()->addPermanentWidget(mZoomInButton); |
| 798 | + statusBar()->addPermanentWidget(mZoomEdit); |
| 799 | + |
757 | 800 | QIcon terminalIcon(QLatin1String("://images/24/terminal.png")); |
758 | 801 | terminalIcon.addFile(QLatin1String("://images/16/terminal.png")); |
759 | 802 | terminalIcon.addFile(QLatin1String("://images/32/terminal.png")); |
@@ -788,6 +831,33 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) |
788 | 831 | myStatusBar->addWidget(consoleToggleButton); |
789 | 832 | myStatusBar->addWidget(issuesCounter); |
790 | 833 |
|
| 834 | + // Connect zoom controls to existing zoom actions / Zoomable |
| 835 | + connect(mZoomOutButton, &QToolButton::clicked, |
| 836 | + this, &MainWindow::zoomOut); |
| 837 | + connect(mZoomInButton, &QToolButton::clicked, |
| 838 | + this, &MainWindow::zoomIn); |
| 839 | + |
| 840 | + connect(mZoomSlider, &QSlider::valueChanged, this, [this](int value) { |
| 841 | + if (!mZoomable) |
| 842 | + return; |
| 843 | + const qreal scale = value / 100.0; |
| 844 | + mZoomable->setScale(scale); |
| 845 | + }); |
| 846 | + |
| 847 | + connect(mZoomEdit, &QLineEdit::returnPressed, this, [this]() { |
| 848 | + if (!mZoomable) |
| 849 | + return; |
| 850 | + |
| 851 | + QString text = mZoomEdit->text().remove(QLatin1Char('%')).trimmed(); |
| 852 | + bool ok = false; |
| 853 | + int percent = text.toInt(&ok); |
| 854 | + if (!ok) |
| 855 | + return; |
| 856 | + |
| 857 | + percent = qBound(mZoomSlider->minimum(), percent, mZoomSlider->maximum()); |
| 858 | + mZoomable->setScale(percent / 100.0); |
| 859 | + }); |
| 860 | + |
791 | 861 | // Add the 'Views and Toolbars' submenu. This needs to happen after all |
792 | 862 | // the dock widgets and toolbars have been added to the main window. |
793 | 863 | mViewsAndToolbarsMenu = new QMenu(this); |
@@ -2268,6 +2338,19 @@ void MainWindow::updateZoomActions() |
2268 | 2338 | mUi->actionZoomOut->setEnabled(mZoomable && mZoomable->canZoomOut()); |
2269 | 2339 | mUi->actionZoomNormal->setEnabled(scale != 1); |
2270 | 2340 | mUi->actionFitInView->setEnabled(mDocument && mDocument->type() == Document::MapDocumentType); |
| 2341 | + |
| 2342 | + const int percent = qRound(scale * 100); |
| 2343 | + |
| 2344 | + if (mZoomSlider) { |
| 2345 | + mZoomSlider->blockSignals(true); |
| 2346 | + mZoomSlider->setValue(qBound(mZoomSlider->minimum(), |
| 2347 | + percent, |
| 2348 | + mZoomSlider->maximum())); |
| 2349 | + mZoomSlider->blockSignals(false); |
| 2350 | + } |
| 2351 | + |
| 2352 | + if (mZoomEdit) |
| 2353 | + mZoomEdit->setText(QStringLiteral("%1 %").arg(percent)); |
2271 | 2354 | } |
2272 | 2355 |
|
2273 | 2356 | void MainWindow::openDocumentation() |
|
0 commit comments