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, bool wrapText) {
69  auto widget = addWidget(label, new QLabel(this), !label.isEmpty(), property, "text");
70  widget->setWordWrap(wrapText);
71  return widget;
72 }
73 
74 QLineEdit *AssetWrapperPanel::addLineEdit(const QString &label, const char *property, bool readOnly) {
75  auto widget = addWidget(label, new QLineEdit(this), true, property, "text");
76  if (readOnly) {
77  widget->setReadOnly(readOnly);
78  } else {
79  connect(widget, SIGNAL(editingFinished()), this, SLOT(dataChanged()));
80  }
81  return widget;
82 }
83 
84 QTextEdit *AssetWrapperPanel::addTextEdit(const QString &label, const char *property, bool readOnly) {
85  auto widget = addWidget(label, new QTextEdit(this), false, property, "plainText");
86  if (readOnly) {
87  widget->setReadOnly(readOnly);
88  } else {
89  connect(widget, SIGNAL(textChanged()), this, SLOT(dataChanged()));
90  }
91  return widget;
92 }
93 
94 QCheckBox *AssetWrapperPanel::addCheckBox(const QString &label, const char *property, bool readOnly) {
95  auto widget = addWidget(label, new QCheckBox(this), true, property, "checked");
96  if (readOnly) {
97  widget->setEnabled(false);
98  } else {
99  connect(widget, SIGNAL(toggled(bool)), this, SLOT(dataChanged()));
100  }
101  return widget;
102 }
103 
104 void AssetWrapperPanel::addFaceChoice(const QString &label, const char *property, bool readOnly, bool allowNone) {
105  auto widget = addWidget(label, new FaceComboBox(this, allowNone), true, property, "face");
106  if (readOnly) {
107  widget->setEnabled(false);
108  } else {
109  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
110  }
111 }
112 
113 void AssetWrapperPanel::addQuestChoice(const QString &label, const char *property, bool readOnly, bool allowNone) {
114  auto widget = addWidget(label, new QuestComboBox(this, allowNone), true, property, "quest");
115  widget->setEnabled(!readOnly);
116 }
117 
118 QSpinBox *AssetWrapperPanel::addSpinBox(const QString &label, const char *property, int min, int max, bool readOnly) {
119  auto widget = addWidget(label, new QSpinBox(this), true, property, "value");
120  widget->setMinimum(min);
121  widget->setMaximum(max);
122  if (readOnly) {
123  widget->setReadOnly(true);
124  } else {
125  connect(widget, SIGNAL(valueChanged(int)), this, SLOT(dataChanged()));
126  }
127  return widget;
128 }
129 
130 TreasureListComboBox *AssetWrapperPanel::addTreasureList(const QString &label, const char *property, bool readOnly, bool allowNone) {
131  auto widget = addWidget(label, new TreasureListComboBox(this, allowNone), true, property, "list");
132  if (readOnly) {
133  widget->setEnabled(false);
134  } else {
135  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
136  }
137  return widget;
138 }
139 
140 ArchetypeComboBox *AssetWrapperPanel::addArchetype(const QString &label, const char *property, bool readOnly, bool allowNone) {
141  auto widget = addWidget(label, new ArchetypeComboBox(this, allowNone), true, property, "arch");
142  if (readOnly) {
143  widget->setEnabled(false);
144  } else {
145  connect(widget, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
146  }
147  return widget;
148 }
149 
150 AssetUseTree *AssetWrapperPanel::addAssetUseTree(const QString &label, AssetModel *assets, const char *property) {
151  return addWidget(label, new AssetUseTree(assets, this), false, property, "filter");
152 }
153 
155  QWidget *bottomFiller = new QWidget(this);
156  bottomFiller->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
157  myLayout->addWidget(bottomFiller, myLayout->rowCount(), 0, 1, 2);
158 }
159 
161  if (!myAsset) {
162  return;
163  }
164  QObject *widget = sender();
165  for (auto link : myLinks) {
166  if (link.widget == widget) {
167  myInhibit = true;
168  myAsset->setProperty(link.assetPropertyName, widget->property(link.widgetPropertyName));
169  myInhibit = false;
170  break;
171  }
172  }
173 }
FaceComboBox
Definition: FaceComboBox.h:23
AssetWrapper.h
AssetWrapperPanel::addTextEdit
QTextEdit * addTextEdit(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:84
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:74
TreasureListComboBox.h
QuestComboBox.h
AssetWrapperPanel::addAssetUseTree
AssetUseTree * addAssetUseTree(const QString &label, AssetModel *assets, const char *property)
Definition: AssetWrapperPanel.cpp:150
AssetWrapperPanel::addQuestChoice
void addQuestChoice(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:113
AssetWrapperPanel::addLabel
QLabel * addLabel(const QString &label, const char *property, bool wrapText=false)
Definition: AssetWrapperPanel.cpp:68
AssetWrapperPanel::addSpinBox
QSpinBox * addSpinBox(const QString &label, const char *property, int min=0, int max=100, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:118
AssetWrapperPanel::~AssetWrapperPanel
virtual ~AssetWrapperPanel()
Definition: AssetWrapperPanel.cpp:27
AssetWrapperPanel::myChanged
QMetaObject::Connection myChanged
Definition: AssetWrapperPanel.h:60
AssetWrapperPanel::addArchetype
ArchetypeComboBox * addArchetype(const QString &label, const char *property, bool readOnly=false, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:140
AssetWrapperPanel::myLayout
QGridLayout * myLayout
Definition: AssetWrapperPanel.h:56
AssetWrapperPanel::dataChanged
void dataChanged()
Definition: AssetWrapperPanel.cpp:160
AssetWrapperPanel::AssetWrapperPanel
AssetWrapperPanel(QWidget *parent)
Definition: AssetWrapperPanel.cpp:23
AssetWrapper
Definition: AssetWrapper.h:25
AssetWrapperPanel::myAsset
AssetWrapper * myAsset
Definition: AssetWrapperPanel.h:58
AssetWrapperPanel::addBottomFiller
void addBottomFiller()
Definition: AssetWrapperPanel.cpp:154
AssetModel
Definition: AssetModel.h:29
title
Definition: readable.cpp:108
ArchetypeComboBox
Definition: ArchetypeComboBox.h:23
say.max
dictionary max
Definition: say.py:148
AssetWrapperPanel::itemChanged
void itemChanged()
Definition: AssetWrapperPanel.cpp:59
AssetWrapperPanel::myInhibit
bool myInhibit
Definition: AssetWrapperPanel.h:59
QuestComboBox
Definition: QuestComboBox.h:23
AssetWrapperPanel::myDelete
QMetaObject::Connection myDelete
Definition: AssetWrapperPanel.h:61
AssetWrapperPanel.h
AssetWrapperPanel::myLinks
QList< PropertyLink > myLinks
Definition: AssetWrapperPanel.h:85
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:64
AssetWrapperPanel::addTreasureList
TreasureListComboBox * addTreasureList(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:130
FaceComboBox.h
AssetWrapperPanel::setAsset
virtual void setAsset(AssetWrapper *item)
Definition: AssetWrapperPanel.cpp:46
AssetWrapperPanel::myTab
QTabWidget * myTab
Definition: AssetWrapperPanel.h:57
connect
Definition: connect.py:1
AssetWrapperPanel::addCheckBox
QCheckBox * addCheckBox(const QString &label, const char *property, bool readOnly=true)
Definition: AssetWrapperPanel.cpp:94
altar_valkyrie.pl
pl
Definition: altar_valkyrie.py:28
AssetWrapperPanel::addFaceChoice
void addFaceChoice(const QString &label, const char *property, bool readOnly=true, bool allowNone=true)
Definition: AssetWrapperPanel.cpp:104