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  if (readOnly) {
105  widget->setEnabled(false);
106  } else {
107  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
108  }
109 }
110 
111 void AssetWrapperPanel::addQuestChoice(const QString &label, const char *property, bool readOnly, bool allowNone) {
112  auto widget = addWidget(label, new QuestComboBox(this, allowNone), true, property, "quest");
113  widget->setEnabled(!readOnly);
114 }
115 
116 QSpinBox *AssetWrapperPanel::addSpinBox(const QString &label, const char *property, int min, int max, bool readOnly) {
117  auto widget = addWidget(label, new QSpinBox(this), true, property, "value");
118  widget->setMinimum(min);
119  widget->setMaximum(max);
120  if (readOnly) {
121  widget->setReadOnly(true);
122  } else {
123  connect(widget, SIGNAL(valueChanged(int)), this, SLOT(dataChanged()));
124  }
125  return widget;
126 }
127 
128 TreasureListComboBox *AssetWrapperPanel::addTreasureList(const QString &label, const char *property, bool readOnly, bool allowNone) {
129  auto widget = addWidget(label, new TreasureListComboBox(this, allowNone), true, property, "list");
130  if (readOnly) {
131  widget->setEnabled(false);
132  } else {
133  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
134  }
135  return widget;
136 }
137 
138 ArchetypeComboBox *AssetWrapperPanel::addArchetype(const QString &label, const char *property, bool readOnly, bool allowNone) {
139  auto widget = addWidget(label, new ArchetypeComboBox(this, allowNone), true, property, "arch");
140  if (readOnly) {
141  widget->setEnabled(false);
142  } else {
143  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
144  }
145  return widget;
146 }
147 
148 AssetUseTree *AssetWrapperPanel::addAssetUseTree(const QString &label, AssetModel *assets, const char *property) {
149  return addWidget(label, new AssetUseTree(assets, this), false, property, "filter");
150 }
151 
153  QWidget *bottomFiller = new QWidget(this);
154  bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
155  myLayout->addWidget(bottomFiller, myLayout->rowCount(), 0, 1, 2);
156 }
157 
159  if (!myAsset) {
160  return;
161  }
162  QObject *widget = sender();
163  for (auto link : myLinks) {
164  if (link.widget == widget) {
165  myInhibit = true;
166  myAsset->setProperty(link.assetPropertyName, widget->property(link.widgetPropertyName));
167  myInhibit = false;
168  break;
169  }
170  }
171 }
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:148
AssetWrapperPanel::addQuestChoice
void addQuestChoice(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:111
AssetWrapperPanel::addSpinBox
QSpinBox * addSpinBox(const QString &label, const char *property, int min=0, int max=100, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:116
AssetWrapperPanel::~AssetWrapperPanel
virtual ~AssetWrapperPanel()
Definition: AssetWrapperPanel.cpp:27
AssetWrapperPanel::myChanged
QMetaObject::Connection myChanged
Definition: AssetWrapperPanel.h:59
AssetWrapperPanel::addArchetype
ArchetypeComboBox * addArchetype(const QString &label, const char *property, bool readOnly=false, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:138
AssetWrapperPanel::myLayout
QGridLayout * myLayout
Definition: AssetWrapperPanel.h:55
titlestruct
Definition: readable.cpp:108
AssetWrapperPanel::dataChanged
void dataChanged()
Definition: AssetWrapperPanel.cpp:158
AssetWrapperPanel::AssetWrapperPanel
AssetWrapperPanel(QWidget *parent)
Definition: AssetWrapperPanel.cpp:23
AssetWrapper
Definition: AssetWrapper.h:25
AssetWrapperPanel::myAsset
AssetWrapper * myAsset
Definition: AssetWrapperPanel.h:57
AssetWrapperPanel::addBottomFiller
void addBottomFiller()
Definition: AssetWrapperPanel.cpp:152
AssetModel
Definition: AssetModel.h:29
ArchetypeComboBox
Definition: ArchetypeComboBox.h:23
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:58
QuestComboBox
Definition: QuestComboBox.h:23
AssetWrapperPanel::myDelete
QMetaObject::Connection myDelete
Definition: AssetWrapperPanel.h:60
AssetWrapperPanel.h
AssetWrapperPanel::myLinks
QList< PropertyLink > myLinks
Definition: AssetWrapperPanel.h:84
AssetUseTree.h
AssetUseTree
Definition: AssetUseTree.h:25
TreasureListComboBox
Definition: TreasureListComboBox.h:23
ArchetypeComboBox.h
AssetWrapperPanel::addWidget
T * addWidget(const QString &label, T *widget, bool sideBySide, const char *property, const char *widgetProperty)
Definition: AssetWrapperPanel.h:63
AssetWrapperPanel::addTreasureList
TreasureListComboBox * addTreasureList(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:128
FaceComboBox.h
AssetWrapperPanel::setAsset
virtual void setAsset(AssetWrapper *item)
Definition: AssetWrapperPanel.cpp:46
AssetWrapperPanel::myTab
QTabWidget * myTab
Definition: AssetWrapperPanel.h:56
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