File indexing completed on 2024-04-28 03:58:59

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2006 Olivier Goffart <ogoffart at kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #ifndef KASSISTANTDIALOG_H
0009 #define KASSISTANTDIALOG_H
0010 
0011 #include <kpagedialog.h>
0012 
0013 #include <kwidgetsaddons_export.h>
0014 
0015 class KAssistantDialogPrivate;
0016 
0017 /**
0018  * @class KAssistantDialog kassistantdialog.h KAssistantDialog
0019  *
0020  * This class provides a framework for assistant dialogs.
0021  *
0022  * An assistant dialog consists of a sequence of pages.
0023  * Its purpose is to guide the user (assist) through a process step by step.
0024  * Assistant dialogs are useful for complex or infrequently occurring tasks
0025  * that people may find difficult to learn or do.
0026  * Sometimes a task requires too many input fields to fit them on a single dialog.
0027  *
0028  * Create and populate dialog pages that inherit from QWidget and add them
0029  * to the assistant dialog using addPage().
0030  *
0031  * The functions next() and back() are virtual and may be reimplemented to
0032  * override the default actions of the next and back buttons.
0033  *
0034  * \image html kassistantdialog.png "KAssistantDialog"
0035  *
0036  * @author Olivier Goffart <ogoffart at kde.org>
0037  */
0038 class KWIDGETSADDONS_EXPORT KAssistantDialog : public KPageDialog
0039 {
0040     Q_OBJECT
0041 public:
0042     /**
0043      * Construct a new assistant dialog with @p parent as parent.
0044      * @param parent is the parent of the widget.
0045      * @flags the window flags to give to the assistant dialog. The
0046      * default of zero is usually what you want.
0047      */
0048     explicit KAssistantDialog(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
0049     ~KAssistantDialog() override;
0050 
0051     /**
0052      * Specify if the content of the page is valid, and if the next button may be enabled on this page.
0053      * By default all pages are valid.
0054      *
0055      * This will disable or enable the next button on the specified page
0056      *
0057      * @param page the page on which the next button will be enabled/disable
0058      * @param enable if true the next button will be enabled, if false it will be disabled
0059      */
0060     void setValid(KPageWidgetItem *page, bool enable);
0061 
0062     /**
0063      * return if a page is valid
0064      * @param page the page to check the validity of
0065      * @see setValid()
0066      */
0067     bool isValid(KPageWidgetItem *page) const;
0068 
0069     /**
0070      * Specify whether a page is appropriate.
0071      *
0072      * A page is considered inappropriate if it should not be shown due to
0073      * the contents of other pages making it inappropriate.
0074      *
0075      * A page which is inappropriate will not be shown.
0076      *
0077      * The last page in an assistant dialog should always be appropriate
0078      * @param page the page to set as appropriate
0079      * @param appropriate flag indicating the appropriateness of the page.
0080      * If @p appropriate is true, then @p page is appropriate and will be
0081      * shown in the assistant dialog. If false, @p page will not be shown.
0082      */
0083     void setAppropriate(KPageWidgetItem *page, bool appropriate);
0084 
0085     /**
0086      * Check if a page is appropriate for use in the assistant dialog.
0087      * @param page is the page to check the appropriateness of.
0088      * @return true if @p page is appropriate, false if it is not
0089      */
0090     bool isAppropriate(KPageWidgetItem *page) const;
0091 
0092     /**
0093      * @returns the next button
0094      */
0095     QPushButton *nextButton() const;
0096 
0097     /**
0098      * @returns the finish button
0099      */
0100     QPushButton *backButton() const;
0101 
0102     /**
0103      * @returns the finish button
0104      */
0105     QPushButton *finishButton() const;
0106 
0107 public Q_SLOTS:
0108     /**
0109      * Called when the user clicks the Back button.
0110      *
0111      * This function will show the preceding relevant page in the sequence.
0112      * Do nothing if the current page is the first page in the sequence.
0113      */
0114     virtual void back();
0115 
0116     /**
0117      * Called when the user clicks the Next/Finish button.
0118      *
0119      * This function will show the next relevant page in the sequence.
0120      * If the current page is the last page, it will call accept()
0121      */
0122     virtual void next();
0123 
0124 protected:
0125     /**
0126      * Construct an assistant dialog from a single widget.
0127      * @param widget the widget to construct the dialog with
0128      * @param parent the parent of the assistant dialog
0129      * @flags the window flags to use when creating the widget. The default
0130      * of zero is usually fine.
0131      *
0132      * Calls the KPageDialog(KPageWidget *widget, QWidget *parent, Qt::WindowFlags flags) constructor
0133      */
0134     explicit KAssistantDialog(KPageWidget *widget, QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
0135 
0136     void showEvent(QShowEvent *event) override;
0137 
0138 private:
0139     Q_DECLARE_PRIVATE(KAssistantDialog)
0140 
0141     Q_DISABLE_COPY(KAssistantDialog)
0142 };
0143 
0144 #endif