File indexing completed on 2024-05-12 16:44:16
0001 /* 0002 SPDX-FileCopyrightText: 2006 Thomas Baumagrt <ipwizard@users.sourceforge.net> 0003 SPDX-FileCopyrightText: 2017 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com> 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef KMYMONEYWIZARD_H 0008 #define KMYMONEYWIZARD_H 0009 0010 // ---------------------------------------------------------------------------- 0011 // QT Includes 0012 0013 #include <QDialog> 0014 0015 // ---------------------------------------------------------------------------- 0016 // KDE Includes 0017 0018 // ---------------------------------------------------------------------------- 0019 // Project Includes 0020 0021 class KMyMoneyWizardPage; 0022 0023 template <class T> class QList; 0024 0025 /** 0026 * @author Thomas Baumgart (C) 2006 0027 * 0028 * This is a base class for implementation of the KMyMoneyWizard. It provides 0029 * the following layout of a wizard: 0030 * 0031 * @code 0032 * +-wizardLayout-----------------------------------------------+ 0033 * | | 0034 * +------------------------------------------------------------+ 0035 * |+-stepLayout--++-------------------------------------------+| 0036 * || ||+-pageLayout------------------------------+|| 0037 * || ||| ||| 0038 * || ||| ||| 0039 * || ||| ||| 0040 * || ||| ||| 0041 * || ||| ||| 0042 * || ||| ||| 0043 * || ||+-----------------------------------------+|| 0044 * || |||+-buttonLayout--------------------------+||| 0045 * || |||| |||| 0046 * || |||+---------------------------------------+||| 0047 * || ||+-----------------------------------------+|| 0048 * |+-------------++-------------------------------------------+| 0049 * +------------------------------------------------------------+ 0050 * @endcode 0051 * 0052 * The top bar is filled with a KMyMoneyTitleLabel as known from 0053 * KMyMoney's views. To the left there is an area in the same color 0054 * as the title bar showing the steps for this wizard. Each such step 0055 * can consist of one or more wizard pages. At the bottom of this area 0056 * the text "Step x of y" is shown and updated. To the right of this 0057 * part, the actual wizard page is shown. At the bottom of the page 0058 * the class inserts a standard button widget consisting of a Help, 0059 * Back, Next/Finish and Cancel button. 0060 * 0061 * The wizard serves as container for the wizard pages. In order to access 0062 * the data filled into the pages, one would have to provide getter methods. 0063 * 0064 * Here is an example how this object could be used. Please also see the 0065 * example described with the KMyMoneyWizardPage class. 0066 * 0067 * @code 0068 * 0069 * class KNewUserGeneral; 0070 * class KNewUserPersonal; 0071 * 0072 * class KNewUserWizard : public KMyMoneyWizard 0073 * { 0074 * Q_OBJECT 0075 * public: 0076 * KNewUserWizard(QWidget* parent = nullptr, const char* name = 0, bool modal = false, Qt::WindowFlags flags = 0); 0077 * 0078 * private: 0079 * KNewUserGeneral* m_generalPage; 0080 * KNewUserPersonal* m_personalPage; 0081 * KNewUserFinal* m_finalPage; 0082 * // add more pages here 0083 * 0084 * friend class KNewUserGeneral; 0085 * friend class KNewUserPersonal; 0086 * friend class KNewUserFinal; 0087 * // add more pages here 0088 * }; 0089 * @endcode 0090 * 0091 * The implementation is also easy and looks like this: 0092 * 0093 * @code 0094 * KNewUserWizard::KNewUserWizard(QWidget* parent, const char* name, bool modal, Qt::WindowFlags flags) : 0095 * KMyMoneyWizard(parent, name, modal, flags) 0096 * { 0097 * setTitle("KMyMoney New User Setup"); 0098 * addStep("General Data"); 0099 * addStep("Personal Data"); 0100 * addStep("Finish"); 0101 * 0102 * m_generalPage = new KNewUserGeneral(this); 0103 * m_personalPage = new KNewUserPersonal(this); 0104 * m_finalPage = new KNewUserFinal(this); 0105 * 0106 * setFirstPage(m_testPage1); 0107 * } 0108 * @endcode 0109 * 0110 * Don't forget to call setFirstPage() to get things started. 0111 * 0112 * The code to use this whole structure would then look something like this: 0113 * 0114 * @code 0115 * KNewUserWizard* wizard = new KNewUserWizard(this, "NewUserWizard"); 0116 * int rc = wizard->exec(); 0117 * @endcode 0118 * 0119 * The return code of exec() is either @p QDialog::Accepted or 0120 * @p QDialog::Rejected. 0121 * 0122 * @note The implementation of this class is heavily based on ideas found at 0123 * https://doc.qt.io/qt-5/qtwidgets-dialogs-licensewizard-example.html 0124 */ 0125 class KMyMoneyWizardPrivate; 0126 class KMyMoneyWizard : public QDialog 0127 { 0128 friend class KMyMoneyWizardPage; 0129 0130 Q_OBJECT 0131 Q_DISABLE_COPY(KMyMoneyWizard) 0132 0133 public: 0134 /** 0135 * Modify the title of the wizard to be @p txt. 0136 * 0137 * @param txt The text that should be used as title 0138 */ 0139 void setTitle(const QString& txt); 0140 0141 /** 0142 * Add step @p text to the wizard 0143 * 0144 * @param text Text to be shown for this step 0145 */ 0146 void addStep(const QString& text); 0147 0148 QList<KMyMoneyWizardPage*> historyPages() const; 0149 0150 /** 0151 * This method repeats selection of the current step in the 0152 * step frame. 0153 * This is used to allow changes made to showing and hiding 0154 * pages to immediately to be reflected in the step frame 0155 */ 0156 void reselectStep(); 0157 0158 /** 0159 * Setup a global help context for the wizard. It will be used whenever 0160 * there is no specific help context available for the current page. 0161 * 0162 * @sa KMyMoneyWizardPage::helpContext() 0163 */ 0164 void setHelpContext(const QString& ctx); 0165 0166 virtual ~KMyMoneyWizard(); 0167 0168 public Q_SLOTS: 0169 void selectNextPage(); 0170 void selectPreviousPage(); 0171 0172 Q_SIGNALS: 0173 // /** 0174 // * This signal is sent out, when a new payee needs to be created 0175 // * @sa KMyMoneyCombo::createItem() 0176 // * 0177 // * @param txt The name of the payee to be created 0178 // * @param id A connected slot should store the id of the created object in this variable 0179 // */ 0180 // void createPayee(const QString& txt, QString& id); 0181 0182 // /** 0183 // * This signal is sent out, when a new category needs to be created 0184 // * @sa KMyMoneyCombo::createItem() 0185 // * 0186 // * @param txt The name of the category to be created 0187 // * @param id A connected slot should store the id of the created object in this variable 0188 // */ 0189 // void createCategory(const QString& txt, QString& id); 0190 0191 protected: 0192 KMyMoneyWizardPrivate * const d_ptr; 0193 KMyMoneyWizard(KMyMoneyWizardPrivate &dd, QWidget* parent = nullptr, bool modal = false, Qt::WindowFlags f = 0); 0194 /** 0195 * Constructor (kept protected, so that one cannot create such an object directly) 0196 */ 0197 explicit KMyMoneyWizard(QWidget* parent = nullptr, bool modal = false, Qt::WindowFlags f = 0); 0198 0199 protected Q_SLOTS: 0200 void accept() override; 0201 void completeStateChanged(); 0202 0203 private Q_SLOTS: 0204 void backButtonClicked(); 0205 void nextButtonClicked(); 0206 void helpButtonClicked(); 0207 0208 private: 0209 Q_DECLARE_PRIVATE(KMyMoneyWizard) 0210 }; 0211 0212 #endif