Skip to content

Commit

Permalink
Made the zoom actions also functional in the tileset editor
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn committed Nov 1, 2016
1 parent 9cf8f68 commit 4a936bb
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/tiled/editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ namespace Tiled {
namespace Internal {

class Document;
class Zoomable;

class Editor : public QObject
{
Expand All @@ -48,6 +49,7 @@ class Editor : public QObject
virtual Document *currentDocument() const = 0;

virtual QWidget *editorWidget() const = 0;
virtual Zoomable *zoomable() const = 0;

virtual QList<QToolBar*> toolBars() const = 0;
virtual QList<QDockWidget*> dockWidgets() const = 0;
Expand Down
49 changes: 34 additions & 15 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
, mActionManager(new ActionManager)
, mUi(new Ui::MainWindow)
, mDocument(nullptr)
, mActionHandler(new MapDocumentActionHandler(this))
, mConsoleDock(new ConsoleDock(this))
, mObjectTypesEditor(new ObjectTypesEditor(this))
Expand Down Expand Up @@ -441,6 +440,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
mActionHandler, SLOT(copyPosition()));

updateActions();
updateZoomActions();
readSettings();

connect(mAutomappingManager, SIGNAL(warningsOccurred(bool)),
Expand Down Expand Up @@ -1120,20 +1120,20 @@ void MainWindow::labelVisibilityActionTriggered(QAction *action)

void MainWindow::zoomIn()
{
if (MapView *mapView = mDocumentManager->currentMapView())
mapView->zoomable()->zoomIn();
if (mZoomable)
mZoomable->zoomIn();
}

void MainWindow::zoomOut()
{
if (MapView *mapView = mDocumentManager->currentMapView())
mapView->zoomable()->zoomOut();
if (mZoomable)
mZoomable->zoomOut();
}

void MainWindow::zoomNormal()
{
if (MapView *mapView = mDocumentManager->currentMapView())
mapView->zoomable()->resetZoom();
if (mZoomable)
mZoomable->resetZoom();
}

void MainWindow::setFullScreen(bool fullScreen)
Expand Down Expand Up @@ -1501,19 +1501,38 @@ void MainWindow::updateActions()
mLayerMenu->menuAction()->setVisible(mapDocument);

// mCommandButton->setEnabled(mapDocument);
}

updateZoomActions();
void MainWindow::updateZoomable()
{
Zoomable *zoomable = nullptr;
if (auto editor = mDocumentManager->currentEditor())
zoomable = editor->zoomable();

if (zoomable != mZoomable) {
if (mZoomable)
mZoomable->disconnect(this);

mZoomable = zoomable;

if (zoomable) {
connect(zoomable, &Zoomable::scaleChanged, this, &MainWindow::updateZoomActions);
connect(zoomable, &Zoomable::destroyed, this, [=] {
if (mZoomable == zoomable)
mZoomable = nullptr;
});
}

updateZoomActions();
}
}

void MainWindow::updateZoomActions()
{
MapView *mapView = mDocumentManager->currentMapView();

Zoomable *zoomable = mapView ? mapView->zoomable() : nullptr;
const qreal scale = zoomable ? zoomable->scale() : 1;
const qreal scale = mZoomable ? mZoomable->scale() : 1;

mUi->actionZoomIn->setEnabled(zoomable && zoomable->canZoomIn());
mUi->actionZoomOut->setEnabled(zoomable && zoomable->canZoomOut());
mUi->actionZoomIn->setEnabled(mZoomable && mZoomable->canZoomIn());
mUi->actionZoomOut->setEnabled(mZoomable && mZoomable->canZoomOut());
mUi->actionZoomNormal->setEnabled(scale != 1);
}

Expand Down Expand Up @@ -1595,7 +1614,6 @@ void MainWindow::retranslateUi()
{
updateWindowTitle();

// mRandomButton->setToolTip(tr("Random Mode"));
mLayerMenu->setTitle(tr("&Layer"));
mNewLayerMenu->setTitle(tr("&New"));
mViewsAndToolbarsAction->setText(tr("Views and Toolbars"));
Expand Down Expand Up @@ -1632,6 +1650,7 @@ void MainWindow::documentChanged(Document *document)

updateWindowTitle();
updateActions();
updateZoomable();
}

void MainWindow::closeDocument(int index)
Expand Down
5 changes: 4 additions & 1 deletion src/tiled/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class MapView;
class ObjectTypesEditor;
class TmxMapFormat;
class TsxTilesetFormat;
class Zoomable;

/**
* The main editor window.
Expand Down Expand Up @@ -141,6 +142,7 @@ private slots:

void updateWindowTitle();
void updateActions();
void updateZoomable();
void updateZoomActions();
void openDocumentation();
void becomePatron();
Expand Down Expand Up @@ -198,7 +200,8 @@ private slots:

ActionManager *mActionManager;
Ui::MainWindow *mUi;
Document *mDocument;
Document *mDocument = nullptr;
Zoomable *mZoomable = nullptr;
MapDocumentActionHandler *mActionHandler;
ConsoleDock *mConsoleDock;
QDockWidget *mUndoDock;
Expand Down
7 changes: 7 additions & 0 deletions src/tiled/mapeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ MapView *MapEditor::currentMapView() const
return viewForDocument(mCurrentMapDocument);
}

Zoomable *MapEditor::zoomable() const
{
if (auto view = currentMapView())
return view->zoomable();
return nullptr;
}

void MapEditor::showMessage(const QString &text, int timeout)
{
mMainWindow->statusBar()->showMessage(text, timeout);
Expand Down
1 change: 1 addition & 0 deletions src/tiled/mapeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class MapEditor : public Editor

MapView *viewForDocument(MapDocument *mapDocument) const;
MapView *currentMapView() const;
Zoomable *zoomable() const override;

void showMessage(const QString &text, int timeout = 0);

Expand Down
7 changes: 7 additions & 0 deletions src/tiled/tileseteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ Tileset *TilesetEditor::currentTileset() const
return nullptr;
}

Zoomable *TilesetEditor::zoomable() const
{
if (auto view = currentTilesetView())
return view->zoomable();
return nullptr;
}

void TilesetEditor::currentWidgetChanged()
{
auto view = static_cast<TilesetView*>(mWidgetStack->currentWidget());
Expand Down
1 change: 1 addition & 0 deletions src/tiled/tileseteditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class TilesetEditor : public Editor

TilesetView *currentTilesetView() const;
Tileset *currentTileset() const;
Zoomable *zoomable() const override;

TileAnimationEditor *tileAnimationEditor() const;
TileCollisionEditor *tileCollisionEditor() const;
Expand Down

0 comments on commit 4a936bb

Please sign in to comment.