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

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2007 Aurélien Gâteau <agateau@kde.org>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018 
0019 */
0020 #ifndef SLIDECONTAINER_H
0021 #define SLIDECONTAINER_H
0022 
0023 // Qt
0024 #include <QFrame>
0025 #include <QPointer>
0026 
0027 #include <lib/gwenviewlib_export.h>
0028 
0029 class QPropertyAnimation;
0030 
0031 namespace Gwenview
0032 {
0033 /**
0034  * This widget is design to contain one child widget, the "content" widget.
0035  * It will start hidden by default. Calling slideIn() will slide in the content
0036  * widget from the top border. Calling slideOut() will slide it out.
0037  */
0038 class GWENVIEWLIB_EXPORT SlideContainer : public QFrame
0039 {
0040     Q_OBJECT
0041     Q_PROPERTY(int slideHeight READ slideHeight WRITE setSlideHeight)
0042 public:
0043     explicit SlideContainer(QWidget *parent = nullptr);
0044 
0045     /**
0046      * Returns the content widget
0047      */
0048     QWidget *content() const;
0049 
0050     /**
0051      * Defines the content widget
0052      */
0053     void setContent(QWidget *content);
0054 
0055     QSize sizeHint() const override;
0056 
0057     QSize minimumSizeHint() const override;
0058 
0059     int slideHeight() const;
0060 
0061     Q_INVOKABLE void setSlideHeight(int height);
0062 
0063 public Q_SLOTS:
0064     /**
0065      * Slides the content widget in.
0066      * Calling it multiple times won't cause the animation to be replayed.
0067      */
0068     void slideIn();
0069 
0070     /**
0071      * Slides the content widget out.
0072      * Calling it multiple times won't cause the animation to be replayed.
0073      */
0074     void slideOut();
0075 
0076 Q_SIGNALS:
0077     void slidedIn();
0078     void slidedOut();
0079 
0080 protected:
0081     void resizeEvent(QResizeEvent *) override;
0082     bool eventFilter(QObject *, QEvent *event) override;
0083 
0084 private Q_SLOTS:
0085     void slotAnimFinished();
0086 
0087 private:
0088     QPointer<QWidget> mContent;
0089     QPointer<QPropertyAnimation> mAnim;
0090     bool mSlidingOut;
0091 
0092     void adjustContentGeometry();
0093 
0094     void animTo(int height);
0095 };
0096 
0097 } /* namespace */
0098 
0099 #endif /* SLIDECONTAINER_H */