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