1 /* 2 SPDX-FileCopyrightText: 2014 Montel Laurent <montel@kde.org> 3 based on code: 4 SPDX-FileCopyrightText: 2009 Aurélien Gâteau <agateau@kde.org> 5 6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 7 */ 8 #ifndef KSPLITTERCOLLAPSERBUTTON_H 9 #define KSPLITTERCOLLAPSERBUTTON_H 10 11 // Qt 12 #include <QToolButton> 13 #include <kwidgetsaddons_export.h> 14 #include <memory> 15 16 class QSplitter; 17 18 /** 19 * @class KSplitterCollapserButton ksplittercollapserbutton.h KSplitterCollapserButton 20 * 21 * A button which appears on the side of a splitter handle and allows easy 22 * collapsing of the widget on the opposite side 23 * @since 5.5 24 */ 25 class KWIDGETSADDONS_EXPORT KSplitterCollapserButton : public QToolButton 26 { 27 Q_OBJECT 28 public: 29 /** 30 * @brief KSplitterCollapserButton create a splitter collapser 31 * @param childWidget the widget, child of the splitter, whose size is controlled by this collapser 32 * @param splitter the splitter which this collapser should be associated with. 33 */ 34 explicit KSplitterCollapserButton(QWidget *childWidget, QSplitter *splitter); 35 36 /** 37 * Destructor 38 */ 39 ~KSplitterCollapserButton() override; 40 41 /** 42 * @brief isWidgetCollapsed 43 * @return true if splitter is collapsed. 44 */ 45 bool isWidgetCollapsed() const; 46 47 QSize sizeHint() const override; 48 49 public Q_SLOTS: 50 /** 51 * @brief collapse, this function collapses the splitter if splitter is not collapsed. 52 */ 53 void collapse(); 54 /** 55 * @brief restore, call this function to restore previous splitter position. 56 */ 57 void restore(); 58 /** 59 * @brief setCollapsed, this function allows to collapse or not the splitter. 60 * @param collapsed if the splitter should be collapsed 61 */ 62 void setCollapsed(bool collapsed); 63 64 private Q_SLOTS: 65 void slotClicked(); 66 67 protected: 68 bool eventFilter(QObject *, QEvent *) override; 69 void paintEvent(QPaintEvent *) override; 70 71 void enterEvent(QEvent *event) override; 72 void leaveEvent(QEvent *event) override; 73 void showEvent(QShowEvent *event) override; 74 75 private: 76 std::unique_ptr<class KSplitterCollapserButtonPrivate> const d; 77 }; 78 79 #endif /* KSPLITTERCOLLAPSERBUTTON_H */ 80