Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'New Tileset...' button when no tileset is opened #1789

Merged
merged 8 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion src/tiled/tilesetdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <QComboBox>
#include <QDropEvent>
#include <QFileDialog>
#include <QPushButton>
#include <QHBoxLayout>
#include <QMenu>
#include <QMessageBox>
Expand All @@ -73,6 +74,21 @@ using namespace Tiled::Internal;

namespace {

class NewTilesetView : public QWidget
{
public:
explicit NewTilesetView(TilesetDock *parent = nullptr)
: QWidget(parent)
{
QWidget *w = new QWidget(this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This widget serves no purpose apart from adding just another level to the widget hierarchy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I'll take a look at all of that.

I tried to center the button, but everything I tried didn't work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You basically just need spacer items on all 4 sides for centering the button, and for that it needs to be in a grid layout.


QPushButton *newTilesetButton = new QPushButton(w);
newTilesetButton->setText(QStringLiteral("New Tileset..."));

connect(newTilesetButton, SIGNAL(released()), parent, SLOT(newTileset()));
}
};

class TilesetMenuButton : public QToolButton
{
public:
Expand Down Expand Up @@ -154,6 +170,7 @@ TilesetDock::TilesetDock(QWidget *parent)
, mMapDocument(nullptr)
, mTilesetDocumentsFilterModel(new TilesetDocumentsFilterModel(this))
, mTabBar(new WheelEnabledTabBar)
, mSuperViewStack(new QStackedWidget)
, mViewStack(new QStackedWidget)
, mToolBar(new QToolBar)
, mCurrentTile(nullptr)
Expand Down Expand Up @@ -189,7 +206,10 @@ TilesetDock::TilesetDock(QWidget *parent)
vertical->setSpacing(0);
vertical->setMargin(0);
vertical->addLayout(horizontal);
vertical->addWidget(mViewStack);
vertical->addWidget(mSuperViewStack);

mSuperViewStack->insertWidget(0, new NewTilesetView(this));
mSuperViewStack->insertWidget(1, mViewStack);

horizontal = new QHBoxLayout;
horizontal->setSpacing(0);
Expand Down Expand Up @@ -508,6 +528,9 @@ void TilesetDock::createTilesetView(int index, TilesetDocument *tilesetDocument)

TilesetView *view = new TilesetView;

// Hides the "New Tileset..." special view if it is shown.
mSuperViewStack->setCurrentIndex(1);

// Insert view before the tab to make sure it is there when the tab index
// changes (happens when first tab is inserted).
mViewStack->insertWidget(index, view);
Expand Down Expand Up @@ -553,6 +576,10 @@ void TilesetDock::deleteTilesetView(int index)
delete view; // view needs to go before the tab
mTabBar->removeTab(index);

// Make the "New Tileset..." special tab reappear if there is no tileset open
if (mTilesets.isEmpty())
mSuperViewStack->setCurrentIndex(0);

// Make sure we don't reference this tileset anymore
if (mCurrentTiles && mCurrentTiles->referencesTileset(tileset)) {
TileLayer *cleaned = mCurrentTiles->clone();
Expand Down
1 change: 1 addition & 0 deletions src/tiled/tilesetdock.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private slots:
TilesetDocumentsFilterModel *mTilesetDocumentsFilterModel;

QTabBar *mTabBar;
QStackedWidget *mSuperViewStack;
QStackedWidget *mViewStack;
QToolBar *mToolBar;
Tile *mCurrentTile;
Expand Down