File indexing completed on 2024-04-14 05:34:14

0001 /*
0002     SPDX-FileCopyrightText: 2015 Tomasz Bojczuk <seelook@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef DIALOGBASE_H
0008 #define DIALOGBASE_H
0009 
0010 #include <QDialog>
0011 #include <QDialogButtonBox>
0012 #include <QBoxLayout>
0013 #include <QPushButton>
0014 
0015 /**
0016  * QDialog subclass with common method used in the plugin classes.
0017  * It has already initialized layout (@class QBoxLayout), with @p buttonBox(),
0018  * so adding other widgets/layout should be invoked by:
0019  * @p layout()->insert() to keep buttonBox at the bottom.
0020  * It also handles CTRL+Enter shortcut to accept - as old Kdialog did.
0021  */
0022 class DialogBase : public QDialog
0023 {
0024 
0025     Q_OBJECT
0026 
0027 public:
0028     /**
0029      * Creates Dialog window with given buttons types.
0030      * But only OK and Cancel are supported so far
0031      * and available through @p okButton() and @p cancelButton()
0032      */
0033     explicit DialogBase(QDialogButtonBox::StandardButtons buttons, QWidget* parent = nullptr);
0034 
0035     QPushButton* okButton() { return m_okButton; }
0036     QPushButton* cancelButton() { return m_cancelButton; }
0037     QDialogButtonBox* buttonBox() { return m_buttonBox; }
0038     /**
0039      * Layout of a dialog. By default vertical (@p QBoxLayout::TopToBottom)
0040      * Use  layout()->insertLayout(0, someLaayout) or
0041      * layout()->insertWidget(0, someWidget)
0042      * to keep buttonBox at the dialog bottom.
0043      */
0044     QBoxLayout* layout() { return m_layout; }
0045 
0046 protected:
0047     void keyReleaseEvent(QKeyEvent* event) override; // to handle CTRL+Enter shortcut to accept dialog
0048 
0049 private:
0050     QPushButton               *m_okButton;
0051     QPushButton               *m_cancelButton;
0052     QDialogButtonBox          *m_buttonBox;
0053     QBoxLayout                *m_layout;
0054 
0055 };
0056 
0057 #endif // DIALOGBASE_H