File indexing completed on 2024-05-05 04:47:42
0001 /*************************************************************************** 0002 * Copyright (c) 2008 Jeff Mitchell <mitchell@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify * 0005 * it under the terms of the GNU General Public License as published by * 0006 * the Free Software Foundation; either version 2 of the License, or * 0007 * (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the * 0016 * Free Software Foundation, Inc., * 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 0018 ***************************************************************************/ 0019 0020 #ifndef POPUPDROPPER_H 0021 #define POPUPDROPPER_H 0022 0023 #include <QGraphicsScene> 0024 #include <QGraphicsView> 0025 #include <QStack> 0026 0027 #include "PopupDropper_Export.h" 0028 0029 class QMenu; 0030 class QSvgRenderer; 0031 class QTimeLine; 0032 class QWidget; 0033 class PopupDropper; 0034 class PopupDropperItem; 0035 class PopupDropperPrivate; 0036 0037 class POPUPDROPPER_EXPORT PopupDropper : public QObject 0038 { 0039 Q_OBJECT 0040 0041 Q_PROPERTY( Fading fading READ fading WRITE setFading ) 0042 Q_PROPERTY( int overlayLevel READ overlayLevel ) 0043 Q_PROPERTY( int deleteTimeout READ deleteTimeout WRITE setDeleteTimeout ) 0044 Q_PROPERTY( bool standalone READ standalone ) 0045 Q_PROPERTY( bool quitOnDragLeave READ quitOnDragLeave WRITE setQuitOnDragLeave ) 0046 Q_PROPERTY( QColor windowColor READ windowColor WRITE setWindowColor ) 0047 Q_PROPERTY( QBrush windowBackgroundBrush READ windowBackgroundBrush WRITE setWindowBackgroundBrush ) 0048 Q_PROPERTY( QColor baseTextColor READ baseTextColor WRITE setBaseTextColor ) 0049 Q_PROPERTY( QPen hoveredBorderPen READ hoveredBorderPen WRITE setHoveredBorderPen ) 0050 Q_PROPERTY( QBrush hoveredFillBrush READ hoveredFillBrush WRITE setHoveredFillBrush ) 0051 Q_PROPERTY( QString windowTitle READ windowTitle WRITE setWindowTitle ) 0052 Q_PROPERTY( QString svgFile READ svgFile WRITE setSvgFile ) 0053 Q_PROPERTY( QSvgRenderer* svgRenderer READ svgRenderer WRITE setSvgRenderer ) 0054 Q_PROPERTY( int horizontalOffset READ horizontalOffset WRITE setHorizontalOffset ) 0055 Q_PROPERTY( const QTimeLine* fadeHideTimer READ fadeHideTimer ) 0056 Q_PROPERTY( const QTimeLine* fadeShowTimer READ fadeShowTimer ) 0057 Q_PROPERTY( const QSize viewSize READ viewSize ) 0058 0059 public: 0060 enum Fading { NoFade, FadeIn, FadeOut, FadeInOut }; 0061 Q_ENUM( Fading ) 0062 0063 explicit PopupDropper( QWidget *parent, bool standalone = false ); 0064 ~PopupDropper() override; 0065 0066 int overlayLevel() const; 0067 void initOverlay( QWidget* parent, PopupDropperPrivate* priv = nullptr ); 0068 0069 void addOverlay(); 0070 0071 PopupDropperItem* addSubmenu( PopupDropper** pd, const QString &text ); 0072 0073 bool addMenu( const QMenu *menu ); 0074 0075 bool standalone() const; 0076 0077 void show(); 0078 void showAllOverlays(); 0079 void hideAllOverlays(); 0080 void update(); 0081 void updateAllOverlays(); 0082 bool isHidden() const; 0083 bool isEmpty( bool allItems = true ) const; 0084 0085 bool quitOnDragLeave() const; 0086 void setQuitOnDragLeave( bool quit ); 0087 0088 int fadeInTime() const; 0089 void setFadeInTime( const int msecs ); 0090 int fadeOutTime() const; 0091 void setFadeOutTime( const int msecs ); 0092 PopupDropper::Fading fading() const; 0093 void setFading( PopupDropper::Fading fade ); 0094 const QTimeLine* fadeHideTimer() const; 0095 const QTimeLine* fadeShowTimer() const; 0096 0097 void setDeleteTimeout( int msecs ); 0098 int deleteTimeout() const; 0099 0100 QColor windowColor() const; 0101 void setWindowColor( const QColor &window ); 0102 QBrush windowBackgroundBrush() const; 0103 void setWindowBackgroundBrush( const QBrush &window ); 0104 QColor baseTextColor() const; 0105 void setBaseTextColor( const QColor &baseText ); 0106 QColor hoveredTextColor() const; 0107 void setHoveredTextColor( const QColor &hoveredText ); 0108 QPen hoveredBorderPen() const; 0109 void setHoveredBorderPen( const QPen &hoveredBorder ); 0110 QBrush hoveredFillBrush() const; 0111 void setHoveredFillBrush( const QBrush &hoveredFill ); 0112 void setColors( const QColor &window, const QColor &baseText, const QColor &hoveredText, const QColor &hoveredBorder, const QColor &hoveredFill ); 0113 void setPalette( const QColor &window ); 0114 void setPalette( const QColor &window, const QColor &baseText, const QColor &hoveredText, const QColor &hoveredBorder, const QColor &hoveredFill ); 0115 0116 QString windowTitle() const; 0117 void setWindowTitle( const QString &title ); 0118 0119 QString svgFile() const; 0120 void setSvgFile( const QString &file ); 0121 QSvgRenderer* svgRenderer(); 0122 void setSvgRenderer( QSvgRenderer *renderer ); 0123 0124 void setHorizontalOffset( int pixels ); 0125 int horizontalOffset() const; 0126 0127 const QSize viewSize() const; 0128 0129 void addItem( PopupDropperItem *item, bool useSharedRenderer = true ); 0130 QList<PopupDropperItem *> items() const; 0131 QList<PopupDropperItem *> submenuItems( const PopupDropperItem *item ) const; 0132 void forEachItem( void callback(void*) ); 0133 void addSeparator( PopupDropperItem *separator = nullptr ); 0134 0135 Q_SIGNALS: 0136 void fadeHideFinished(); 0137 0138 public Q_SLOTS: 0139 void clear(); 0140 void hide(); 0141 bool subtractOverlay(); 0142 0143 private Q_SLOTS: 0144 void activateSubmenu(); 0145 void slotHideAllOverlays(); 0146 0147 private: 0148 friend class PopupDropperView; 0149 friend class PopupDropperPrivate; 0150 PopupDropperPrivate* d; 0151 0152 void addOverlay( PopupDropperPrivate* newD ); 0153 void addItem( PopupDropperItem *item, bool useSharedRenderer, bool appendToList ); 0154 void forEachItemPrivate( PopupDropperPrivate *pdp, void callback(void*) ); 0155 0156 QStack<PopupDropperPrivate*> m_viewStack; 0157 }; 0158 0159 #endif //POPUPDROPPER_H