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

0001 /*
0002     SPDX-FileCopyrightText: 2006-2010 Tony Bloomfield <tonybloom@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 KGUIUTILS_H
0008 #define KGUIUTILS_H
0009 
0010 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <QObject>
0014 
0015 // ----------------------------------------------------------------------------
0016 // KDE Includes
0017 
0018 // ----------------------------------------------------------------------------
0019 // Project Includes
0020 
0021 #include "kmm_base_widgets_export.h"
0022 
0023 class QWidget;
0024 class QPushButton;
0025 
0026 /**
0027   * @author Tony Bloomfield
0028   */
0029 class KMandatoryFieldGroupPrivate;
0030 class KMM_BASE_WIDGETS_EXPORT KMandatoryFieldGroup : public QObject
0031 {
0032     Q_OBJECT
0033     Q_DISABLE_COPY(KMandatoryFieldGroup)
0034 
0035 public:
0036     explicit KMandatoryFieldGroup(QObject *parent);
0037     ~KMandatoryFieldGroup();
0038 
0039     /**
0040       * This method adds a widget to the list of mandatory fields for the current dialog
0041       *
0042       * @param widget pointer to the widget to be added
0043       */
0044     void add(QWidget *widget);
0045 
0046     /**
0047       * This method removes a widget form the list of mandatory fields for the current dialog
0048       *
0049       * @param widget pointer to the widget to be removed
0050       */
0051     void remove(QWidget *widget);
0052 
0053     /**
0054      * This method removes all widgets from the list of mandatory fields for the current dialog
0055      */
0056     void removeAll();
0057 
0058     /**
0059       * This method designates the button to be enabled when all mandatory fields
0060       * have been completed
0061       *
0062       * @param button pointer to the 'ok' button
0063       */
0064     void setOkButton(QPushButton *button);
0065 
0066     /**
0067       * This method returns if all requirements for the mandatory group
0068       * have been fulfilled (@p true) or not (@p false).
0069       */
0070     bool isEnabled() const;
0071 
0072 public Q_SLOTS:
0073     void clear();
0074 
0075     /**
0076       * Force update of ok button
0077       */
0078     void changed();
0079 
0080     /**
0081      * Use this slot to set the initial @a state when checking
0082      * for all mandatory data. This can be used to add support
0083      * for widgets that are not directly supported by
0084      * this object. The default @a state when this method
0085      * was never called is @c true.
0086      */
0087     void setExternalMandatoryState(bool state);
0088 
0089 Q_SIGNALS:
0090     void stateChanged();
0091     void stateChanged(bool state);
0092 
0093 private:
0094     KMandatoryFieldGroupPrivate * const d_ptr;
0095     Q_DECLARE_PRIVATE(KMandatoryFieldGroup)
0096 };
0097 
0098 #endif // KGUIUTILS_H