1 /* 2 * advwidget.h - AdvancedWidget template class 3 * Copyright (C) 2005-2007 Michail Pishchagin 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Lesser General Public 7 * License as published by the Free Software Foundation; either 8 * version 2.1 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public 16 * License along with this library; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 * 19 */ 20 21 #ifndef ADVWIDGET_H 22 #define ADVWIDGET_H 23 24 #include <QWidget> 25 26 class GAdvancedWidget : public QObject 27 { 28 Q_OBJECT 29 public: 30 GAdvancedWidget(QWidget *parent); 31 32 static bool stickEnabled(); 33 static void setStickEnabled(bool val); 34 35 static int stickAt(); 36 static void setStickAt(int val); 37 38 static bool stickToWindows(); 39 static void setStickToWindows(bool val); 40 41 QString geometryOptionPath() const; 42 void setGeometryOptionPath(const QString& optionPath); 43 44 void showWithoutActivation(); 45 46 bool flashing() const; 47 void doFlash(bool on); 48 49 #ifdef Q_OS_WIN 50 bool winEvent(MSG* msg, long* result); 51 #endif 52 53 void moveEvent(QMoveEvent *e); 54 void changeEvent(QEvent *event); 55 56 57 public: 58 class Private; 59 private: 60 Private *d; 61 }; 62 63 template <class BaseClass> 64 class AdvancedWidget : public BaseClass 65 { 66 private: 67 GAdvancedWidget *gAdvWidget; 68 69 public: 70 AdvancedWidget(QWidget *parent = 0, Qt::WindowFlags f = 0) BaseClass(parent)71 : BaseClass(parent) 72 , gAdvWidget(0) 73 { 74 if (f != 0) 75 BaseClass::setWindowFlags(f); 76 gAdvWidget = new GAdvancedWidget( this ); 77 } 78 ~AdvancedWidget()79 virtual ~AdvancedWidget() 80 { 81 } 82 setWindowIcon(const QIcon & icon)83 void setWindowIcon(const QIcon& icon) 84 { 85 #ifdef Q_OS_MAC 86 Q_UNUSED(icon); 87 #else 88 BaseClass::setWindowIcon(icon); 89 #endif 90 } 91 stickEnabled()92 static bool stickEnabled() { return GAdvancedWidget::stickEnabled(); } setStickEnabled(bool val)93 static void setStickEnabled( bool val ) { GAdvancedWidget::setStickEnabled( val ); } 94 stickAt()95 static int stickAt() { return GAdvancedWidget::stickAt(); } setStickAt(int val)96 static void setStickAt( int val ) { GAdvancedWidget::setStickAt( val ); } 97 stickToWindows()98 static bool stickToWindows() { return GAdvancedWidget::stickToWindows(); } setStickToWindows(bool val)99 static void setStickToWindows( bool val ) { GAdvancedWidget::setStickToWindows( val ); } 100 geometryOptionPath()101 QString geometryOptionPath() const 102 { 103 if (gAdvWidget) 104 return gAdvWidget->geometryOptionPath(); 105 return QString(); 106 } 107 setGeometryOptionPath(const QString & optionPath)108 void setGeometryOptionPath(const QString& optionPath) 109 { 110 if (gAdvWidget) 111 gAdvWidget->setGeometryOptionPath(optionPath); 112 } 113 flashing()114 bool flashing() const 115 { 116 if (gAdvWidget) 117 return gAdvWidget->flashing(); 118 return false; 119 } 120 showWithoutActivation()121 void showWithoutActivation() 122 { 123 if (gAdvWidget) 124 gAdvWidget->showWithoutActivation(); 125 } 126 doFlash(bool on)127 virtual void doFlash( bool on ) 128 { 129 if (gAdvWidget) 130 gAdvWidget->doFlash( on ); 131 } 132 133 #ifdef Q_OS_WIN winEvent(MSG * msg,long * result)134 bool winEvent(MSG* msg, long* result) 135 { 136 if (gAdvWidget) 137 return gAdvWidget->winEvent(msg, result); 138 return BaseClass::winEvent(msg, result); 139 } 140 #endif 141 moveEvent(QMoveEvent * e)142 void moveEvent( QMoveEvent *e ) 143 { 144 if (gAdvWidget) 145 gAdvWidget->moveEvent(e); 146 } 147 setWindowTitle(const QString & c)148 void setWindowTitle( const QString &c ) 149 { 150 BaseClass::setWindowTitle( c ); 151 windowTitleChanged(); 152 } 153 154 protected: windowTitleChanged()155 virtual void windowTitleChanged() 156 { 157 doFlash(flashing()); 158 } 159 160 protected: changeEvent(QEvent * event)161 void changeEvent(QEvent *event) 162 { 163 if (gAdvWidget) { 164 gAdvWidget->changeEvent(event); 165 } 166 BaseClass::changeEvent(event); 167 } 168 }; 169 170 #endif 171