File indexing completed on 2024-05-05 17:56:44

0001 /*
0002     SPDX-FileCopyrightText: 2004 Shie Erlich <erlich@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2004 Rafi Yanai <yanai@users.sourceforge.net>
0004     SPDX-FileCopyrightText: 2004 Jonas Bähr <jonas.baehr@web.de>
0005     SPDX-FileCopyrightText: 2004-2022 Krusader Krew <https://krusader.org>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef ADDPLACEHOLDERPOPUP_H
0011 #define ADDPLACEHOLDERPOPUP_H
0012 
0013 // QtCore
0014 #include <QList>
0015 #include <QString>
0016 // QtWidgets
0017 #include <QDialog>
0018 #include <QMenu>
0019 
0020 #include "../UserAction/expander.h"
0021 
0022 class KLineEdit;
0023 class QToolButton;
0024 class QCheckBox;
0025 class KComboBox;
0026 class QSpinBox;
0027 
0028 /**
0029  * This reads Expander::placeholder[] and
0030  * fills a popup for easy access to the UserAction Placeholder
0031  */
0032 class AddPlaceholderPopup : public QMenu
0033 {
0034 public:
0035     explicit AddPlaceholderPopup(QWidget *parent);
0036 
0037     /**
0038      * Use this to exec the popup.
0039      * @param pos Position where the popup should appear
0040      * @return the expression which can be placed in the UserAction commandline
0041      */
0042     QString getPlaceholder(const QPoint &pos);
0043 
0044 protected:
0045     /**
0046      * This is called when a Placeholder got parameter.
0047      * @param currentPlaceholder A pointer to the Placeholder the user has chosen
0048      * @return a parameter-string
0049      */
0050     QString getParameter(exp_placeholder *currentPlaceholder);
0051 
0052 private:
0053     QMenu *_activeSub, *_otherSub, *_leftSub, *_rightSub, *_independentSub;
0054 };
0055 
0056 ////////////////////////////////////////////////////////////////////////////////////////////
0057 ///////////////////////////// Parameter Widgets ///////////////////////////////////
0058 ////////////////////////////////////////////////////////////////////////////////////////////
0059 
0060 /**
0061  *  abstract baseclass for all Parameter widgets
0062  */
0063 class ParameterBase : public QWidget
0064 {
0065 public:
0066     inline ParameterBase(const exp_parameter &parameter, QWidget *parent)
0067         : QWidget(parent)
0068     {
0069         _necessary = parameter.necessary();
0070     }
0071     /**
0072      * @return the text for the parameter
0073      */
0074     virtual QString text() = 0;
0075     /**
0076      * @return the default of the parameter
0077      */
0078     virtual QString preset() = 0;
0079     /**
0080      * re-init the parameter with the default
0081      */
0082     virtual void reset() = 0;
0083     /**
0084      * @return true if the Parameter as a valid value
0085      */
0086     virtual bool valid() = 0;
0087     /**
0088      * @return true if the Placeholder really needs this parameter
0089      */
0090     inline bool necessary()
0091     {
0092         return _necessary;
0093     }
0094 
0095 private:
0096     bool _necessary;
0097 };
0098 
0099 /**
0100  *  The simple Parameter widgets: a line-edit with the description above
0101  *  used by default
0102  */
0103 class ParameterText : public ParameterBase
0104 {
0105 public:
0106     ParameterText(const exp_parameter &parameter, QWidget *parent);
0107     QString text() override;
0108     QString preset() override;
0109     void reset() override;
0110     bool valid() override;
0111 
0112 private:
0113     KLineEdit *_lineEdit;
0114     QString _preset;
0115 };
0116 
0117 /**
0118  *  A line-edit with the "addPlaceholder"-button
0119  *  used with default = "__placeholder"
0120  */
0121 class ParameterPlaceholder : public ParameterBase
0122 {
0123     Q_OBJECT
0124 public:
0125     ParameterPlaceholder(const exp_parameter &parameter, QWidget *parent);
0126     QString text() override;
0127     QString preset() override;
0128     void reset() override;
0129     bool valid() override;
0130 
0131 private:
0132     KLineEdit *_lineEdit;
0133     QToolButton *_button;
0134 private slots:
0135     void addPlaceholder();
0136 };
0137 
0138 /**
0139  *  A Checkbox, default: checked; retuns "No" if unchecked
0140  *  used with default = "__yes"
0141  */
0142 class ParameterYes : public ParameterBase
0143 {
0144 public:
0145     ParameterYes(const exp_parameter &parameter, QWidget *parent);
0146     QString text() override;
0147     QString preset() override;
0148     void reset() override;
0149     bool valid() override;
0150 
0151 private:
0152     QCheckBox *_checkBox;
0153 };
0154 
0155 /**
0156  *  A Checkbox, default: unchecked; retuns "Yes" if checked
0157  *  used with default = "__no"
0158  */
0159 class ParameterNo : public ParameterBase
0160 {
0161 public:
0162     ParameterNo(const exp_parameter &parameter, QWidget *parent);
0163     QString text() override;
0164     QString preset() override;
0165     void reset() override;
0166     bool valid() override;
0167 
0168 private:
0169     QCheckBox *_checkBox;
0170 };
0171 
0172 /**
0173  *  A line-edit with the "file open"-button
0174  *  used with default = "__file"
0175  */
0176 class ParameterFile : public ParameterBase
0177 {
0178     Q_OBJECT
0179 public:
0180     ParameterFile(const exp_parameter &parameter, QWidget *parent);
0181     QString text() override;
0182     QString preset() override;
0183     void reset() override;
0184     bool valid() override;
0185 
0186 private:
0187     KLineEdit *_lineEdit;
0188     QToolButton *_button;
0189 private slots:
0190     void addFile();
0191 };
0192 
0193 /**
0194  *  A ComboBox with the description above
0195  *  used with default = "__choose:item1;item2;..."
0196  */
0197 class ParameterChoose : public ParameterBase
0198 {
0199 public:
0200     ParameterChoose(const exp_parameter &parameter, QWidget *parent);
0201     QString text() override;
0202     QString preset() override;
0203     void reset() override;
0204     bool valid() override;
0205 
0206 private:
0207     KComboBox *_combobox;
0208 };
0209 
0210 /**
0211  *  An editable ComboBox with the predefined selections
0212  *  used with default = "__select"
0213  */
0214 class ParameterSelect : public ParameterBase
0215 {
0216 public:
0217     ParameterSelect(const exp_parameter &parameter, QWidget *parent);
0218     QString text() override;
0219     QString preset() override;
0220     void reset() override;
0221     bool valid() override;
0222 
0223 private:
0224     KComboBox *_combobox;
0225 };
0226 
0227 /**
0228  *  A line-edit with a "choose dir"- and a bookmark-button
0229  *  used with default = "__goto"
0230  */
0231 class ParameterGoto : public ParameterBase
0232 {
0233     Q_OBJECT
0234 public:
0235     ParameterGoto(const exp_parameter &parameter, QWidget *parent);
0236     QString text() override;
0237     QString preset() override;
0238     void reset() override;
0239     bool valid() override;
0240 
0241 private:
0242     KLineEdit *_lineEdit;
0243     QToolButton *_dirButton, *_placeholderButton;
0244 private slots:
0245     void setDir();
0246     void addPlaceholder();
0247 };
0248 
0249 /**
0250  *  A ComboBox with all profiles available for the Synchronizer
0251  *  used with default = "__syncprofile"
0252  */
0253 class ParameterSyncprofile : public ParameterBase
0254 {
0255 public:
0256     ParameterSyncprofile(const exp_parameter &parameter, QWidget *parent);
0257     QString text() override;
0258     QString preset() override;
0259     void reset() override;
0260     bool valid() override;
0261 
0262 private:
0263     KComboBox *_combobox;
0264 };
0265 
0266 /**
0267  *  A ComboBox with all profiles available for the panels
0268  *  used with default = "__panelprofile"
0269  */
0270 class ParameterPanelprofile : public ParameterBase
0271 {
0272 public:
0273     ParameterPanelprofile(const exp_parameter &parameter, QWidget *parent);
0274     QString text() override;
0275     QString preset() override;
0276     void reset() override;
0277     bool valid() override;
0278 
0279 private:
0280     KComboBox *_combobox;
0281 };
0282 
0283 /**
0284  *  A ComboBox with all profiles available for the Searchmodule
0285  *  used with default = "__searchprofile"
0286  */
0287 class ParameterSearch : public ParameterBase
0288 {
0289 public:
0290     ParameterSearch(const exp_parameter &parameter, QWidget *parent);
0291     QString text() override;
0292     QString preset() override;
0293     void reset() override;
0294     bool valid() override;
0295 
0296 private:
0297     KComboBox *_combobox;
0298 };
0299 
0300 /**
0301  *  A SpinBox for integer
0302  *  used with default = "__int:min;max;step;value"
0303  */
0304 class ParameterInt : public ParameterBase
0305 {
0306 public:
0307     ParameterInt(const exp_parameter &parameter, QWidget *parent);
0308     QString text() override;
0309     QString preset() override;
0310     void reset() override;
0311     bool valid() override;
0312 
0313 private:
0314     QSpinBox *_spinbox;
0315     int _default;
0316 };
0317 
0318 ////////////////////////////////////////////////////////////////////////////////////////////
0319 /////////////////////////////// ParameterDialog ////////////////////////////////////
0320 ////////////////////////////////////////////////////////////////////////////////////////////
0321 
0322 /**
0323  *  Opens a dialog for the parameter. Depending on the default (preset) a different widget is used.
0324  *  See Parameter-Classes for details
0325  */
0326 class ParameterDialog : public QDialog
0327 {
0328     Q_OBJECT
0329 public:
0330     ParameterDialog(const exp_placeholder *currentPlaceholder, QWidget *parent);
0331 
0332     /**
0333      * Use this to execute the dialog.
0334      * @return a QString with all parameters; omitting the optional ones if they have the default-value.
0335      */
0336     QString getParameter();
0337 
0338 private:
0339     typedef QList<ParameterBase *> ParameterList;
0340     ParameterList _parameter;
0341     int _parameterCount;
0342 private slots:
0343     void reset();
0344     void slotOk();
0345 };
0346 
0347 #endif // ADDPLACEHOLDERPOPUP_H