00001 #ifndef BALL_VIEW_WIDGETS_PROPERTYEDITOR_H
00002 #define BALL_VIEW_WIDGETS_PROPERTYEDITOR_H
00003
00004 #ifndef BALL_COMMON_GLOBAL_H
00005 # include <BALL/COMMON/global.h>
00006 #endif
00007
00008 #ifndef BALL_DATATYPE_HASHMAP_H
00009 # include <BALL/DATATYPE/hashMap.h>
00010 #endif
00011
00012 #include <BALL/VIEW/UIC/ui_propertyEditor.h>
00013 #include <BALL/VIEW/UIC/ui_propEditorWidget.h>
00014 #include <BALL/VIEW/UIC/ui_editorPDBInfoDialog.h>
00015
00016 #ifndef BALL_FORMAT_PDBINFO_H
00017 # include <BALL/FORMAT/PDBInfo.h>
00018 #endif
00019
00020 #include <QtGui/QWidget>
00021
00022 class QLabel;
00023 class QSpinBox;
00024 class QLineEdit;
00025 class QCheckBox;
00026
00027 namespace BALL
00028 {
00029 class NamedProperty;
00030 class PropertyManager;
00031
00032 namespace VIEW
00033 {
00038 class PropEditorWidget : public QWidget
00039 {
00040 Q_OBJECT
00041
00042 public:
00046 PropEditorWidget(const std::string& name, QWidget* parent);
00047
00051 virtual const QString& getName() const;
00052
00056 void setEditable(bool mode);
00057
00061 bool isEditable() const;
00062
00070 void apply(PropertyManager* man, bool create = false);
00071
00075 void reset(PropertyManager* man);
00076
00081 virtual PropEditorWidget* clone(const std::string& name, QWidget* parent) = 0;
00082
00083 signals:
00087 void deleteProperty();
00088
00092 void duplicateProperty();
00093
00097 void valueChanged();
00098
00099 protected:
00100 void setupUi_();
00101
00105 bool addWidget_(int i, QWidget* w);
00106
00111 virtual void apply_(PropertyManager* man) = 0;
00112
00117 virtual void reset_(const NamedProperty& prop) = 0;
00118
00119 QString name_;
00120 Ui::PropEditorWidget ui_;
00121 };
00122
00123 class BoolEditorWidget : public PropEditorWidget
00124 {
00125 Q_OBJECT
00126
00127 public:
00128 BoolEditorWidget(const NamedProperty& prop, QWidget* parent);
00129 virtual BoolEditorWidget* clone(const std::string& name, QWidget* parent);
00130
00131 protected:
00132 virtual void apply_(PropertyManager* man);
00133 virtual void reset_(const NamedProperty& prop);
00134
00135 private:
00136 QCheckBox* box_;
00137 };
00138
00139 class IntEditorWidget : public PropEditorWidget
00140 {
00141 Q_OBJECT
00142
00143 public:
00144 IntEditorWidget(const NamedProperty& prop, QWidget* parent);
00145 virtual IntEditorWidget* clone(const std::string& name, QWidget* parent);
00146
00147 protected:
00148 virtual void apply_(PropertyManager* man);
00149 virtual void reset_(const NamedProperty& prop);
00150
00151
00152 private:
00153 QSpinBox* box_;
00154 };
00155
00156 class UIntEditorWidget : public PropEditorWidget
00157 {
00158 Q_OBJECT
00159
00160 public:
00161 UIntEditorWidget(const NamedProperty& prop, QWidget* parent);
00162 virtual UIntEditorWidget* clone(const std::string& name, QWidget* parent);
00163
00164 protected:
00165 virtual void apply_(PropertyManager* man);
00166 virtual void reset_(const NamedProperty& prop);
00167
00168 private:
00169 QSpinBox* box_;
00170 };
00171
00172 class FloatEditorWidget : public PropEditorWidget
00173 {
00174 Q_OBJECT
00175
00176 public:
00177 FloatEditorWidget(const NamedProperty& prop, QWidget* parent);
00178 virtual FloatEditorWidget* clone(const std::string& name, QWidget* parent);
00179
00180 protected:
00181 virtual void apply_(PropertyManager* man);
00182 virtual void reset_(const NamedProperty& prop);
00183
00184 private:
00185 QLineEdit* edit_;
00186 };
00187
00188 class DoubleEditorWidget : public PropEditorWidget
00189 {
00190 Q_OBJECT
00191
00192 public:
00193 DoubleEditorWidget(const NamedProperty& prop, QWidget* parent);
00194 virtual DoubleEditorWidget* clone(const std::string& name, QWidget* parent);
00195
00196 protected:
00197 virtual void apply_(PropertyManager* man);
00198 virtual void reset_(const NamedProperty& prop);
00199
00200 private:
00201 QLineEdit* edit_;
00202 };
00203
00204 class StringEditorWidget : public PropEditorWidget
00205 {
00206 Q_OBJECT
00207
00208 public:
00209 StringEditorWidget(const NamedProperty& prop, QWidget* parent);
00210 virtual StringEditorWidget* clone(const std::string& name, QWidget* parent);
00211
00212 protected:
00213 virtual void apply_(PropertyManager* man);
00214 virtual void reset_(const NamedProperty& prop);
00215
00216 private:
00217 QLineEdit* edit_;
00218 };
00219
00223 class PropDeleteWidget : public PropEditorWidget
00224 {
00225 public:
00226 PropDeleteWidget(const NamedProperty& prop, QWidget* parent)
00227 : PropEditorWidget(prop.getName(), parent)
00228 {
00229 addWidget_(1,new QLabel(tr("(not editable)"),this));
00230 ui_.duplicate_button->setEnabled(false);
00231 }
00232 virtual PropEditorWidget* clone(const std::string&, QWidget*)
00233 {
00234 return NULL;
00235 }
00236 protected:
00237 virtual void apply_(PropertyManager *) {}
00238 virtual void reset_(const NamedProperty &) {}
00239 };
00240
00241 class PDBInfoEditorWidget : public PropEditorWidget
00242 {
00243 Q_OBJECT
00244
00245 public:
00246 PDBInfoEditorWidget(const PDBInfo& info, QWidget* parent);
00247 virtual PDBInfoEditorWidget* clone(const std::string& name, QWidget* parent);
00248
00249 protected slots:
00250 void startEditorDialog();
00251
00252 protected:
00253 virtual void apply_(PropertyManager* man);
00254 virtual void reset_(const NamedProperty& prop);
00255
00256 private:
00257
00258 class EditorPDBInfoDialog : public QDialog {
00259 public:
00260 EditorPDBInfoDialog(QWidget* parent) : QDialog(parent)
00261 {
00262 ui_.setupUi(this);
00263 QFont mono("Monaco"); mono.setStyleHint(QFont::TypeWriter);
00264 ui_.textEditor->setFont(mono);
00265 }
00266 protected:
00267 friend class PDBInfoEditorWidget;
00268 Ui::editorPDBInfoDialog ui_;
00269 };
00270
00271 PDBInfo localCopy_;
00272 EditorPDBInfoDialog* editorDialog_;
00273 };
00274
00281 class BALL_VIEW_EXPORT PropertyEditor : public QWidget
00282 {
00283 Q_OBJECT
00284
00285 public:
00292 explicit PropertyEditor(QWidget* parent = 0, bool editable = true);
00293
00301 PropertyEditor(PropertyManager* manager, QWidget* parent, bool editable = true);
00302
00308 void setPropertyManager(PropertyManager* man);
00309
00313 void setEditable(bool mode);
00314
00318 bool isEditable() const;
00319
00323 bool hasChanges() const;
00324
00325 public slots:
00329 void apply();
00330
00334 void reset();
00335
00336 signals:
00340 void valueChanged();
00341
00342 protected:
00343 void setupUi_();
00344
00345 PropEditorWidget* addProperty_(const NamedProperty& prop);
00346 PropEditorWidget* addProperty_(PropEditorWidget* editor);
00347 PropEditorWidget* createEditorWidget_(const NamedProperty& prop);
00348 QString chooseName_(const QString& initial);
00349 void deleteProperty_(PropEditorWidget* editor);
00350
00351 protected slots:
00352 void scheduleDelete_();
00353 void scheduleDuplicate_();
00354 void valueChanged_();
00355
00356 void createNewBool_();
00357 void createNewInt_();
00358 void createNewUInt_();
00359 void createNewFloat_();
00360 void createNewDouble_();
00361 void createNewString_();
00362
00363 private:
00364 bool has_changes_;
00365 bool is_editable_;
00366 PropertyManager* manager_;
00367 QList<PropEditorWidget*> new_properties_;
00368 QList<PropEditorWidget*> deleted_properties_;
00369
00370 Ui::PropertyEditor ui_;
00371 };
00372
00373 }
00374 }
00375
00376 #endif //BALL_VIEW_WIDGETS_PROPERTYEDITOR_H