File indexing completed on 2024-04-28 04:18:51

0001 // vim: set tabstop=4 shiftwidth=4 expandtab:
0002 /*
0003 Gwenview: an image viewer
0004 Copyright 2008 Aurélien Gâteau <agateau@kde.org>
0005 
0006 This program is free software; you can redistribute it and/or
0007 modify it under the terms of the GNU General Public License
0008 as published by the Free Software Foundation; either version 2
0009 of the License, or (at your option) any later version.
0010 
0011 This program is distributed in the hope that it will be useful,
0012 but WITHOUT ANY WARRANTY; without even the implied warranty of
0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014 GNU General Public License for more details.
0015 
0016 You should have received a copy of the GNU General Public License
0017 along with this program; if not, write to the Free Software
0018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA.
0019 
0020 */
0021 #ifndef INVISIBLEBUTTONGROUP_H
0022 #define INVISIBLEBUTTONGROUP_H
0023 
0024 #include <lib/gwenviewlib_export.h>
0025 
0026 // Qt
0027 #include <QWidget>
0028 
0029 // KF
0030 
0031 // Local
0032 
0033 class QAbstractButton;
0034 
0035 namespace Gwenview
0036 {
0037 struct InvisibleButtonGroupPrivate;
0038 /**
0039  * This class makes it possible to create radio buttons without having to put
0040  * them in a dedicated QGroupBox or KButtonGroup. This is useful when you do not
0041  * want to add visual frames to create a set of radio buttons.
0042  *
0043  * It is a QWidget so that it can support KConfigXT: it is completely
0044  * invisible and does not require the radio buttons to be its children.
0045  * The most common way to use it is to create your dialog with Designer,
0046  * including the radio buttons, and to instantiate an instance of
0047  * InvisibleButtonGroup from your code.
0048  *
0049  * Example:
0050  *
0051  * We assume "config" is a KConfigSkeleton object which contains a
0052  * "ViewMode" key. This key is an int where 1 means "list" and 2 means
0053  * "detail".
0054  * We also assume "ui" has been created with Designer and contains two
0055  * QRadioButton named "listRadioButton" and "detailRadioButton".
0056  *
0057  * @code
0058  * // Prepare the config dialog
0059  * KConfigDialog* dialog(parent, "Settings", config);
0060  *
0061  * // Create a widget in the dialog
0062  * QWidget* pageWidget = new QWidget;
0063  * ui->setupUi(pageWidget);
0064  * dialog->addPage(pageWidget, i18n("Page Title"));
0065  * @endcode
0066  *
0067  * Now we can setup an InvisibleButtonGroup to handle both radio
0068  * buttons and ensure they follow the "ViewMode" config key.
0069  *
0070  * @code
0071  * InvisibleButtonGroup* group = new InvisibleButtonGroup(pageWidget);
0072  * group->setObjectName( QLatin1String("kcfg_ViewMode" ));
0073  * group->addButton(ui->listRadioButton, 1);
0074  * group->addButton(ui->detailRadioButton, 2);
0075  * @endcode
0076  */
0077 class GWENVIEWLIB_EXPORT InvisibleButtonGroup : public QWidget
0078 {
0079     Q_OBJECT
0080     Q_PROPERTY(int current READ selected WRITE setSelected NOTIFY selectionChanged USER true)
0081 public:
0082     explicit InvisibleButtonGroup(QWidget *parent = nullptr);
0083     ~InvisibleButtonGroup() override;
0084 
0085     int selected() const;
0086 
0087     void addButton(QAbstractButton *button, int id);
0088 
0089 public Q_SLOTS:
0090     void setSelected(int id);
0091 
0092 Q_SIGNALS:
0093     void selectionChanged(int id);
0094 
0095 private:
0096     InvisibleButtonGroupPrivate *const d;
0097 };
0098 
0099 } // namespace
0100 
0101 #endif /* INVISIBLEBUTTONGROUP_H */