-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced ListEdit widget for the Properties view
* VariantPropertyManager now displays the number of list items. * VariantEditorFactory now instantiates a ListEdit widget when a list value is selected, which features a button to add an item to the list (currently just "0" integer values).
- Loading branch information
Showing
8 changed files
with
220 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* listedit.h | ||
* Copyright 2024, Thorbjørn Lindeijer <[email protected]> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "listedit.h" | ||
|
||
#include "utils.h" | ||
|
||
#include <QHBoxLayout> | ||
#include <QLabel> | ||
#include <QToolButton> | ||
|
||
namespace Tiled { | ||
|
||
ListEdit::ListEdit(QWidget *parent) | ||
: QWidget{parent} | ||
{ | ||
QHBoxLayout *layout = new QHBoxLayout{this}; | ||
layout->setContentsMargins(0, 0, 0, 0); | ||
layout->setSpacing(0); | ||
|
||
mLabel = new QLabel{this}; | ||
mLabel->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred)); | ||
|
||
QToolButton *addButton = new QToolButton{this}; | ||
addButton->setIcon(QIcon(QStringLiteral(":/images/22/add.png"))); | ||
Utils::setThemeIcon(addButton, "add"); | ||
|
||
QToolButton *editButton = new QToolButton{this}; | ||
editButton->setSizePolicy(QSizePolicy{QSizePolicy::Fixed, QSizePolicy::Preferred}); | ||
editButton->setText(tr("Edit...")); | ||
layout->addWidget(mLabel); | ||
layout->addWidget(addButton); | ||
layout->addWidget(editButton); | ||
|
||
setFocusProxy(editButton); | ||
setFocusPolicy(Qt::StrongFocus); | ||
|
||
connect(addButton, &QToolButton::clicked, | ||
this, &ListEdit::addButtonClicked); | ||
connect(editButton, &QToolButton::clicked, | ||
this, &ListEdit::editButtonClicked); | ||
} | ||
|
||
void ListEdit::setValue(const QVariantList &value) | ||
{ | ||
mValue = value; | ||
mLabel->setText(valueText(value)); | ||
} | ||
|
||
QString ListEdit::valueText(const QVariantList &value) | ||
{ | ||
return value.isEmpty() ? tr("<empty>") | ||
: tr("%1 items").arg(value.count()); | ||
} | ||
|
||
void ListEdit::addButtonClicked() | ||
{ | ||
// todo: spawn a kind of "add property" dialog, but without a name field? | ||
// or maybe add button is a dropdown with the available types? | ||
mValue.append(0); | ||
emit valueChanged(mValue); | ||
} | ||
|
||
void ListEdit::editButtonClicked() | ||
{ | ||
// todo: spawn list edit dialog | ||
} | ||
|
||
} // namespace Tiled | ||
|
||
#include "moc_listedit.cpp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* listedit.h | ||
* Copyright 2024, Thorbjørn Lindeijer <[email protected]> | ||
* | ||
* This file is part of Tiled. | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the Free | ||
* Software Foundation; either version 2 of the License, or (at your option) | ||
* any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
* more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with | ||
* this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <QWidget> | ||
|
||
class QLabel; | ||
|
||
namespace Tiled { | ||
|
||
/** | ||
* The widget that enables the user to edit a list property. | ||
*/ | ||
class ListEdit final : public QWidget | ||
{ | ||
Q_OBJECT | ||
Q_PROPERTY(QVariantList value READ value WRITE setValue NOTIFY valueChanged FINAL) | ||
|
||
public: | ||
explicit ListEdit(QWidget *parent = nullptr); | ||
|
||
const QVariantList &value() const { return mValue; } | ||
void setValue(const QVariantList &value); | ||
|
||
static QString valueText(const QVariantList &value); | ||
|
||
signals: | ||
void valueChanged(const QVariantList &value); | ||
|
||
private: | ||
void addButtonClicked(); | ||
void editButtonClicked(); | ||
|
||
QLabel *mLabel; | ||
QVariantList mValue; | ||
}; | ||
|
||
} // namespace Tiled |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
|
||
#pragma once | ||
|
||
#include "properties.h" | ||
#include "variantpropertymanager.h" | ||
|
||
#include <QWidget> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.