Skip to content

Commit f2df507

Browse files
bjornAayushmaan-24
authored andcommitted
Moved zoom controls (zoom in/out, slider, and text field) to the main
window status bar to provide a consistent zoom experience across all editors. - Removed QComboBox-based zoom controls from Map Editor, Tileset Editor, Tileset Dock, Tile Collision Dock, and Tile Animation Editor. - Added QSlider and QLineEdit to MainWindow for global zoom management. - Synchronized global zoom controls with the active editor's zoom level. - Cleaned up redundant zoom-related code in various editor components.
1 parent 8f704ff commit f2df507

File tree

11 files changed

+98
-41
lines changed

11 files changed

+98
-41
lines changed

appveyor.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ environment:
2121
QTDIR: C:\Qt\6.10.2\msvc2022_64
2222
PYTHONHOME: C:\Python312-x64
2323
DEFAULT_PROFILE: MSVC2022-x64
24+
FILE_SUFFIX: Windows-10+_msvc_x86_64
2425
PUSH_RELEASE: false
2526
ENABLE_ZSTD: false
2627
- QT_VERSION: 5.15.2
@@ -31,6 +32,7 @@ environment:
3132
MINGW: C:\Qt\Tools\mingw810_32
3233
MINGW_COMPONENT: tools_mingw
3334
MINGW_VARIANT: qt.tools.win32_mingw810
35+
FILE_SUFFIX: Windows-7-8_x86
3436
PUSH_RELEASE: true
3537
ENABLE_ZSTD: true
3638
CC: i686-w64-mingw32-gcc.exe
@@ -43,6 +45,7 @@ environment:
4345
MINGW: C:\Qt\Tools\mingw1310_64
4446
MINGW_COMPONENT: tools_mingw1310
4547
MINGW_VARIANT: qt.tools.win64_mingw1310
48+
FILE_SUFFIX: Windows-10+_x86_64
4649
PUSH_RELEASE: true
4750
ENABLE_ZSTD: true
4851
CC: x86_64-w64-mingw32-gcc.exe
@@ -96,15 +99,15 @@ build_script:
9699
after_build:
97100
- cd release
98101
- cd installer*
99-
- move tiled-*.msi %APPVEYOR_BUILD_FOLDER%
102+
- move tiled-*.msi %APPVEYOR_BUILD_FOLDER%\Tiled-%TILED_VERSION%_%FILE_SUFFIX%.msi
100103
- cd ..
101104
- cd archive*
102105
- move tiled-*.7z %APPVEYOR_BUILD_FOLDER%
103106
- cd ..\..
104107

105108
artifacts:
106109
- name: Installer
107-
path: 'tiled-*.msi'
110+
path: 'Tiled-*.msi'
108111
- name: Archive
109112
path: 'tiled-*.7z'
110113

src/tiled/mainwindow.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@
8282
#include <QDesktopServices>
8383
#include <QFileDialog>
8484
#include <QLabel>
85+
#include <QLineEdit>
8586
#include <QMessageBox>
8687
#include <QMimeData>
8788
#include <QRegularExpression>
8889
#include <QShortcut>
90+
#include <QSlider>
8991
#include <QStandardPaths>
9092
#include <QStatusBar>
9193
#include <QTextStream>
@@ -754,6 +756,47 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
754756
myStatusBar->addPermanentWidget(mNewsButton);
755757
myStatusBar->addPermanentWidget(new NewVersionButton(NewVersionButton::AutoVisible, myStatusBar));
756758

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+
757800
QIcon terminalIcon(QLatin1String("://images/24/terminal.png"));
758801
terminalIcon.addFile(QLatin1String("://images/16/terminal.png"));
759802
terminalIcon.addFile(QLatin1String("://images/32/terminal.png"));
@@ -788,6 +831,33 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
788831
myStatusBar->addWidget(consoleToggleButton);
789832
myStatusBar->addWidget(issuesCounter);
790833

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+
791861
// Add the 'Views and Toolbars' submenu. This needs to happen after all
792862
// the dock widgets and toolbars have been added to the main window.
793863
mViewsAndToolbarsMenu = new QMenu(this);
@@ -2268,6 +2338,19 @@ void MainWindow::updateZoomActions()
22682338
mUi->actionZoomOut->setEnabled(mZoomable && mZoomable->canZoomOut());
22692339
mUi->actionZoomNormal->setEnabled(scale != 1);
22702340
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));
22712354
}
22722355

22732356
void MainWindow::openDocumentation()

src/tiled/mainwindow.h

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

3739
class QComboBox;
3840
class QLabel;
@@ -267,6 +269,12 @@ class TILED_EDITOR_EXPORT MainWindow : public QMainWindow
267269
QList<QWidget*> mEditorStatusBarWidgets;
268270
QToolButton *mNewsButton;
269271

272+
// Zoom controls in the status bar
273+
QToolButton *mZoomOutButton = nullptr;
274+
QToolButton *mZoomInButton = nullptr;
275+
QSlider *mZoomSlider = nullptr;
276+
QLineEdit *mZoomEdit = nullptr;
277+
270278
QPointer<PreferencesDialog> mPreferencesDialog;
271279

272280
QMap<QMainWindow*, QByteArray> mMainWindowStates;

src/tiled/mapeditor.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
#include "worldmanager.h"
7979
#include "worldmovemaptool.h"
8080

81-
#include <QComboBox>
8281
#include <QDialogButtonBox>
8382
#include <QHBoxLayout>
8483
#include <QIdentityProxyModel>
@@ -152,7 +151,6 @@ MapEditor::MapEditor(QObject *parent)
152151
, mComboBoxProxyModel(new ComboBoxProxyModel(this))
153152
, mReversingProxyModel(new ReversingProxyModel(this))
154153
, mZoomable(nullptr)
155-
, mZoomComboBox(new QComboBox)
156154
, mStatusInfoLabel(new QLabel)
157155
, mMainToolBar(new MainToolBar(mMainWindow))
158156
, mToolManager(new ToolManager(this))
@@ -395,7 +393,6 @@ void MapEditor::setCurrentDocument(Document *document)
395393
mLayerDock->setMapDocument(mapDocument);
396394

397395
if (mZoomable) {
398-
mZoomable->setComboBox(nullptr);
399396
mZoomable = nullptr;
400397
}
401398

@@ -416,7 +413,6 @@ void MapEditor::setCurrentDocument(Document *document)
416413

417414
if (mapView) {
418415
mZoomable = mapView->zoomable();
419-
mZoomable->setComboBox(mZoomComboBox.get());
420416
}
421417

422418
connect(mCurrentMapDocument, &MapDocument::currentObjectSet,
@@ -498,8 +494,7 @@ QList<QWidget *> MapEditor::statusBarWidgets() const
498494
QList<QWidget *> MapEditor::permanentStatusBarWidgets() const
499495
{
500496
return {
501-
mLayerComboBox.get(),
502-
mZoomComboBox.get()
497+
mLayerComboBox.get()
503498
};
504499
}
505500

src/tiled/mapeditor.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ class MapEditor final : public Editor
198198
ReversingProxyModel *mReversingProxyModel;
199199

200200
Zoomable *mZoomable;
201-
std::unique_ptr<QComboBox> mZoomComboBox;
202201
std::unique_ptr<QLabel> mStatusInfoLabel;
203202

204203
StampBrush *mStampBrush;

src/tiled/tileanimationeditor.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ TileAnimationEditor::TileAnimationEditor(QWidget *parent)
287287

288288
mUi->frameList->setModel(mFrameListModel);
289289
mUi->tilesetView->setMarkAnimatedTiles(false);
290-
mUi->tilesetView->zoomable()->setComboBox(mUi->zoomComboBox);
291290
mUi->frameTime->setValue(mFrameListModel->defaultDuration());
292291

293292
mUi->frameList->setContextMenuPolicy(Qt::CustomContextMenu);

src/tiled/tilecollisiondock.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,11 @@ TileCollisionDock::TileCollisionDock(QWidget *parent)
193193
objectsViewIcon.addFile(QLatin1String("://images/32/layer-object.png"));
194194

195195
auto objectsViewButton = new QToolButton;
196-
objectsViewButton->setMenu(objectsViewMenu);
197-
objectsViewButton->setPopupMode(QToolButton::InstantPopup);
198-
objectsViewButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
199-
objectsViewButton->setAutoRaise(true);
200-
objectsViewButton->setIcon(objectsViewIcon);
201-
objectsViewButton->setToolTip(tr("Objects list"));
202-
203-
QComboBox *zoomComboBox = new QComboBox;
204-
mMapView->zoomable()->setComboBox(zoomComboBox);
205196

206197
auto rightToolBar = new QToolBar;
207198
rightToolBar->setIconSize(Utils::smallIconSize());
208199
rightToolBar->addWidget(objectsViewButton);
209200
rightToolBar->addSeparator();
210-
rightToolBar->addWidget(zoomComboBox);
211201

212202
auto horizontal = new QHBoxLayout;
213203
horizontal->setSpacing(Utils::dpiScaled(5));

src/tiled/tilesetdock.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,18 +287,8 @@ TilesetDock::TilesetDock(QWidget *parent)
287287
stretch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
288288

289289
mToolBar->setIconSize(Utils::smallIconSize());
290-
mToolBar->addAction(mNewTileset);
291-
mToolBar->addAction(mEmbedTileset);
292-
mToolBar->addAction(mExportTileset);
293-
mToolBar->addAction(mEditTileset);
294-
mToolBar->addAction(mReplaceTileset);
295-
mToolBar->addAction(mRemoveTileset);
296-
mToolBar->addWidget(stretch);
297290
mToolBar->addAction(mDynamicWrappingToggle);
298291

299-
mZoomComboBox = new QComboBox;
300-
horizontal->addWidget(mZoomComboBox);
301-
302292
connect(mViewStack, &QStackedWidget::currentChanged,
303293
this, &TilesetDock::onCurrentTilesetChanged);
304294

@@ -482,8 +472,6 @@ void TilesetDock::onCurrentTilesetChanged()
482472
if (!mSynchronizingSelection)
483473
updateCurrentTiles();
484474

485-
view->zoomable()->setComboBox(mZoomComboBox);
486-
487475
if (const QItemSelectionModel *s = view->selectionModel()) {
488476
QScopedValueRollback<bool> noChangeCurrentObject(mNoChangeCurrentObject, true);
489477
setCurrentTile(view->tilesetModel()->tileAt(s->currentIndex()));

src/tiled/tilesetdock.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,6 @@ class TilesetDock : public QDockWidget
205205
QActionGroup *mTilesetActionGroup;
206206
QAction *mShowTilesetFilter;
207207

208-
QComboBox *mZoomComboBox;
209-
210208
bool mEmittingStampCaptured = false;
211209
bool mSynchronizingSelection = false;
212210
bool mNoChangeCurrentObject = false;

src/tiled/tileseteditor.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060

6161
#include <QAction>
6262
#include <QCheckBox>
63-
#include <QComboBox>
6463
#include <QCoreApplication>
6564
#include <QDropEvent>
6665
#include <QFileDialog>
@@ -144,7 +143,6 @@ TilesetEditor::TilesetEditor(QObject *parent)
144143
, mTileCollisionDock(new TileCollisionDock(mMainWindow))
145144
, mTemplatesDock(new TemplatesDock(mMainWindow))
146145
, mWangDock(new WangDock(mMainWindow))
147-
, mZoomComboBox(new QComboBox)
148146
, mStatusInfoLabel(new QLabel)
149147
{
150148
mMainWindow->setDockOptions(mMainWindow->dockOptions() | QMainWindow::GroupedDragging);
@@ -357,7 +355,6 @@ void TilesetEditor::setCurrentDocument(Document *document)
357355

358356
mWidgetStack->setCurrentWidget(tilesetView);
359357
tilesetView->setEditWangSet(mWangDock->isVisible());
360-
tilesetView->zoomable()->setComboBox(mZoomComboBox);
361358
}
362359

363360
mPropertiesDock->setDocument(document);
@@ -419,9 +416,7 @@ QList<QWidget *> TilesetEditor::statusBarWidgets() const
419416

420417
QList<QWidget *> TilesetEditor::permanentStatusBarWidgets() const
421418
{
422-
return {
423-
mZoomComboBox
424-
};
419+
return {};
425420
}
426421

427422
Editor::StandardActions TilesetEditor::enabledStandardActions() const

0 commit comments

Comments
 (0)