1 // Adapted from oxygenwindowmanager.cpp svnversion: 1139230 2 // and QtCurve's windowmanager.cpp v1.8.17 3 4 /* 5 * Copyright (C) Pedram Pourang (aka Tsu Jan) 2014-2019 <tsujan2000@gmail.com> 6 * 7 * Kvantum is free software: you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License as published by the 9 * Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * Kvantum is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 15 * See the GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License along 18 * with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef WINDOWMANAGER_OLD_H 22 #define WINDOWMANAGER_OLD_H 23 24 #include <QBasicTimer> 25 #include <QSet> 26 #include <QPointer> 27 #include <QWidget> 28 29 namespace Kvantum { 30 class WindowManager: public QObject 31 { 32 Q_OBJECT 33 public: 34 enum Drag { 35 DRAG_NONE, 36 DRAG_MENUBAR_ONLY, 37 DRAG_MENUBAR_AND_PRIMARY_TOOLBAR, 38 DRAG_ALL, 39 40 DRAG_COUNT 41 }; 42 toDrag(const QString & str)43 static Drag toDrag (const QString &str) 44 { 45 for (int i = 0; i < DRAG_COUNT; ++i) 46 { 47 if (toStr (static_cast<Drag>(i)) == str) 48 return static_cast<Drag>(i); 49 } 50 return DRAG_NONE; 51 } 52 toStr(Drag drag)53 static QString toStr (Drag drag) 54 { 55 switch (drag) 56 { 57 default: 58 case DRAG_ALL: return "all"; 59 case DRAG_NONE: return "none"; 60 case DRAG_MENUBAR_ONLY: return "menubar"; 61 case DRAG_MENUBAR_AND_PRIMARY_TOOLBAR: return "menubar_and_primary_toolbar"; 62 } 63 } 64 65 explicit WindowManager (QObject *parent, Drag drag); ~WindowManager()66 virtual ~WindowManager() {} 67 68 void initialize (const QStringList &whiteList=QStringList(), 69 const QStringList &blackList=QStringList()); 70 71 void registerWidget (QWidget*); 72 void unregisterWidget (QWidget*); 73 virtual bool eventFilter (QObject*, QEvent*); 74 protected: 75 // timer event, 76 /* used to start drag if button is pressed for a long enough time */ 77 void timerEvent (QTimerEvent*); 78 bool mousePressEvent (QObject*, QEvent*); 79 bool mouseMoveEvent (QObject*, QEvent*); 80 bool mouseReleaseEvent (QObject*, QEvent*); enabled()81 bool enabled() const 82 { 83 return enabled_; 84 } setEnabled(bool value)85 void setEnabled (bool value) 86 { 87 enabled_ = value; 88 } 89 // drag distance (pixels) setDragDistance(int value)90 void setDragDistance (int value) 91 { 92 dragDistance_ = value; 93 } 94 // drag delay (msec) setDragDelay(int value)95 void setDragDelay (int value) 96 { 97 dragDelay_ = value; 98 } 99 100 void initializeWhiteList (const QStringList &list); 101 void initializeBlackList (const QStringList &list); 102 bool isDragable (QWidget*); 103 bool isBlackListed (QWidget*); 104 bool isWhiteListed (QWidget*) const; 105 // returns true if drag can be started from current widget 106 bool canDrag (QWidget*); 107 bool canDrag (QWidget*, QWidget*, const QPoint&); 108 void resetDrag(); 109 void startDrag (QWidget*, const QPoint&); 110 bool isDockWidgetTitle (const QWidget*) const; 111 setLocked(bool value)112 void setLocked (bool value) 113 { 114 locked_ = value; 115 } isLocked()116 bool isLocked() const 117 { 118 return locked_; 119 } 120 private: 121 // the value of QT_DEVICE_PIXEL_RATIO 122 bool enabled_; 123 int dragDistance_; 124 int dragDelay_; 125 126 // wrapper for exception id 127 class ExceptionId: public QPair<QString, QString> 128 { 129 public: ExceptionId(const QString & value)130 ExceptionId (const QString &value) 131 { 132 const QStringList args (value.split (QStringLiteral("@"))); 133 if (args.isEmpty()) 134 return; 135 second = args[0].trimmed(); 136 if (args.size() > 1) 137 first = args[1].trimmed(); 138 } appName()139 const QString& appName() const 140 { 141 return first; 142 } className()143 const QString& className() const 144 { 145 return second; 146 } 147 }; 148 149 typedef QSet<ExceptionId> ExceptionSet; 150 ExceptionSet whiteList_; 151 ExceptionSet blackList_; 152 153 QPoint dragPoint_; 154 QPoint globalDragPoint_; 155 QBasicTimer dragTimer_; 156 QPointer<QWidget> target_; 157 bool dragAboutToStart_; 158 bool dragInProgress_; 159 bool locked_; 160 Drag drag_; 161 bool cursorOverride_; 162 163 // provide application-wise event filter 164 /* 165 it is used to unlock dragging and make sure event look 166 is properly restored after a drag has occurred 167 */ 168 class AppEventFilter: public QObject 169 { 170 public: AppEventFilter(WindowManager * parent)171 AppEventFilter (WindowManager *parent) : 172 QObject (parent), 173 parent_ (parent) 174 {} 175 virtual bool eventFilter (QObject*, QEvent*); 176 private: 177 WindowManager *parent_; 178 }; 179 180 AppEventFilter *_appEventFilter; 181 // allow access of all private members to the app event filter 182 friend class AppEventFilter; 183 }; 184 } 185 186 #endif 187