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

0001 /*
0002     SPDX-FileCopyrightText: 2014 Montel Laurent <montel@kde.org>
0003     based on code:
0004     SPDX-FileCopyrightText: 2009 Aurélien Gâteau <agateau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 #ifndef KSPLITTERCOLLAPSERBUTTON_H
0009 #define KSPLITTERCOLLAPSERBUTTON_H
0010 
0011 // Qt
0012 #include <QToolButton>
0013 #include <kwidgetsaddons_export.h>
0014 #include <memory>
0015 
0016 class QSplitter;
0017 
0018 /**
0019  * @class KSplitterCollapserButton ksplittercollapserbutton.h KSplitterCollapserButton
0020  *
0021  * A button which appears on the side of a splitter handle and allows easy
0022  * collapsing of the widget on the opposite side
0023  * @since 5.5
0024  */
0025 class KWIDGETSADDONS_EXPORT KSplitterCollapserButton : public QToolButton
0026 {
0027     Q_OBJECT
0028 public:
0029     /**
0030      * @brief KSplitterCollapserButton create a splitter collapser
0031      * @param childWidget the widget, child of the splitter, whose size is controlled by this collapser
0032      * @param splitter the splitter which this collapser should be associated with.
0033      */
0034     explicit KSplitterCollapserButton(QWidget *childWidget, QSplitter *splitter);
0035 
0036     /**
0037      * Destructor
0038      */
0039     ~KSplitterCollapserButton() override;
0040 
0041     /**
0042      * @brief isWidgetCollapsed
0043      * @return true if splitter is collapsed.
0044      */
0045     bool isWidgetCollapsed() const;
0046 
0047     QSize sizeHint() const override;
0048 
0049 public Q_SLOTS:
0050     /**
0051      * @brief collapse, this function collapses the splitter if splitter is not collapsed.
0052      */
0053     void collapse();
0054     /**
0055      * @brief restore, call this function to restore previous splitter position.
0056      */
0057     void restore();
0058     /**
0059      * @brief setCollapsed, this function allows to collapse or not the splitter.
0060      * @param collapsed if the splitter should be collapsed
0061      */
0062     void setCollapsed(bool collapsed);
0063 
0064 private Q_SLOTS:
0065     KWIDGETSADDONS_NO_EXPORT void slotClicked();
0066 
0067 protected:
0068     bool eventFilter(QObject *, QEvent *) override;
0069     void paintEvent(QPaintEvent *) override;
0070     void enterEvent(QEnterEvent *event) override;
0071     void leaveEvent(QEvent *event) override;
0072     void showEvent(QShowEvent *event) override;
0073 
0074 private:
0075     std::unique_ptr<class KSplitterCollapserButtonPrivate> const d;
0076 };
0077 
0078 #endif /* KSPLITTERCOLLAPSERBUTTON_H */