File indexing completed on 2024-10-06 04:26:00
0001 /* 0002 SPDX-FileCopyrightText: 1998-2008 Sebastian Trueg <trueg@k3b.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _K3B_INTERACTION_DIALOG_H_ 0008 #define _K3B_INTERACTION_DIALOG_H_ 0009 0010 #include <KConfigGroup> 0011 0012 #include <QEvent> 0013 #include <QDialog> 0014 #include <QGridLayout> 0015 #include <QLabel> 0016 0017 0018 class QGridLayout; 0019 class QLabel; 0020 class QPushButton; 0021 class KGuiItem; 0022 class QToolButton; 0023 0024 0025 namespace K3b { 0026 class ThemedHeader; 0027 0028 /** 0029 * This is the base dialog for all the dialogs in K3b that start 0030 * some job. Use setMainWidget to set the contents or let mainWidget() 0031 * create an empty plain page. 0032 * The default implementations of the slots just emit the 0033 * corresponding signals. 0034 */ 0035 class InteractionDialog : public QDialog 0036 { 0037 Q_OBJECT 0038 0039 public: 0040 /** 0041 * The constructor. 0042 * loadSettings will be called automatically when the dialog is showing. 0043 * 0044 * @param title the text to be displayed in the K3b header (not the widget frame) 0045 * @param subTitle additional text that will be displayed after the title in smaller size 0046 * @param buttonMask combination of Buttons 0047 * @param defaultButton may also be null to deactivate the feature 0048 * @param configgroup The config group used for the loadSettings and saveSettings methods 0049 */ 0050 explicit InteractionDialog( QWidget* parent = 0, 0051 const QString& title = QString(), 0052 const QString& subTitle = QString(), 0053 int buttonMask = START_BUTTON|CANCEL_BUTTON, 0054 int defaultButton = START_BUTTON, 0055 const QString& configgroup = QString() ); 0056 ~InteractionDialog() override; 0057 0058 void setMainWidget( QWidget* w ); 0059 void setTitle( const QString& title, const QString& subTitle = QString() ); 0060 void setDefaultButton( int b ); 0061 0062 /** 0063 * In contract to "normal" dialogs InteractionDialog will not return from exec 0064 * until close() has been called. This allows one to hide the dialog while a progress 0065 * dialog is shown. 0066 */ 0067 int exec() override; 0068 0069 /** 0070 * reimplemented to allow initialization after the dialog has been opened. 0071 */ 0072 void show(); 0073 0074 /** 0075 * If no mainWidget has been set a plain page will be created. 0076 */ 0077 QWidget* mainWidget(); 0078 0079 enum Buttons { 0080 START_BUTTON = 1, 0081 SAVE_BUTTON = 2, 0082 CANCEL_BUTTON = 4 0083 }; 0084 0085 QSize sizeHint() const override; 0086 0087 QString configGroup() const { return m_configGroup; } 0088 0089 enum StartUpSettings { 0090 LOAD_K3B_DEFAULTS = 1, 0091 LOAD_SAVED_SETTINGS = 2, 0092 LOAD_LAST_SETTINGS = 3 0093 }; 0094 0095 Q_SIGNALS: 0096 void started(); 0097 void canceled(); 0098 void saved(); 0099 0100 public Q_SLOTS: 0101 /** 0102 * \deprecated use setButtonText 0103 */ 0104 void setStartButtonText( const QString& text, 0105 const QString& tooltip = QString(), 0106 const QString& whatsthis = QString() ); 0107 /** 0108 * \deprecated use setButtonText 0109 */ 0110 void setCancelButtonText( const QString& text, 0111 const QString& tooltip = QString(), 0112 const QString& whatsthis = QString() ); 0113 /** 0114 * \deprecated use setButtonText 0115 */ 0116 void setSaveButtonText( const QString& text, 0117 const QString& tooltip = QString(), 0118 const QString& whatsthis = QString() ); 0119 0120 void setButtonGui( int button, 0121 const KGuiItem& ); 0122 0123 void setButtonText( int button, 0124 const QString& text, 0125 const QString& tooltip = QString(), 0126 const QString& whatsthis = QString() ); 0127 0128 void setButtonEnabled( int button, bool enabled ); 0129 void setButtonShown( int button, bool enabled ); 0130 0131 /** 0132 * If set true the init() method will be called via a QTimer to ensure event 0133 * handling be done before (default: false). 0134 */ 0135 void setDelayedInitialization( bool b ) { m_delayedInit = b; } 0136 0137 /** 0138 * Hide the dialog but do not return from the exec call. 0139 */ 0140 void hideTemporarily(); 0141 0142 /** 0143 * Close the dialog and return from any exec call. 0144 */ 0145 void close(); 0146 0147 /** 0148 * Close the dialog and return from any exec call. 0149 */ 0150 void done( int r ) override; 0151 0152 protected Q_SLOTS: 0153 // FIXME: replace these with protected methods which are called from private slots. 0154 virtual void slotStartClicked(); 0155 0156 /** 0157 * The default implementation emits the canceled() signal 0158 * and calls close() 0159 */ 0160 virtual void slotCancelClicked(); 0161 virtual void slotSaveClicked(); 0162 0163 /** 0164 * This slot will call the toggleAll() method protecting from infinite loops 0165 * caused by one element influencing another element which in turn influences 0166 * the first. 0167 * 0168 * Connect this slot to GUI elements (like Checkboxes) that change 0169 * the state of the whole dialog. 0170 */ 0171 void slotToggleAll(); 0172 0173 protected: 0174 /** 0175 * Reimplement this method in case you are using slotToggleAll() 0176 */ 0177 virtual void toggleAll(); 0178 0179 /** 0180 * Reimplement this to support the save/load user default buttons. 0181 * @p config is already set to the correct group. 0182 * 0183 * The save/load buttons are only activated if the config group is 0184 * set in the constructor. 0185 */ 0186 virtual void saveSettings( KConfigGroup config ); 0187 0188 /** 0189 * Reimplement this to support the save/load user default buttons. 0190 * @p config is already set to the correct group. 0191 * 0192 * The save/load buttons are only activated if the config group is 0193 * set in the constructor. 0194 * 0195 * This method will also be called to load defaults. In that case 0196 * \m config will ignore local settings. 0197 */ 0198 virtual void loadSettings( const KConfigGroup& config ); 0199 0200 /** 0201 * This is called after the dialog has been shown. 0202 * Use this for initialization that should happen 0203 * when the user already sees the dialog. 0204 */ 0205 virtual void init() {} 0206 0207 /** 0208 * reimplemented from QDialog 0209 */ 0210 bool eventFilter( QObject*, QEvent* ) override; 0211 0212 void hideEvent( QHideEvent* ) override; 0213 0214 private Q_SLOTS: 0215 void slotLoadK3bDefaults(); 0216 void slotLoadUserDefaults(); 0217 void slotSaveUserDefaults(); 0218 void slotLoadLastSettings(); 0219 void slotStartClickedInternal(); 0220 void slotInternalInit(); 0221 0222 private: 0223 void initConnections(); 0224 void initToolTipsAndWhatsThis(); 0225 void saveLastSettings(); 0226 void loadStartupSettings(); 0227 0228 QPushButton* getButton( int ); 0229 0230 ThemedHeader* m_dialogHeader; 0231 QPushButton* m_buttonStart; 0232 QPushButton* m_buttonSave; 0233 QPushButton* m_buttonCancel; 0234 QWidget* m_mainWidget; 0235 0236 QToolButton* m_buttonLoadSettings; 0237 QToolButton* m_buttonSaveSettings; 0238 0239 QGridLayout* mainGrid; 0240 int m_defaultButton; 0241 QString m_configGroup; 0242 0243 bool m_inToggleMode; 0244 bool m_delayedInit; 0245 }; 0246 } 0247 0248 #endif