-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwidget.h
148 lines (125 loc) · 4.28 KB
/
widget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#ifndef WIDGET_H
#define WIDGET_H
#include "codeeditor.h"
#include "Utils/path.h"
#include <QLineEdit>
#include <QTime>
#include <QTimeLine>
#include <QWidget>
#include "Utils/systemapi.h"
#include <windows.h>
#include "Utils/timeclipboard.h"
#include "Utils/WinUtility.h"
#include "powersettingdia.h"
#include "Utils/AudioDevice.h"
#include "toolmenu.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE
class Widget : public QWidget {
Q_OBJECT
public:
Widget(QWidget* parent = nullptr);
~Widget();
private:
Ui::Widget* ui;
private:
QPointF winPos; //center pos
//const qreal disLimit = 10;
const int Margin = DPI(5); //between MainWindow and LineEditor
HWND Hwnd;
QRect Screen;
QRect validScreen;
QScreen* pScreen;
enum State {
STILL,
MOVE,
INPUT
};
enum TeleportMode {
ON = 1, //总是开启(ALWAYS)
AUTO = 0, //自动判断(全屏)
OFF = -1 //总是关闭(NEVER)
};
enum LongPressState{
Ready,
Cancel,
Done
};
State state;
TeleportMode teleportMode;
CodeEditor* lineEdit = nullptr;
QTimer* timer_move = nullptr;
QPointF preMousePos = {-1, -1};
bool isChangingState = false; //改变状态中间态
bool hasPower;
bool teleportKeyDown = false;
ATOM HotKeyId;
ATOM Atom;
QString atomStr = "Follower_MrBeanC_Teleport";
const QString AppName = "Follower v2.0";
//SystemAPI sys;
const QString iniFilePath = Path::iniFile();
TimeClipboard tClip {128}; //记录textChangeTime的ClipBoard
QTimer* timer_audioTip = nullptr;
HPOWERNOTIFY hPowerNotify = NULL; //睡眠休眠通知注册句柄
HPOWERNOTIFY hPowerSetting = NULL; //显示器电源设置通知
bool isHideAfterExecute = true;
//QString audioOuptputDev = Win::activeAudioOutputDevice(); //缓存 避免paintEvent频繁获取 //首次获取会卡顿可能是载入dll 所以放这儿
AudioDevice audioOuptputDev = AudioDevice::defaultOutputDevice();
ScreenSetting screenSetting;
ToolMenu* tMenu = nullptr;
QMap<Qt::MouseButton, LongPressState> isMBLongPressed;
static constexpr int LPDelay = 180; //ms Long Press Dealy
bool isScreenOn = true;
private:
inline bool moveGuide(QPoint dest, QPointF& pos, qreal speed, qreal limit = 10);
inline bool moveWindow(qreal speed = 2);
inline void getInputFocus(void);
inline void catchFocus(void);
void changeSizeSlow(QSize size, int step = 1, bool isAuto = false); //auto
void updateWindow(void);
inline QPoint centerToLT(const QPoint& pos);
inline bool isCursorInWindow(void);
inline void setState(State toState, int step = 1);
inline bool isUnderCursor(void);
inline bool isState(State _state);
inline bool isGetMouseButton(void); //LBUTTON || MBUTTON || RBUTTON
inline bool isTeleportKey(void); //Ctrl+Shift+E
inline void updateScreenInfo(void);
inline void teleport(void); //瞬移
inline void setTeleportMode(TeleportMode mode);
QSize StateSize(State _state);
void writeIni(const QString& key, const QVariant& value);
void readIni(void);
void Init_SystemTray(void);
void setAlwaysTop(bool bTop = true);
void switchAudioOutputDevice(const AudioDevice& dev, bool toPre = false);
void minimize(void);
void Init_ToolMenu(void);
// 判断鼠标下方的是否是浏览器标签栏,目前仅支持Edge、Chrome
bool isTabStripUnderCursor(void); // 中键点击标签栏,一般是关闭标签操作
signals:
void powerSwitched(bool isPowerOn, bool force = false);
// QWidget interface
protected:
void paintEvent(QPaintEvent* event) override;
void resizeEvent(QResizeEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
void mouseMoveEvent(QMouseEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override;
void wheelEvent(QWheelEvent* event) override;
// QWidget interface
protected:
bool nativeEvent(const QByteArray& eventType, void* message, long* result) override;
// QWidget interface
protected:
void closeEvent(QCloseEvent* event) override;
// QWidget interface
protected:
void keyPressEvent(QKeyEvent* event) override;
void keyReleaseEvent(QKeyEvent* event) override;
};
#endif // WIDGET_H