Crossfire Server, Trunk
AssetWrapperPanel.cpp
Go to the documentation of this file.
1 /*
2  * Crossfire -- cooperative multi-player graphical RPG and adventure game
3  *
4  * Copyright (c) 2022 the Crossfire Development Team
5  *
6  * Crossfire is free software and comes with ABSOLUTELY NO WARRANTY. You are
7  * welcome to redistribute it under certain conditions. For details, please
8  * see COPYING and LICENSE.
9  *
10  * The authors can be reached via e-mail at <crossfire@metalforge.org>.
11  */
12 
13 #include "AssetWrapperPanel.h"
14 #include "AssetWrapper.h"
15 #include <QVariant>
16 #include <QGridLayout>
17 #include "FaceComboBox.h"
18 #include "quests/QuestComboBox.h"
21 #include "assets/AssetUseTree.h"
22 
23 AssetWrapperPanel::AssetWrapperPanel(QWidget *parent) : QWidget(parent), myTab(nullptr), myAsset(nullptr), myInhibit(false) {
24  myLayout = new QGridLayout(this);
25 }
26 
28  if (myChanged) {
29  disconnect(myChanged);
30  }
31  if (myDelete) {
32  disconnect(myDelete);
33  }
34 }
35 
36 void AssetWrapperPanel::addTab(const QString &title) {
37  if (!myTab) {
38  myTab = new QTabWidget(this);
39  myLayout->addWidget(myTab);
40  }
41  QWidget *tab = new QWidget(myTab);
42  myLayout = new QGridLayout(tab);
43  myTab->addTab(tab, title);
44 }
45 
47  if (myAsset) {
48  disconnect(myChanged);
49  disconnect(myDelete);
50  }
51  myAsset = asset;
52  if (myAsset) {
53  myChanged = connect(myAsset, SIGNAL(modified()), this, SLOT(itemChanged()));
54  myDelete = connect(myAsset, &QObject::destroyed, [this] () { setAsset(nullptr); });
55  itemChanged();
56  }
57 }
58 
60  if (!myAsset || myInhibit) {
61  return;
62  }
63  for (auto pl : myLinks) {
64  pl.widget->setProperty(pl.widgetPropertyName, myAsset->property(pl.assetPropertyName));
65  }
66 }
67 
68 QLabel *AssetWrapperPanel::addLabel(const QString &label, const char *property) {
69  return addWidget(label, new QLabel(this), !label.isEmpty(), property, "text");
70 }
71 
72 QLineEdit *AssetWrapperPanel::addLineEdit(const QString &label, const char *property, bool readOnly) {
73  auto widget = addWidget(label, new QLineEdit(this), true, property, "text");
74  if (readOnly) {
75  widget->setReadOnly(readOnly);
76  } else {
77  connect(widget, SIGNAL(editingFinished()), this, SLOT(dataChanged()));
78  }
79  return widget;
80 }
81 
82 QTextEdit *AssetWrapperPanel::addTextEdit(const QString &label, const char *property, bool readOnly) {
83  auto widget = addWidget(label, new QTextEdit(this), false, property, "plainText");
84  if (readOnly) {
85  widget->setReadOnly(readOnly);
86  } else {
87  connect(widget, SIGNAL(textChanged()), this, SLOT(dataChanged()));
88  }
89  return widget;
90 }
91 
92 QCheckBox *AssetWrapperPanel::addCheckBox(const QString &label, const char *property, bool readOnly) {
93  auto widget = addWidget(label, new QCheckBox(this), true, property, "checked");
94  if (readOnly) {
95  widget->setEnabled(false);
96  } else {
97  connect(widget, SIGNAL(toggled(bool)), this, SLOT(dataChanged()));
98  }
99  return widget;
100 }
101 
102 void AssetWrapperPanel::addFaceChoice(const QString &label, const char *property, bool readOnly, bool allowNone) {
103  auto widget = addWidget(label, new FaceComboBox(this, allowNone), true, property, "face");
104  widget->setEnabled(!readOnly);
105 }
106 
107 void AssetWrapperPanel::addQuestChoice(const QString &label, const char *property, bool readOnly, bool allowNone) {
108  auto widget = addWidget(label, new QuestComboBox(this, allowNone), true, property, "quest");
109  widget->setEnabled(!readOnly);
110 }
111 
112 QSpinBox *AssetWrapperPanel::addSpinBox(const QString &label, const char *property, int min, int max, bool readOnly) {
113  auto widget = addWidget(label, new QSpinBox(this), true, property, "value");
114  widget->setMinimum(min);
115  widget->setMaximum(max);
116  if (readOnly) {
117  widget->setReadOnly(true);
118  } else {
119  connect(widget, SIGNAL(valueChanged(int)), this, SLOT(dataChanged()));
120  }
121  return widget;
122 }
123 
124 TreasureListComboBox *AssetWrapperPanel::addTreasureList(const QString &label, const char *property, bool readOnly, bool allowNone) {
125  auto widget = addWidget(label, new TreasureListComboBox(this, allowNone), true, property, "list");
126  if (readOnly) {
127  widget->setEnabled(false);
128  } else {
129  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
130  }
131  return widget;
132 }
133 
134 ArchetypeComboBox *AssetWrapperPanel::addArchetype(const QString &label, const char *property, bool readOnly, bool allowNone) {
135  auto widget = addWidget(label, new ArchetypeComboBox(this, allowNone), true, property, "arch");
136  if (readOnly) {
137  widget->setEnabled(false);
138  } else {
139  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
140  }
141  return widget;
142 }
143 
144 AssetUseTree *AssetWrapperPanel::addAssetUseTree(const QString &label, AssetModel *assets, const char *property) {
145  return addWidget(label, new AssetUseTree(assets, this), false, property, "filter");
146 }
147 
149  QWidget *bottomFiller = new QWidget(this);
150  bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
151  myLayout->addWidget(bottomFiller, myLayout->rowCount(), 0, 1, 2);
152 }
153 
155  if (!myAsset) {
156  return;
157  }
158  QObject *widget = sender();
159  for (auto link : myLinks) {
160  if (link.widget == widget) {
161  myInhibit = true;
162  myAsset->setProperty(link.assetPropertyName, widget->property(link.widgetPropertyName));
163  myInhibit = false;
164  break;
165  }
166  }
167 }
FaceComboBox
Definition: FaceComboBox.h:23
AssetWrapper.h
AssetWrapperPanel::addTextEdit
QTextEdit * addTextEdit(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:82
AssetWrapperPanel::addTab
void addTab(const QString &title)
Definition: AssetWrapperPanel.cpp:36
AssetWrapperPanel::addLineEdit
QLineEdit * addLineEdit(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:72
TreasureListComboBox.h
pl
Definition: player.h:105
QuestComboBox.h
AssetWrapperPanel::addAssetUseTree
AssetUseTree * addAssetUseTree(const QString &label, AssetModel *assets, const char *property)
Definition: AssetWrapperPanel.cpp:144
AssetWrapperPanel::addQuestChoice
void addQuestChoice(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:107
AssetWrapperPanel::addSpinBox
QSpinBox * addSpinBox(const QString &label, const char *property, int min=0, int max=100, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:112
AssetWrapperPanel::~AssetWrapperPanel
virtual ~AssetWrapperPanel()
Definition: AssetWrapperPanel.cpp:27
AssetWrapperPanel::myChanged
QMetaObject::Connection myChanged
Definition: AssetWrapperPanel.h:58
AssetWrapperPanel::addArchetype
ArchetypeComboBox * addArchetype(const QString &label, const char *property, bool readOnly=false, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:134
AssetWrapperPanel::myLayout
QGridLayout * myLayout
Definition: AssetWrapperPanel.h:54
titlestruct
Definition: readable.c:107
AssetWrapperPanel::dataChanged
void dataChanged()
Definition: AssetWrapperPanel.cpp:154
AssetWrapperPanel::AssetWrapperPanel
AssetWrapperPanel(QWidget *parent)
Definition: AssetWrapperPanel.cpp:23
AssetWrapper
Definition: AssetWrapper.h:22
AssetWrapperPanel::myAsset
AssetWrapper * myAsset
Definition: AssetWrapperPanel.h:56
AssetWrapperPanel::addBottomFiller
void addBottomFiller()
Definition: AssetWrapperPanel.cpp:148
AssetModel
Definition: AssetModel.h:26
ArchetypeComboBox
Definition: ArchetypeComboBox.h:25
say.max
dictionary max
Definition: say.py:148
AssetWrapperPanel::addLabel
QLabel * addLabel(const QString &label, const char *property)
Definition: AssetWrapperPanel.cpp:68
AssetWrapperPanel::itemChanged
void itemChanged()
Definition: AssetWrapperPanel.cpp:59
AssetWrapperPanel::myInhibit
bool myInhibit
Definition: AssetWrapperPanel.h:57
QuestComboBox
Definition: QuestComboBox.h:23
AssetWrapperPanel::myDelete
QMetaObject::Connection myDelete
Definition: AssetWrapperPanel.h:59
AssetWrapperPanel.h
AssetWrapperPanel::myLinks
QList< PropertyLink > myLinks
Definition: AssetWrapperPanel.h:83
AssetUseTree.h
AssetUseTree
Definition: AssetUseTree.h:22
TreasureListComboBox
Definition: TreasureListComboBox.h:25
ArchetypeComboBox.h
AssetWrapperPanel::addWidget
T * addWidget(const QString &label, T *widget, bool sideBySide, const char *property, const char *widgetProperty)
Definition: AssetWrapperPanel.h:62
AssetWrapperPanel::addTreasureList
TreasureListComboBox * addTreasureList(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:124
FaceComboBox.h
AssetWrapperPanel::setAsset
virtual void setAsset(AssetWrapper *item)
Definition: AssetWrapperPanel.cpp:46
AssetWrapperPanel::myTab
QTabWidget * myTab
Definition: AssetWrapperPanel.h:55
connect
Definition: connect.py:1
AssetWrapperPanel::addCheckBox
QCheckBox * addCheckBox(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:92
AssetWrapperPanel::addFaceChoice
void addFaceChoice(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:102