1 /*************************************************************************** 2 * Copyright (c) 2008 Jeff Mitchell <mitchell@kde.org> * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 18 ***************************************************************************/ 19 20 #ifndef POPUPDROPPER_H 21 #define POPUPDROPPER_H 22 23 #include <QGraphicsScene> 24 #include <QGraphicsView> 25 #include <QStack> 26 27 #include "PopupDropper_Export.h" 28 29 class QMenu; 30 class QSvgRenderer; 31 class QTimeLine; 32 class QWidget; 33 class PopupDropper; 34 class PopupDropperItem; 35 class PopupDropperPrivate; 36 37 class POPUPDROPPER_EXPORT PopupDropper : public QObject 38 { 39 Q_OBJECT 40 41 Q_PROPERTY( Fading fading READ fading WRITE setFading ) 42 Q_PROPERTY( int overlayLevel READ overlayLevel ) 43 Q_PROPERTY( int deleteTimeout READ deleteTimeout WRITE setDeleteTimeout ) 44 Q_PROPERTY( bool standalone READ standalone ) 45 Q_PROPERTY( bool quitOnDragLeave READ quitOnDragLeave WRITE setQuitOnDragLeave ) 46 Q_PROPERTY( QColor windowColor READ windowColor WRITE setWindowColor ) 47 Q_PROPERTY( QBrush windowBackgroundBrush READ windowBackgroundBrush WRITE setWindowBackgroundBrush ) 48 Q_PROPERTY( QColor baseTextColor READ baseTextColor WRITE setBaseTextColor ) 49 Q_PROPERTY( QPen hoveredBorderPen READ hoveredBorderPen WRITE setHoveredBorderPen ) 50 Q_PROPERTY( QBrush hoveredFillBrush READ hoveredFillBrush WRITE setHoveredFillBrush ) 51 Q_PROPERTY( QString windowTitle READ windowTitle WRITE setWindowTitle ) 52 Q_PROPERTY( QString svgFile READ svgFile WRITE setSvgFile ) 53 Q_PROPERTY( QSvgRenderer* svgRenderer READ svgRenderer WRITE setSvgRenderer ) 54 Q_PROPERTY( int horizontalOffset READ horizontalOffset WRITE setHorizontalOffset ) 55 Q_PROPERTY( const QTimeLine* fadeHideTimer READ fadeHideTimer ) 56 Q_PROPERTY( const QTimeLine* fadeShowTimer READ fadeShowTimer ) 57 Q_PROPERTY( const QSize viewSize READ viewSize ) 58 59 public: 60 enum Fading { NoFade, FadeIn, FadeOut, FadeInOut }; 61 Q_ENUM( Fading ) 62 63 explicit PopupDropper( QWidget *parent, bool standalone = false ); 64 ~PopupDropper() override; 65 66 int overlayLevel() const; 67 void initOverlay( QWidget* parent, PopupDropperPrivate* priv = nullptr ); 68 69 void addOverlay(); 70 71 PopupDropperItem* addSubmenu( PopupDropper** pd, const QString &text ); 72 73 bool addMenu( const QMenu *menu ); 74 75 bool standalone() const; 76 77 void show(); 78 void showAllOverlays(); 79 void hideAllOverlays(); 80 void update(); 81 void updateAllOverlays(); 82 bool isHidden() const; 83 bool isEmpty( bool allItems = true ) const; 84 85 bool quitOnDragLeave() const; 86 void setQuitOnDragLeave( bool quit ); 87 88 int fadeInTime() const; 89 void setFadeInTime( const int msecs ); 90 int fadeOutTime() const; 91 void setFadeOutTime( const int msecs ); 92 PopupDropper::Fading fading() const; 93 void setFading( PopupDropper::Fading fade ); 94 const QTimeLine* fadeHideTimer() const; 95 const QTimeLine* fadeShowTimer() const; 96 97 void setDeleteTimeout( int msecs ); 98 int deleteTimeout() const; 99 100 QColor windowColor() const; 101 void setWindowColor( const QColor &window ); 102 QBrush windowBackgroundBrush() const; 103 void setWindowBackgroundBrush( const QBrush &window ); 104 QColor baseTextColor() const; 105 void setBaseTextColor( const QColor &baseText ); 106 QColor hoveredTextColor() const; 107 void setHoveredTextColor( const QColor &hoveredText ); 108 QPen hoveredBorderPen() const; 109 void setHoveredBorderPen( const QPen &hoveredBorder ); 110 QBrush hoveredFillBrush() const; 111 void setHoveredFillBrush( const QBrush &hoveredFill ); 112 void setColors( const QColor &window, const QColor &baseText, const QColor &hoveredText, const QColor &hoveredBorder, const QColor &hoveredFill ); 113 void setPalette( const QColor &window ); 114 void setPalette( const QColor &window, const QColor &baseText, const QColor &hoveredText, const QColor &hoveredBorder, const QColor &hoveredFill ); 115 116 QString windowTitle() const; 117 void setWindowTitle( const QString &title ); 118 119 QString svgFile() const; 120 void setSvgFile( const QString &file ); 121 QSvgRenderer* svgRenderer(); 122 void setSvgRenderer( QSvgRenderer *renderer ); 123 124 void setHorizontalOffset( int pixels ); 125 int horizontalOffset() const; 126 127 const QSize viewSize() const; 128 129 void addItem( PopupDropperItem *item, bool useSharedRenderer = true ); 130 QList<PopupDropperItem *> items() const; 131 QList<PopupDropperItem *> submenuItems( const PopupDropperItem *item ) const; 132 void forEachItem( void callback(void*) ); 133 void addSeparator( PopupDropperItem *separator = nullptr ); 134 135 Q_SIGNALS: 136 void fadeHideFinished(); 137 138 public Q_SLOTS: 139 void clear(); 140 void hide(); 141 bool subtractOverlay(); 142 143 private Q_SLOTS: 144 void activateSubmenu(); 145 void slotHideAllOverlays(); 146 147 private: 148 friend class PopupDropperView; 149 friend class PopupDropperPrivate; 150 PopupDropperPrivate* d; 151 152 void addOverlay( PopupDropperPrivate* newD ); 153 void addItem( PopupDropperItem *item, bool useSharedRenderer, bool appendToList ); 154 void forEachItemPrivate( PopupDropperPrivate *pdp, void callback(void*) ); 155 156 QStack<PopupDropperPrivate*> m_viewStack; 157 }; 158 159 #endif //POPUPDROPPER_H 160