-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfocuswindow.h
More file actions
94 lines (79 loc) · 2.5 KB
/
focuswindow.h
File metadata and controls
94 lines (79 loc) · 2.5 KB
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
#ifndef FOCUSWINDOW_H
#define FOCUSWINDOW_H
#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QGroupBox>
#include <QFrame>
#include <QTimer>
#include <QDateTime>
#include <QComboBox>
#include <QSpinBox>
#include <QMessageBox>
#include "focusmanager.h"
class FocusWindow : public QWidget
{
Q_OBJECT
public:
explicit FocusWindow(QWidget *parent = nullptr,
const QString &windowId = "Main",
bool isMainWindow = true,
FocusManager *globalManager = nullptr,
QSize windowSize = QSize(450, 420));
~FocusWindow();
QString getWindowId() const { return m_windowId; }
bool isMainWindow() const { return m_isMainWindow; }
protected:
// 重写事件处理函数来检测焦点变化
void focusInEvent(QFocusEvent *event) override;
void focusOutEvent(QFocusEvent *event) override;
void changeEvent(QEvent *event) override;
void closeEvent(QCloseEvent *event) override;
private slots:
void onCreateNewWindow();
void onCloseWindow();
void onFocusChanged(const QString &winId, bool hasFocus, const QString ×tamp);
void checkFocusStatus();
private:
void setupUI();
QSize getSelectedWindowSize() const;
int getSelectedWindowCount() const;
void updateBackgroundColor();
void updateFocusStatus();
void updateWindowFocusState(bool hasFocus);
// 时间差计算的辅助方法
qint64 calculateTimeDifference(const QDateTime &fromTime, const QDateTime &toTime);
QString formatTimeDifference(qint64 milliseconds);
void calculateAndShowTimeDiff();
// 成员变量
QString m_windowId;
bool m_isMainWindow;
bool m_hasFocus;
FocusManager *m_globalFocusManager;
// 窗口自己的时间记录
QDateTime m_focusGainedTime;
QDateTime m_focusLostTime;
// UI组件
QVBoxLayout *m_mainLayout;
QLabel *m_titleLabel;
QFrame *m_windowIdFrame;
QLabel *m_windowIdLabel;
QFrame *m_statusFrame;
QLabel *m_statusLabel;
QGroupBox *m_timeGroupBox;
QLineEdit *m_focusGainedEdit;
QLineEdit *m_focusLostEdit;
QLineEdit *m_timeDiffEdit;
QPushButton *m_newWindowBtn;
QPushButton *m_closeBtn;
QComboBox *m_sizeComboBox;
QSpinBox *m_countSpinBox;
QSize m_windowSize;
QTimer *m_focusCheckTimer;
QString m_focusGainedTimeString;
QString m_focusLostTimeString;
};
#endif // FOCUSWINDOW_H