File indexing completed on 2024-05-12 05:08:07

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 KMYMONEYWIZARDPAGE_H
0008 #define KMYMONEYWIZARDPAGE_H
0009 
0010 #include "kmm_wizard_export.h"
0011 
0012 // ----------------------------------------------------------------------------
0013 // QT Includes
0014 
0015 #include <qglobal.h>
0016 
0017 // ----------------------------------------------------------------------------
0018 // KDE Includes
0019 
0020 // ----------------------------------------------------------------------------
0021 // Project Includes
0022 
0023 class QString;
0024 class QWidget;
0025 
0026 class KMyMoneyWizard;
0027 
0028 /**
0029   * @author Thomas Baumgart (C) 2006
0030   *
0031   * @note: the following documentation is somewhat outdated
0032   * as of May 2007. Wizards should use a namespace
0033   * for the pages and can use the WizardPage<T> template class.
0034   * See the NewUserWizard class and NewUserWizardPages namespace
0035   * as an example of this setup.
0036   *
0037   * This class represents the base class for wizard pages for the
0038   * KMyMoneyWizard. One cannot create a wizard page directly, but
0039   * must derive from it. The KMyMoneyWizardPage class provides the
0040   * necessary functionality to work in concert with KMyMoneyWizard.
0041   *
0042   * Therefore, few steps are necessary to use this class. They seem to
0043   * be awkward at some stage, but I wanted to be able to use Qt designer
0044   * to actually design the widget for the page. That's why some things
0045   * aren't implemented in a more straight fashion than one would
0046   * normally do this.
0047   *
0048   * The first step is to derive a specific base page for the specific wizard.
0049   * In this example we use the name NewUser as template for the specific wizard.
0050   * This class provides a 'back'-pointer to the actual wizard object
0051   * for all pages.
0052   *
0053   * @code
0054   * class KNewUserPage : public KMyMoneyWizardPage
0055   * {
0056   * public:
0057   *   KNewUserPage(unsigned int step, QWidget* widget, KNewUserWizard* parent, const char* name);
0058   *
0059   * protected:
0060   *   KNewUserWizard*    m_wizard;
0061   * }
0062   * @endcode
0063   *
0064   * The implementation of this class is rather straight-forward:
0065   *
0066   * @code
0067   * KNewUserPage::KNewUserPage(unsigned int step, QWidget* widget, KNewUserWizard* parent, const char* name) :
0068   *   KMyMoneyWizardPage(step, widget, name),
0069   *   m_wizard(parent)
0070   * {
0071   * }
0072   * @endcode
0073   *
0074   * For each page of the wizard, you will have to create a @p ui file with
0075   * Qt designer.
0076   * Let's assume we call the first page of the wizard 'General' and go
0077   * from there.
0078   * We also assume, that the wizard has more than one page.
0079   * The ui designer generated class should have the name KNewUserGeneral
0080   * as all other dialogs. The class definition of KNewUserGeneral will
0081   * look like this:
0082   *
0083   * @code
0084   * class KNewUserGeneral : public KNewUserGeneral, public KNewUserPage
0085   * {
0086   *   Q_OBJECT
0087   * public:
0088   *   KNewUserGeneral(KNewUserWizard* parent, const char* name = 0);
0089   *   KMyMoneyWizardPage* nextPage();
0090   *   bool isLastPage() { return false; }
0091   *
0092   * protected:
0093   *   KNewUserWizard*    m_wizard;
0094   * }
0095   * @endcode
0096   *
0097   * The implementation depends heavily on the logic of your code. If you only
0098   * fill some widgets, it could be as simple as:
0099   *
0100   * @code
0101   * KNewUserGeneral::KNewUserGeneral(KNewUserWizard* parent, const char* name) :
0102   *   KNewUserGeneral(parent),
0103   *   KNewUserPage(1, this, parent, name)
0104   * {
0105   *   KMandatoryFieldGroup* mandatoryGroup = new KMandatoryFieldGroup(this);
0106   *   mandatoryGroup->add(m_userName);
0107   *   connect(m_mandatoryGroup, SIGNAL(stateChanged()), object(), SIGNAL(completeStateChanged()));
0108   * }
0109   *
0110   * KMyMoneyWizardPage* KNewUserGeneral::nextPage()
0111   * {
0112   *   return m_wizard->m_personalPage;
0113   * }
0114   * @endcode
0115   *
0116   * A note on the first parameter to KNewUserPage in the above example: it ties
0117   * this page to be part of step 1 (see KMyMoneyWizard::addStep() for details).
0118   *
0119   * Depending on the actual logic of the page, you would want to override the
0120   * following methods: resetPage, nextPage, isLastPage and isComplete.
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 KMyMoneyWizardPagePrivate;
0126 class KMM_WIZARD_EXPORT KMyMoneyWizardPage
0127 {
0128 public:
0129     /**
0130       * This method is called by the wizard when the page is entered from
0131       * the previous page. The default implementation does nothing.
0132       */
0133     virtual void enterPage();
0134 
0135     /**
0136       * This method is called by the wizard when the page is left to return to
0137       * the previous page. The default implementation does nothing.
0138       */
0139     virtual void leavePage();
0140 
0141     /**
0142       * This method is called by the wizard whenever a page is entered
0143       * (either in forward or backward direction). The default
0144       * implementation does nothing.
0145       */
0146     virtual void resetPage();
0147 
0148     /**
0149       * This method returns a pointer to the next page that should be
0150       * shown when the user presses the 'Next' button.
0151       *
0152       * @return pointer to next wizard page
0153       */
0154     virtual KMyMoneyWizardPage* nextPage() const;
0155 
0156     /**
0157       * This returns, if the current page is the last page of the wizard.
0158       * The default implementation returns @p false if nextPage() returns 0,
0159       * @p true otherwise.
0160       *
0161       * @retval false more pages follow
0162       * @retval true this is the last page of the wizard
0163       */
0164     virtual bool isLastPage() const;
0165 
0166     /**
0167       * This returns, if all necessary data for this page has been
0168       * filled. It is used to enabled the 'Next' or 'Finish' button.
0169       * The button is only enabled, if this method returns @p true,
0170       * which is the default implementation.
0171       *
0172       * @retval false more data required from the user before we can proceed
0173       * @retval true all data available, we allow to switch to the next page
0174       */
0175     virtual bool isComplete() const;
0176 
0177     /**
0178       * This method returns the step to which this page belongs.
0179       * It is required by the KMyMoneyWizard and is not intended
0180       * to be used by application code.
0181       *
0182       * @return step of wizard this page belongs to
0183       */
0184     unsigned int step() const;
0185 
0186     /**
0187       * This method returns a pointer to the widget of the page.
0188       * It is required by the KMyMoneyWizard and is not intended
0189       * to be used by application code.
0190       *
0191       * @return pointer to widget of page
0192       */
0193     QWidget* widget() const;
0194 
0195     /**
0196       * This method returns a pointer to the QObject used for
0197       * the signal/slot mechanism.
0198       * It is required by the KMyMoneyWizard and can be used
0199       * by application code for signal/slot connections as well.
0200       * Other use is not foreseen.
0201       */
0202     const KMyMoneyWizardPagePrivate *object() const;
0203 
0204     /**
0205       * This method returns a pointer to the widget which should
0206       * receive the focus when the page is opened.
0207       *
0208       * @return pointer to widget or 0 if none is to be selected
0209       *         The default implementation returns 0
0210       */
0211     virtual QWidget* initialFocusWidget() const;
0212 
0213     virtual KMyMoneyWizard* wizard() const = 0;
0214 
0215     /**
0216      * This method returns a specific help context for the page shown
0217      * The default returns an empty string.
0218      */
0219     virtual QString helpContext() const;
0220 
0221     virtual ~KMyMoneyWizardPage();
0222 protected:
0223     KMyMoneyWizardPagePrivate * const d_ptr;
0224 
0225     KMyMoneyWizardPage(KMyMoneyWizardPagePrivate &dd, uint step, QWidget *widget);
0226     Q_DECLARE_PRIVATE(KMyMoneyWizardPage)
0227 
0228     /**
0229       * Constructor (kept protected, so that one cannot create such an object directly)
0230       */
0231     explicit KMyMoneyWizardPage(uint step, QWidget* widget);
0232 
0233     /**
0234       * This method must be called by the implementation when the
0235       * data in the fields of the wizard change and the state of
0236       * completeness changed.
0237       *
0238       * @note If you do not override isComplete() then there is no need
0239       * to call this method.
0240       */
0241     void completeStateChanged();
0242 };
0243 #endif