| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <QObject> |
| 4 |
|
| 5 |
class QWidget; |
| 6 |
class QWindow; |
| 7 |
class QScreen; |
| 8 |
|
| 9 |
struct UkuiWindowHelperPrivate; |
| 10 |
|
| 11 |
class UkuiWindowHelper : public QObject |
| 12 |
{ |
| 13 |
Q_OBJECT |
| 14 |
public: |
| 15 |
explicit UkuiWindowHelper(QWidget *widget); |
| 16 |
explicit UkuiWindowHelper(QWindow *window); |
| 17 |
~UkuiWindowHelper(); |
| 18 |
|
| 19 |
enum class WindowRole { |
| 20 |
// UKUI window types which is supported on ukui wayland environment. |
| 21 |
Normal = 0, |
| 22 |
Desktop = 1, |
| 23 |
Panel = 2, |
| 24 |
OnScreenDisplay = 3, |
| 25 |
Notification = 4, |
| 26 |
Tooltip = 5, |
| 27 |
CriticalNotification = 6, |
| 28 |
AppletPopup = 7, |
| 29 |
ScreenLock = 8, |
| 30 |
Watermark = 9, |
| 31 |
SystemWindow = 10, |
| 32 |
InputPanel = 11, |
| 33 |
Logout = 12, |
| 34 |
ScreenLockNotification = 13, |
| 35 |
Switcher = 14, |
| 36 |
Authentication = 15, |
| 37 |
|
| 38 |
// Other upstream window types contains kde specific window types and standard window types |
| 39 |
// Warning: These types are not supported on ukui wayland environment. |
| 40 |
Override = 101, |
| 41 |
Dialog = 102, |
| 42 |
Menu = 103, |
| 43 |
TopMenu = 104, |
| 44 |
ToolBar = 105, |
| 45 |
Dock = 106, |
| 46 |
Utility = 107, |
| 47 |
Splash = 108, |
| 48 |
DropdownMenu = 109, |
| 49 |
PopupMenu = 110, |
| 50 |
ComboBox = 111, |
| 51 |
DNDIcon = 112, |
| 52 |
}; |
| 53 |
Q_ENUM(WindowRole) |
| 54 |
|
| 55 |
enum class State : uint32_t { |
| 56 |
Minimizable = 0x1, |
| 57 |
Maximizable = 0x2, |
| 58 |
Closeable = 0x4, |
| 59 |
Fullscreenable = 0x8, |
| 60 |
Movable = 0x10, |
| 61 |
Resizable = 0x20, |
| 62 |
Focusable = 0x40, |
| 63 |
Activatable = 0x80, |
| 64 |
KeepAbove = 0x100, |
| 65 |
KeepBelow = 0x200, |
| 66 |
}; |
| 67 |
Q_DECLARE_FLAGS(States, State) |
| 68 |
|
| 69 |
enum class DecorationState : uint32_t { |
| 70 |
RoundCorner = 0x1, |
| 71 |
Border = 0x2, |
| 72 |
Shadow = 0x4, |
| 73 |
}; |
| 74 |
Q_DECLARE_FLAGS(DecorationStates, DecorationState) |
| 75 |
|
| 76 |
enum class Position { |
| 77 |
Left = 0, |
| 78 |
Top = 1, |
| 79 |
Right = 2, |
| 80 |
Bottom = 3 |
| 81 |
}; |
| 82 |
Q_ENUM(Position) |
| 83 |
|
| 84 |
enum class DecorationComponent : uint32_t { |
| 85 |
RoundCorner = 0x1, |
| 86 |
Border = 0x2, |
| 87 |
Shadow = 0x4, |
| 88 |
}; |
| 89 |
Q_DECLARE_FLAGS(DecorationComponents, DecorationComponent) |
| 90 |
|
| 91 |
void removeTitleBar(); |
| 92 |
void setWindowRole(WindowRole role); |
| 93 |
void setWindowState(States state); |
| 94 |
void setWindowIcon(const QString &iconName); |
| 95 |
void setSkipTaskBar(bool skip); |
| 96 |
void setSkipSwitcher(bool skip); |
| 97 |
void setPanelAutoHide(bool autoHide); |
| 98 |
void grabKeyboard(); |
| 99 |
void openUnderCursor(QPoint pos); |
| 100 |
void setBlurEffect(QRegion region, int level = 0, bool enable = true); |
| 101 |
void setSlideEffect(Position position, int offset = 0, bool enable = true); |
| 102 |
States defaultState() const; |
| 103 |
|
| 104 |
Q_DECL_DEPRECATED_X("Use UkuiWindowHelper::showTileFlyout(QRect rect) instead") |
| 105 |
void showTileFlyout(); |
| 106 |
Q_DECL_DEPRECATED_X("Use UkuiWindowHelper::setDecorationCompoents(DecorationComponents components) instead") |
| 107 |
void setDecorationState(DecorationStates state); |
| 108 |
|
| 109 |
/** |
| 110 |
* @brief showTileFlyout |
| 111 |
* Show the tile flyout, the flyout will be closed when the poiner leave the given rect. |
| 112 |
* @param rect The rect to show the flyout. |
| 113 |
* @note The rect is in the coordinate of the window. |
| 114 |
*/ |
| 115 |
void showTileFlyout(QRect rect); |
| 116 |
void setDecorationCompoents(DecorationComponents components); |
| 117 |
|
| 118 |
/** |
| 119 |
* @brief requestGetCurrentScreen |
| 120 |
* Request to get the screen where the pointer is located. |
| 121 |
* This is useful when the screen information is not available immediately. You need to |
| 122 |
* connect to the `currentScreenChanged(QScreen *screen)` signal to get the current |
| 123 |
* screen after this request. |
| 124 |
* @note This function is only available on Wayland. |
| 125 |
*/ |
| 126 |
void requestGetCurrentScreen(); |
| 127 |
|
| 128 |
/** |
| 129 |
* @brief currentScreen |
| 130 |
* Get the current screen where the window is located. |
| 131 |
* If the window has not been mapped to a screen yet, this function may return nullptr. |
| 132 |
* You should connect to the `currentScreenChanged(QScreen *screen)` signal to |
| 133 |
* get the current screen. |
| 134 |
* @return The current screen, or nullptr if not available. |
| 135 |
*/ |
| 136 |
QScreen *currentScreen() const; |
| 137 |
|
| 138 |
/** |
| 139 |
* Get the current screen where the window is located. |
| 140 |
* Warning: it's a block function |
| 141 |
*/ |
| 142 |
QScreen *getCurrentScreenBlocking(); |
| 143 |
|
| 144 |
void setOpaqueRegion(QRegion region); |
| 145 |
|
| 146 |
void setPosition(QPoint pos); |
| 147 |
QPoint position() const; |
| 148 |
|
| 149 |
void setWindowStateEx(States mask, States state); |
| 150 |
|
| 151 |
Q_SIGNALS: |
| 152 |
/** |
| 153 |
* @brief currentScreenChanged |
| 154 |
* This signal is emitted after requestedGetCurrentScreen() being called. |
| 155 |
* @param screen The current screen where the window is located. |
| 156 |
*/ |
| 157 |
void currentScreenChanged(QScreen *screen); |
| 158 |
|
| 159 |
private: |
| 160 |
UkuiWindowHelperPrivate *p = nullptr; |
| 161 |
|
| 162 |
friend class UkuiWindowHelperPrivate; |
| 163 |
}; |
| 164 |
|
| 165 |
Q_DECLARE_OPERATORS_FOR_FLAGS(UkuiWindowHelper::States) |
| 166 |
Q_DECLARE_OPERATORS_FOR_FLAGS(UkuiWindowHelper::DecorationComponents) |