File indexing completed on 2024-04-28 17:06:09
0001 /* 0002 SPDX-FileCopyrightText: 2003 Csaba Karai <krusader@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #ifndef KONFIGURATORITEMS_H 0009 #define KONFIGURATORITEMS_H 0010 0011 // QtCore 0012 #include <QList> 0013 #include <QObject> 0014 #include <QString> 0015 // QtGui 0016 #include <QFont> 0017 #include <QPixmap> 0018 // QtWidgets 0019 #include <QBoxLayout> 0020 #include <QCheckBox> 0021 #include <QComboBox> 0022 #include <QLabel> 0023 #include <QLineEdit> 0024 #include <QPushButton> 0025 #include <QRadioButton> 0026 #include <QSpinBox> 0027 #include <QToolButton> 0028 0029 #include <KIOWidgets/KUrlRequester> 0030 0031 #include "../GUI/krlistwidget.h" 0032 0033 #define FIRST_PAGE 0 0034 0035 class KonfiguratorExtension : public QObject 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 KonfiguratorExtension(QObject *obj, QString cfgGroup, QString cfgName, bool restartNeeded = false, int page = FIRST_PAGE); 0041 0042 virtual void loadInitialValue(); 0043 virtual bool apply(); 0044 virtual void setDefaults(); 0045 virtual bool isChanged(); 0046 virtual void setSubPage(int page) 0047 { 0048 subpage = page; 0049 } 0050 virtual int subPage() 0051 { 0052 return subpage; 0053 } 0054 0055 inline QObject *object() 0056 { 0057 return objectPtr; 0058 } 0059 0060 inline QString getConfigGroup() 0061 { 0062 return configGroup; 0063 } 0064 inline QString getConfigName() 0065 { 0066 return configName; 0067 } 0068 0069 public slots: 0070 void setChanged() 0071 { 0072 emit sigChanged(changed = true); 0073 } 0074 void setChanged(bool chg) 0075 { 0076 emit sigChanged(changed = chg); 0077 } 0078 0079 signals: 0080 void applyManually(QObject *, QString, QString); 0081 void applyAuto(QObject *, QString, QString); 0082 void setDefaultsManually(QObject *); 0083 void setDefaultsAuto(QObject *); 0084 void setInitialValue(QObject *); 0085 void sigChanged(bool); 0086 0087 protected: 0088 QObject *objectPtr; 0089 0090 bool applyConnected; 0091 bool setDefaultsConnected; 0092 bool changed; 0093 bool restartNeeded; 0094 int subpage; 0095 0096 QString configGroup; 0097 QString configName; 0098 0099 void connectNotify(const QMetaMethod &signal) override; 0100 }; 0101 0102 // KonfiguratorCheckBox class 0103 /////////////////////////////// 0104 0105 class KonfiguratorCheckBox : public QCheckBox 0106 { 0107 Q_OBJECT 0108 0109 public: 0110 KonfiguratorCheckBox(QString configGroup, 0111 QString name, 0112 bool defaultValue, 0113 const QString &text, 0114 QWidget *parent = nullptr, 0115 bool restart = false, 0116 int page = FIRST_PAGE); 0117 ~KonfiguratorCheckBox() override; 0118 0119 inline KonfiguratorExtension *extension() 0120 { 0121 return ext; 0122 } 0123 0124 // indicate that a checkobox is dependent of this, 0125 // meaning that dep is only available if this box is checked 0126 void addDep(KonfiguratorCheckBox *dep); 0127 0128 public slots: 0129 virtual void loadInitialValue(); 0130 void slotApply(QObject *, const QString &, const QString &); 0131 void slotSetDefaults(QObject *); 0132 0133 protected: 0134 void checkStateSet() override; 0135 void nextCheckState() override; 0136 void updateDeps(); 0137 0138 bool defaultValue; 0139 KonfiguratorExtension *ext; 0140 QList<KonfiguratorCheckBox *> deps; 0141 }; 0142 0143 // KonfiguratorSpinBox class 0144 /////////////////////////////// 0145 0146 class KonfiguratorSpinBox : public QSpinBox 0147 { 0148 Q_OBJECT 0149 0150 public: 0151 KonfiguratorSpinBox(QString configGroup, 0152 QString configName, 0153 int defaultValue, 0154 int min, 0155 int max, 0156 QWidget *parent = nullptr, 0157 bool restartNeeded = false, 0158 int page = FIRST_PAGE); 0159 ~KonfiguratorSpinBox() override; 0160 0161 inline KonfiguratorExtension *extension() 0162 { 0163 return ext; 0164 } 0165 0166 public slots: 0167 virtual void loadInitialValue(); 0168 void slotApply(QObject *, const QString &, const QString &); 0169 void slotSetDefaults(QObject *); 0170 0171 protected: 0172 int defaultValue; 0173 KonfiguratorExtension *ext; 0174 }; 0175 0176 // KonfiguratorCheckBoxGroup class 0177 /////////////////////////////// 0178 0179 class KonfiguratorCheckBoxGroup : public QWidget 0180 { 0181 public: 0182 explicit KonfiguratorCheckBoxGroup(QWidget *parent = nullptr) 0183 : QWidget(parent) 0184 { 0185 } 0186 0187 void add(KonfiguratorCheckBox *); 0188 int count() 0189 { 0190 return checkBoxList.count(); 0191 }; 0192 KonfiguratorCheckBox *find(int index); 0193 KonfiguratorCheckBox *find(const QString &name); 0194 0195 private: 0196 QList<KonfiguratorCheckBox *> checkBoxList; 0197 }; 0198 0199 // KonfiguratorRadioButtons class 0200 /////////////////////////////// 0201 0202 class KonfiguratorRadioButtons : public QWidget 0203 { 0204 Q_OBJECT 0205 0206 public: 0207 KonfiguratorRadioButtons(QString configGroup, QString name, QString defaultValue, QWidget *parent = nullptr, bool restart = false, int page = FIRST_PAGE); 0208 ~KonfiguratorRadioButtons() override; 0209 0210 inline KonfiguratorExtension *extension() 0211 { 0212 return ext; 0213 } 0214 0215 void addRadioButton(QRadioButton *radioWidget, const QString &name, const QString &value); 0216 0217 void selectButton(const QString &value); 0218 0219 int count() 0220 { 0221 return radioButtons.count(); 0222 } 0223 QString selectedValue(); 0224 QRadioButton *find(int index); 0225 QRadioButton *find(const QString &name); 0226 0227 public slots: 0228 virtual void loadInitialValue(); 0229 void slotApply(QObject *, const QString &, const QString &); 0230 void slotSetDefaults(QObject *); 0231 0232 protected: 0233 QList<QRadioButton *> radioButtons; 0234 QList<QString> radioValues; 0235 QList<QString> radioNames; 0236 0237 QString defaultValue; 0238 0239 KonfiguratorExtension *ext; 0240 }; 0241 0242 // KonfiguratorEditBox class 0243 /////////////////////////////// 0244 0245 class KonfiguratorEditBox : public QLineEdit 0246 { 0247 Q_OBJECT 0248 0249 public: 0250 KonfiguratorEditBox(QString configGroup, QString name, QString defaultValue, QWidget *parent = nullptr, bool restart = false, int page = FIRST_PAGE); 0251 ~KonfiguratorEditBox() override; 0252 0253 inline KonfiguratorExtension *extension() 0254 { 0255 return ext; 0256 } 0257 0258 public slots: 0259 virtual void loadInitialValue(); 0260 void slotApply(QObject *, const QString &, const QString &); 0261 void slotSetDefaults(QObject *); 0262 0263 protected: 0264 QString defaultValue; 0265 KonfiguratorExtension *ext; 0266 }; 0267 0268 // KonfiguratorURLRequester class 0269 /////////////////////////////// 0270 0271 class KonfiguratorURLRequester : public KUrlRequester 0272 { 0273 Q_OBJECT 0274 0275 public: 0276 KonfiguratorURLRequester(QString configGroup, 0277 QString name, 0278 QString defaultValue, 0279 QWidget *parent = nullptr, 0280 bool restart = false, 0281 int page = FIRST_PAGE, 0282 bool expansion = true); 0283 ~KonfiguratorURLRequester() override; 0284 0285 inline KonfiguratorExtension *extension() 0286 { 0287 return ext; 0288 } 0289 0290 public slots: 0291 virtual void loadInitialValue(); 0292 void slotApply(QObject *, const QString &, const QString &); 0293 void slotSetDefaults(QObject *); 0294 0295 protected: 0296 QString defaultValue; 0297 KonfiguratorExtension *ext; 0298 bool expansion; 0299 }; 0300 0301 // KonfiguratorFontChooser class 0302 /////////////////////////////// 0303 0304 class KonfiguratorFontChooser : public QWidget 0305 { 0306 Q_OBJECT 0307 0308 public: 0309 KonfiguratorFontChooser(QString configGroup, 0310 QString name, 0311 const QFont &defaultValue, 0312 QWidget *parent = nullptr, 0313 bool restart = false, 0314 int page = FIRST_PAGE); 0315 ~KonfiguratorFontChooser() override; 0316 0317 inline KonfiguratorExtension *extension() 0318 { 0319 return ext; 0320 } 0321 0322 public slots: 0323 virtual void loadInitialValue(); 0324 void slotApply(QObject *, const QString &, const QString &); 0325 void slotSetDefaults(QObject *); 0326 void slotBrowseFont(); 0327 0328 protected: 0329 QFont defaultValue; 0330 QFont font; 0331 KonfiguratorExtension *ext; 0332 0333 QLabel *pLabel; 0334 QToolButton *pToolButton; 0335 0336 void setFont(); 0337 }; 0338 0339 // KONFIGURATOR_NAME_VALUE_PAIR structure 0340 /////////////////////////////// 0341 0342 struct KONFIGURATOR_NAME_VALUE_PAIR { 0343 QString text; 0344 QString value; 0345 }; 0346 0347 // KONFIGURATOR_NAME_VALUE_TIP structure 0348 /////////////////////////////// 0349 0350 struct KONFIGURATOR_NAME_VALUE_TIP { 0351 QString text; 0352 QString value; 0353 QString tooltip; 0354 }; 0355 0356 // KonfiguratorComboBox class 0357 /////////////////////////////// 0358 0359 class KonfiguratorComboBox : public QComboBox 0360 { 0361 Q_OBJECT 0362 0363 public: 0364 KonfiguratorComboBox(QString configGroup, 0365 QString name, 0366 QString defaultValue, 0367 KONFIGURATOR_NAME_VALUE_PAIR *listIn, 0368 int listInLen, 0369 QWidget *parent = nullptr, 0370 bool restart = false, 0371 bool editable = false, 0372 int page = FIRST_PAGE); 0373 ~KonfiguratorComboBox() override; 0374 0375 inline KonfiguratorExtension *extension() 0376 { 0377 return ext; 0378 } 0379 0380 public slots: 0381 virtual void loadInitialValue(); 0382 void slotApply(QObject *, const QString &, const QString &); 0383 void slotSetDefaults(QObject *); 0384 0385 protected: 0386 QString defaultValue; 0387 KONFIGURATOR_NAME_VALUE_PAIR *list; 0388 int listLen; 0389 KonfiguratorExtension *ext; 0390 0391 void selectEntry(const QString &entry); 0392 }; 0393 0394 // KonfiguratorColorChooser class 0395 /////////////////////////////// 0396 0397 typedef struct { 0398 QString name; 0399 QColor color; 0400 QString value; 0401 } ADDITIONAL_COLOR; 0402 0403 class KonfiguratorColorChooser : public QComboBox 0404 { 0405 Q_OBJECT 0406 0407 public: 0408 KonfiguratorColorChooser(QString configGroup, 0409 QString name, 0410 const QColor &defaultValue, 0411 QWidget *parent = nullptr, 0412 bool restart = false, 0413 ADDITIONAL_COLOR *addColPtr = nullptr, 0414 int addColNum = 0, 0415 int page = FIRST_PAGE); 0416 ~KonfiguratorColorChooser() override; 0417 0418 inline KonfiguratorExtension *extension() 0419 { 0420 return ext; 0421 } 0422 0423 void setDefaultColor(QColor dflt); 0424 void setDefaultText(const QString &text); 0425 QColor getColor(); 0426 void changeAdditionalColor(int num, const QColor &color); 0427 QString getValue(); 0428 bool isValueRGB(); 0429 void setValue(const QString &value); 0430 0431 public slots: 0432 virtual void loadInitialValue(); 0433 void slotApply(QObject *, const QString &, const QString &); 0434 void slotSetDefaults(QObject *); 0435 void slotCurrentChanged(int number); 0436 0437 signals: 0438 void colorChanged(); 0439 0440 private: 0441 void addColor(const QString &text, const QColor &color); 0442 QPixmap createPixmap(const QColor &color); 0443 0444 protected: 0445 QColor defaultValue; 0446 QColor customValue; 0447 QList<QColor> palette; 0448 QList<ADDITIONAL_COLOR> additionalColors; 0449 KonfiguratorExtension *ext; 0450 bool disableColorChooser; 0451 }; 0452 0453 // KonfiguratorListBox class 0454 /////////////////////////////// 0455 0456 class KonfiguratorListBox : public KrListWidget 0457 { 0458 Q_OBJECT 0459 0460 public: 0461 KonfiguratorListBox(QString configGroup, QString name, QStringList defaultValue, QWidget *parent = nullptr, bool restart = false, int page = FIRST_PAGE); 0462 ~KonfiguratorListBox() override; 0463 0464 inline KonfiguratorExtension *extension() 0465 { 0466 return ext; 0467 } 0468 0469 void addItem(const QString &); 0470 void removeItem(const QString &); 0471 0472 public slots: 0473 virtual void loadInitialValue(); 0474 void slotApply(QObject *, const QString &, const QString &); 0475 void slotSetDefaults(QObject *); 0476 0477 protected: 0478 QStringList list(); 0479 void setList(const QStringList &); 0480 0481 QStringList defaultValue; 0482 KonfiguratorExtension *ext; 0483 }; 0484 0485 #endif /* __KONFIGURATOR_ITEMS_H__ */