1 //=========================================== 2 // Lumina Desktop source code 3 // Copyright (c) 2017, Ken Moore 4 // Available under the 3-clause BSD license 5 // See the LICENSE file for full details 6 //=========================================== 7 // This class embeds a native window 8 // within the RootWindow area 9 //=========================================== 10 #ifndef _LUMINA_ROOT_WINDOW_SUB_WINDOW_H 11 #define _LUMINA_ROOT_WINDOW_SUB_WINDOW_H 12 13 #include <QWindow> 14 #include <QWidget> 15 #include <QCloseEvent> 16 #include <QFrame> 17 #include <QBoxLayout> 18 #include <QLabel> 19 #include <QToolButton> 20 #include <QMenu> 21 #include <QPropertyAnimation> 22 #include <NativeWindow.h> 23 #include <NativeEmbedWidget.h> 24 25 class RootSubWindow : public QFrame{ 26 Q_OBJECT 27 public: 28 RootSubWindow(QWidget *root, NativeWindow *win); 29 ~RootSubWindow(); 30 31 WId id(); 32 NativeWindow* nativeWindow(); 33 34 private: 35 //Window status 36 enum ModState{Normal, Move, ResizeTop, ResizeTopRight, ResizeRight, ResizeBottomRight, ResizeBottom, ResizeBottomLeft, ResizeLeft, ResizeTopLeft}; 37 ModState activeState; 38 ModState currentCursor; 39 QPoint offset; //needed for movement calculations (offset from mouse click to movement point) 40 //Functions for getting/setting state 41 ModState getStateAtPoint(QPoint pt, bool setoffset = false); //generally used for mouse location detection 42 void setMouseCursor(ModState, bool override = false); //Update the mouse cursor based on state 43 44 //Native window embed objects 45 NativeWindow *WIN; 46 NativeEmbedWidget *WinWidget; 47 bool closing; 48 //Title bar objects 49 QBoxLayout *titleBarL, *mainLayout; 50 QToolButton *closeB, *maxB, *minB, *otherB; 51 QLabel *titleLabel; 52 QMenu *otherM; //menu of other actions 53 QWidget *titleBar; 54 //Other random objects (animations,etc) 55 QPropertyAnimation *anim; 56 QVariant animResetProp; 57 QTimer *moveTimer; 58 QRect lastGeom, lastMaxGeom; //frame coordinates 59 60 void initWindowFrame(); 61 void enableFrame(bool); 62 void enableFrame(QList<NativeWindow::Type> types); 63 64 void LoadProperties( QList< NativeWindow::Property> list); 65 66 static QStringList validAnimations(NativeWindow::Property); 67 68 public slots: ensureVisible()69 void ensureVisible(){ WIN->setProperty(NativeWindow::Visible, true); } giveMouseFocus()70 void giveMouseFocus(){ WinWidget->raiseWindow(); } removeMouseFocus()71 void removeMouseFocus(){ WinWidget->lowerWindow(); } giveKeyboardFocus()72 void giveKeyboardFocus(){ WIN->requestProperty(NativeWindow::Active, true, true); } 73 74 void clientClosed(); 75 void LoadAllProperties(); 76 77 QRect clientGlobalGeom(); 78 79 //Button Actions - public so they can be tied to key shortcuts and stuff as well 80 void toggleMinimize(); 81 void toggleMaximize(); 82 void triggerClose(); 83 void toggleSticky(); 84 void activate(); 85 86 //Mouse Interactivity 87 void startMoving(); 88 void startResizing(); 89 90 private slots: 91 void propertiesChanged(QList<NativeWindow::Property>, QList<QVariant>); 92 93 void loadAnimation(QString name, NativeWindow::Property, QVariant nval); //new val 94 void animFinished(); 95 96 protected: 97 void mousePressEvent(QMouseEvent*); 98 void mouseMoveEvent(QMouseEvent*); 99 void mouseReleaseEvent(QMouseEvent*); 100 //void leaveEvent(QEvent *ev); 101 //void enterEvent(QEvent *ev); 102 void moveEvent(QMoveEvent *ev); 103 104 signals: 105 void windowMoved(RootSubWindow*); 106 void windowAnimFinished(); 107 }; 108 109 #endif 110