Skip to content

Commit

Permalink
Projects: Added various missing pieces
Browse files Browse the repository at this point in the history
* Added Recent Projects menu
* Added action to remove a folder from the project
* Added small tool bar at bottom of Project view
* Don't reset project model when adding/removing folders
* Improved suggested file name and location for first project

Issue #1665
  • Loading branch information
bjorn committed Dec 4, 2019
1 parent 5894019 commit e8e83d6
Show file tree
Hide file tree
Showing 13 changed files with 337 additions and 145 deletions.
54 changes: 47 additions & 7 deletions src/tiled/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
, mActionManager(new ActionManager(this))
, mUi(new Ui::MainWindow)
, mActionHandler(new MapDocumentActionHandler(this))
, mConsoleDock(new ConsoleDock(this))
, mProjectDock(new ProjectDock(this))
, mIssuesDock(new IssuesDock(this))
, mObjectTypesEditor(new ObjectTypesEditor(this))
, mAutomappingManager(new AutomappingManager(this))
, mDocumentManager(DocumentManager::instance())
Expand All @@ -226,21 +223,25 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
ActionManager::registerAction(mUi->actionAbout, "About");
ActionManager::registerAction(mUi->actionAboutQt, "AboutQt");
ActionManager::registerAction(mUi->actionAddExternalTileset, "AddExternalTileset");
ActionManager::registerAction(mUi->actionAddFolderToProject, "AddFolderToProject");
ActionManager::registerAction(mUi->actionAutoMap, "AutoMap");
ActionManager::registerAction(mUi->actionAutoMapWhileDrawing, "AutoMapWhileDrawing");
ActionManager::registerAction(mUi->actionDonate, "Donate");
ActionManager::registerAction(mUi->actionClearRecentFiles, "ClearRecentFiles");
ActionManager::registerAction(mUi->actionClearRecentProjects, "ClearRecentProjects");
ActionManager::registerAction(mUi->actionClearView, "ClearView");
ActionManager::registerAction(mUi->actionClose, "Close");
ActionManager::registerAction(mUi->actionCloseAll, "CloseAll");
ActionManager::registerAction(mUi->actionCloseProject, "CloseProject");
ActionManager::registerAction(mUi->actionCopy, "Copy");
ActionManager::registerAction(mUi->actionCut, "Cut");
ActionManager::registerAction(mUi->actionDelete, "Delete");
ActionManager::registerAction(mUi->actionDocumentation, "Documentation");
ActionManager::registerAction(mUi->actionDonate, "Donate");
ActionManager::registerAction(mUi->actionEditCommands, "EditCommands");
ActionManager::registerAction(mUi->actionExport, "Export");
ActionManager::registerAction(mUi->actionExportAs, "ExportAs");
ActionManager::registerAction(mUi->actionExportAsImage, "ExportAsImage");
ActionManager::registerAction(mUi->actionFitInView, "FitInView");
ActionManager::registerAction(mUi->actionFullScreen, "FullScreen");
ActionManager::registerAction(mUi->actionHighlightCurrentLayer, "HighlightCurrentLayer");
ActionManager::registerAction(mUi->actionHighlightHoveredObject, "HighlightHoveredObject");
Expand All @@ -254,15 +255,18 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
ActionManager::registerAction(mUi->actionNoLabels, "NoLabels");
ActionManager::registerAction(mUi->actionOffsetMap, "OffsetMap");
ActionManager::registerAction(mUi->actionOpen, "Open");
ActionManager::registerAction(mUi->actionOpenProject, "OpenProject");
ActionManager::registerAction(mUi->actionPaste, "Paste");
ActionManager::registerAction(mUi->actionPasteInPlace, "PasteInPlace");
ActionManager::registerAction(mUi->actionPreferences, "Preferences");
ActionManager::registerAction(mUi->actionQuit, "Quit");
ActionManager::registerAction(mUi->actionRefreshProjectFolders, "RefreshProjectFolders");
ActionManager::registerAction(mUi->actionReload, "Reload");
ActionManager::registerAction(mUi->actionResizeMap, "ResizeMap");
ActionManager::registerAction(mUi->actionSave, "Save");
ActionManager::registerAction(mUi->actionSaveAll, "SaveAll");
ActionManager::registerAction(mUi->actionSaveAs, "SaveAs");
ActionManager::registerAction(mUi->actionSaveProjectAs, "SaveProjectAs");
ActionManager::registerAction(mUi->actionShowGrid, "ShowGrid");
ActionManager::registerAction(mUi->actionShowTileAnimations, "ShowTileAnimations");
ActionManager::registerAction(mUi->actionShowTileCollisionShapes, "ShowTileCollisionShapes");
Expand All @@ -273,9 +277,8 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
ActionManager::registerAction(mUi->actionSnapToPixels, "SnapToPixels");
ActionManager::registerAction(mUi->actionTilesetProperties, "TilesetProperties");
ActionManager::registerAction(mUi->actionZoomIn, "ZoomIn");
ActionManager::registerAction(mUi->actionZoomOut, "ZoomOut");
ActionManager::registerAction(mUi->actionZoomNormal, "ZoomNormal");
ActionManager::registerAction(mUi->actionFitInView, "FitInView");
ActionManager::registerAction(mUi->actionZoomOut, "ZoomOut");

#ifdef Q_OS_MAC
MacSupport::addFullscreen(this);
Expand Down Expand Up @@ -341,6 +344,10 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
ActionManager::registerAction(undoAction, "Undo");
ActionManager::registerAction(redoAction, "Redo");

mProjectDock = new ProjectDock(this); // uses some actions registered above
mConsoleDock = new ConsoleDock(this);
mIssuesDock = new IssuesDock(this);

addDockWidget(Qt::LeftDockWidgetArea, mProjectDock);
addDockWidget(Qt::BottomDockWidgetArea, mConsoleDock);
addDockWidget(Qt::BottomDockWidgetArea, mIssuesDock);
Expand Down Expand Up @@ -572,6 +579,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
connect(mUi->actionCloseProject, &QAction::triggered, mProjectDock, &ProjectDock::closeProject);
connect(mUi->actionAddFolderToProject, &QAction::triggered, mProjectDock, &ProjectDock::addFolderToProject);
connect(mUi->actionRefreshProjectFolders, &QAction::triggered, mProjectDock, &ProjectDock::refreshProjectFolders);
connect(mUi->actionClearRecentProjects, &QAction::triggered, preferences, &Preferences::clearRecentProjects);

connect(mUi->actionDocumentation, &QAction::triggered, this, &MainWindow::openDocumentation);
connect(mUi->actionForum, &QAction::triggered, this, &MainWindow::openForum);
Expand All @@ -591,14 +599,14 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
this, &MainWindow::openRecentFile);
}
mUi->menuRecentFiles->insertSeparator(mUi->actionClearRecentFiles);
mUi->menuRecentFiles->setToolTipsVisible(true);

connect(mProjectDock, &ProjectDock::projectFileNameChanged, this, &MainWindow::updateWindowTitle);

setThemeIcon(mUi->menuNew, "document-new");
setThemeIcon(mUi->actionOpen, "document-open");
setThemeIcon(mUi->menuRecentFiles, "document-open-recent");
setThemeIcon(mUi->actionClearRecentFiles, "edit-clear");
setThemeIcon(mUi->actionClearRecentProjects, "edit-clear");
setThemeIcon(mUi->actionSave, "document-save");
setThemeIcon(mUi->actionSaveAs, "document-save-as");
setThemeIcon(mUi->actionClose, "window-close");
Expand All @@ -616,6 +624,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
setThemeIcon(mUi->actionResizeMap, "document-page-setup");
setThemeIcon(mUi->actionMapProperties, "document-properties");
setThemeIcon(mUi->actionOpenProject, "document-open");
setThemeIcon(mUi->menuRecentProjects, "document-open-recent");
setThemeIcon(mUi->actionSaveProjectAs, "document-save-as");
setThemeIcon(mUi->actionCloseProject, "window-close");
setThemeIcon(mUi->actionAddFolderToProject, "folder-new");
Expand Down Expand Up @@ -715,6 +724,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags)
#endif

connect(preferences, &Preferences::recentFilesChanged, this, &MainWindow::updateRecentFilesMenu);
connect(preferences, &Preferences::recentProjectsChanged, this, &MainWindow::updateRecentProjectsMenu);

QTimer::singleShot(500, this, [this,preferences] {
if (preferences->shouldShowDonationDialog())
Expand Down Expand Up @@ -1489,6 +1499,13 @@ void MainWindow::openRecentFile()
openFile(action->data().toString());
}

void MainWindow::openRecentProject()
{
QAction *action = qobject_cast<QAction *>(sender());
if (action)
mProjectDock->openProjectFile(action->data().toString());
}

/**
* Updates the recent files menu.
*/
Expand All @@ -1511,14 +1528,35 @@ void MainWindow::updateRecentFilesMenu()
mUi->menuRecentFiles->setEnabled(numRecentFiles > 0);
}

void MainWindow::updateRecentProjectsMenu()
{
auto menu = mUi->menuRecentProjects;
menu->clear();

const QStringList files = Preferences::instance()->recentProjects();

for (const QString &file : files) {
const QFileInfo fileInfo(file);
auto action = menu->addAction(fileInfo.fileName(), this, &MainWindow::openRecentProject);
action->setData(file);
action->setToolTip(fileInfo.filePath());
}

menu->addSeparator();
menu->addAction(mUi->actionClearRecentProjects);
menu->setEnabled(!files.isEmpty());
}

void MainWindow::resetToDefaultLayout()
{
// Make sure we're not in Clear View mode
mUi->actionClearView->setChecked(false);

// Reset the Console and Issues dock
addDockWidget(Qt::LeftDockWidgetArea, mProjectDock);
addDockWidget(Qt::BottomDockWidgetArea, mConsoleDock);
addDockWidget(Qt::BottomDockWidgetArea, mIssuesDock);
mProjectDock->setVisible(true);
mConsoleDock->setVisible(false);
mIssuesDock->setVisible(false);
tabifyDockWidget(mConsoleDock, mIssuesDock);
Expand All @@ -1531,6 +1569,7 @@ void MainWindow::updateViewsAndToolbarsMenu()
{
mViewsAndToolbarsMenu->clear();

mViewsAndToolbarsMenu->addAction(mProjectDock->toggleViewAction());
mViewsAndToolbarsMenu->addAction(mConsoleDock->toggleViewAction());
mViewsAndToolbarsMenu->addAction(mIssuesDock->toggleViewAction());

Expand Down Expand Up @@ -1678,6 +1717,7 @@ void MainWindow::readSettings()
QByteArray()).toByteArray());
mSettings.endGroup();
updateRecentFilesMenu();
updateRecentProjectsMenu();

auto &worldManager = WorldManager::instance();
const QStringList worldFiles = mSettings.value(QLatin1String("LoadedWorlds")).toStringList();
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class MainWindow : public QMainWindow
void showDonationDialog();
void aboutTiled();
void openRecentFile();
void openRecentProject();

void documentChanged(Document *document);
void documentSaved(Document *document);
Expand Down Expand Up @@ -193,6 +194,7 @@ class MainWindow : public QMainWindow
void readSettings();

void updateRecentFilesMenu();
void updateRecentProjectsMenu();
void updateViewsAndToolbarsMenu();

void retranslateUi();
Expand Down
21 changes: 21 additions & 0 deletions src/tiled/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<iconset resource="tiled.qrc">
<normaloff>:/images/16/document-open-recent.png</normaloff>:/images/16/document-open-recent.png</iconset>
</property>
<property name="toolTipsVisible">
<bool>true</bool>
</property>
<addaction name="actionClearRecentFiles"/>
</widget>
<widget class="QMenu" name="menuNew">
Expand Down Expand Up @@ -181,7 +184,21 @@
<property name="title">
<string>&amp;Project</string>
</property>
<widget class="QMenu" name="menuRecentProjects">
<property name="title">
<string>&amp;Recent Projects</string>
</property>
<property name="icon">
<iconset resource="tiled.qrc">
<normaloff>:/images/16/document-open-recent.png</normaloff>:/images/16/document-open-recent.png</iconset>
</property>
<property name="toolTipsVisible">
<bool>true</bool>
</property>
</widget>
<addaction name="actionOpenProject"/>
<addaction name="menuRecentProjects"/>
<addaction name="separator"/>
<addaction name="actionSaveProjectAs"/>
<addaction name="actionCloseProject"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -678,6 +695,10 @@
</property>
</action>
<action name="actionClearRecentProjects">
<property name="icon">
<iconset resource="tiled.qrc">
<normaloff>:/images/16/edit-clear.png</normaloff>:/images/16/edit-clear.png</iconset>
</property>
<property name="text">
<string>Clear Recent Projects</string>
</property>
Expand Down
47 changes: 40 additions & 7 deletions src/tiled/mapsdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@
#include <QLineEdit>
#include <QMouseEvent>
#include <QPushButton>
#include <QTreeView>

using namespace Tiled;
namespace Tiled {

/**
* Class represents the file system model with disabled dragging of directories.
Expand All @@ -58,6 +59,38 @@ class FileSystemModel : public QFileSystemModel
}
};

/**
* Shows the list of files and directories.
*/
class MapsView : public QTreeView
{
Q_OBJECT

public:
MapsView(QWidget *parent = nullptr);

/**
* Returns a sensible size hint.
*/
QSize sizeHint() const override;

QFileSystemModel *model() const { return mFileSystemModel; }

protected:
void mousePressEvent(QMouseEvent *event) override;

private:
void onMapsDirectoryChanged();
void onActivated(const QModelIndex &index);

void pluginObjectAddedOrRemoved(QObject *object);

void updateNameFilters();

QFileSystemModel *mFileSystemModel;
};


MapsDock::MapsDock(QWidget *parent)
: QDockWidget(parent)
, mDirectoryEdit(new QLineEdit)
Expand Down Expand Up @@ -152,7 +185,6 @@ MapsView::MapsView(QWidget *parent)
setHeaderHidden(true);
setItemsExpandable(false);
setUniformRowHeights(true);
setDragEnabled(true);
setDefaultDropAction(Qt::MoveAction);

Preferences *prefs = Preferences::instance();
Expand Down Expand Up @@ -198,11 +230,8 @@ QSize MapsView::sizeHint() const

void MapsView::mousePressEvent(QMouseEvent *event)
{
QModelIndex index = indexAt(event->pos());
if (index.isValid()) {
// Prevent drag-and-drop starting when clicking on an unselected item.
setDragEnabled(selectionModel()->isSelected(index));
}
// Prevent drag-and-drop starting when clicking on an unselected item.
setDragEnabled(selectionModel()->isSelected(indexAt(event->pos())));

QTreeView::mousePressEvent(event);
}
Expand Down Expand Up @@ -252,3 +281,7 @@ void MapsView::updateNameFilters()

mFileSystemModel->setNameFilters(nameFilters);
}

} // namespace Tiled

#include "mapsdock.moc"
33 changes: 0 additions & 33 deletions src/tiled/mapsdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
#pragma once

#include <QDockWidget>
#include <QTreeView>

class QFileSystemModel;
class QLineEdit;

namespace Tiled {
Expand Down Expand Up @@ -51,35 +49,4 @@ class MapsDock : public QDockWidget
MapsView *mMapsView;
};

/**
* Shows the list of files and directories.
*/
class MapsView : public QTreeView
{
Q_OBJECT

public:
MapsView(QWidget *parent = nullptr);

/**
* Returns a sensible size hint.
*/
QSize sizeHint() const override;

QFileSystemModel *model() const { return mFileSystemModel; }

protected:
void mousePressEvent(QMouseEvent *event) override;

private:
void onMapsDirectoryChanged();
void onActivated(const QModelIndex &index);

void pluginObjectAddedOrRemoved(QObject *object);

void updateNameFilters();

QFileSystemModel *mFileSystemModel;
};

} // namespace Tiled
Loading

0 comments on commit e8e83d6

Please sign in to comment.