-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some general suggestions regarding the code style 🙂
src/tiled/tilesetdock.cpp
Outdated
@@ -553,6 +576,11 @@ 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.count() == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can remove the braces since it's only 1 line block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already changed that in the second commit.
Or maybe I didn't?
I'll check again.
EDIT: You were right, I removed the brackets in the first commit but somehow added them again?
Anyway it's fixed now!
src/tiled/tilesetdock.h
Outdated
@@ -165,7 +165,7 @@ private slots: | |||
TilesetDocumentsFilterModel *mTilesetDocumentsFilterModel; | |||
|
|||
QTabBar *mTabBar; | |||
QStackedWidget *mViewStack; | |||
QStackedWidget *mSuperViewStack, *mViewStack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please define each variable in a new line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do on the third commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this!
I didn't get around to trying it out yet, but here's my comments on the code.
src/tiled/tilesetdock.cpp
Outdated
class NewTilesetView : public QWidget | ||
{ | ||
public: | ||
explicit NewTilesetView(QWidget *tmb = nullptr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's a tmb
? Normally this parameter is called the parent
.
src/tiled/tilesetdock.cpp
Outdated
{ | ||
QWidget *w = new QWidget(this); | ||
|
||
QPushButton *pbNewTileset = new QPushButton(w); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just call it newTilesetButton
.
src/tiled/tilesetdock.cpp
Outdated
QPushButton *pbNewTileset = new QPushButton(w); | ||
pbNewTileset->setText(QStringLiteral("New Tileset...")); | ||
|
||
connect(pbNewTileset, SIGNAL(released()), tmb, SLOT(newTileset())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point, "tmb" is just a widget. It does not indicate what this "newTileset" slot may be, which is bad for code readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it, instead of giving a QWidget, I'll specify you need to give the TilesetDock itself, which is what this QWidget is.
src/tiled/tilesetdock.cpp
Outdated
@@ -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.count() == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use mTilesets.isEmpty()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried it out but, but here's out it looks on my side:
There's two problems here:
- The button didn't receive the size it needs for the label to fit properly.
- I think the button should be centered.
You'll need to set a layout (probably QGridLayout
) on the NewTilesetView
(which I think would be better named NoTilesetWidget
) that will apply the size preferences of the button and to which you can add QSpacerItem
instances for centering the button. You could check out noeditorwidget.ui
to see how this could be achieved and either do the same in code (see the generated ui_noeditorwidget.h
when in doubt) or also make a .ui
file for this widget.
src/tiled/tilesetdock.cpp
Outdated
explicit NewTilesetView(TilesetDock *parent = nullptr) | ||
: QWidget(parent) | ||
{ | ||
QWidget *w = new QWidget(this); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
I tried to center the button, but no matter which way I took the problem from, I couldn't do better than that. This is a simple task, yet somehow the QGridLayout widget is not taking the whole space the QDockWidget provides, so the button is centered horizontally but not vertically. I surrounded it with QSpacerItem objects, but I couldn't center it vertically anyway. Tell me if this is good enough (I really hope it is) |
src/tiled/tilesetdock.cpp
Outdated
QGridLayout *gridLayout = new QGridLayout(this); | ||
|
||
QSpacerItem *spacerVertTop = new QSpacerItem(1, 1, QSizePolicy::Ignored, QSizePolicy::Expanding); | ||
gridLayout->addItem(spacerVertTop, 1, 0, Qt::AlignCenter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't doing what you think it does. You're actually passing Qt::AlignCenter
as the row-span argument to addItem
, which explains why the centering isn't working correctly.
I found out that the use of spacers isn't needed at all though, since we can just pass Qt::AlignCenter
when adding the New Tileset button. I'll push this change in a moment.
Of course it isn't good enough to have a bunch of code sitting there not achieving what it is meant to do. :-) It wasn't easy for me either to find out what was going on though. A compiler warning would have certainly helped, but in C++ passing an enum value to an |
Thanks! :-) |
Feature announced in the issue #1766.