├── .gitignore
├── README.md
├── Sapphire.pro
├── Sapphire_zh_CN.ts
├── SysFunctions.cpp
├── SysFunctions.h
├── ed_bgshower.cpp
├── ed_bgshower.h
├── ed_block.cpp
├── ed_block.h
├── ed_blockcontainer.cpp
├── ed_blockcontainer.h
├── ed_blocklayout.cpp
├── ed_blocklayout.h
├── ed_container.cpp
├── ed_container.h
├── ed_dock.cpp
├── ed_dock.h
├── ed_editbox.cpp
├── ed_editbox.h
├── ed_hidetextblock.cpp
├── ed_hidetextblock.h
├── ed_layout.cpp
├── ed_layout.h
├── ed_linearlayout.cpp
├── ed_linearlayout.h
├── ed_unit.cpp
├── ed_unit.h
├── filepreviewwidget.cpp
├── filepreviewwidget.h
├── hitokoto.cpp
├── hitokoto.h
├── layershower.cpp
├── layershower.h
├── main.cpp
├── mainwindow.cpp
├── mainwindow.h
├── mainwindow.ui
├── mousehook.cpp
├── mousehook.h
├── picturebox.cpp
├── picturebox.h
├── res.qrc
├── roundshower.cpp
├── roundshower.h
├── style.cpp
├── style.h
├── testBackgroud.jpg
├── weather.cpp
└── weather.h
/.gitignore:
--------------------------------------------------------------------------------
1 | # This file is used to ignore files which are generated
2 | # ----------------------------------------------------------------------------
3 |
4 | *~
5 | *.autosave
6 | *.a
7 | *.core
8 | *.moc
9 | *.o
10 | *.obj
11 | *.orig
12 | *.rej
13 | *.so
14 | *.so.*
15 | *_pch.h.cpp
16 | *_resource.rc
17 | *.qm
18 | .#*
19 | *.*#
20 | core
21 | !core/
22 | tags
23 | .DS_Store
24 | .directory
25 | *.debug
26 | Makefile*
27 | *.prl
28 | *.app
29 | moc_*.cpp
30 | ui_*.h
31 | qrc_*.cpp
32 | Thumbs.db
33 | *.res
34 | *.rc
35 | /.qmake.cache
36 | /.qmake.stash
37 |
38 | build/*
39 | .vs/*
40 |
41 | # qtcreator generated files
42 | *.pro.user*
43 | CMakeLists.txt.user*
44 |
45 | # xemacs temporary files
46 | *.flc
47 |
48 | # Vim temporary files
49 | .*.swp
50 |
51 | # Visual Studio generated files
52 | *.ib_pdb_index
53 | *.idb
54 | *.ilk
55 | *.pdb
56 | *.sln
57 | *.suo
58 | *.vcproj
59 | *vcproj.*.*.user
60 | *.ncb
61 | *.sdf
62 | *.opensdf
63 | *.vcxproj
64 | *vcxproj.*
65 |
66 | # MinGW generated files
67 | *.Debug
68 | *.Release
69 |
70 | # Python byte code
71 | *.pyc
72 |
73 | # Binaries
74 | # --------
75 | *.dll
76 | *.exe
77 |
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sapphire-EnhancedDesktop
2 |
3 | 现代化的 Windows 桌面取代/桌面增强软件
4 |
5 | # 项目概述
6 |
7 | - **项目**: "Sapphire-EnhancedDesktop",意在提供一个增强的桌面体验。
8 | - **环境**:使用 Windows API 和 Qt 框架,mingw32 编译,只保证兼容 Windows 11。
9 | - 由原项目`Enhanced-desktop`接续开发,使用`Sapphire`作为新的软件名与原项目进行区别。
10 |
11 | - README 文件对应版本:`V1.2.2.0`
12 |
13 | # 项目特点
14 |
15 | - 系统级别的植入和事件处理。
16 | - 符合直觉和使用习惯的交互。
17 | - 无学习成本、即开即用。
18 | - 模块化设计,统一管理。
19 | - 灵活的动态布局管理解决方案。
20 | - 可自定义的外观。
21 | - 美观、高级、精致、可选的外观特效。
22 | - 方便开发的设计。
23 |
24 | # 功能细节
25 |
26 | ## 系统和算法
27 |
28 | - 接入并覆盖原生 Windows 图标层
29 | - 获取系统主题色作为默认颜色
30 | - 系统级别事件钩子(默认未启用)
31 | - 扫描用户桌面和公共桌面
32 | - 追踪快捷方式
33 | - 转化文件信息为项目组件
34 | - 调用系统 URL
35 | - 网络 API 使用
36 | - Steam 专项优化
37 |
38 | ## 全局
39 |
40 | - 完美兼容 WallpaperEngine(需在设置中设置`当其他程序成为焦点时`为`始终运行`)
41 | - 自选和显示图片背景(待完善)
42 | - 组件拖动
43 | - 组件定位
44 | - 组件创建
45 | - 双击隐藏(可设置始终显示)
46 | - 聚焦动画
47 | - 位移动画
48 | - 从文件夹拖动
49 | - 用户可控:
50 | - 开关背景透视
51 | - 切换大图标填充模式
52 | - 开关光效特效追踪
53 | - 开关绘制矩形
54 | - 开关绘制光效
55 | - 控制所有组件的精简模式
56 | - 控制所有组件的缩放系数
57 | - 控制所有组件的圆角大小
58 |
59 | ## Style.ini 详细配置
60 |
61 | _斜体_ 表示已在可视化组件中给出
62 |
63 | ### Color
64 |
65 | - sleep_alpha 未聚焦的颜色 Alpha
66 | - active_alpha 聚焦时的颜色 Alpha
67 | - sleep_alpha_deep 深色图标未聚焦的颜色 Alpha
68 | - active_alpha_deep 深色图标聚焦时的颜色 Alpha
69 | - sleep_color_ratio 未聚焦的色值比率(RBG)
70 | - active_color_ratio 聚焦时的色值比率(RBG)
71 |
72 | ### Effect
73 |
74 | - light_alpha_start 光效的起点 Alpha
75 | - light_alpha_end 光效的终点 Alpha
76 | - icon_shadow_alpha 图标阴影特效 Alpha
77 | - icon_shadow_blur_radiu 图标阴影特效 Radius(扩散半径)
78 | - unit_shadow_alpha 所有组件阴影特效 Alpha
79 | - unit_shadow_blur_radius 所有组件阴影特效 Radius(扩散半径)
80 |
81 | ### Render
82 |
83 | - _unit_radius_ 组件圆角
84 | - _ShowRect_ 绘制组件的矩形
85 | - ShowSide 绘制组件边框(用于 Debug)
86 | - _ShowLight_ 绘制组件光效
87 | - _enable_background_transparent_ 背景透视
88 | - enable_background_blur 背景模糊(未完工)
89 | - _enable_light_track_ 特效追踪
90 | - _enable_intime_repaint_ 即时重绘(用于 Debug)
91 |
92 | ### Preference
93 |
94 | - _enable_image_fill_ 大图标填充
95 | - muilt_icon_default_type 设置 Steam 图标获取方式
96 | - 0 小图标,1 竖图标,2 横图标(切换未完工)
97 | - scale_fix_ratio 聚焦时缩放比率
98 | - enable_lnk_redirect 快捷方式的图标重定向
99 | - 开启会获取原软件的图标,没有小箭头,但可能会有错误
100 | - 关闭会获取快捷方式本身的图标,有小箭头
101 |
102 | # Todo
103 |
104 | - [ ] 自定义图标
105 | - [X] 更好的保存逻辑
106 | - [ ] 文件夹缩放
107 | - [ ] 多屏适配
108 | - [ ] 更好的右键菜单
109 |
110 | # 须知
111 |
112 | - 本软件目前定位为**美化**软件,而非**生产力**,如果您需要原生桌面作为生产力需要,该软件目前还不能满足您的要求。
113 | - 本软件目前开发者只有我一人,开发进度较为缓慢,待完善功能较多,欢迎开发/美化人员加入合作。
114 | - 本软件目前没有盈利打算,完全免费。
115 | - 如果您喜欢,请给我一个 Star,或者在视频平台点赞,以帮助该软件让更多人看到,谢谢!
116 |
--------------------------------------------------------------------------------
/Sapphire.pro:
--------------------------------------------------------------------------------
1 | QT += core gui widgets winextras network multimedia multimediawidgets concurrent
2 | win32 {
3 | LIBS+= -luser32 # 使用WindowsAPI需要链接库
4 | LIBS+= -ldwmapi
5 | }
6 |
7 | VERSION = 1.2.2.0
8 | QMAKE_PROJECT_DEPTH = 0
9 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
10 |
11 | CONFIG += c++17
12 |
13 | # You can make your code fail to compile if it uses deprecated APIs.
14 | # In order to do so, uncomment the following line.
15 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
16 |
17 | SOURCES += \
18 | SysFunctions.cpp \
19 | ed_bgshower.cpp \
20 | ed_block.cpp \
21 | ed_blockcontainer.cpp \
22 | ed_blocklayout.cpp \
23 | ed_container.cpp \
24 | ed_dock.cpp \
25 | ed_editbox.cpp \
26 | ed_hidetextblock.cpp \
27 | ed_layout.cpp \
28 | ed_linearlayout.cpp \
29 | ed_unit.cpp \
30 | filepreviewwidget.cpp \
31 | hitokoto.cpp \
32 | layershower.cpp \
33 | main.cpp \
34 | mainwindow.cpp \
35 | mousehook.cpp \
36 | picturebox.cpp \
37 | roundshower.cpp \
38 | style.cpp \
39 | weather.cpp
40 |
41 | HEADERS += \
42 | SysFunctions.h \
43 | ed_bgshower.h \
44 | ed_block.h \
45 | ed_blockcontainer.h \
46 | ed_blocklayout.h \
47 | ed_container.h \
48 | ed_dock.h \
49 | ed_editbox.h \
50 | ed_hidetextblock.h \
51 | ed_layout.h \
52 | ed_linearlayout.h \
53 | ed_unit.h \
54 | filepreviewwidget.h \
55 | hitokoto.h \
56 | layershower.h \
57 | mainwindow.h \
58 | mousehook.h \
59 | picturebox.h \
60 | roundshower.h \
61 | style.h \
62 | weather.h
63 |
64 | FORMS += \
65 | mainwindow.ui
66 |
67 | TRANSLATIONS += \
68 | Sapphire_zh_CN.ts \
69 | CONFIG += lrelease \
70 | CONFIG += embed_translations \
71 |
72 |
73 | # TEMPLATE = subdirs
74 |
75 | SUBDIRS += \
76 | ContextMenu/ContextMenu.pro
77 |
78 | # Default rules for deployment.
79 | qnx: target.path = /tmp/$${TARGET}/bin
80 | else: unix:!android: target.path = /opt/$${TARGET}/bin
81 | !isEmpty(target.path): INSTALLS += target
82 |
83 |
84 | RESOURCES += \
85 | res.qrc
86 |
87 | DISTFILES += \
88 | AcrylicMaterial/CMakeLists.txt \
89 | README.md \
90 | style.json
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/Sapphire_zh_CN.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/SysFunctions.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "layershower.h"
3 | #include"mainwindow.h"
4 | #include "qapplication.h"
5 | #include "qpainter.h"
6 | #include "qpainterpath.h"
7 | #include"windows.h"
8 | #include "shlobj.h"
9 | #include"mousehook.h"
10 | #include"SysFunctions.h"
11 | #include"QTextCodec"
12 | #include
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 |
25 | MainWindow* pmw;;
26 | MouseHook* pmh;
27 | LayerShower* pls;
28 |
29 | QTextCodec* utf8 = QTextCodec::codecForName("utf-8");
30 | QTextCodec* gbk = QTextCodec::codecForName("GBK");
31 |
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | static QMutex mutex;
40 |
41 | #define AUTO_RUN_KEY "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run"
42 | //设置/取消自启动
43 | //isStart: true(开机启动) false(开机不启动)
44 |
45 | QColor GetWindowsThemeColor()
46 | {
47 | DWORD crColorization;
48 | BOOL fOpaqueBlend;
49 | QColor res;
50 | HRESULT result = DwmGetColorizationColor(&crColorization, &fOpaqueBlend);
51 | if (result == S_OK)
52 | {
53 | BYTE r, g, b;
54 | r = (crColorization >> 16) % 256;
55 | g = (crColorization >> 8) % 256;
56 | b = crColorization % 256;
57 | res = QColor(r, g, b);
58 | }
59 | return res;
60 | }
61 |
62 |
63 | void setMyAppAutoRun(bool isStart)
64 | {
65 | QString application_name = QApplication::applicationName();//获取应用名称
66 | QSettings *settings = new QSettings(AUTO_RUN_KEY, QSettings::NativeFormat);//创建QSetting, 需要添加QSetting头文件
67 | if(isStart)
68 | {
69 | QString application_path = QApplication::applicationFilePath();//找到应用的目录
70 | settings->setValue(application_name, application_path.replace("/", "\\"));//写入注册表
71 | }
72 | else
73 | {
74 | settings->remove(application_name); //从注册表中删除
75 | }
76 | }
77 |
78 | void customMessageHandler(QtMsgType type,
79 | const QMessageLogContext &context,
80 | const QString &msg)
81 | {
82 | //Q_UNUSED(context)
83 | QDateTime _datetime = QDateTime::currentDateTime();
84 | QString szDate = _datetime.toString("yyyy-MM-dd hh:mm:ss.zzz");//"yyyy-MM-dd hh:mm:ss ddd"
85 | QString txt(szDate);
86 | switch (type)
87 | {
88 | case QtDebugMsg://调试信息提示
89 | {
90 | txt += QString(" [Debug] ");
91 | break;
92 | }
93 | case QtInfoMsg://信息输出
94 | {
95 | txt += QString(" [Info] ");
96 | break;
97 | }
98 | case QtWarningMsg://一般的warning提示
99 | {
100 | txt += QString(" [Warning] ");
101 | break;
102 | }
103 | case QtCriticalMsg://严重错误提示
104 | {
105 | txt += QString(" [Critical] ");
106 | break;
107 | }
108 | case QtFatalMsg://致命错误提示
109 | {
110 | txt += QString(" [Fatal] ");
111 | //abort();
112 | break;
113 | }
114 | default:
115 | {
116 | txt += QString(" [Trace] ");
117 | break;
118 | }
119 | }
120 |
121 | txt.append( QString(" %1").arg(context.file) );
122 | txt.append( QString("<%1>: ").arg(context.line) );
123 | txt.append(msg);
124 |
125 | mutex.lock();
126 | QFile file("log.txt");
127 | file.open(QIODevice::WriteOnly | QIODevice::Append);
128 | QTextStream text_stream(&file);
129 | text_stream << txt << "\r\n";
130 | file.close();
131 | mutex.unlock();
132 | }
133 | QRect AbsoluteRect(QWidget* aim){
134 | auto tem = aim->geometry();
135 | auto pos = aim->parentWidget()->pos();
136 | return QRect(pos.x()+tem.x(),pos.y()+tem.y(),tem.width(),tem.height());
137 | }
138 |
139 | ED_Unit* from_json(QJsonObject data){
140 | QString name = data.value("Class").toString();
141 | int id = QMetaType::type(name.toStdString().c_str());
142 | if (id == QMetaType::UnknownType){
143 | qDebug()<<"error";
144 | return nullptr;
145 | ; // ERROR HERE
146 |
147 | }
148 | auto k = QMetaType::create(id);
149 | ED_Unit *unit = static_cast(QMetaType::create(id));
150 | unit->load_json(data);
151 | return unit;
152 |
153 | }
154 |
155 | void paintRect(QWidget* aim,QColor color){
156 | bool another = true;
157 | bool choosen = false;
158 |
159 | if(aim->inherits("ED_Unit")) {
160 | color.setAlpha(color.alpha()*((ED_Unit*)aim)->nowPadRatio);
161 | another = ((ED_Unit*)aim)->showRect;
162 | choosen = ((ED_Unit*)aim)->onmouse;
163 | }
164 | if(ShowRect&(another)){
165 | QPainter painter(aim);
166 | painter.setRenderHint(QPainter::Antialiasing);
167 | painter.setPen(Qt::NoPen);
168 | painter.setBrush(color);
169 | painter.drawRect(aim->rect());;
170 | }
171 | }
172 |
173 | double rectLen(int w,int h){
174 | return sqrt(w*w+h*h);
175 | }
176 |
177 | void paintLight(QWidget* aim,QColor color){
178 | bool another = true;
179 | bool choosen = false;
180 | if(aim->inherits("ED_Unit")) {
181 | color.setAlpha(color.alpha()*((ED_Unit*)aim)->nowPadRatio);
182 | // qDebug()<showLight;
184 | choosen = ((ED_Unit*)aim)->onmouse;
185 | }
186 |
187 |
188 | if(ShowLight&(another)){
189 | auto pos =aim->mapFromGlobal(aim->cursor().pos());
190 | QRadialGradient* radialGradient;
191 | if(enable_light_track&&choosen){
192 | radialGradient = new QRadialGradient(aim->width()/2 , aim->height()/2, rectLen(aim->width(),aim->height())/2,pos.x() ,pos.y());
193 | }
194 | else{
195 | radialGradient = new QRadialGradient(aim->width()/2 , aim->height()/2, rectLen(aim->width(),aim->height())/2,0, aim->height());
196 | }
197 | //创建了一个QRadialGradient对象实例,参数分别为中心坐标,半径长度和焦点坐标,如果需要对称那么中心坐标和焦点坐标要一致
198 | QPainter painter(aim);
199 | painter.setRenderHint(QPainter::Antialiasing);
200 | painter.setPen(Qt::NoPen);
201 | color.setAlpha(light_alpha_start);
202 | if(aim->inherits("ED_Unit")) {
203 | color.setAlpha(color.alpha()*((ED_Unit*)aim)->nowPadRatio);
204 | }
205 | radialGradient->setColorAt(0,color);
206 | color.setAlpha(light_alpha_end);
207 | if(aim->inherits("ED_Unit")) {
208 | color.setAlpha(color.alpha()*((ED_Unit*)aim)->nowPadRatio);
209 | // qDebug()<setColorAt(1.0,color);
212 | painter.setBrush(QBrush(*radialGradient));
213 | painter.drawRect(aim->rect());//在相应的坐标画出来
214 | }
215 | }
216 |
217 | void paintSide(QWidget* aim,QColor color){
218 | bool another = true;
219 | if(aim->inherits("ED_Unit")){
220 |
221 | another = ((ED_Unit*)aim)->showSide;
222 | // 恢复默认混合模式,绘制边框,如果没有则不用
223 | if(ShowSide&&another){
224 | QPainter painter(aim);
225 | QPainterPath path;
226 | //这里圆角区域需要根据dpi、size调整
227 | path.addRoundedRect(QRectF(aim->rect()).adjusted(1.5, 1.5, -1.5, -1.5), unit_radius, unit_radius);
228 | painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
229 | painter.setPen(QPen(QColor(0xCA64EA), 1.0));
230 | painter.drawPath(path);
231 | }
232 | }
233 | else if(ShowSide){
234 | QPainter p(aim);
235 | p.setPen(color); //设置画笔记颜色
236 | p.drawRect(0, 0, aim->width() -1, aim->height() -1); //绘制边框
237 | }
238 | }
239 |
240 | void mouse_move(int x,int y){
241 |
242 | qDebug()<<"move"<move(x,y);
244 | }
245 | void mouse_on(int x,int y){
246 |
247 | qDebug()<<"on"<SetMouseMoveCallBack(mouse_move);
257 | pmh->SetMouseOffCallBack(mouse_off);
258 | pmh->SetMouseOnCallBack(mouse_on);
259 | }
260 |
261 |
262 | void Init(MainWindow* mainwindow){
263 | //初始化
264 | qDebug()<<"Initing";
265 | //无边框全屏
266 |
267 | //注入壁纸
268 | inplace((QWidget* )mainwindow);
269 |
270 | qDebug()<<"Initing done";
271 | }
272 |
273 |
274 |
275 | void inplace(QWidget* aim) {
276 | // 接入到图标层
277 | HWND background = NULL;
278 | HWND hwnd = FindWindowA("Progman", "Program Manager");
279 | HWND worker = NULL;
280 |
281 | // 循环查找WorkerW窗口
282 | do {
283 | worker = FindWindowExA(NULL, worker, "WorkerW", NULL);
284 | if (worker != NULL) {
285 | // 尝试找到SHELLDLL_DefView窗口
286 | HWND shelldlldefview = FindWindowExA(worker, NULL, "SHELLDLL_DefView", NULL);
287 | if (shelldlldefview != NULL) {
288 | // 检查SHELLDLL_DefView的父窗口是否为当前的WorkerW窗口
289 | HWND parent = GetParent(shelldlldefview);
290 | if (parent == worker) {
291 | // 找到了正确的WorkerW窗口
292 | background = worker;
293 | break; // 结束循环
294 | }
295 | }
296 | }
297 | } while (worker != NULL);
298 |
299 | // 如果找到了正确的WorkerW窗口,设置父窗口
300 | if (background != NULL) {
301 | SetParent((HWND)aim->winId(), background);
302 | SetWindowPos((HWND)aim->winId(), HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
303 | SetWindowPos((HWND)aim->winId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
304 | SetFocus((HWND)aim->winId());
305 | } else {
306 | // 如果没有找到合适的WorkerW窗口,可以在这里处理错误
307 | qDebug() << "未能找到合适的WorkerW窗口";
308 | }
309 | }
310 |
311 | void inplace2(QWidget* pmw2) {
312 | // 接入到壁纸层
313 | HWND background = NULL;
314 | HWND hwnd = FindWindowA("Progman", "Program Manager");
315 | HWND worker = NULL;
316 |
317 | // 循环查找WorkerW窗口
318 | do
319 | {
320 | worker = FindWindowExA(NULL,worker,"WorkerW",NULL);
321 | if(worker!=NULL){
322 | char buff[200] = {0};
323 |
324 | int ret = GetClassName(worker,(WCHAR*)buff,sizeof(buff)*2);
325 | if(ret == 0){
326 | int err = GetLastError();
327 | qDebug()<<"err:"<winId(),background);
336 |
337 | // 如果找到了符合条件的 WorkerW 窗口,设置 Qt 窗口的父窗口
338 | }
339 |
340 | QListgetFormFileInfo(QFileInfo x){
341 | QList files;
342 | FileInfo file;
343 | file.type = FileInfo::NORM;
344 | file.filePath=x.absoluteFilePath();
345 | QString fileName = x.fileName();
346 | int lastDotIndex = fileName.lastIndexOf('.');
347 | if (lastDotIndex != -1)
348 | {
349 | fileName.remove(lastDotIndex, fileName.length() - lastDotIndex);
350 | }
351 | file.name=fileName;
352 | // qDebug()< scandesktopfiles(const QString &desktopPath)
443 | {
444 | //对于指定桌面路径,返还桌面路径中的文件信息的列表
445 | QList files;
446 | QDir desktopDir(desktopPath);
447 | desktopDir.setFilter(QDir::Files|QDir::Dirs|QDir::NoDotAndDotDot);
448 | QFileInfoList fileInfoList=desktopDir.entryInfoList();
449 | foreach(const QFileInfo &x,fileInfoList)
450 | {
451 | files.append(getFormFileInfo(x));
452 | }
453 | std::sort(files.begin(), files.end());
454 | return files;
455 | }
456 |
457 |
458 | QList scanalldesktopfiles()
459 | {
460 | //寻找桌面路径,并返回两个桌面中所有文件信息的列表
461 | QList files;
462 | // QString userdesktoppath=QDir::homePath()+"/Desktop";
463 | // files.append(scandesktopfiles(userdesktoppath));
464 | QString publicdesktoppath=QDir::toNativeSeparators("C:/Users/Public/Desktop");
465 | files.append(scandesktopfiles(publicdesktoppath));
466 | QString another = getDesktopPath();
467 | files.append(scandesktopfiles(another));
468 | std::sort(files.begin(),files.end());
469 | qDebug()<toUnicode(ba.constData(), ba.size(), &state);
479 | if (state.invalidChars > 0)
480 | {
481 | qDebug()<<"GBK";
482 | text = gbk->toUnicode(ba);
483 | }
484 | else
485 | {
486 | qDebug()<<"utf-8";
487 | text = ba;
488 | }
489 | return text;
490 | }
491 |
492 | QString elidedLineText(QWidget *pWidget, int nLine, QString strText)
493 | {
494 | //调整输出
495 | if (nLine == 0)
496 | return "";
497 |
498 | QFontMetrics fontMetrics(pWidget->font());
499 |
500 | if (nLine == 1) {
501 | return fontMetrics.elidedText(strText, Qt::ElideRight, pWidget->width());
502 | }
503 |
504 | QStringList strListLine;
505 |
506 | for (int i = 0; i < strText.size(); i++)
507 | {
508 | if (fontMetrics.width(strText.left(i)) >= pWidget->width())
509 | {
510 | strListLine.append(strText.left(i));
511 | if (strListLine.size() == nLine)
512 | {
513 | break;
514 | }
515 | strText = strText.right(strText.size() - i);
516 | i = 0;
517 | }
518 | }
519 |
520 | if (strListLine.size() < nLine)
521 | {
522 | if (!strText.isEmpty()) {
523 | strListLine.append(strText);
524 | }
525 | }
526 |
527 | bool bHasElided = true;
528 | if (fontMetrics.width(strText) < pWidget->width())
529 | {
530 | bHasElided = false;
531 | }
532 |
533 | if (bHasElided && !strListLine.isEmpty())
534 | {
535 | QString strLast = strListLine.last();
536 | QString strElided = "...";
537 | strLast.insert(strLast.length(), strElided);
538 | while (fontMetrics.width(strLast) >= pWidget->width())
539 | {
540 | strLast = strLast.replace(0, 1, "");
541 | }
542 |
543 | strListLine.replace(strListLine.count() - 1, strLast);
544 | }
545 | QString strResult = strListLine.join("\n");
546 |
547 | return strResult;
548 | }
549 |
550 |
551 | QColor pixmapMainColor(QPixmap p, double bright) //p为目标图片 bright为亮度系数,为1则表示保持不变
552 | {
553 | int step=20; //步长:在图片中取点时两点之间的间隔,若为1,则取所有点,适当将此值调大有利于提高运行速度
554 | int t=0; //点数:记录一共取了多少个点,用于做计算平均数的分母
555 | QImage image=p.toImage(); //将Pixmap类型转为QImage类型
556 | int r=0,g=0,b=0; //三元色的值,分别用于记录各个点的rgb值的和
557 | for (int i=0;i255?255:int(bright*r/t),
569 | int(bright*g/t)>255?255:int(bright*g/t),
570 | int(bright*b/t)>255?255:int(bright*b/t)); //最后返回的值是亮度系数×平均数,若超出255则设置为255也就是最大值,防止乘与亮度系数后导致某些值大于255的情况。
571 | }
572 |
573 | void repaintAround(QWidget* aim){
574 | auto tem = aim->geometry();
575 | auto rrect = QRect(tem.x()-100,tem.y()-100,tem.width()+200,tem.height()+200);
576 | pmw->repaint(rrect);
577 |
578 | }
579 |
580 | QString getDesktopPath()
581 | {
582 | LPITEMIDLIST pidl;
583 | LPMALLOC pShellMalloc;
584 | char szDir[200];
585 | if (SUCCEEDED(SHGetMalloc(&pShellMalloc)))
586 | {
587 | if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl))) {
588 | // 如果成功返回true
589 | SHGetPathFromIDListA(pidl, szDir);
590 | pShellMalloc->Free(pidl);
591 | }
592 | pShellMalloc->Release();
593 | }
594 |
595 | return QString(szDir);
596 | }
597 |
598 | #define Write(TYPE,DIS,NAME) \
599 | styleIni->setValue(#DIS"/"#NAME, QString::number(NAME));\
600 |
601 | void writeStyleIni(){
602 | qDebug()<<"Write";
603 | //Qt中使用QSettings类读写ini文件
604 | //QSettings构造函数的第一个参数是ini文件的路径,第二个参数表示针对ini文件,第三个参数可以缺省
605 | QSettings *styleIni = new QSettings("style.ini", QSettings::IniFormat);
606 | //向ini文件中写入内容,setValue函数的两个参数是键值对
607 |
608 | Write(Int,color,sleep_alpha);
609 | Write(Int,color,active_alpha);
610 |
611 | Write(Int,color,sleep_alpha_deep);
612 | Write(Int,color,active_alpha_deep);
613 |
614 | Write(Float,color,sleep_color_ratio);
615 | Write(Float,color,active_color_ratio);
616 |
617 | Write(Int,effect,light_alpha_start);
618 | Write(Int,effect,light_alpha_end);
619 |
620 | Write(Int,effect,icon_shadow_alpha);
621 | Write(Int,effect,icon_shadow_blur_radius);
622 |
623 | Write(Int,effect,unit_shadow_alpha);
624 | Write(Int,effect,unit_shadow_blur_radius);
625 |
626 | Write(Int,render,unit_radius);
627 |
628 | Write(Bool,render,ShowRect);
629 | Write(Bool,render,ShowSide);
630 | Write(Bool,render,ShowLight);
631 |
632 | Write(Bool,render,enable_background_transparent);
633 | Write(Bool,render,enable_background_blur);
634 | Write(Bool,render,enable_light_track);
635 |
636 | Write(Bool,render,enable_intime_repaint);
637 |
638 | Write(Bool,preference,enable_image_fill);
639 | Write(Bool,preference,muilt_icon_default_type);
640 |
641 | Write(Double,preference,scale_fix_ratio);
642 |
643 | Write(Bool,preference,enable_lnk_redirect);
644 |
645 | //写入完成后删除指针
646 | delete styleIni;
647 | }
648 |
649 |
650 | #define Read(TYPE,DIS,NAME) \
651 | NAME = styleIni->value( #DIS"/"#NAME ).to##TYPE(); \
652 |
653 | void readStyleIni(){
654 |
655 | QFileInfo fi("style.ini");
656 | if(fi.exists()){
657 | QSettings *styleIni = new QSettings("style.ini", QSettings::IniFormat);
658 |
659 | Read(Int,color,sleep_alpha);
660 | Read(Int,color,active_alpha);
661 |
662 | Read(Int,color,sleep_alpha_deep);
663 | Read(Int,color,active_alpha_deep);
664 |
665 | Read(Float,color,sleep_color_ratio);
666 | Read(Float,color,active_color_ratio);
667 |
668 | Read(Int,effect,light_alpha_start);
669 | Read(Int,effect,light_alpha_end);
670 |
671 | Read(Int,effect,icon_shadow_alpha);
672 | Read(Int,effect,icon_shadow_blur_radius);
673 |
674 | Read(Int,effect,unit_shadow_alpha);
675 | Read(Int,effect,unit_shadow_blur_radius);
676 |
677 | Read(Int,render,unit_radius);
678 |
679 | Read(Bool,render,ShowRect);
680 | Read(Bool,render,ShowSide);
681 | Read(Bool,render,ShowLight);
682 |
683 | Read(Bool,render,enable_background_transparent);
684 | Read(Bool,render,enable_background_blur);
685 | Read(Bool,render,enable_light_track);
686 |
687 | Read(Bool,render,enable_intime_repaint);
688 |
689 | Read(Bool,preference,enable_image_fill);
690 | Read(Bool,preference,muilt_icon_default_type);
691 |
692 | Read(Double,preference,scale_fix_ratio);
693 |
694 | Read(Bool,preference,enable_lnk_redirect);
695 |
696 | delete styleIni;
697 | }
698 | else{
699 | writeStyleIni();
700 | }
701 | }
702 |
703 | void writeJson(){
704 | QJsonObject rootObj = pmw->inside->to_json();
705 | QJsonDocument document;
706 | document.setObject(rootObj);
707 |
708 | QByteArray byte_array = document.toJson(QJsonDocument::Compact);
709 | QString json_str(byte_array);
710 | //根据实际填写路径
711 | QFile file("content.json");
712 |
713 |
714 | if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate))
715 | {
716 | qDebug() << "file error!";
717 | }
718 | QTextStream in(&file);
719 | in.setCodec("UTF-8");
720 | in << json_str;
721 |
722 | file.close(); // 关闭file
723 | }
724 |
725 | void readJson(){
726 | QFile file("content.json");
727 | file.open(QIODevice::ReadOnly | QIODevice::Text);
728 | QString value = file.readAll();
729 | file.close();
730 |
731 | QJsonParseError parseJsonErr;
732 | QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr);
733 | if (! (parseJsonErr.error == QJsonParseError::NoError)) {
734 | QMessageBox::about(NULL, "提示", "配置文件错误!");
735 | return;
736 | }
737 |
738 | QJsonObject jsonObject = document.object();
739 | pmw->inside->load_json(jsonObject);
740 |
741 | }
742 |
--------------------------------------------------------------------------------
/SysFunctions.h:
--------------------------------------------------------------------------------
1 | #ifndef SYSFUNCTIONS_H
2 | #define SYSFUNCTIONS_H
3 | #include
4 | #include
5 | #include"mainwindow.h"
6 | #include "qfileinfo.h"
7 | void Init(MainWindow* mainwindow);
8 | void inplace();
9 | void InitMouseHook();
10 | QString Unicode2GBK(QString c);
11 | QString Unicode2Utf(QString c);
12 | QString GetCorrectUnicode(const QByteArray &ba);
13 | QString elidedLineText(QWidget *pWidget, int nLine, QString strText);
14 |
15 | struct FileInfo
16 | {
17 | //定义返回的结构体
18 | enum TYPE{
19 | NORM = 0,
20 | HORI = 1,
21 | VERT = 2
22 | };
23 | bool multi =false;
24 | TYPE type;
25 | QString name;
26 | QString filePath;
27 | QIcon icon;
28 | bool operator<(FileInfo& another) const{
29 | return type scanalldesktopfiles();
33 | QListgetFormFileInfo(QFileInfo x);
34 | void paintRect(QWidget* aim,QColor color);
35 | void repaintAround(QWidget* aim);
36 | void inplace(QWidget* aim);
37 | void inplace2(QWidget* aim);
38 | QString getDesktopPath();
39 | QColor pixmapMainColor(QPixmap p, double bright);
40 | void paintSide(QWidget* aim,QColor color);
41 | void paintLight(QWidget* aim,QColor color);
42 | void customMessageHandler(QtMsgType type,
43 | const QMessageLogContext &context,
44 | const QString &msg);
45 |
46 | void readStyleIni();
47 | void writeStyleIni();
48 | void writeJson();
49 | void readJson();
50 | void setMyAppAutoRun(bool isStart);
51 | ED_Unit* from_json(QJsonObject data);
52 | QColor GetWindowsThemeColor();
53 |
54 | #endif // SYSFUNCTIONS_H
55 |
--------------------------------------------------------------------------------
/ed_bgshower.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_bgshower.h"
2 | #include "mainwindow.h"
3 | #include "qgraphicseffect.h"
4 | #include "qpainter.h"
5 | #include "QDebug"
6 |
7 | ED_BGShower::ED_BGShower(QWidget *parent)
8 | : QWidget{parent}
9 | {
10 | QGraphicsBlurEffect* ef = new QGraphicsBlurEffect(this);
11 | ef->setBlurHints(QGraphicsBlurEffect::PerformanceHint);
12 | ef->setEnabled(true);
13 | ef->setBlurRadius(30);
14 | setGraphicsEffect(ef);
15 |
16 | setWindowTitle("BG_Shower");
17 | setAttribute(Qt::WA_TransparentForMouseEvents, true);
18 | setAttribute(Qt::WA_TranslucentBackground);
19 | }
20 |
21 | void ED_BGShower::paintEvent(QPaintEvent * ev){
22 | // qDebug()<<"bg_pre_painted"<transparent;
23 | auto tem = updateMask();
24 | QPainter painter(this);
25 | painter.setClipRegion(tem);
26 | if(enable_background_transparent&&cap){
27 | painter.drawPixmap(rect(),captrued);
28 | }
29 | else{
30 | painter.drawPixmap(rect(),pmw->bg);
31 | }
32 | }
33 |
34 | QRegion ED_BGShower::updateMask(){
35 | QRegion tem = pmw->inside->region;
36 | if(pMovingUnit){
37 | auto pos = pMovingUnit->mapToGlobal(QPoint(0,0));
38 | auto geo = pMovingUnit->geometry();
39 | tem = tem.united(QRect(pos.x(),pos.y(),geo.width(),geo.height()));
40 | }
41 | return tem;
42 | }
43 |
--------------------------------------------------------------------------------
/ed_bgshower.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_BGSHOWER_H
2 | #define ED_BGSHOWER_H
3 |
4 | #include
5 | #include
6 |
7 | class ED_BGShower : public QWidget
8 | {
9 | Q_OBJECT
10 | public:
11 | explicit ED_BGShower(QWidget *parent = nullptr);
12 | QRegion updateMask();
13 | QPixmap captrued;
14 | bool cap = false;
15 | public:
16 | void paintEvent(QPaintEvent * ev) override;
17 |
18 | };
19 | #endif // ED_BGSHOWER_H
20 |
--------------------------------------------------------------------------------
/ed_block.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_block.h"
2 | #include "SysFunctions.h"
3 | #include "QWidget"
4 | #include"QProcess"
5 | #include "qboxlayout.h"
6 | #include"SysFunctions.h"
7 | #include "qfileinfo.h"
8 | #include "qlabel.h"
9 | #include"QDebug"
10 | #include"QUrl"
11 | #include"QDesktopServices"
12 | #include"QTextCodec"
13 | #include "qpainter.h"
14 | #include"QGraphicsDropShadowEffect"
15 |
16 | int ED_Block::default_size = 48;
17 | ED_Block::ED_Block(QWidget *parent, int sizex, int sizey):ED_Unit(parent, sizex, sizey){
18 | filePath = "empty";
19 | name = "empty";
20 |
21 | // 初始化内部组件
22 | vl = new QVBoxLayout(this);
23 | vl->setContentsMargins(0, 5, 0, 5);
24 | vl->addSpacing(0);
25 |
26 | gv = new PictureBox(this, 1.0);
27 | lb = new QLabel(this);
28 | // lb->adjustSize();
29 |
30 | // 显示图标
31 | // double defaultRatio = (double)default_size/image.size().width();
32 | iconmap=QPixmap();
33 | setMainColor(pixmapMainColor(iconmap,sleep_color_ratio));
34 |
35 | (( QGraphicsDropShadowEffect*)graphicsEffect())->setColor(mainColor);
36 | gv->setImage(iconmap);
37 | gv->setBackground(QBrush (QColor(0,0,0,0)));
38 | gv->setVisible(true);
39 | // vl->setAlignment(Qt::AlignHCenter);
40 |
41 | // 添加布局
42 | // vl->addStretch();
43 | vl->addWidget(gv);
44 | vl->setAlignment(gv, Qt::AlignCenter);
45 | // vl->setAlignment(gv, Qt::AlignVCenter);
46 |
47 | vl->addWidget(lb);
48 | vl->setAlignment(lb, Qt::AlignCenter);
49 | // vl->addStretch();
50 |
51 | // 显示名字
52 | lb->setAlignment(Qt::AlignCenter);
53 | lb->setFont(QFont("MiSans", 10, 40));
54 | lb->setFixedWidth(width() - 5);
55 | lb->setText(elidedLineText(lb, 3, name));
56 |
57 |
58 | auto tem = mainColor;
59 | tem.setAlpha(icon_shadow_alpha);
60 |
61 | icon_shadow = new QGraphicsDropShadowEffect;
62 | icon_shadow->setColor(tem);
63 | icon_shadow->setBlurRadius(10); // 模糊半径
64 | icon_shadow->setOffset(10); // 偏移量
65 | lb->setGraphicsEffect(icon_shadow);
66 |
67 | text_shadow = new QGraphicsDropShadowEffect;
68 | text_shadow->setColor(tem);
69 | text_shadow->setBlurRadius(icon_shadow_blur_radius); // 模糊半径
70 | text_shadow->setOffset(0, 0); // 偏移量
71 | gv->setGraphicsEffect(text_shadow);
72 | setScale(1.0);
73 | }
74 |
75 |
76 |
77 | ED_Block::ED_Block(QWidget *parent, QPixmap image, QString _name, QString filepath, int sizex, int sizey)
78 | : ED_Block(parent, sizex, sizey)
79 | {
80 | filePath = filepath;
81 | name = _name;
82 | // 初始化内部组件
83 | // 显示图标
84 | iconmap=image;
85 | setMainColor(pixmapMainColor(iconmap,sleep_color_ratio));
86 |
87 | ((QGraphicsDropShadowEffect*)graphicsEffect())->setColor(mainColor);
88 |
89 | gv->setImage(image);
90 |
91 | lb->setText(elidedLineText(lb, 3, name));
92 |
93 |
94 | auto tem = mainColor;
95 | tem.setAlpha(icon_shadow_alpha);
96 | icon_shadow->setColor(tem);
97 | text_shadow->setColor(tem);
98 |
99 | }
100 |
101 |
102 | ED_Block::ED_Block(QWidget *parent, QString path, int sizeX, int sizeY):ED_Block(parent,sizeX,sizeY)
103 | {
104 | unzip(path);
105 | }
106 | //---------------------------------------------------
107 |
108 | void ED_Block::afterResize(QResizeEvent* event){
109 | ED_Unit::afterResize(event);
110 | lb->setFixedWidth(qBound(10, width()-5,9999));
111 | lb->setText(elidedLineText(lb,4,name));
112 | gv->updateDispaly();
113 | }
114 | void ED_Block::mouse_enter_action(){
115 | ED_Unit::mouse_enter_action();
116 | mainColor = pixmapMainColor(iconmap, active_color_ratio);
117 | qDebug()<size();
118 | // 文件预览
119 | QFileInfo fileInfo(filePath); // 去掉 "file:///"
120 | qDebug() << "File info: " << fileInfo.filePath()<m_scale<displaySize<actualSize; // 调试信息
121 | // if (fileInfo.isFile()) {
122 | // if (fileInfo.suffix() == "txt") {
123 | // QFile file(fileInfo.filePath());
124 | // if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
125 | // QTextStream in(&file);
126 | // in.setCodec("UTF-8"); // 设置为UTF-8编码
127 | // QString content = in.readAll();
128 | // file.close();
129 |
130 | // // 如果UTF-8读取失败,尝试其他编码
131 | // if (content.contains(QChar(0xFFFD))) { // 检查是否有替换字符
132 | // file.open(QIODevice::ReadOnly | QIODevice::Text);
133 | // in.setCodec("GBK"); // 尝试GBK编码
134 | // content = in.readAll();
135 | // file.close();
136 | // }
137 |
138 | // // 限制预览内容的长度
139 | // if (content.length() > 1000) {
140 | // content = content.left(1000) + "\n...";
141 | // }
142 |
143 | // previewWidget->setText(content);
144 | // previewWidget->move(mapToGlobal(QPoint(0, height())));
145 | // previewWidget->show();
146 | // qDebug() << "Text file preview shown"; // 调试信息
147 | // }
148 | // } else if (fileInfo.suffix() == "png") {
149 | // QImage image(fileInfo.filePath());
150 | // previewWidget->setImage(image);
151 | // previewWidget->move(mapToGlobal(QPoint(0, height())));
152 | // previewWidget->show();
153 | // qDebug() << "Image file preview shown"; // 调试信息
154 | // }
155 | // }
156 | }
157 |
158 | void ED_Block::mouse_leave_action(){
159 | // 最终移动执行
160 | ED_Unit::mouse_leave_action();
161 |
162 | mainColor = pixmapMainColor(iconmap, sleep_color_ratio);
163 | // 文件预览
164 | // previewWidget->hide();
165 | // 隐藏视频预览
166 | }
167 |
168 | void ED_Block::double_click_action(){
169 | //最终双击执行
170 | ED_Unit::double_click_action();
171 | QString cmd= QString("file:///")+filePath;
172 | qDebug("cmd = %s",qPrintable(cmd));
173 | QDesktopServices::openUrl(QUrl(cmd));
174 | }
175 |
176 | void ED_Block::paintEvent(QPaintEvent *event)
177 | {
178 | // qDebug()<<"painter";
179 | ED_Unit::paintEvent(event);
180 | QColor alphaed = mainColor_Alphaed();
181 | paintRect(this,alphaed);
182 | }
183 |
184 | QJsonObject ED_Block::to_json()
185 | {
186 | QJsonObject rootObject = ED_Unit::to_json();
187 | rootObject.insert("path",filePath);
188 | return rootObject;
189 | }
190 |
191 | void ED_Block::load_json(QJsonObject rootObject)
192 | {
193 | ED_Unit::load_json(rootObject);
194 | unzip(rootObject.value("path").toString());
195 | }
196 |
197 | void ED_Block::whenMainColorChange(QColor val)
198 | {
199 | ED_Unit::whenMainColorChange(val);
200 | if(dark){
201 | lb->setStyleSheet("color:white;");
202 | }
203 | else{
204 | lb->setStyleSheet("color:black;");
205 | }
206 | }
207 |
208 | void ED_Block::ed_update()
209 | {
210 | ED_Unit::ed_update();
211 | whenScaleChange(scale*scaleFix);
212 | }
213 | void ED_Block::whenSimpleModeChange(bool val){
214 | lb->setVisible(!val);
215 | }
216 |
217 | void ED_Block::whenScaleChange(double val){
218 | // qDebug()<<"called"<setScale(val*default_scale);
220 | }
221 |
222 | void ED_Block::unzip(QString filepath)
223 | {
224 | QList infos = getFormFileInfo(QFileInfo(filepath));
225 | FileInfo info = infos[0];
226 | qDebug() << info.name;
227 |
228 | filePath = info.filePath;
229 | name = info.name;
230 | // 初始化内部组件
231 |
232 | // 显示图标
233 | iconmap=info.icon.pixmap(512);
234 | // qDebug()<setColor(mainColor);
239 |
240 | gv->setImage(iconmap);
241 |
242 | lb->setText(elidedLineText(lb, 3, name));
243 |
244 | auto tem = mainColor;
245 | tem.setAlpha(icon_shadow_alpha);
246 | icon_shadow->setColor(tem);
247 | text_shadow->setColor(tem);
248 | }
249 |
--------------------------------------------------------------------------------
/ed_block.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_BLOCK_H
2 | #define ED_BLOCK_H
3 |
4 | #include "SysFunctions.h"
5 | #include "ed_unit.h"
6 | #include "filepreviewwidget.h"
7 | #include "picturebox.h"
8 | #include "qboxlayout.h"
9 | #include "qlabel.h"
10 | #include
11 | //新增
12 | #include
13 | #include
14 | #include
15 |
16 | class ED_Block : public ED_Unit
17 | {
18 | Q_OBJECT;
19 |
20 | public:
21 | QLabel* lb ;
22 | QPixmap iconmap;
23 | QString filePath;
24 | double default_scale = 0.5;
25 | static int default_size;
26 | QString name;
27 | PictureBox* gv ;
28 | QVBoxLayout* vl;
29 | QGraphicsDropShadowEffect* icon_shadow;
30 | QGraphicsDropShadowEffect* text_shadow;
31 | explicit ED_Block():ED_Block(nullptr,1,1){};
32 | explicit ED_Block(QWidget *parent, int sizex =1, int sizey=1);
33 | explicit ED_Block(QWidget *parent, QPixmap image, QString _name, QString _cmd, int sizex=1, int sizey=1);
34 | explicit ED_Block(QWidget *parent,QString path,int sizeX = 1,int sizeY = 1);
35 |
36 | ED_Block(const ED_Block& other):ED_Block(other.parentWidget(),other.iconmap,other.name,other.filePath,other.sizeX,other.sizeY){};
37 |
38 | void afterResize(QResizeEvent* event) override;
39 | void mouse_enter_action() override;
40 | void mouse_leave_action()override;
41 | void whenSimpleModeChange(bool) override;
42 | void whenScaleChange(double) override;
43 |
44 |
45 | void unzip(QString filepath);
46 |
47 | void double_click_action() override;
48 | void paintEvent(QPaintEvent *event) override;
49 | // FilePreviewWidget *previewWidget;
50 | QVBoxLayout *layout; // 新增 QVBoxLayout 成员
51 | QJsonObject to_json() override;
52 | void load_json(QJsonObject rootObject) override;
53 | void whenMainColorChange(QColor val) override;
54 | virtual void ed_update() override;
55 | };
56 |
57 | Q_DECLARE_METATYPE(ED_Block)
58 |
59 | #endif // ED_BLOCK_H
60 |
--------------------------------------------------------------------------------
/ed_blockcontainer.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_blockcontainer.h"
2 | #include "ed_blocklayout.h"
3 | #include "qdebug.h"
4 | #include"QJsonObject"
5 | #include "qjsonarray.h"
6 |
7 | ED_BlockContainer::ED_BlockContainer(QWidget *parent,int sizeX,int sizeY,int row,int cal,int space,int spaceX,int spaceY )
8 | : ED_Container(parent,sizeX,sizeY),row(row),col(cal),space(space),spaceX(spaceX),spaceY(spaceY)
9 | {
10 | int temx,temy;
11 | if(spaceX == 0)
12 | temx = space;
13 | else temx = spaceX;
14 |
15 | if(spaceY ==0)
16 | temy = space;
17 | else temy = spaceY;
18 | inside = new ED_BlockLayout(this,row,cal,space,temx,temy);
19 | }
20 |
21 |
22 | void ED_BlockContainer::paintEvent(QPaintEvent *event){
23 | ED_Unit::paintEvent(event);
24 | Q_UNUSED(event);
25 | }
26 |
27 | QJsonObject ED_BlockContainer::to_json()
28 | {
29 |
30 | return ED_Container::to_json();
31 | }
32 |
33 | void ED_BlockContainer::load_json(QJsonObject rootObject)
34 | {
35 | ED_Container::load_json(rootObject);
36 | ED_BlockLayout* inside_ = (ED_BlockLayout*)inside;
37 | row = inside_->row;
38 | col = inside_->col;
39 | space = inside_->space;
40 | spaceX = inside_->spaceX;
41 | spaceY = inside_->spaceY;
42 | }
43 |
44 | void ED_BlockContainer::Say(){
45 | for(ED_Unit* content:*(inside->contents)){
46 | qDebug()<pos()<mapToGlobal(content->pos())<size()<<"X,Y"<indX<indY;
47 | }
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/ed_blockcontainer.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_BLOCKCONTAINER_H
2 | #define ED_BLOCKCONTAINER_H
3 |
4 | #include
5 | #include "ed_container.h"
6 |
7 | class ED_BlockContainer : public ED_Container
8 | {
9 | Q_OBJECT
10 | public:
11 | explicit ED_BlockContainer():ED_BlockContainer(nullptr,1,1,1,1,1){}
12 | explicit ED_BlockContainer(QWidget *parent,int sizeX,int sizeY,int row,int cal,int space,int spaceX =0,int spaceY = 0);
13 | explicit ED_BlockContainer(QWidget *parent, QJsonObject rootObject);
14 | ED_BlockContainer(const ED_BlockContainer &other)
15 | :ED_BlockContainer(other.parentWidget(),other.sizeX,other.sizeY,other.row,other.col,other.space,other.spaceX,other.spaceY)
16 | {}
17 | int row,col,space,spaceX,spaceY;
18 | // virtual void InitLayout();
19 | void Say();
20 |
21 |
22 |
23 | protected:
24 | void paintEvent(QPaintEvent *event);
25 |
26 | // ED_Unit interface
27 | public:
28 | QJsonObject to_json() ;
29 | void load_json(QJsonObject rootObject) ;
30 | };
31 | Q_DECLARE_METATYPE(ED_BlockContainer)
32 |
33 | #endif // ED_BLOCKCONTAINER_H
34 |
--------------------------------------------------------------------------------
/ed_blocklayout.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_blocklayout.h"
2 |
3 |
4 |
5 | ED_BlockLayout::ED_BlockLayout(QWidget *father, int row, int col, int borad_space,int space_x,int space_y):ED_Layout(father) {
6 | this->row = row;
7 | this->col = col;
8 | this->space = borad_space;
9 | this->spaceX = space_x;
10 | this->spaceY = space_y;
11 | this->pContainer = father;
12 | for(int i=0;ioccupied = false;
16 | }
17 | }
18 | visibal = true;
19 | }
20 |
21 | QPoint ED_BlockLayout::pos2Ind(int posx,int posy){
22 | return QPoint((posx-space)/(W_Block_Clean()+spaceX),(posy-space)/(H_Block_Clean()+spaceY));
23 | }
24 |
25 | //从Block序号获取中心坐标
26 |
27 | QPoint ED_BlockLayout::ind2CenterPoint(int x,int y){
28 | auto aim = ind2Unit(x,y);
29 | QPoint size(W_Block_Clean()*aim->sizeX+(aim->sizeX-1)*spaceX,H_Block_Clean()*aim->sizeY+(aim->sizeY-1)*spaceY);
30 | QPoint pos(blocks[x][y]->posX(),blocks[x][y]->posY());
31 | return (pos+size/2);
32 | }
33 |
34 | QSize ED_BlockLayout::ind2Size(int xind, int yind)
35 | {
36 | auto aim = ind2Unit(xind,yind);
37 | int w = W_Block_Clean()*aim->sizeX+(aim->sizeX-1)*spaceX;
38 | int h = H_Block_Clean()*aim->sizeY+(aim->sizeY-1)*spaceY;
39 |
40 | if(aim->sizeX==1&&aim->sizeY==1&&!isMain){
41 | return QSize(std::min(w,h),std::min(w,h));
42 | }
43 |
44 |
45 |
46 | return QSize(w,h);
47 | }
48 |
49 | QPoint ED_BlockLayout::defaultPutableInd(ED_Unit *aim)
50 | {
51 | for(int j=0;jsizeX;
71 | int y = aim->sizeY;
72 | for(int i=0;ioccupied = false;
75 | blocks[indx+i][indy+k]->content = nullptr;
76 | }
77 | }
78 | }
79 |
80 | QPoint ED_BlockLayout::clearPutableInd(ED_Unit *aim)
81 | {
82 | auto pos = pContainer->mapFromGlobal(aim->pos());
83 | int posx = pos.x();
84 | int posy = pos.y();
85 | int mindeltaw=W_Container();
86 | int mindeltah=H_Container();
87 | int bpw,bph;
88 | bpw=bph=-1;
89 | for(int i=0;isizeX;
111 | int y = aim->sizeY;
112 | for(int i=0;ioccupied = true;
115 | blocks[indx+i][indy+k]->content = aim;
116 | }
117 | }
118 | }
119 |
120 | QPoint ED_BlockLayout::ind2Pos(int xind, int yind)
121 | {
122 | return QPoint(blocks[xind][yind]->posX(),blocks[xind][yind]->posY());
123 | }
124 |
125 | //从Block序号获取是否占用
126 | bool ED_BlockLayout::Occupied(int x,int y){
127 | if(x<0||y<0||x>=row||y>=col)
128 | {
129 | return false;
130 | }
131 | return blocks[x][y]->occupied;
132 | }
133 |
134 | bool ED_BlockLayout::OKForUnit(ED_Unit* aim,int xind,int yind){
135 | int x = aim->sizeX;
136 | int y = aim->sizeY;
137 | if(x+xind>row)return false;
138 | if(y+yind>col) return false;
139 | for(int i=0;icontent;
150 | }
151 |
152 | //将一个ED_Unit放置在Block中,并在双方的变量中纪律以便之后识别
153 |
154 | // void ED_BlockLayout::put_ED_Unit(ED_Unit* aim,int xind,int yind){
155 | // aim->setParent(pContainer);
156 | // int x = aim->sizeX;
157 | // int y = aim->sizeY;
158 | // for(int i=0;icontent = aim;
162 | // }
163 | // }
164 | // aim->indX = xind;
165 | // aim->indY = yind;
166 |
167 | // aim->setFixedSize(W_Block_Clean()*aim->sizeX+(aim->sizeX-1)*spaceX,H_Block_Clean()*aim->sizeY+(aim->sizeY-1)*spaceY);
168 | // aim->move(blocks[xind][yind]->posX(),blocks[xind][yind]->posY());
169 |
170 | // aim->update_after_resize();
171 | // aim->edlayout = this;
172 | // aim->setVisible(true);
173 | // if(isMain){
174 | // aim->showRect = true;
175 | // aim->showLight = true;
176 | // }
177 | // else{
178 | // aim->showRect = false;
179 | // aim->showLight = false;
180 | // }
181 |
182 | // pContainer->raise();
183 | // aim->raise();
184 |
185 | // contents->push_back(aim);
186 | // if(aim->alwaysShow){
187 | // contents_AlwaysShow->push_back(aim);
188 | // }
189 | // else{
190 | // contents_Show->push_back(aim);
191 | // }
192 |
193 | // qDebug()<<"Put Done,Container Pos:"<pos()<<"Aim geometry "<geometry()<<"Pos: "<pos();
194 | // if(enable_background_blur) Update_Region();
195 | // // aim->ed_update();
196 | // }
197 |
198 |
199 | //将一个ED_Unit按序号最下且可放置的位置放置
200 |
201 |
202 | QJsonObject ED_BlockLayout::to_json()
203 | {
204 | QJsonObject rootObject = ED_Layout::to_json();
205 | rootObject.insert("row",row);
206 | rootObject.insert("col",col);
207 | rootObject.insert("space",space);
208 | rootObject.insert("spaceX",spaceX);
209 | rootObject.insert("spaceY",spaceY);
210 | return rootObject;
211 | }
212 |
213 | void ED_BlockLayout::load_json(QJsonObject rootObject)
214 | {
215 |
216 | for(int i=0;ioccupied = false;
233 | }
234 | }
235 |
236 | ED_Layout::load_json(rootObject);
237 | }
238 |
--------------------------------------------------------------------------------
/ed_blocklayout.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_BLOCKLAYOUT_H
2 | #define ED_BLOCKLAYOUT_H
3 |
4 | #include "ed_unit.h"
5 | #include "qwidget.h"
6 | class ED_BlockLayout:public ED_Layout
7 | {
8 | struct little_Block{
9 | int indX;
10 | int indY;
11 | int posX(){
12 | return playout->space+indX*(playout->spaceX+w());
13 | };
14 | int posY(){
15 | return playout->space+indY*(playout->spaceY+h());
16 | };
17 | int w(){
18 | return playout->W_Block_Clean();
19 | };
20 | int h(){
21 | return playout->H_Block_Clean();
22 | };
23 | bool occupied;
24 | ED_BlockLayout* playout;
25 | ED_Unit* content;
26 | int CenterX(){
27 | return posX() +w()/2;
28 | }
29 | int CenterY(){
30 | return posY() +h()/2;
31 | }
32 | QPoint CenterPoint(){
33 | return QPoint(CenterX(),CenterY());
34 | };
35 | little_Block(ED_BlockLayout* playout,int indx,int indy):indX(indx),indY(indy),playout(playout){
36 | }
37 | };
38 | public:
39 | int row;
40 | int col;
41 | int W_Container(){
42 | return pContainer->width()-2*space;
43 | };
44 | int H_Container(){
45 | return pContainer->height()-2*space;
46 | };
47 | int W_Block_Clean(){
48 | return (W_Container()-(row-1)*spaceX)/row;
49 | };
50 | int H_Block_Clean(){
51 | return (H_Container()-(col-1)*spaceY)/col;
52 | };
53 | int space;
54 | int spaceX;
55 | int spaceY;
56 |
57 | little_Block* blocks[50][50];
58 |
59 |
60 | ED_BlockLayout(QWidget *father,int row, int col,int borad_space,int space_x,int space_y);
61 |
62 | QPoint pos2Ind(int posx,int posy)override;
63 |
64 | bool Occupied(int x,int y)override;
65 |
66 | //判断一个ED_Unit的左上角放置在该Block中是否合法
67 | bool OKForUnit(ED_Unit* aim,int xind,int yind);
68 |
69 | //根据一个Block索引获取对应的ED_Unit指针
70 | ED_Unit* ind2Unit(int xind,int yind)override;
71 |
72 | //判断放置一个ED_Unit是否合法
73 |
74 | void load_json(QJsonObject rootObject)override;
75 | QJsonObject to_json()override;
76 |
77 |
78 | // ED_Layout interface
79 | public:
80 | // QSize areaSize() override;
81 | QPoint ind2CenterPoint(int x, int y) override;
82 | QSize ind2Size(int xind, int yind) override;
83 | QPoint defaultPutableInd(ED_Unit *aim) override;
84 |
85 | // ED_Layout interface
86 | public:
87 | void updateAfterPut(ED_Unit *, int, int) override;
88 | void updateAfterRemove(ED_Unit *, int, int) override;
89 |
90 | // ED_Layout interface
91 | public:
92 | QPoint clearPutableInd(ED_Unit *aim) override;
93 |
94 | // ED_Layout interface
95 | public:
96 | void updateBeforePut(ED_Unit *, int, int) override;
97 |
98 |
99 | // ED_Layout interface
100 | public:
101 | QPoint ind2Pos(int xind, int yind) override;
102 | };
103 |
104 | #endif // ED_BLOCKLAYOUT_H
105 |
--------------------------------------------------------------------------------
/ed_container.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_container.h"
2 |
3 | ED_Container::ED_Container(QWidget *parent, int sizeX, int sizeY):ED_Unit(parent,sizeX,sizeY)
4 | {
5 | type = Container;
6 | }
7 | void ED_Container::setSimpleMode(bool val){
8 | ED_Unit::setSimpleMode(val);
9 | for(ED_Unit* content:*(inside->contents)){
10 | content->setSimpleMode(val);
11 | }
12 | }
13 |
14 | void ED_Container::setScale(double val){
15 | ED_Unit::setScale(val);
16 | for(ED_Unit* content:*(inside->contents)){
17 | content->setScale(val);
18 | }
19 | }
20 |
21 | void ED_Container::ed_update(){
22 | ED_Unit::ed_update();
23 | for(ED_Unit* content:*(inside->contents)){
24 | content->ed_update();
25 | }
26 | }
27 |
28 |
29 | void ED_Container::afterResize(QResizeEvent *event){
30 | inside->UpdateContentPositon();
31 | }
32 |
33 | QJsonObject ED_Container::to_json()
34 | {
35 | QJsonObject rootObject = ED_Unit::to_json();
36 | QJsonObject contentObject = inside->to_json();
37 | rootObject.insert("content",contentObject);
38 | return rootObject;
39 | }
40 |
41 | void ED_Container::load_json(QJsonObject rootObject)
42 | {
43 | ED_Unit::load_json(rootObject);
44 | inside->load_json(rootObject.value("content").toObject());
45 | }
46 | void ED_Container::clearPut(ED_Unit* aim, bool animated){
47 | inside->clearPut(aim,animated);
48 | }
49 |
50 | bool ED_Container::OKForClearPut(ED_Unit* aim){
51 | return inside->OKForClearPut(aim);
52 | }
53 |
--------------------------------------------------------------------------------
/ed_container.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_CONTAINER_H
2 | #define ED_CONTAINER_H
3 |
4 | #include "ed_unit.h"
5 | #include
6 |
7 | class ED_Container : public ED_Unit
8 | {
9 | Q_OBJECT
10 | public:
11 |
12 | explicit ED_Container(QWidget *parent = nullptr,int sizeX=3,int sizeY=3);
13 | explicit ED_Container(QWidget *parent, QJsonObject rootObject);
14 | ED_Container(const ED_Container &other)
15 | :ED_Container(other.parentWidget(),other.sizeX,other.sizeY)
16 | {
17 |
18 | }
19 | ED_Layout* inside;
20 | // virtual void InitLayout();
21 | void clearPut(ED_Unit* aim,bool animated);
22 | bool OKForClearPut(ED_Unit* aim);
23 | void afterResize(QResizeEvent* event) override;
24 | void setSimpleMode(bool)override;
25 | void setScale(double val)override;
26 | void ed_update()override;
27 |
28 | // ED_Unit interface
29 | public:
30 | QJsonObject to_json()override ;
31 | void load_json(QJsonObject rootObject)override ;
32 | signals:
33 | };
34 |
35 | #endif // ED_CONTAINER_H
36 |
--------------------------------------------------------------------------------
/ed_dock.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_dock.h"
2 | #include "ed_linearlayout.h"
3 | #include"ed_unit.h"
4 | #include "qdebug.h"
5 | #include"QPainterPath"
6 | #include"QPainter"
7 | #include"QJsonObject"
8 | ED_Dock::ED_Dock(QWidget *parent,int outSizeX,int outSizeY)
9 | : ED_Container(parent,outSizeX,outSizeY)
10 | {
11 | alwaysShow = true;
12 | setMainColor(QColor(79,98,124));
13 | inside = new ED_LinearLayout(this);
14 | }
15 |
16 |
17 | void ED_Dock::paintEvent(QPaintEvent *event){
18 | // paintRect(this,QColor(0,0,155,aim_Alpha));
19 |
20 |
21 | QPainter painter(this);
22 | QLinearGradient linearGradient(QPoint(0,0),QPoint(width(),0));
23 |
24 | auto tem = mainColor_Alphaed();
25 |
26 | int count=0;
27 | ED_LinearLayout* inside_ = (ED_LinearLayout*) inside;
28 | for(int i=0;inum();i++){
29 | // for(int i =0;i<10;i++){
30 | // if(inside_->blocks[i]==nullptr) qDebug()<ind2Unit(i,0)->mainColor;
35 | float ratio = 1.0*(inside->ind2CenterPoint(i,0).x())/width();
36 | temm.setAlpha(colorAlpha);
37 | linearGradient.setColorAt(ratio, temm);
38 | }
39 |
40 | if(count){
41 | linearGradient.setColorAt(0, QColor(255,255,255,0));
42 | linearGradient.setColorAt(1, QColor(255,255,255,0));
43 | }
44 | else{
45 | linearGradient.setColorAt(0, tem);
46 | linearGradient.setColorAt(1, tem);
47 | }
48 |
49 |
50 | // 使用线性渐变创建一个画刷,用来填充
51 |
52 | QBrush brush(linearGradient);
53 | painter.setBrush(brush);
54 | painter.setPen(Qt::NoPen);
55 | // x, y, w, h
56 | painter.drawRect(rect());
57 |
58 | // paintLight(this,mainColor);
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/ed_dock.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_DOCK_H
2 | #define ED_DOCK_H
3 |
4 | #include "ed_blockcontainer.h"
5 | #include "ed_unit.h"
6 | #include
7 |
8 | class ED_Dock : public ED_Container
9 | {
10 | Q_OBJECT
11 | public:
12 | explicit ED_Dock(QWidget *parent = nullptr, int outSizeX=5, int outSizeY=1);
13 | explicit ED_Dock(QWidget *parent, QJsonObject rootObject);
14 | ED_Dock(const ED_BlockContainer &other)
15 | :ED_Dock(other.parentWidget())
16 | {}
17 |
18 |
19 |
20 | void paintEvent(QPaintEvent *event);
21 | signals:
22 | };
23 | Q_DECLARE_METATYPE(ED_Dock);
24 | #endif // ED_DOCK_H
25 |
--------------------------------------------------------------------------------
/ed_editbox.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_editbox.h"
2 | #include "mainwindow.h"
3 | #include "qmessagebox.h"
4 | #include"qcheckbox.h"
5 | #include"QSlider"
6 |
7 | ED_EditBox::ED_EditBox(QWidget *parent)
8 | : ED_Unit(parent,3,2)
9 | {
10 | type = Unit;
11 | settings= new QHBoxLayout(this);
12 |
13 | overall = new QVBoxLayout(this);
14 | settings->addLayout(overall);
15 |
16 | QCheckBox *checkBox1 = new QCheckBox("背景透视",this); //创建QCheckBox对象
17 | checkBox1->setChecked(enable_background_transparent);
18 | overall->addWidget(checkBox1);
19 | connect(checkBox1, &QCheckBox::clicked, this, [](bool checked) {
20 | pmw->setTransparent(checked);
21 | pmw->update();
22 | });
23 |
24 | #ifdef QT_DEBUG
25 | QCheckBox *checkBox2 = new QCheckBox("背景模糊",this);
26 | checkBox2->setChecked(enable_background_blur);
27 | overall->addWidget(checkBox2);
28 | connect(checkBox2, &QCheckBox::clicked, this, [](bool checked) {
29 | pmw->setBlur(checked);
30 | pmw->update();
31 | });
32 | #endif
33 |
34 | QCheckBox *checkBox3 = new QCheckBox("特效追踪",this);
35 | checkBox3->setChecked(enable_light_track);
36 | overall->addWidget(checkBox3);
37 | connect(checkBox3, &QCheckBox::clicked, this, [](bool checked) {
38 | enable_light_track = checked;
39 | pmw->update();
40 | });
41 |
42 | paint = new QVBoxLayout(this);
43 | settings->addLayout(paint);
44 |
45 |
46 | #ifdef QT_DEBUG
47 |
48 | QCheckBox *checkBox4 = new QCheckBox("绘制边框",this);
49 | checkBox4->setChecked(ShowSide);
50 | paint->addWidget(checkBox4);
51 | connect(checkBox4, &QCheckBox::clicked, this, [](bool checked) {
52 | ShowSide = checked;
53 | pmw->update();
54 | });
55 |
56 | #endif
57 |
58 | QCheckBox *checkBox5 = new QCheckBox("绘制矩形",this);
59 | checkBox5->setChecked(ShowRect);
60 | paint->addWidget(checkBox5);
61 | connect(checkBox5, &QCheckBox::clicked, this, [](bool checked) {
62 | ShowRect = checked;
63 | pmw->update();
64 | });
65 |
66 |
67 |
68 |
69 | QCheckBox *checkBox6 = new QCheckBox("绘制光效",this);
70 | checkBox6->setChecked(ShowLight);
71 | paint->addWidget(checkBox6);
72 | connect(checkBox6, &QCheckBox::clicked, this, [](bool checked) {
73 | ShowLight = checked;
74 | pmw->repaint();
75 | });
76 |
77 | QCheckBox *checkBox7 = new QCheckBox("大图标填充",this);
78 | checkBox7->setChecked(enable_image_fill);
79 | connect(checkBox7, &QCheckBox::clicked, this, [](bool checked) {
80 | enable_image_fill = checked;
81 | pmw->ed_update();
82 | });
83 | overall->addWidget(checkBox7);
84 |
85 | QCheckBox *checkBox8 = new QCheckBox("即时重绘",this);
86 | checkBox8->setChecked(enable_intime_repaint);
87 | connect(checkBox8, &QCheckBox::clicked, this, [](bool checked) {
88 | enable_intime_repaint = checked;
89 | pmw->repaint();
90 | });
91 | paint->addWidget(checkBox8);
92 |
93 | QSlider* scale_Slider = new QSlider(this);
94 | scale_Slider->setRange(0, 100);
95 | scale_Slider->setValue(100);
96 | connect(scale_Slider, &QSlider::valueChanged, this, [](int val) {
97 | pmw->setScale(1.0*val/100);
98 | });
99 | settings->addWidget(scale_Slider);
100 |
101 | QSlider* radius_Slider = new QSlider(this);
102 | radius_Slider->setRange(0, 80);
103 | radius_Slider->setValue(unit_radius);
104 | connect(radius_Slider, &QSlider::valueChanged, this, [](int val) {
105 | unit_radius = val;
106 | pmw->ed_update();
107 | });
108 | settings->addWidget(radius_Slider);
109 |
110 | QPushButton *button = new QPushButton("选择背景", this);
111 | connect(button, &QPushButton::clicked, this, []() {
112 | // 点击按钮后的处理逻辑
113 | pmw->onSelectBackground();
114 | });
115 | paint->addWidget(button);
116 | }
117 |
--------------------------------------------------------------------------------
/ed_editbox.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_EDITBOX_H
2 | #define ED_EDITBOX_H
3 |
4 | #include "ed_unit.h"
5 | #include "qboxlayout.h"
6 | #include
7 |
8 | class ED_EditBox : public ED_Unit
9 | {
10 | Q_OBJECT
11 | public:
12 | explicit ED_EditBox(QWidget *parent = nullptr);
13 | QHBoxLayout* settings;
14 | QVBoxLayout* overall;
15 | QVBoxLayout* paint;
16 | QVBoxLayout* scale;
17 | QVBoxLayout* tem;
18 | signals:
19 | };
20 | Q_DECLARE_METATYPE(ED_EditBox)
21 | #endif // ED_EDITBOX_H
22 |
--------------------------------------------------------------------------------
/ed_hidetextblock.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_hidetextblock.h"
2 | #include"QDesktopServices"
3 | #include "SysFunctions.h"
4 |
5 | ED_HideTextBlock::ED_HideTextBlock(QWidget *parent, int sizey, int sizex) : ED_Block(parent, sizex, sizey)
6 | {
7 | deepColor =true;
8 | lb->setVisible(false);
9 | setScale(1.0);
10 | vl->setMargin(0);
11 | gv->requireFill = true;
12 | }
13 | ED_HideTextBlock::ED_HideTextBlock(QWidget *parent, QPixmap image, QString _name, QString filepath, int sizex, int sizey):ED_HideTextBlock(parent,sizex,sizey){
14 | filePath = filepath;
15 | name = _name;
16 |
17 | // 初始化内部组件
18 | // 显示图标
19 | iconmap=image;
20 | setMainColor(pixmapMainColor(iconmap,sleep_color_ratio));
21 |
22 | ((QGraphicsDropShadowEffect*)graphicsEffect())->setColor(mainColor);
23 |
24 | gv->setImage(image);
25 |
26 |
27 | lb->setText(elidedLineText(lb, 3, name));
28 |
29 | auto tem = mainColor;
30 | tem.setAlpha(icon_shadow_alpha);
31 | icon_shadow->setColor(tem);
32 | text_shadow->setColor(tem);
33 | }
34 |
35 | void ED_HideTextBlock::whenSimpleModeChange(bool val)
36 | {
37 |
38 | }
39 |
40 | void ED_HideTextBlock::whenScaleChange(double val)
41 | {
42 | // qDebug()<<"HSCalled";
43 | gv->setScale(1.0*scaleFix);
44 | }
45 |
46 | // void ED_HideTextBlock::ed_update()
47 | // {
48 | // ED_Unit::ed_update();
49 | // // gv->setScale(1.0);
50 | // }
51 |
--------------------------------------------------------------------------------
/ed_hidetextblock.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_HIDETEXTBLOCK_H
2 | #define ED_HIDETEXTBLOCK_H
3 |
4 | #include "ed_block.h"
5 | class ED_HideTextBlock:public ED_Block
6 | {
7 | Q_OBJECT
8 |
9 | public:
10 | // using ED_Block::ED_Block;
11 | explicit ED_HideTextBlock():ED_HideTextBlock(nullptr,1,1){};
12 | explicit ED_HideTextBlock(QWidget *parent, int sizey = 1, int sizex = 1);
13 | explicit ED_HideTextBlock(QWidget *parent, QPixmap image, QString _name, QString filepath, int sizex, int sizey);
14 | ED_HideTextBlock(const ED_HideTextBlock& other):ED_HideTextBlock(other.parentWidget(),other.iconmap,other.name,other.filePath,other.sizeX,other.sizeY){};
15 | void whenSimpleModeChange(bool val) override;
16 | void whenScaleChange(double) override;
17 | // void ed_update() override;
18 | };
19 | Q_DECLARE_METATYPE(ED_HideTextBlock)
20 | #endif // ED_HIDETEXTBLOCK_H
21 |
--------------------------------------------------------------------------------
/ed_layout.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_layout.h"
2 | #include "SysFunctions.h"
3 | #include "mainwindow.h"
4 | #include "qtimer.h"
5 | #include
6 | #include"QFuture"
7 | #include
8 |
9 | int cmp(const ED_Unit* a,const ED_Unit* b)
10 | {
11 | ED_Unit* p1=(ED_Unit*)a;
12 | ED_Unit* p2=(ED_Unit*)b;
13 | //将a和b强制类型转换后分别存入int型指针变量p1和p2
14 | return *p1<*p2;
15 |
16 | }
17 |
18 | ED_Layout::ED_Layout(QWidget *father)
19 | {
20 | pContainer = father;
21 | }
22 |
23 | QPoint ED_Layout::pos2Ind(QPoint point)
24 | {
25 | return pos2Ind(point.x(),point.y());
26 | }
27 |
28 | QPoint ED_Layout::ind2CenterPoint(QPoint ind)
29 | {
30 | return ind2CenterPoint(ind.x(),ind.y());
31 | }
32 |
33 | QSize ED_Layout::ind2Size(QPoint ind)
34 | {
35 | return ind2Size(ind.x(),ind.y());
36 | }
37 |
38 | QPoint ED_Layout::ind2Pos(QPoint ind)
39 | {
40 | return ind2Pos(ind.x(),ind.y());
41 | }
42 |
43 | QPoint ED_Layout::ind2Pos_Centual(QPoint ind)
44 | {
45 | return ind2Pos_Centual(ind.x(),ind.y());
46 | }
47 |
48 | QPoint ED_Layout::ind2Pos_Centual(int xind, int yind)
49 | {
50 | QSize size = ind2Size(xind,yind);
51 | return ind2CenterPoint(xind,yind)-QPoint(size.width(),size.height())/2;
52 | }
53 |
54 | bool ED_Layout::Occupied(QPoint ind)
55 | {
56 | return Occupied(ind.x(),ind.y());
57 | }
58 |
59 | void ED_Layout::putUnit(ED_Unit *aim, int xind, int yind, bool animated)
60 | {
61 | updateBeforePut(aim,xind,yind);
62 |
63 | aim->indX = xind;
64 | aim->indY = yind;
65 |
66 | aim->layout = this;
67 |
68 |
69 | //setRect
70 | if(isMain){
71 |
72 | }
73 | else{
74 | aim->showLight =true;
75 | aim->showRect = true;
76 | }
77 |
78 | contents->push_back(aim);
79 | if(aim->alwaysShow){
80 | contents_AlwaysShow->push_back(aim);
81 | }
82 | else{
83 | contents_Show->push_back(aim);
84 | }
85 |
86 |
87 | aim->preSetInLayout(animated);
88 |
89 | updateBeforePutAnimation(aim,xind,yind);
90 |
91 | if(enable_background_blur) UpdateRegion();
92 |
93 | if(animated){
94 | QTimer *pTimer = new QTimer(pContainer);
95 | pTimer->singleShot(position_animation_time*2,[=](){
96 | if(aim->layout!=nullptr){
97 | aim->setInLayout(true);
98 | updateAfterPut(aim,xind,yind);
99 | qDebug()<<"timer setted end";
100 | }
101 | // qDebug()<<"timer end";
102 | });
103 | }
104 | else{
105 | aim->setInLayout(false);
106 | updateAfterPut(aim,xind,yind);
107 | }
108 |
109 | QFuture future = QtConcurrent::run(writeJson);
110 | }
111 |
112 | void ED_Layout::putUnit(ED_Unit *aim, QPoint ind, bool animated)
113 | {
114 | putUnit(aim,ind.x(),ind.y(),animated);
115 | }
116 |
117 | void ED_Layout::RemoveAUnit(ED_Unit *aim)
118 | {
119 | QPoint tempos = aim->mapToGlobal(QPoint(0,0));
120 | int indx = aim->indX;
121 | int indy = aim->indY;
122 |
123 | updateBeforeRemove(aim,indx,indy);
124 | aim->indX = -1;
125 | aim->indY = -1;
126 | aim->layout = nullptr;
127 | aim->setParent(pmw);
128 | aim->move(tempos);
129 | aim->setEnabled(true);
130 | aim->setVisible(true);
131 | aim->raise();
132 | auto s = std::find(contents->begin(), contents->end(), aim);//第一个参数是array的起始地址,第二个参数是array的结束地址,第三个参数是需要查找的值
133 | if (s != contents->end())//如果找到,就输出这个元素
134 | {
135 | contents->erase(s);
136 | }
137 | else//如果没找到
138 | {
139 | qDebug() << "not find!";
140 | }
141 |
142 | if(aim->alwaysShow){
143 | auto s = std::find(contents_AlwaysShow->begin(), contents_AlwaysShow->end(), aim);//第一个参数是array的起始地址,第二个参数是array的结束地址,第三个参数是需要查找的值
144 | if (s != contents_AlwaysShow->end())//如果找到,就输出这个元素
145 | {
146 | contents_AlwaysShow->erase(s);
147 | }
148 | else//如果没找到
149 | {
150 | qDebug() << "not find!";
151 | }
152 | }
153 | else{
154 | auto s = std::find(contents_Show->begin(), contents_Show->end(), aim);//第一个参数是array的起始地址,第二个参数是array的结束地址,第三个参数是需要查找的值
155 | if (s != contents_Show->end())//如果找到,就输出这个元素
156 | {
157 | contents_Show->erase(s);
158 | }
159 | else//如果没找到
160 | {
161 | qDebug() << "not find!";
162 | }
163 | }
164 |
165 |
166 |
167 | updateAfterRemove(aim,indx,indy);
168 |
169 | UpdateRegion();
170 | }
171 |
172 | void ED_Layout::clearPut(ED_Unit *aim,bool animated)
173 | {
174 | if(OKForClearPut(aim)){
175 | putUnit(aim,clearPutableInd(aim),animated);
176 | }
177 | else{
178 | qDebug()<<"No Area";
179 | }
180 | }
181 | bool ED_Layout::OKForClearPut(ED_Unit *aim)
182 | {
183 | if(clearPutableInd(aim)==QPoint(-1,-1)) return false;
184 | else return true;
185 | }
186 |
187 | bool ED_Layout::OKForDefaultPut(ED_Unit *aim)
188 | {
189 | if(defaultPutableInd(aim)==QPoint(-1,-1)) return false;
190 | else return true;
191 | }
192 |
193 | ED_Unit *ED_Layout::ind2Unit(QPoint ind)
194 | {
195 | return ind2Unit(ind.x(),ind.y());
196 | }
197 |
198 | void ED_Layout::defaultPut(ED_Unit *aim, bool animated)
199 | {
200 | QPoint dis = defaultPutableInd(aim);
201 | putUnit(aim,dis,animated);
202 | }
203 |
204 | void ED_Layout::setVisible(bool val, bool force)
205 | {
206 | int countt =0;
207 | if(force){
208 | foreach(ED_Unit* unit,*contents){
209 |
210 | unit->setVisible(val);
211 | countt ++;
212 |
213 | }
214 | }
215 | else{
216 | foreach (ED_Unit* unit,*contents_Show) {
217 | unit->setVisible(val);
218 | countt ++;
219 | }
220 |
221 | if(!val){
222 | foreach (ED_Unit* unit,*contents_AlwaysShow) {
223 | unit->raise();
224 | }
225 | }
226 | }
227 |
228 | visibal = val;
229 | UpdateRegion();
230 | pContainer->update();
231 | qDebug()<<"setted"<isVisible()){
240 | auto tem = content->mapToGlobal(QPoint(0,0));
241 | region = region.united(QRegion(tem.x(),tem.y(),content->width(),content->height()));
242 | countt++;
243 | }
244 |
245 | }
246 | qDebug()<<"Region count"<updateInLayout();
253 | }
254 | }
255 |
256 | void ED_Layout::updateAfterPut(ED_Unit *, int, int)
257 | {
258 |
259 | }
260 |
261 | void ED_Layout::updateBeforePutAnimation(ED_Unit *, int, int)
262 | {
263 |
264 | }
265 |
266 | void ED_Layout::updateAfterRemove(ED_Unit *, int, int)
267 | {
268 |
269 | }
270 |
271 | void ED_Layout::updateBeforePut(ED_Unit *, int, int)
272 | {
273 |
274 | }
275 |
276 | void ED_Layout::updateBeforeRemove(ED_Unit *, int, int)
277 | {
278 |
279 | }
280 |
281 | void ED_Layout::load_json(QJsonObject rootObject)
282 | {
283 | contents->clear();
284 | QJsonArray contentArray = rootObject.value("contents").toArray();
285 | QVector tem;
286 | foreach (QJsonValue contentValue , (contentArray)) {
287 | QJsonObject contentObject = contentValue.toObject();
288 | ED_Unit* unit = from_json(contentObject);
289 | tem.append(unit);
290 | }
291 | std::sort(tem.begin(),tem.end(),cmp);
292 | foreach (ED_Unit* aim , tem) {
293 | putUnit(aim,aim->indX,aim->indY,false);
294 | }
295 | }
296 |
297 | QJsonObject ED_Layout::to_json()
298 | {
299 | QJsonObject rootObject;
300 | QJsonArray contentArray;
301 | // std::sort(contents->begin(),contents->end());
302 |
303 | foreach (ED_Unit* content, *(contents)) {
304 | contentArray.append(content->to_json());
305 | }
306 | rootObject.insert("contents",contentArray);
307 | return rootObject;
308 | }
309 |
--------------------------------------------------------------------------------
/ed_layout.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_LAYOUT_H
2 | #define ED_LAYOUT_H
3 |
4 | #include "qjsonobject.h"
5 | #include "qregion.h"
6 | #include
7 | class ED_Unit;
8 |
9 | void writeJson();
10 |
11 | class ED_Layout
12 | {
13 | public:
14 | ED_Layout();
15 | // virtual QSize areaSize() =0;
16 |
17 | bool visibal;
18 | bool isMain = false;
19 |
20 | QRegion region;
21 | QWidget* pContainer;
22 | QVector* contents = new QVector;
23 | QVector* contents_AlwaysShow = new QVector;
24 | QVector* contents_Show = new QVector;
25 |
26 |
27 | ED_Layout(QWidget *father);
28 |
29 | // 从坐标获得最近的Block序号
30 | QPoint pos2Ind(QPoint point);
31 | virtual QPoint pos2Ind(int posx,int posy) = 0;
32 |
33 |
34 | //从Block序号获取中心坐标
35 | QPoint ind2CenterPoint(QPoint ind);
36 | virtual QPoint ind2CenterPoint(int x,int y) =0;
37 |
38 | QSize ind2Size(QPoint ind);
39 | virtual QSize ind2Size(int xind,int yind) = 0;
40 |
41 | QPoint ind2Pos(QPoint ind);
42 | virtual QPoint ind2Pos(int xind,int yind) = 0;
43 |
44 | QPoint ind2Pos_Centual(QPoint ind);
45 | QPoint ind2Pos_Centual(int xind,int yind);
46 |
47 | //从Block序号获取是否占用
48 | bool Occupied(QPoint ind);
49 | virtual bool Occupied(int x,int y) =0;
50 |
51 | //将一个ED_Unit放置在Block中,并在双方的变量中纪律以便之后识别
52 | void putUnit(ED_Unit* aim,int xind,int yind,bool animated);
53 | void putUnit(ED_Unit* aim,QPoint ind,bool animated);
54 |
55 | // 从坐标获得最近的可放置Block序号
56 | // QPoint NearestEmptyBlockInd(ED_Unit* aim,int posx,int posy);
57 | // QPoint NearestEmptyBlockInd(ED_Unit* aim,QPoint pos);
58 |
59 | //将一个Unit从坐标体系中脱离
60 | void RemoveAUnit(ED_Unit* aim);
61 | //将一个Unit加入到坐标体系中
62 | void clearPut(ED_Unit* aim,bool animated);
63 | virtual void defaultPut(ED_Unit* aim,bool animated);
64 |
65 | //判断一个ED_Unit的左上角放置在该Block中是否合法
66 |
67 | bool OKForClearPut(ED_Unit* aim);
68 | bool OKForDefaultPut(ED_Unit* aim);
69 |
70 | //根据一个Block索引获取对应的ED_Unit指针
71 | virtual ED_Unit* ind2Unit(int xind,int yind) =0;
72 | ED_Unit* ind2Unit(QPoint ind);
73 |
74 | virtual QPoint defaultPutableInd(ED_Unit* aim)=0;
75 | virtual QPoint clearPutableInd(ED_Unit* aim)=0;
76 |
77 |
78 | //将一个ED_Unit按序号最下且可放置的位置放置
79 |
80 | virtual void setVisible(bool val, bool force = false);
81 |
82 | void UpdateRegion();
83 | void UpdateContentPositon();
84 |
85 |
86 | virtual void updateAfterPut(ED_Unit*,int,int);
87 | virtual void updateBeforePutAnimation(ED_Unit*,int,int);
88 | virtual void updateAfterRemove(ED_Unit*,int,int);
89 | virtual void updateBeforePut(ED_Unit*,int,int);
90 | virtual void updateBeforeRemove(ED_Unit*,int,int);
91 |
92 | virtual void load_json(QJsonObject rootObject);
93 | virtual QJsonObject to_json();
94 |
95 | void saveLayout(){
96 | writeJson();
97 | }
98 | };
99 |
100 |
101 |
102 | #endif // ED_LAYOUT_H
103 |
--------------------------------------------------------------------------------
/ed_linearlayout.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_linearlayout.h"
2 | #include "ed_block.h"
3 |
4 | ED_LinearLayout::ED_LinearLayout(QWidget *parent)
5 | : ED_Layout(parent)
6 | {
7 | for(int i=0;i<10;i++){
8 | blocks[i] = nullptr;
9 | }
10 | }
11 |
12 | void ED_LinearLayout::refresh()
13 | {
14 | for(int i=0;i<10;i++){
15 | if(blocks[i]!=nullptr){
16 | blocks[i]->setInd(i);
17 | }
18 | }
19 | }
20 |
21 | QPoint ED_LinearLayout::pos2Ind(int posx, int posy)
22 | {
23 | return QPoint(int(posx/fixedDis()),0);
24 | }
25 |
26 | QPoint ED_LinearLayout::ind2CenterPoint(int x, int y)
27 | {
28 | return QPoint(fixedCX(x), pContainer->height()/2);
29 | }
30 |
31 | QSize ED_LinearLayout::ind2Size(int xind, int yind)
32 | {
33 | return QSize(insideHeight(),insideHeight());
34 | }
35 |
36 | QPoint ED_LinearLayout::ind2Pos(int xind, int yind)
37 | {
38 | return QPoint(fixedDis()*xind,0);
39 | }
40 |
41 | bool ED_LinearLayout::Occupied(int x, int y)
42 | {
43 | if(num()>9)
44 | return false;
45 | }
46 |
47 | ED_Unit *ED_LinearLayout::ind2Unit(int xind, int yind)
48 | {
49 | return blocks[xind]->content;
50 | }
51 |
52 | QPoint ED_LinearLayout::defaultPutableInd(ED_Unit *aim)
53 | {
54 | if(num()<=9)
55 | return QPoint(num(),0);
56 | else return QPoint(-1,-1);
57 | }
58 |
59 | QPoint ED_LinearLayout::clearPutableInd(ED_Unit *aim)
60 | {
61 | if(num()>9)
62 | return QPoint(-1,-1);
63 | if (!num())return QPoint(0,0);
64 |
65 | int posx = pContainer->mapFromGlobal(pContainer->cursor().pos()).x();
66 | return QPoint((posx+fixedDis()/2)/fixedDis(),0);
67 | }
68 |
69 |
70 |
71 | void ED_LinearLayout::updateAfterRemove(ED_Unit *aim, int x, int y)
72 | {
73 |
74 | for(int i =x;i=x;i--){
88 | blocks[i+1] = blocks[i];
89 | }
90 | blocks[x] = new littleBlock(x,aim);
91 | refresh();
92 | }
93 |
94 | void ED_LinearLayout::load_json(QJsonObject rootObject)
95 | {
96 |
97 | ED_Layout::load_json(rootObject);
98 | for(int i=0;icontent->updateInLayout();
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/ed_linearlayout.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_LINEARLAYOUT_H
2 | #define ED_LINEARLAYOUT_H
3 |
4 | #include "ed_layout.h"
5 | #include "ed_unit.h"
6 | #include "qwidget.h"
7 | #include
8 |
9 | class ED_LinearLayout : public ED_Layout
10 | {
11 | public:
12 | explicit ED_LinearLayout(QWidget *parent = nullptr);
13 | int num(){
14 | return contents->size();
15 | }
16 | int maxSize = 10;
17 | int insideHeight(){
18 | return pContainer->height()*0.9;
19 | }
20 | struct littleBlock{
21 | int ind;
22 | ED_Unit* content;
23 | littleBlock(int ind,ED_Unit* content):ind(ind),content(content){};
24 | void setInd(int ind){
25 | this->ind = ind;
26 | content->indX = ind;
27 | }
28 | };
29 |
30 | littleBlock* blocks[100];
31 | double disToCursor(int posx){
32 | return abs(pContainer->mapFromGlobal(pContainer->cursor().pos()).x()-posx);
33 | }
34 |
35 | double fixedDis(){
36 | if(num())
37 | return ((double)pContainer->width())/num();
38 | else return 1;
39 | }
40 |
41 | void refresh();
42 |
43 | double fixedCX(int ind){
44 | return fixedDis()*(ind+0.5);
45 | }
46 |
47 | signals:
48 | // ED_Layout interface
49 | public:
50 | //采用(x,0)作为索引
51 | QPoint pos2Ind(int posx, int posy) override;
52 | QPoint ind2CenterPoint(int x, int y) override;
53 | QSize ind2Size(int xind, int yind) override;
54 | QPoint ind2Pos(int xind, int yind) override;
55 | bool Occupied(int x, int y) override;
56 | ED_Unit *ind2Unit(int xind, int yind) override;
57 | QPoint defaultPutableInd(ED_Unit *aim) override;
58 | QPoint clearPutableInd(ED_Unit *aim) override;
59 |
60 |
61 | // ED_Layout interface
62 | public:
63 | void updateAfterRemove(ED_Unit *, int, int) override;
64 | void updateBeforePut(ED_Unit *, int, int) override;
65 |
66 |
67 |
68 | // ED_Layout interface
69 | public:
70 | void load_json(QJsonObject rootObject) override;
71 |
72 | // ED_Layout interface
73 | public:
74 | void updateAfterPut(ED_Unit *, int, int) override;
75 |
76 | // ED_Layout interface
77 | public:
78 | void updateBeforePutAnimation(ED_Unit *, int, int) override;
79 | };
80 |
81 | #endif // ED_LINEARLAYOUT_H
82 |
--------------------------------------------------------------------------------
/ed_unit.cpp:
--------------------------------------------------------------------------------
1 | #include "ed_unit.h"
2 | #include "mainwindow.h"
3 | #include "qaction.h"
4 | #include "qdebug.h"
5 | #include "qevent.h"
6 | #include"SysFunctions.h"
7 | #include"ed_blockcontainer.h"
8 | #include "qgraphicseffect.h"
9 | #include "style.h"
10 | #include"QPropertyAnimation"
11 | #include
12 | #include "QBitmap"
13 |
14 | ED_Unit::ED_Unit(): ED_Unit(nullptr,1,1){
15 |
16 | };
17 |
18 | #define SET_ANIMATION(ANIMATION,NAME,GROUP,TIME)\
19 | ANIMATION = new QPropertyAnimation(this,#NAME);\
20 | ANIMATION->setDuration(TIME);\
21 | ANIMATION->setEasingCurve(QEasingCurve::InSine);\
22 | GROUP->addAnimation(ANIMATION);
23 |
24 |
25 | ED_Unit::ED_Unit(QWidget *parent,int sizex,int sizey): QWidget{parent}
26 | {
27 | sizeX = sizex;
28 | sizeY = sizey;
29 | shadow_main_color = new QGraphicsDropShadowEffect;
30 | shadow_main_color->setBlurRadius(unit_shadow_blur_radius); //模糊半径
31 | shadow_main_color->setOffset(0); //偏移量
32 | shadow_main_color->setEnabled(true);
33 | setGraphicsEffect(shadow_main_color);
34 |
35 | setMainColor(GetWindowsThemeColor());
36 |
37 | colorAlpha = aim_alpha();
38 |
39 | focusAnimations = new QParallelAnimationGroup(this);
40 | positionAnimations = new QParallelAnimationGroup(this);
41 |
42 | SET_ANIMATION(alphaAnimation,colorAlpha,focusAnimations,100);
43 |
44 | SET_ANIMATION(scaleFixAnimation,scaleFix,focusAnimations,100);
45 |
46 | SET_ANIMATION(padRatioAnimation,nowPadRatio,focusAnimations,100);
47 |
48 | SET_ANIMATION(sizeAnimation,nowSize,positionAnimations,position_animation_time);
49 |
50 | SET_ANIMATION(posAnimation,nowPos,positionAnimations,position_animation_time);
51 |
52 |
53 |
54 | // setMouseTracking(true);
55 |
56 | connect(this,&ED_Unit::alpha_changed,this,[=](int val){
57 | update();
58 | // qDebug()<raise();
79 | setupMenu();
80 | }
81 |
82 | void ED_Unit::single_click_action(){
83 | //最终单击执行
84 | }
85 |
86 | void ED_Unit::double_click_action(){
87 | //最终双击执行
88 | }
89 |
90 | void ED_Unit::mouse_enter_action(){
91 |
92 | }
93 | void ED_Unit::mouse_leave_action(){
94 | }
95 |
96 | void ED_Unit::mouse_move_action(){
97 | //最终移动执行
98 |
99 |
100 | }
101 |
102 | void ED_Unit::mouse_release_action(){
103 | //最终释放执行
104 |
105 | }
106 |
107 | void ED_Unit::removeFromLayout(){
108 | layout->RemoveAUnit(this);
109 | }
110 |
111 | void ED_Unit::setupMenu()
112 | {
113 |
114 | setContextMenuPolicy(Qt::ActionsContextMenu);
115 |
116 | QAction* act1 = new QAction("加宽");
117 | this->addAction(act1);
118 | connect(act1, &QAction::triggered, this, [=]()
119 | {
120 | setBlockSize(sizeX+1,sizeY);
121 | });
122 |
123 | QAction* act3 = new QAction("减宽");
124 | this->addAction(act3);
125 | connect(act3, &QAction::triggered, this, [=]()
126 | {
127 | if(sizeX>=2)
128 | setBlockSize(sizeX-1,sizeY);
129 | });
130 |
131 | QAction* act2 = new QAction("加高");
132 | this->addAction(act2);
133 | connect(act2, &QAction::triggered, this, [=]()
134 | {
135 | setBlockSize(sizeX,sizeY+1);
136 | });
137 |
138 |
139 |
140 | QAction* act4 = new QAction("减高");
141 | this->addAction(act4);
142 | connect(act4, &QAction::triggered, this, [=]()
143 | {
144 | if(sizeY>=2)
145 | setBlockSize(sizeX,sizeY-1);
146 | });
147 |
148 |
149 |
150 | QAction* act5 = new QAction("切换复杂度");
151 | this->addAction(act5);
152 | connect(act5, &QAction::triggered, this, [=]()
153 | {
154 | changeSimpleMode();
155 | });
156 |
157 |
158 | QAction* act6 = new QAction("删除");
159 | this->addAction(act6);
160 | connect(act6, &QAction::triggered, this, [=]()
161 | {
162 | removeFromLayout();
163 | deleteLater();
164 | });
165 |
166 | QAction* act7 = new QAction("切换始终显示");
167 | this->addAction(act7);
168 | connect(act7, &QAction::triggered, this, [=]()
169 | {
170 | setAlwaysShow(!alwaysShow);
171 | });
172 | }
173 |
174 | void ED_Unit::mousePressEvent(QMouseEvent *event)
175 | {
176 | qDebug()<button() == Qt::LeftButton){
178 | grabMouse();
179 | single_click_action();
180 | premove = true;
181 | relativeP = event->pos();
182 | }
183 | event->accept();
184 |
185 |
186 | }
187 |
188 | void ED_Unit::mouseReleaseEvent(QMouseEvent *event)
189 | {
190 | releaseMouse();
191 | mouse_release_action();
192 | if(moving){
193 | //首先检查是否拖到文件夹
194 | ED_Layout* mwlayout = pmw->inside;
195 | QPoint point = mwlayout->pos2Ind(pos().x()+width()/2,pos().y()+height()/2);
196 |
197 | if(mwlayout->Occupied(point)){
198 | if(mwlayout->ind2Unit(point)->type == ED_Unit::Container){
199 | qDebug()<<"Container";
200 | ED_BlockContainer* c = (ED_BlockContainer*)mwlayout->ind2Unit(point);
201 | if(c->OKForClearPut(this)){
202 | c->clearPut(this,true);
203 | moving = false;
204 | return;
205 | }
206 | }
207 | }
208 | // 放置
209 | pMovingUnit = nullptr;
210 | mwlayout->clearPut(this,true);
211 | moving = false;
212 | }
213 | premove = false;
214 | // repaintAround(this);
215 | event->accept();
216 |
217 | }
218 |
219 | void ED_Unit::mouseDoubleClickEvent(QMouseEvent *event)
220 | {
221 | Q_UNUSED(event);
222 | double_click_action();
223 | }
224 |
225 | void ED_Unit::mouseMoveEvent(QMouseEvent *event)
226 | {
227 | mouse_move_action();
228 | // update();
229 |
230 | if (moving)
231 | {
232 | move(cursor().pos()-relativeP);
233 | }
234 | else if(premove){
235 | auto tem = mapFromGlobal(cursor().pos());
236 | int dis =sqrt ((tem.x()-relativeP.x())*(tem.x()-relativeP.x())+(tem.y()-relativeP.y())*(tem.y()-relativeP.y()));
237 | // qDebug()<<(dis)<pos()<=2){
239 | QPoint usedp = mapToGlobal(QPoint(0,0));
240 | positionAnimations->stop();
241 | if(layout)
242 | removeFromLayout();
243 | move(usedp);
244 | pMovingUnit = this;
245 | moving = true;
246 | }
247 | }
248 | event->accept();
249 | }
250 |
251 | void ED_Unit::updateInLayout()
252 | {
253 | //当Layout改变大小等调用(不包含初次放置)
254 | moveto(MyPos_Centual(),MySize());
255 | }
256 |
257 | void ED_Unit::moveto(QPoint pos, QSize size)
258 | {
259 | aim_pos = pos;
260 | aim_size = (size);
261 | updatePositionAnimation();
262 | // updataFocusAnimation();
263 | }
264 |
265 | void ED_Unit::resizeEvent(QResizeEvent *event)
266 | {
267 | QWidget::resizeEvent(event);
268 | rs->updateDisplay();
269 | afterResize(event);
270 | }
271 |
272 | void ED_Unit::enterEvent(QEvent *event){
273 | onmouse = true ;
274 | mouse_enter_action();
275 | updataFocusAnimation();
276 | event->accept();
277 | if(layout!=nullptr)
278 | if(!layout->isMain){
279 | layout->pContainer->update();
280 | }
281 | update();
282 | }
283 |
284 | void ED_Unit::leaveEvent(QEvent *event){
285 | onmouse = false ;
286 | // qDebug()<isMain)){
291 | layout->pContainer->update();
292 | }
293 | premove = false;
294 | moving = false;
295 | }
296 |
297 | void ED_Unit::setBlockSize(int w,int h){
298 | ED_Layout* tem = nullptr;
299 | if(layout){
300 | tem = layout;
301 | removeFromLayout();
302 | ED_Unit temu(nullptr,w,h);
303 | if(tem->OKForClearPut(&temu)){
304 | sizeX = w;
305 | sizeY = h;
306 | }
307 | tem->clearPut(this,true);
308 | }
309 | else{
310 | sizeX = w;
311 | sizeY = h;
312 | }
313 | }
314 |
315 | void ED_Unit::setSimpleMode(bool val){
316 | simpleMode = val;
317 | whenSimpleModeChange(val);
318 | }
319 |
320 | void ED_Unit::changeSimpleMode(){
321 | setSimpleMode(!simpleMode);
322 | }
323 |
324 | void ED_Unit::setMainColor(QColor val)
325 | {
326 | mainColor = val;
327 | auto tem = val;
328 | tem.setAlpha(unit_shadow_alpha);
329 | shadow_main_color->setColor(tem);
330 | shadow_main_color->setEnabled(true);
331 | shadow_main_color->update();
332 |
333 | if (val.red()*.299+val.green()*.587+val.blue()*.114<80){
334 | dark = true;
335 | }
336 | else{
337 | dark = false;
338 | }
339 | emit mainColor_changed(val);
340 | }
341 |
342 | void ED_Unit::whenSimpleModeChange(bool val){}
343 |
344 | void ED_Unit::whenScaleChange(double val){}
345 |
346 | void ED_Unit::setScale(double val){
347 | scale = val;
348 | emit scale_changed(val);
349 | }
350 |
351 | void ED_Unit::setScaleFix(double val)
352 | {
353 | scaleFix = val;
354 | emit scaleFix_changed(val);
355 | }
356 |
357 | void ED_Unit::setAlwaysShow(bool val)
358 | {
359 | alwaysShow = val;
360 | if(layout!=nullptr){
361 | if(val){
362 | auto s = std::find(layout->contents_Show->begin(), layout->contents_Show->end(), this);//第一个参数是array的起始地址,第二个参数是array的结束地址,第三个参数是需要查找的值
363 | if (s != layout->contents_Show->end())//如果找到,就输出这个元素
364 | {
365 | layout->contents_Show->erase(s);
366 | }
367 | else//如果没找到
368 | {
369 | qDebug() << "not find!";
370 | }
371 |
372 | layout->contents_AlwaysShow->push_back(this);
373 | }
374 | else{
375 |
376 | auto s = std::find(layout->contents_AlwaysShow->begin(), layout->contents_AlwaysShow->end(), this);//第一个参数是array的起始地址,第二个参数是array的结束地址,第三个参数是需要查找的值
377 | if (s != layout->contents_AlwaysShow->end())//如果找到,就输出这个元素
378 | {
379 | layout->contents_AlwaysShow->erase(s);
380 | }
381 | else//如果没找到
382 | {
383 | qDebug() << "not find!";
384 | }
385 |
386 | layout->contents_Show->push_back(this);
387 | }
388 | }
389 | }
390 |
391 | void ED_Unit::paintEvent(QPaintEvent *event)
392 | {
393 | Q_UNUSED(event);
394 | paintSide(this,QColor("green"));
395 | paintRect(this,mainColor_Alphaed());
396 | paintLight(this,mainColor);
397 | }
398 |
399 | void ED_Unit::ed_update(){
400 | rs->updateDisplay();
401 | rs->raise();
402 | update();
403 | }
404 |
405 | QColor ED_Unit::mainColor_Alphaed(){
406 | QColor tem = mainColor;
407 | tem.setAlpha(colorAlpha);
408 | return tem;
409 | }
410 |
411 | void ED_Unit::updataFocusAnimation()
412 | {
413 | focusAnimations->stop();
414 |
415 | alphaAnimation->setStartValue(colorAlpha);
416 | alphaAnimation->setEndValue(aim_alpha());
417 |
418 | padRatioAnimation->setStartValue(nowPadRatio);
419 | padRatioAnimation->setEndValue(aim_padRatio());
420 |
421 | scaleFixAnimation->setStartValue(scaleFix);
422 | scaleFixAnimation->setEndValue(aim_scaleFix());
423 |
424 | focusAnimations->start();
425 | }
426 |
427 | void ED_Unit::updatePositionAnimation()
428 | {
429 | positionAnimations->stop();
430 | posAnimation->setStartValue(pos());
431 | posAnimation->setEndValue(aim_pos);
432 |
433 | sizeAnimation->setStartValue(size());
434 | sizeAnimation->setEndValue(aim_size);
435 | positionAnimations->start();
436 | }
437 |
438 | void ED_Unit::preSetInLayout(bool animated)
439 | {
440 | raise();
441 |
442 | if(animated){
443 | moveto(layout->pContainer->mapToGlobal(MyPos_Centual()),MySize());
444 | }
445 | else{
446 | move(layout->pContainer->mapToGlobal(MyPos_Centual()));
447 | setFixedSize(MySize());
448 | }
449 |
450 | }
451 |
452 | void ED_Unit::setInLayout(bool animated)
453 | {
454 | QPoint tem = mapToGlobal(QPoint(0,0));
455 | QPoint dis = layout->pContainer->mapFromGlobal(tem);
456 | // qDebug()<pContainer);
459 | setVisible(true);
460 | raise();
461 | move(dis);
462 | }
463 |
464 | QJsonObject ED_Unit::to_json(){
465 | QJsonObject rootObject;
466 | rootObject.insert("Class",metaObject()->className());
467 | rootObject.insert("type",type);
468 | rootObject.insert("sizeX",sizeX);
469 | rootObject.insert("sizeY",sizeY);
470 | rootObject.insert("indX",indX);
471 | rootObject.insert("indY",indY);
472 | rootObject.insert("alwaysShow",alwaysShow);
473 | rootObject.insert("simpleMode",simpleMode);
474 | rootObject.insert("dark",deepColor);
475 | rootObject.insert("showRect",showRect);
476 | rootObject.insert("showLight",showLight);
477 | rootObject.insert("showSide",showSide);
478 | return rootObject;
479 | }
480 |
481 | void ED_Unit::load_json(QJsonObject rootObject)
482 | {
483 | ED_Unit* tem = nullptr;
484 | type = (ED_Unit::ED_TYPE)rootObject.value("type").toInt();
485 | sizeX = rootObject.value("sizeX").toInt();
486 | sizeY = rootObject.value("sizeY").toInt();
487 | indX = rootObject.value("indX").toInt();
488 | indY = rootObject.value("indY").toInt();
489 | alwaysShow = rootObject.value("alwaysShow").toBool();
490 | simpleMode = rootObject.value("simpleMode").toBool();
491 | deepColor = rootObject.value("dark").toBool();
492 | showRect = rootObject.value("showRect").toBool();
493 | showLight = rootObject.value("showLight").toBool();
494 | showSide = rootObject.value("showSide").toBool();
495 | whenSimpleModeChange(simpleMode);
496 | }
497 |
498 | void ED_Unit::whenMainColorChange(QColor val){
499 |
500 | }
501 |
502 | void ED_Unit::afterResize(QResizeEvent* event)
503 | {
504 |
505 | }
506 |
--------------------------------------------------------------------------------
/ed_unit.h:
--------------------------------------------------------------------------------
1 | #ifndef ED_UNIT_H
2 | #define ED_UNIT_H
3 | #include "ed_layout.h"
4 | #include "qgraphicseffect.h"
5 | #include "qparallelanimationgroup.h"
6 | #include "qpropertyanimation.h"
7 | #include "roundshower.h"
8 | #include "style.h"
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 | class ED_Layout;
15 |
16 | class ED_Unit : public QWidget
17 | {
18 | Q_OBJECT
19 | Q_PROPERTY(int colorAlpha MEMBER colorAlpha NOTIFY alpha_changed )
20 | Q_PROPERTY(QColor mainColor MEMBER mainColor NOTIFY mainColor_changed WRITE setMainColor)
21 | Q_PROPERTY(double scale MEMBER scale NOTIFY scale_changed WRITE setScale)
22 | Q_PROPERTY(double scaleFix MEMBER scaleFix NOTIFY scaleFix_changed WRITE setScaleFix)
23 | Q_PROPERTY(QPoint nowPos MEMBER nowPos NOTIFY nowPos_changed)
24 | Q_PROPERTY(QSize nowSize MEMBER nowSize NOTIFY nowSize_changed)
25 | Q_PROPERTY(double nowPadRatio MEMBER nowPadRatio NOTIFY nowPadRatio_changed)
26 | public:
27 | enum ED_TYPE {Unit,Container};
28 | ED_TYPE type = Unit;
29 | ED_Layout* layout;
30 | ED_Layout* preLayout;
31 |
32 |
33 | QPoint nowPos;
34 | QPoint aim_pos;
35 | QSize nowSize;
36 | QSize aim_size;
37 | double nowPadRatio;
38 |
39 | bool moving = false;
40 | bool premove = false;
41 | bool showRect = true;
42 | bool showLight = true;
43 | bool showSide = true;
44 | bool onmouse = false;
45 | bool deepColor = false;
46 | bool dark = false;
47 | double scaleFix = 1.0;
48 | double scale = 1.0;
49 | QPoint relativeP;
50 | QColor mainColor;
51 | QParallelAnimationGroup * positionAnimations;
52 | QPropertyAnimation* alphaAnimation;
53 | QPropertyAnimation* scaleFixAnimation;
54 | QPropertyAnimation* padRatioAnimation;
55 |
56 | QParallelAnimationGroup * focusAnimations;
57 | QPropertyAnimation* posAnimation;
58 | QPropertyAnimation* sizeAnimation;
59 |
60 |
61 | int sizeX = 1;
62 | int sizeY = 1;
63 | int ind;
64 | int aim_alpha(){
65 | if(onmouse){
66 | if(deepColor) return active_alpha_deep;
67 | else return active_alpha;
68 | }
69 | else{
70 | if(deepColor) return sleep_alpha_deep;
71 | else return sleep_alpha;
72 | }
73 | }
74 | double aim_scaleFix(){
75 | if(onmouse){
76 | return scale_fix_ratio;
77 | }
78 | else{
79 | return 1.0;
80 | }
81 | }
82 | double aim_padRatio(){
83 | if(layout==nullptr) return 1.0;
84 | else{
85 | if(layout->isMain) return 1.0;
86 | else{
87 | if(onmouse) return 1.0;
88 | else return 0.0;
89 | }
90 | }
91 | }
92 |
93 | int colorAlpha;
94 | bool alwaysShow = false;
95 | bool simpleMode = false;
96 |
97 | int indX = -1;
98 | int indY = -1;
99 |
100 | roundShower* rs;
101 | QGraphicsDropShadowEffect* shadow_main_color;
102 |
103 | explicit ED_Unit();
104 | explicit ED_Unit(QWidget *parent,int sizex,int sizey);
105 | ED_Unit(const ED_Unit &other)
106 | :ED_Unit(other.parentWidget(),other.sizeX,other.sizeY)
107 | {
108 |
109 | }
110 |
111 | bool operator<(const ED_Unit& another) const{
112 | if(indX!=another.indX) return indXind2Pos_Centual(indX,indY);
164 | }
165 | QPoint MyPos(){
166 | return layout->ind2Pos(indX,indY);
167 | }
168 | QSize MySize(){
169 | return layout->ind2Size(indX,indY);
170 | }
171 |
172 | virtual void preSetInLayout(bool animated);
173 | virtual void setInLayout(bool animated);
174 |
175 | virtual void updateInLayout();
176 |
177 | virtual void moveto(QPoint pos,QSize size);
178 |
179 |
180 | public: signals:
181 | void alpha_changed(int);
182 | void mainColor_changed(QColor);
183 | void scale_changed(double);
184 | void scaleFix_changed(double);
185 | void nowPos_changed(QPoint);
186 | void nowSize_changed(QSize);
187 | void nowPadRatio_changed(double);
188 |
189 | // QOpenGLWidget interface
190 |
191 |
192 | // QWidget interface
193 | protected:
194 | void resizeEvent(QResizeEvent *event) override;
195 | };
196 | Q_DECLARE_METATYPE(ED_Unit);
197 |
198 | #endif // ED_UNIT_H
199 |
--------------------------------------------------------------------------------
/filepreviewwidget.cpp:
--------------------------------------------------------------------------------
1 | #include "filepreviewwidget.h"
2 | #include
3 | #include
4 |
5 | FilePreviewWidget::FilePreviewWidget(QWidget *parent)
6 | : QWidget(parent)
7 | {
8 | contentTextEdit = new QTextEdit(this); // 新增:用于支持滚动条
9 | contentTextEdit->setReadOnly(true); // 设置为只读
10 | contentTextEdit->setAlignment(Qt::AlignCenter);
11 |
12 | imageLabel = new QLabel(this); // 新增:用于显示图片
13 | imageLabel->setAlignment(Qt::AlignCenter);
14 | imageLabel->setVisible(false); // 默认隐藏
15 |
16 | layout = new QVBoxLayout(this);
17 | layout->addWidget(contentTextEdit);
18 | layout->addWidget(imageLabel); // 新增:将图片标签添加到布局中
19 | setLayout(layout);
20 |
21 | setWindowFlags(Qt::ToolTip);
22 | }
23 |
24 | void FilePreviewWidget::setText(const QString &text)
25 | {
26 | contentTextEdit->setPlainText(text); // 使用 QTextEdit 显示文本
27 | contentTextEdit->setVisible(true); // 显示文本框
28 | imageLabel->setVisible(false); // 隐藏图片标签
29 | }
30 |
31 | void FilePreviewWidget::setImage(const QImage &image)
32 | {
33 | imageLabel->setPixmap(QPixmap::fromImage(image).scaled(200, 200, Qt::KeepAspectRatio)); // 显示图片
34 | imageLabel->setVisible(true); // 显示图片标签
35 | contentTextEdit->setVisible(false); // 隐藏文本框
36 | }
37 |
--------------------------------------------------------------------------------
/filepreviewwidget.h:
--------------------------------------------------------------------------------
1 | #ifndef FILEPREVIEWWIDGET_H
2 | #define FILEPREVIEWWIDGET_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include // 新增:用于支持滚动条
8 |
9 | class FilePreviewWidget : public QWidget
10 | {
11 | Q_OBJECT
12 | public:
13 | explicit FilePreviewWidget(QWidget *parent = nullptr);
14 |
15 | void setText(const QString &text);
16 | void setImage(const QImage &image);
17 |
18 | private:
19 | QTextEdit *contentTextEdit; // 新增:用于支持滚动条
20 | QLabel *imageLabel; // 新增:用于显示图片
21 | QVBoxLayout *layout;
22 | };
23 |
24 | #endif // FILEPREVIEWWIDGET_H
25 |
--------------------------------------------------------------------------------
/hitokoto.cpp:
--------------------------------------------------------------------------------
1 | #include "hitokoto.h"
2 | #include "QWidget"
3 | #include"QProcess"
4 | #include "qboxlayout.h"
5 | #include "qlabel.h"
6 | #include"QDebug"
7 | #include"QUrl"
8 | #include
9 | #include
10 | #include "QtNetwork/QHttpMultiPart"
11 | #include "QHttpMultiPart"
12 | #include
13 | #include
14 | #include"QDesktopServices"
15 | #include"QTextCodec"
16 | #include"QGraphicsDropShadowEffect"
17 |
18 | Hitokoto::Hitokoto(QWidget *parent,int sizex,int sizey)
19 | : ED_Unit(parent,sizex,sizey)
20 | {
21 | wlayout=new QVBoxLayout(this);
22 | manager=new QNetworkAccessManager(this);
23 | hitokotolabel=new QLabel(this);
24 | hitokotolabel->setWordWrap(true);
25 | wlayout->addWidget(hitokotolabel, 0, Qt::AlignHCenter);
26 | connect(manager,&QNetworkAccessManager::finished,this,&Hitokoto::handlehitokotoresponse);
27 | gethitokotoinfo();
28 | }
29 |
30 | void Hitokoto::gethitokotoinfo()
31 | {
32 | QUrl url("https://hitokoto.cn/api/restful/v1/hitokoto/62c12303-b3fa-4720-a7c5-2985bf049e60?token=xxx");
33 | manager->get(QNetworkRequest(url));
34 | }
35 |
36 | void Hitokoto::handlehitokotoresponse(QNetworkReply *reply)
37 | {
38 | int statuscode=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
39 | qDebug()<readAll();
41 | qDebug()<setText("让子弹飞一会");
45 | }
46 |
47 | void Hitokoto::parsejson(QByteArray &byteArray)
48 | {
49 | QJsonParseError err;
50 | QJsonDocument doc=QJsonDocument::fromJson(byteArray,&err);
51 | QJsonObject rootobj=doc.object();
52 | QJsonObject dataobj=rootobj.value("data").toObject();
53 | hitokotolabel->setText(rootobj.value("data").toObject().value("hitokoto").toString());
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/hitokoto.h:
--------------------------------------------------------------------------------
1 | #ifndef HITOKOTO_H
2 | #define HITOKOTO_H
3 |
4 |
5 | #include
6 | #include"ed_unit.h"
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 |
16 | class Hitokoto : public ED_Unit
17 | {
18 | Q_OBJECT
19 | public:
20 | explicit Hitokoto(QWidget *parent = nullptr,int sizex=1,int sizey=1);
21 | QLabel *hitokotolabel;
22 | QNetworkAccessManager *manager;
23 | QVBoxLayout *wlayout;
24 | void gethitokotoinfo();
25 | void parsejson(QByteArray& byteArray);
26 | void handlehitokotoresponse(QNetworkReply *reply);
27 |
28 | };
29 | Q_DECLARE_METATYPE(Hitokoto)
30 | #endif // HITOKOTO_H
31 |
--------------------------------------------------------------------------------
/layershower.cpp:
--------------------------------------------------------------------------------
1 | #include "layershower.h"
2 | #include "SysFunctions.h"
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include "QScreen"
9 | #include "QThread"
10 | #include"QStyle"
11 | #include "qapplication.h"
12 | #include "qpainter.h"
13 |
14 | LayerShower::LayerShower(QWidget *parent)
15 | : QWidget{parent}
16 | {
17 | setWindowState(Qt::WindowFullScreen);
18 | setAttribute(Qt::WA_TranslucentBackground);
19 | setAttribute(Qt::WA_TransparentForMouseEvents);
20 | setWindowFlags(Qt::FramelessWindowHint);
21 | inplace((QWidget* )this);
22 | setFixedSize(QGuiApplication::primaryScreen()->availableSize());
23 | move(0,0);
24 | qDebug()<& drawParamList = pmw->drawParamList;
34 |
35 | if (drawParamList.count() >= 2) {
36 | QPainter painter(this);
37 | QColor tem = GetWindowsThemeColor();
38 | tem.setAlpha(200);
39 | painter.setBrush(tem);
40 | int x = (drawParamList[0].x() < drawParamList[1].x()) ? drawParamList[0].x() : drawParamList[1].x();
41 | int y = (drawParamList[0].y() < drawParamList[1].y()) ? drawParamList[0].y() : drawParamList[1].y();
42 | int w = qAbs(drawParamList[0].x() - drawParamList[1].x()) + 1;
43 | int h = qAbs(drawParamList[0].y() - drawParamList[1].y()) + 1;
44 | painter.drawRect(x, y, w, h); // 画长方形
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/layershower.h:
--------------------------------------------------------------------------------
1 | #ifndef LAYERSHOWER_H
2 | #define LAYERSHOWER_H
3 |
4 | #include
5 |
6 | class LayerShower : public QWidget
7 | {
8 | Q_OBJECT
9 | public:
10 | explicit LayerShower(QWidget *parent = nullptr);
11 |
12 | signals:
13 |
14 | // QWidget interface
15 | protected:
16 | void paintEvent(QPaintEvent *event) override;
17 | };
18 |
19 | #endif // LAYERSHOWER_H
20 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include "SysFunctions.h"
2 | #include "ed_block.h"
3 | #include "ed_blockcontainer.h"
4 | #include "ed_dock.h"
5 | #include "ed_editbox.h"
6 | #include "layershower.h"
7 | #include "mainwindow.h"
8 | #include
9 | #include
10 | #include"ed_hidetextblock.h"
11 | #include
12 | #include
13 | #include
14 | #include"QDesktopWidget"
15 |
16 |
17 | int main(int argc, char *argv[])
18 | {
19 | QApplication a(argc, argv);
20 |
21 | qRegisterMetaType();
22 | qRegisterMetaType();
23 | qRegisterMetaType();
24 | qRegisterMetaType();
25 | qRegisterMetaType();
26 | qRegisterMetaType();
27 | qRegisterMetaType();
28 | qRegisterMetaType();
29 |
30 | QSurfaceFormat format;
31 | format.setDepthBufferSize(24);
32 | format.setStencilBufferSize(8);
33 | format.setVersion(3, 2);
34 | format.setProfile(QSurfaceFormat::CoreProfile);
35 | QSurfaceFormat::setDefaultFormat(format);
36 |
37 | #ifndef QT_DEBUG
38 |
39 | debug = false;
40 | qInstallMessageHandler(customMessageHandler);
41 |
42 | #endif
43 |
44 | readStyleIni();
45 |
46 | QTranslator translator;
47 | const QStringList uiLanguages = QLocale::system().uiLanguages();
48 | for (const QString &locale : uiLanguages) {
49 | const QString baseName = "Sapphire_" + QLocale(locale).name();
50 | if (translator.load(":/i18n/" + baseName)) {
51 | a.installTranslator(&translator);
52 | break;
53 | }
54 | }
55 |
56 | MainWindow mw ;
57 | LayerShower ls;
58 | //鼠标钩子
59 | // InitMouseHook();
60 |
61 | mw.show();
62 | ls.show();
63 |
64 | a.exec();
65 |
66 |
67 |
68 | return 0;
69 | }
70 |
--------------------------------------------------------------------------------
/mainwindow.cpp:
--------------------------------------------------------------------------------
1 | #include "mainwindow.h"
2 | #include "ed_bgshower.h"
3 | #include "ed_blockcontainer.h"
4 | #include "ed_block.h"
5 | #include "ed_dock.h"
6 | #include "ed_editbox.h"
7 | #include "ed_hidetextblock.h"
8 | #include "qgraphicseffect.h"
9 | #include "qmimedata.h"
10 | #include "qpainter.h"
11 | #include "roundshower.h"
12 | #include "ui_mainwindow.h"
13 | #include "SysFunctions.h"
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include "QScreen"
20 | #include "QThread"
21 | #include"QStyle"
22 | ED_Unit *pMovingUnit = nullptr;
23 | QDesktopWidget* pdt;
24 | bool debug = true;
25 |
26 | void MainWindow::setupActions()
27 | {
28 | // 只要将某个QAction添加给对应的窗口, 这个action就是这个窗口右键菜单中的一个菜单项了
29 | // 在窗口中点击鼠标右键, 就可以显示这个菜单
30 | setContextMenuPolicy(Qt::ActionsContextMenu);
31 | // 给当前窗口添加QAction对象
32 | QAction *act1 = new QAction("改变可见");
33 | this->addAction(act1);
34 | connect(act1, &QAction::triggered, this, [=]()
35 | { setShoweredVisibal(!showeredVisibal); });
36 |
37 | QAction *act2 = new QAction("切换精简");
38 | this->addAction(act2);
39 |
40 | connect(act2, &QAction::triggered, this, [=]()
41 | {
42 | for(ED_Unit* content:*(inside->contents)){
43 | content->changeSimpleMode();
44 | } });
45 |
46 | QAction *act3 = new QAction("新增文件");
47 | this->addAction(act3);
48 | connect(act3, &QAction::triggered, this, [=]()
49 | {
50 | QFileDialog* fd = new QFileDialog();
51 | QStringList filePaths =QFileDialog::getOpenFileNames(this, QStringLiteral("选择文件"),"D:/",nullptr,nullptr,QFileDialog::Options(QFileDialog::DontResolveSymlinks));;
52 | foreach (const QString& filePath, filePaths) {
53 | addAIcon(filePath);
54 | }
55 | });
56 |
57 | QAction *act4 = new QAction("退出程序");
58 | this->addAction(act4);
59 | connect(act4, &QAction::triggered, this, [=]()
60 | { close();
61 | pls->close(); });
62 |
63 | #ifdef QT_DEBUG
64 |
65 | QAction *act5 = new QAction("获取背景");
66 | this->addAction(act5);
67 | connect(act5, &QAction::triggered, this, [=]()
68 | {
69 | capture();
70 | });
71 |
72 | #endif
73 |
74 |
75 | QAction *act6 = new QAction("新建小型格子");
76 | this->addAction(act6);
77 | connect(act6, &QAction::triggered, this, [=]()
78 | {
79 | auto bc = new ED_BlockContainer(this,2,2,2,2,5,10,10);
80 | InitAUnit(bc); });
81 | QAction *act7 = new QAction("新建中型格子");
82 | this->addAction(act7);
83 | connect(act7, &QAction::triggered, this, [=]()
84 | {
85 | auto bc = new ED_BlockContainer(this,3,3,3,3,5,15,15);
86 | InitAUnit(bc); });
87 |
88 | QAction *act8 = new QAction("新建大型格子");
89 | this->addAction(act8);
90 | connect(act8, &QAction::triggered, this, [=]()
91 | {
92 | auto bc = new ED_BlockContainer(this,4,4,4,4,5,20,20);
93 | InitAUnit(bc); });
94 |
95 | QAction *act9 = new QAction("新建dock栏");
96 | this->addAction(act9);
97 | connect(act9, &QAction::triggered, this, [=]()
98 | {
99 | auto dock = new ED_Dock(this);
100 | InitAUnit(dock); });
101 |
102 | QAction *act10 = new QAction("新建设置箱");
103 | this->addAction(act10);
104 | connect(act10, &QAction::triggered, this, [=]()
105 | {
106 | auto dock = new ED_EditBox(this);
107 | InitAUnit(dock); });
108 | }
109 | void MainWindow::setupUnits()
110 | {
111 | // setMouseTracking(true);
112 | // 设置背景
113 | bgshower = new ED_BGShower(this);
114 | bgshower->setFixedSize(size());
115 | bgshower->setVisible(enable_background_blur);
116 | bgshower->move(0, 0);
117 | bgshower->setVisible(true);
118 | bgshower->lower();
119 | inside = new ED_BlockLayout(this, 20, 12, 5, 10, 10);
120 | inside->isMain = true;
121 | setBlur(enable_background_blur);
122 |
123 |
124 | // qDebug()<W_Container()<H_Container();
125 |
126 | QFileInfo fi("content.json");
127 | if(fi.exists()){
128 | readJson();
129 | }
130 | else{
131 | InitDesktop();
132 | }
133 |
134 |
135 | // 初始化一些
136 | bg = QPixmap(":/images/background");
137 |
138 | setVisible(true);
139 | inside->UpdateRegion();
140 | update();
141 | // bgshower->update();
142 | }
143 |
144 | MainWindow::MainWindow(QWidget *parent)
145 | : QMainWindow(parent), ui(new Ui::MainWindow)
146 | {
147 | pmw = this;
148 | pdt = QApplication::desktop();
149 | ui->setupUi(this);
150 | setWindowState(Qt::WindowFullScreen);
151 | setAttribute(Qt::WA_TranslucentBackground);
152 | setAcceptDrops(true);
153 | Init(this);
154 | setFixedSize(QGuiApplication::primaryScreen()->availableSize());
155 | move(0,0);
156 | qDebug()<start(50); // 每隔0.1s
166 |
167 |
168 | connect(this,&MainWindow::showerSize_changed,this,[=](QSize val){
169 | changeShower->repaint();
170 | });
171 |
172 | connect(this,&MainWindow::showerRadius_changed,this,[=](int val){
173 | qDebug()<distri(&showerSize,&showerRadius);
178 | changeShower->setVisible(true);
179 | changeShower->move(0,0);
180 |
181 | showerSizeAnimation = new QPropertyAnimation(this,"showerSize");
182 | showerRadiusAnimation = new QPropertyAnimation(this,"showerRadius");
183 | showerSizeAnimation->setDuration(500);
184 | showerSizeAnimation->setEasingCurve(QEasingCurve::InSine);
185 | showerRadiusAnimation->setDuration(500);
186 | showerRadiusAnimation->setEasingCurve(QEasingCurve::InSine);
187 |
188 | showerAnimations = new QParallelAnimationGroup(this);
189 | showerAnimations->addAnimation(showerRadiusAnimation);
190 | showerAnimations->addAnimation(showerSizeAnimation);
191 |
192 |
193 | connect(showerAnimations,&QParallelAnimationGroup::finished,this,[=](){
194 | if (showeredVisibal){
195 | // foreach (ED_Unit* content,*(inside->contents)) {
196 | // content->setVisible(true);
197 | // }
198 | inside->setVisible(true);
199 | }
200 | });
201 |
202 |
203 | // buffer = QPixmap(size());
204 | // inside->setVisible(true);
205 | // // setShoweredVisibal(false);
206 | // buffer = this->grab(rect());
207 | // inside->setVisible(false);
208 | setShoweredVisibal(true);
209 | ed_update();
210 | updateBG();
211 | }
212 |
213 | void MainWindow::InitAUnit(ED_Unit *aim,bool animated)
214 | {
215 | // connect(aim, &ED_Unit::sendSelf, this, &MainWindow::getObject);
216 | inside->defaultPut(aim,animated);
217 | // aim->ed_update();
218 | }
219 |
220 | MainWindow::~MainWindow()
221 | {
222 | delete ui;
223 | }
224 |
225 | void MainWindow::setScale(double scale)
226 | {
227 | foreach(ED_Unit *content , *(inside->contents))
228 | {
229 | content->setScale(scale);
230 | }
231 | }
232 |
233 | void MainWindow::ed_update()
234 | {
235 | foreach(ED_Unit *content , *(inside->contents))
236 | {
237 | content->ed_update();
238 | }
239 | }
240 |
241 | void MainWindow::InitDesktop()
242 | {
243 | // 获取图标
244 | QList iconns = scanalldesktopfiles();
245 | QList nametem;
246 | addAIcon(iconns);
247 |
248 | auto eb = new ED_EditBox(this);
249 | InitAUnit(eb);
250 |
251 | }
252 |
253 | void MainWindow::capture()
254 | {
255 | inside->setVisible(false,true);
256 | repaint();
257 | QThread::msleep(100);
258 | QScreen *screen = QGuiApplication::primaryScreen();
259 | bgshower->captrued = screen->grabWindow(0).copy(rect());
260 | bgshower->cap = true;
261 | inside->setVisible(true,true);
262 | }
263 |
264 | void MainWindow::updateBG()
265 | {
266 | if(enable_background_transparent){
267 | if(!bgshower->cap)
268 | capture();
269 | }
270 | else{
271 | bgshower->captrued = bg;
272 | }
273 | }
274 |
275 | void MainWindow::setShoweredVisibal(bool val){
276 | // changeShower->raise();
277 |
278 | if (!val){
279 | foreach (ED_Unit* content,*(inside->contents_AlwaysShow)) {
280 | content->setVisible(false);
281 | }
282 |
283 | buffer = this->grab(rect());
284 |
285 | foreach (ED_Unit* content,*(inside->contents_AlwaysShow)) {
286 | content->setVisible(true);
287 | }
288 |
289 | inside->setVisible(false);
290 | }
291 | showeredVisibal = val;
292 |
293 |
294 | updata_animation();
295 | }
296 |
297 | void MainWindow::updata_animation()
298 | {
299 |
300 | showerAnimations->stop();
301 |
302 | showerSizeAnimation->setStartValue(showerSize);
303 | showerSizeAnimation->setEndValue(aim_showerSize());
304 | showerRadiusAnimation->setStartValue(showerRadius);
305 | showerRadiusAnimation->setEndValue(aim_showerRadius());
306 |
307 | showerAnimations->start();
308 |
309 | }
310 |
311 | void MainWindow::addAIcon(QString path)
312 | {
313 | addAIcon(QFileInfo(path));
314 | }
315 |
316 | void MainWindow::addAIcon(QFileInfo qinfo)
317 | {
318 | QListinfos = getFormFileInfo(qinfo);
319 | addAIcon(infos);
320 | }
321 |
322 | void MainWindow::addAIcon(QList infos)
323 | {
324 | QList nametem;
325 | foreach (const FileInfo &file, infos)
326 | {
327 | qDebug() << file.name << file.type;
328 | int sizex = 1;
329 | int sizey = 1;
330 |
331 | ED_Unit *tem = nullptr;
332 | if (!nametem.contains(file.name))
333 | {
334 |
335 | if (!file.multi)
336 | {
337 |
338 | tem = new ED_Block(this, file.icon.pixmap(32), file.name, file.filePath, sizex, sizey);
339 | nametem.append(file.name);
340 | }
341 | else
342 | {
343 | switch (file.type)
344 | {
345 | case FileInfo::NORM:
346 | if (muilt_icon_default_type == 0)
347 | {
348 |
349 | tem = new ED_Block(this, file.icon.pixmap(256), file.name, file.filePath, sizex, sizey);
350 | nametem.append(file.name);
351 | }
352 | break;
353 | case FileInfo::HORI:
354 | if (muilt_icon_default_type == 1)
355 | {
356 | tem = new ED_HideTextBlock(this, file.icon.pixmap(512), file.name, file.filePath, 2, 1);
357 | nametem.append(file.name);
358 | }
359 | break;
360 | case FileInfo::VERT:
361 | if (muilt_icon_default_type == 2)
362 | {
363 | tem = new ED_HideTextBlock(this, file.icon.pixmap(512), file.name, file.filePath, 1, 2);
364 | nametem.append(file.name);
365 | }
366 |
367 | break;
368 | }
369 | }
370 | }
371 |
372 | if (tem)
373 | {
374 | InitAUnit(tem);
375 | tem->raise();
376 | }
377 | }
378 | }
379 |
380 | void MainWindow::appendPoints(QPoint p)
381 | {
382 | if ( drawParamList.count() == 2 ) {
383 | drawParamList.removeLast(); // 移除最后一个点
384 | }
385 | drawParamList.append(p);
386 | }
387 |
388 | void MainWindow::updatePer01second()
389 | {
390 | if (enable_intime_repaint)
391 | repaint();
392 |
393 | // qDebug()<mimeData()->hasUrls())//处理期望数据类型
399 | {
400 | QList list = e->mimeData()->urls();//获取数据并保存到链表中
401 | for(int i = 0; i < list.count(); i++)
402 | {
403 | addAIcon( list[i].toLocalFile());
404 | }
405 | }
406 | else
407 | {
408 | e->ignore();
409 | }
410 | }
411 |
412 | void MainWindow::dragEnterEvent(QDragEnterEvent *e)
413 | {
414 | if(e->mimeData()->hasUrls())//判断数据类型
415 | {
416 | e->acceptProposedAction();//接收该数据类型拖拽事件
417 | }
418 | else
419 | {
420 | e->ignore();//忽略
421 | }
422 | }
423 |
424 | void MainWindow::mouseReleaseEvent(QMouseEvent *event)
425 | {
426 | appendPoints(event->pos());
427 | pls->update(); // 启动paintEvent
428 | // mouseReleaseAndControl(); // 在鼠标释放后调用快速定位的功能
429 | drawParamList.clear();
430 | }
431 |
432 | void MainWindow::mouseMoveEvent(QMouseEvent *event)
433 | {
434 | appendPoints(event->pos());
435 | pls->update();
436 | }
437 |
438 | void MainWindow::closeEvent(QCloseEvent *event)//关闭窗口会先处理该事件函数
439 | {
440 |
441 | event->accept();
442 | writeStyleIni();
443 | writeJson();
444 | }
445 | void MainWindow::paintEvent(QPaintEvent *ev)
446 | {
447 | if (!enable_background_transparent)
448 | {
449 | QPainter painter(this);
450 | painter.drawPixmap(rect(), bg);
451 | }
452 |
453 | if((!showeredVisibal)||(showeredVisibal&&showerAnimations->state()==QAnimationGroup::Running)){
454 | QPainter painter(this);
455 | painter.drawPixmap(rect(), buffer);
456 | }
457 |
458 |
459 | Q_UNUSED(ev);
460 | }
461 |
462 | void MainWindow::mouseDoubleClickEvent(QMouseEvent *ev)
463 | {
464 | setShoweredVisibal(!showeredVisibal);
465 | pdt->activateWindow();
466 | Q_UNUSED(ev);
467 | }
468 |
469 | void MainWindow::mousePressEvent(QMouseEvent* ev){
470 |
471 | appendPoints(ev->pos());
472 | printf("mousePressEvent \n");
473 | pls->raise();
474 | }
475 |
476 | void MainWindow::onSelectBackground()
477 | {
478 | QString fileName = QFileDialog::getOpenFileName(this, "选择背景文件", "", "Images (*.png *.jpg *.bmp);;Videos (*.mp4 *.avi *.mkv)");
479 | qDebug() << "Selected file:" << fileName; // 调试输出文件路径
480 | if (!fileName.isEmpty())
481 | {
482 | if (fileName.endsWith(".png") || fileName.endsWith(".jpg") || fileName.endsWith(".bmp"))
483 | {
484 | QPalette palette;
485 | QPixmap pixmap(fileName);
486 | if (pixmap.isNull())
487 | {
488 | qDebug() << "Failed to load image";
489 | }
490 | else
491 | {
492 | bg = pixmap;
493 | update();
494 | qDebug() << "Image set as background";
495 | }
496 | }
497 | }
498 | }
499 |
500 | void MainWindow::setTransparent(bool val)
501 | {
502 | enable_background_transparent = val;
503 | if (enable_background_blur)
504 | {
505 | bgshower->setVisible(!val);
506 | bgshower->captrued = bg;
507 | }
508 | updateBG();
509 | // qDebug()<setEnabled(val);
516 | bgshower->setVisible(val);
517 | bgshower->lower();
518 | updateBG();
519 | // qDebug()<
6 | #include
7 | #include // 添加QPushButton头文件
8 | #include "layershower.h"
9 | #include "qdesktopwidget.h"
10 | #include "qfileinfo.h"
11 | #include "qparallelanimationgroup.h"
12 | #include "weather.h"
13 | #include "hitokoto.h"
14 | #include
15 | #include"ed_unit.h"
16 | QT_BEGIN_NAMESPACE
17 | namespace Ui {
18 | class MainWindow;
19 | }
20 | QT_END_NAMESPACE
21 |
22 | struct FileInfo;
23 | class MainWindow : public QMainWindow
24 | {
25 | Q_OBJECT
26 | Q_PROPERTY(QSize showerSize MEMBER showerSize NOTIFY showerSize_changed)
27 | Q_PROPERTY(int showerRadius MEMBER showerRadius NOTIFY showerRadius_changed)
28 | public:
29 | MainWindow(QWidget *parent = nullptr);
30 | ~MainWindow();
31 | Ui::MainWindow *ui;
32 | ED_BGShower* bgshower = nullptr;
33 |
34 | ED_BlockLayout* inside;
35 | QPixmap bg;
36 | QPixmap buffer;
37 | roundShower* changeShower;
38 | QSize showerSize;
39 | QList drawParamList;
40 | bool showeredVisibal = false;
41 | int showerRadius = 500;
42 |
43 | QPropertyAnimation* showerSizeAnimation;
44 | QPropertyAnimation* showerRadiusAnimation;
45 | QParallelAnimationGroup * showerAnimations;
46 |
47 | void InitAUnit(ED_Unit* aim, bool animated=false);
48 | void paintEvent(QPaintEvent * ev) override;
49 | void mouseDoubleClickEvent(QMouseEvent* ev) override;
50 | void mousePressEvent(QMouseEvent* ev) override;
51 |
52 |
53 | QPushButton *selectBackgroundButton; // 新增:选择背景按钮
54 | void setTransparent(bool val);
55 | void setBlur(bool val);
56 | void ed_update();
57 | void InitDesktop();
58 | void capture();
59 | void updateBG();
60 | void setShoweredVisibal(bool val);
61 |
62 | QSize aim_showerSize(){
63 | if(showeredVisibal) return size();
64 | else return QSize(0,0);
65 | }
66 |
67 | int aim_showerRadius(){
68 | if(showeredVisibal) return 0;
69 | else return 500;
70 | }
71 |
72 | void updata_animation();
73 |
74 | void addAIcon(QString path);
75 | void addAIcon(QFileInfo info);
76 | void addAIcon(QList infos);
77 | void appendPoints(QPoint p);
78 |
79 | private:
80 | void setupActions();
81 | void setupUnits();
82 |
83 | public slots:;
84 | void setScale(double Scale);
85 | void onSelectBackground(); // 新增:选择背景文件槽函数
86 | void updatePer01second();
87 |
88 | public: signals:
89 | void showerSize_changed(QSize);
90 | void showerRadius_changed(int);
91 |
92 |
93 |
94 | // QWidget interface
95 | protected:
96 | void dropEvent(QDropEvent *event) override;
97 |
98 |
99 |
100 | // QWidget interface
101 | protected:
102 | void dragEnterEvent(QDragEnterEvent *event) override;
103 |
104 | // QWidget interface
105 | protected:
106 | void mouseReleaseEvent(QMouseEvent *event) override;
107 | void mouseMoveEvent(QMouseEvent *event) override;
108 | void closeEvent( QCloseEvent * event ) override;
109 |
110 | };
111 |
112 | extern MainWindow* pmw;
113 | extern ED_Unit* pMovingUnit;
114 | extern QDesktopWidget* pdt;
115 | extern LayerShower* pls;
116 | extern bool debug;
117 | #endif // MAINWINDOW_H
118 |
--------------------------------------------------------------------------------
/mainwindow.ui:
--------------------------------------------------------------------------------
1 |
2 |
3 | MainWindow
4 |
5 |
6 |
7 | 0
8 | 0
9 | 1599
10 | 1181
11 |
12 |
13 |
14 | MainWindow_ED
15 |
16 |
17 |
18 |
19 | false
20 |
21 |
22 |
23 |
24 | New
25 |
26 |
27 | QAction::NoRole
28 |
29 |
30 |
31 |
32 | Open
33 |
34 |
35 | Open
36 |
37 |
38 | QAction::NoRole
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/mousehook.cpp:
--------------------------------------------------------------------------------
1 | #include "mousehook.h"
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | //静态变量类外初始化
9 | HHOOK MouseHook:: mouse_hook_ = NULL;
10 | void(*MouseHook::m_OnFunc)(int,int) = NULL;
11 | void(*MouseHook::m_OffFunc)(int,int) = NULL;
12 | void(*MouseHook::m_MoveFunc)(int,int) = NULL;
13 | MouseHook::MouseHook()
14 | {
15 | Q_ASSERT(!mouse_hook_);
16 | //构造函数里把MouseHookEvent函数的地址当钩子写入到windows消息循环
17 | mouse_hook_ = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)MouseHookEvent, GetModuleHandle(NULL), 0);
18 | qDebug("hook created");
19 | }
20 |
21 | MouseHook::~MouseHook()
22 | {
23 | //析构函数中释放这个钩子
24 | if (nullptr != mouse_hook_)
25 | {
26 | UnhookWindowsHookEx(mouse_hook_);
27 | }
28 | }
29 |
30 | void MouseHook::SetMouseMoveCallBack(void(*func)(int,int))
31 | {
32 | m_MoveFunc=func;
33 | qDebug("func1 created");
34 | }
35 | void MouseHook::SetMouseOnCallBack(void(*func)(int,int))
36 | {
37 | m_OnFunc=func;
38 | qDebug("func2 created");
39 | }
40 | void MouseHook::SetMouseOffCallBack(void(*func)(int,int))
41 | {
42 | m_OffFunc=func;
43 | qDebug("func3 created");
44 | }
45 |
46 |
47 | LRESULT CALLBACK MouseHook::MouseHookEvent(int ncode, WPARAM wParam, LPARAM lParam)
48 | {
49 | LPMSLLHOOKSTRUCT p = (LPMSLLHOOKSTRUCT)lParam;
50 | POINT pt = p->pt;
51 | DWORD mouseData = p->time;
52 |
53 | const char* info = NULL;
54 | char text[60], pData[50], mData[50];
55 |
56 | PAINTSTRUCT ps;
57 | HDC hdc;
58 | // QPoint point = QCursor::pos(); // 获取鼠标当前位置
59 | // switch (wParam)
60 | // {
61 | // case WM_LBUTTONDOWN: // 鼠标左键按下
62 | // emit GlobalMouseEvent::getInstance()->mouseEvent(new QMouseEvent(QEvent::MouseButtonPress, point, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
63 | // break;
64 | // case WM_MOUSEMOVE: // 鼠标移动
65 | // emit GlobalMouseEvent::getInstance()->mouseEvent(new QMouseEvent(QEvent::MouseMove, point, Qt::NoButton, Qt::NoButton, Qt::NoModifier));
66 | // break;
67 | // case WM_RBUTTONDOWN: // 鼠标右键按下
68 | // emit GlobalMouseEvent::getInstance()->mouseEvent(new QMouseEvent(QEvent::MouseButtonPress, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier));
69 | // break;
70 | // case WM_RBUTTONUP: // 鼠标右键抬起
71 | // emit GlobalMouseEvent::getInstance()->mouseEvent(new QMouseEvent(QEvent::MouseButtonRelease, point, Qt::RightButton, Qt::RightButton, Qt::NoModifier));
72 | // break;
73 | // case WM_LBUTTONUP: // 鼠标左键抬起
74 | // emit GlobalMouseEvent::getInstance()->mouseEvent(new QMouseEvent(QEvent::MouseButtonRelease, point, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier));
75 | // break;
76 | // case WM_MOUSEWHEEL: // 鼠标滚轮
77 | // {
78 | // MSLLHOOKSTRUCT * msll = reinterpret_cast(lParam);
79 | // // qDebug() << QString("坐标:(%1, %2)").arg(msll->pt.x).arg(msll->pt.y); // 获取鼠标坐标
80 | // int delta = GET_WHEEL_DELTA_WPARAM(msll->mouseData); // 获取滚轮状态,向前:120,向后-120
81 | // emit GlobalMouseEvent::getInstance()->wheelEvent(new QWheelEvent(point, delta, Qt::MiddleButton, Qt::NoModifier));
82 | // break;
83 | // }
84 | // default:
85 | // break;
86 | // }
87 |
88 | if (ncode >= 0)
89 | {
90 | if (wParam == WM_MOUSEMOVE)
91 | {
92 | info = "鼠标 [移动]";
93 | m_MoveFunc(pt.x,pt.y);
94 | }
95 | else if (wParam == WM_LBUTTONDOWN)
96 | {
97 | info = "鼠标 [左键] 按下";
98 | m_OnFunc(pt.x,pt.y);
99 | }
100 | else if (wParam == WM_LBUTTONUP)
101 | {
102 | info = "鼠标 [左键] 抬起";
103 | m_OffFunc(pt.x,pt.y);
104 | }
105 | else if (wParam == WM_LBUTTONDBLCLK)
106 | {
107 | info = "鼠标 [左键] 双击";
108 | }
109 | else if (wParam == WM_RBUTTONDOWN)
110 | {
111 | info = "鼠标 [右键] 按下";
112 | m_OnFunc(pt.x,pt.y);
113 | }
114 | else if (wParam == WM_RBUTTONUP)
115 | {
116 | info = "鼠标 [右键] 抬起";
117 | m_OffFunc(pt.x,pt.y);
118 | }
119 | else if (wParam == WM_RBUTTONDBLCLK)
120 | {
121 | info = "鼠标 [右键] 双击";
122 | }
123 | else if (wParam == WM_MBUTTONDOWN)
124 | {
125 | info = "鼠标 [滚轮] 按下";
126 | }
127 | else if (wParam == WM_MBUTTONUP)
128 | {
129 | info = "鼠标 [滚轮] 抬起";
130 | }
131 | else if (wParam == WM_MBUTTONDBLCLK)
132 | {
133 | info = "鼠标 [滚轮] 双击";
134 | }
135 | else if (wParam == WM_MOUSEWHEEL)
136 | {
137 | info = "鼠标 [滚轮] 滚动";
138 | }
139 |
140 | ZeroMemory(text, sizeof(text));
141 | ZeroMemory(pData, sizeof(pData));
142 | ZeroMemory(mData, sizeof(mData));
143 |
144 | qDebug() << "鼠标状态: " << info;
145 | qDebug() << "X: " << pt.x << " Y: " << pt.y ;
146 | qDebug() << "附加数据: " << mouseData ;
147 | }
148 |
149 | return CallNextHookEx(mouse_hook_, ncode, wParam, lParam);
150 | }
151 |
--------------------------------------------------------------------------------
/mousehook.h:
--------------------------------------------------------------------------------
1 | #ifndef MOUSEHOOK_H
2 | #define MOUSEHOOK_H
3 | #include
4 | #include
5 | class MouseHook:public QObject
6 | {
7 | public:
8 | MouseHook();
9 | ~MouseHook();
10 | public:
11 | //钩子函数,处理键盘事件
12 | static LRESULT CALLBACK MouseHookEvent(int nCode, WPARAM wParam,
13 | LPARAM lParam);
14 |
15 | //设置回调函数,可以从外部设置,这样keyHookEvent处理的时候可以执行这个回调
16 | void SetMouseOnCallBack( void(*func)(int,int));
17 | void SetMouseOffCallBack( void(*func)(int,int));
18 | void SetMouseMoveCallBack( void(*func)(int,int));
19 | private:
20 | static HHOOK mouse_hook_;//hook对象
21 | static void(*m_OnFunc)(int,int) ;//按下的回调,int代表键码
22 | static void(*m_OffFunc)(int,int) ;//抬起的回调,int代表键码
23 | static void(*m_MoveFunc)(int,int) ;//抬起的回调,int代表键码
24 | };
25 | #endif
26 |
--------------------------------------------------------------------------------
/picturebox.cpp:
--------------------------------------------------------------------------------
1 | #include "picturebox.h"
2 | #include "SysFunctions.h"
3 | #include
4 | #include
5 | #include "style.h"
6 | static const int IMAGE_WIDTH = 300;
7 | static const int IMAGE_HEIGHT = 300;
8 | static const QSize IMAGE_SIZE = QSize(IMAGE_WIDTH, IMAGE_HEIGHT);
9 |
10 |
11 | PictureBox::PictureBox(QWidget *parent,double m_scale) : QWidget(parent)
12 | {
13 | source = QPixmap(IMAGE_SIZE);
14 | source.fill();
15 | m_brush = QBrush(Qt::white);
16 | setScale(m_scale);
17 | setAttribute(Qt::WA_TransparentForMouseEvents, false);
18 | setMaximumSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX);
19 | setMinimumSize(10,10);
20 | }
21 |
22 | void PictureBox::setBackground(QBrush brush)
23 | {
24 | m_brush = brush;
25 | update();
26 | }
27 |
28 |
29 | void PictureBox::setScale(double scale){
30 |
31 | m_scale = qBound(0.01, scale, 2.0);
32 | updateDispaly();
33 | }
34 |
35 | bool PictureBox::setImage(QPixmap &image)
36 | {
37 | if(image.isNull())
38 | {
39 | return false;
40 | }
41 | source = image;
42 | updateDispaly();
43 | return true;
44 | }
45 |
46 | void PictureBox::paintEvent(QPaintEvent * event)
47 | {
48 | Q_UNUSED(event);
49 | QPainter painter(this);
50 | // qDebug()<width();
68 | window_height = parentWidget()->height();
69 |
70 | image_width = source.width();
71 | image_height = source.height();
72 |
73 | r1 = window_width / image_width;
74 | r2 = window_height / image_height;
75 |
76 | if((enable_image_fill&&requireFill))
77 | r = qMax(r1, r2);
78 | else
79 | r= qMin(r1,r2);
80 |
81 | displaySize =QSize(image_width * r * m_scale+1, image_height * r * m_scale+1);
82 |
83 | actualSize = displaySize;
84 | off_x = 0;
85 | off_y = 0 ;
86 |
87 |
88 | if(displaySize.width()>=window_width){
89 | actualSize.setWidth(window_width);
90 | off_x = -(displaySize.width()-window_width)/2;
91 | }
92 |
93 | if(displaySize.height()>=window_height){
94 | actualSize.setHeight(window_height);
95 | off_y = -(displaySize.height()-window_height)/2;
96 | }
97 |
98 | scaled = source.scaled(displaySize
99 | , Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
100 |
101 |
102 |
103 | setFixedSize(actualSize);
104 | }
105 |
106 | PictureBox::~PictureBox()
107 | {
108 |
109 | }
110 |
--------------------------------------------------------------------------------
/picturebox.h:
--------------------------------------------------------------------------------
1 | #ifndef PICTUREBOX_H
2 | #define PICTUREBOX_H
3 |
4 | #include
5 | #include
6 | #include
7 |
8 |
9 | class PictureBox : public QWidget
10 | {
11 | Q_OBJECT
12 | public:
13 | explicit PictureBox(QWidget *parent=0,double m_scale =1.0);
14 | void setScale(double scale);
15 | ~PictureBox();
16 | bool requireFill =false;
17 | QPixmap source;
18 | QPixmap scaled;
19 | QBrush m_brush;
20 | QSize displaySize;
21 | QSize actualSize;
22 |
23 | int off_x,off_y;
24 | double m_scale = 1.0;
25 | void updateDispaly();
26 | protected:
27 | void paintEvent(QPaintEvent * event);
28 |
29 | public slots:
30 | bool setImage(QPixmap &image);
31 | void setBackground(QBrush brush);
32 | };
33 | #endif
34 |
--------------------------------------------------------------------------------
/res.qrc:
--------------------------------------------------------------------------------
1 |
2 |
3 | testBackgroud.jpg
4 |
5 |
6 |
--------------------------------------------------------------------------------
/roundshower.cpp:
--------------------------------------------------------------------------------
1 | #include "roundshower.h"
2 | #include "qpainter.h"
3 | #include "qpainterpath.h"
4 |
5 | roundShower::roundShower(QWidget *parent)
6 | : QWidget{parent}
7 | {
8 | setFixedSize(parent->size());
9 | setAttribute(Qt::WA_TransparentForMouseEvents);
10 | }
11 |
12 | void roundShower::distri(QSize* sizedis,int* radiusdis)
13 | {
14 | follow = false;
15 | pSize = sizedis;
16 | pRadius = radiusdis;
17 | }
18 |
19 | void roundShower::updateDisplay()
20 | {
21 | if(follow){
22 | setFixedSize(parentWidget()->size());
23 | }
24 | }
25 |
26 |
27 | void roundShower::paintEvent(QPaintEvent *event)
28 | {
29 | // 在改图片上填充一个圆角区域,需要设置抗锯齿
30 | QPixmap tem(size());
31 | tem.fill(QColor(0,0,0,0));
32 | QPainter painter(&tem);
33 | painter.setRenderHint(QPainter::Antialiasing);
34 | QPainterPath path;
35 |
36 | //这里圆角区域需要根据dpi、size调整
37 | if(follow)
38 | path.addRoundedRect(QRectF(0,0,aim_size().width(),aim_size().height()), aim_radius(), aim_radius());
39 | else
40 | path.addRoundedRect(QRectF((parentWidget()->width()-aim_size().width())/2,(parentWidget()->height()-aim_size().height())/2,aim_size().width(),aim_size().height()), aim_radius(), aim_radius());
41 | painter.fillPath(path, Qt::white);
42 | painter.end();
43 | // 在窗口上绘制该圆角图片
44 | painter.begin(this);
45 | painter.setRenderHint(QPainter::Antialiasing);
46 | // 该混合模式会根据source像素的透明度,调整目标的透明度
47 | painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
48 | painter.drawPixmap(0, 0, tem);
49 |
50 | // painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
51 | // painter.setPen(QPen(QColor(0xCA64EA), 1.0));
52 | // painter.drawPath(path);
53 | }
54 |
--------------------------------------------------------------------------------
/roundshower.h:
--------------------------------------------------------------------------------
1 | #ifndef ROUNDSHOWER_H
2 | #define ROUNDSHOWER_H
3 |
4 | #include "style.h"
5 | #include
6 |
7 | class roundShower : public QWidget
8 | {
9 | Q_OBJECT
10 | public:
11 | explicit roundShower(QWidget *parent = nullptr);
12 | QSize* pSize;
13 | int* pRadius;
14 | bool follow = true;
15 |
16 | void distri(QSize* sizedis,int* radiusdis);
17 |
18 | QSize aim_size(){
19 | if(follow) return parentWidget()->size();
20 | else return *pSize;
21 | }
22 |
23 | void updateDisplay();
24 |
25 | int aim_radius(){
26 | if(follow) return unit_radius;
27 | else return *pRadius;
28 | }
29 | signals:
30 |
31 | // QWidget interface
32 | protected:
33 | void paintEvent(QPaintEvent *event) override;
34 | };
35 |
36 | #endif // ROUNDSHOWER_H
37 |
--------------------------------------------------------------------------------
/style.cpp:
--------------------------------------------------------------------------------
1 | #include "style.h"
2 |
3 |
4 | int sleep_alpha = 80;
5 | int active_alpha = 160;
6 |
7 | int sleep_alpha_deep = 140;
8 | int active_alpha_deep = 200;
9 |
10 | float sleep_color_ratio = 0.9;
11 | float active_color_ratio = 0.9;
12 |
13 | int light_alpha_start = 120;
14 | int light_alpha_end = 0;
15 |
16 | bool ShowRect = true;
17 | bool ShowSide = false;
18 | bool ShowLight = true;
19 |
20 | int icon_shadow_alpha = 180;
21 | int icon_shadow_blur_radius = 50;
22 |
23 | int unit_shadow_alpha = 120;
24 | int unit_shadow_blur_radius = 80;
25 |
26 | int unit_radius = 30;
27 | int position_animation_time = 100;
28 |
29 | bool enable_background_transparent = true;
30 | bool enable_background_blur = false;
31 | bool enable_light_track = false;
32 |
33 | bool enable_intime_repaint = false;
34 |
35 | bool enable_image_fill=false;
36 |
37 | int muilt_icon_default_type =1;
38 | double scale_fix_ratio = 1.3;
39 | bool enable_lnk_redirect = 1;
40 |
--------------------------------------------------------------------------------
/style.h:
--------------------------------------------------------------------------------
1 | #ifndef STYLE_H
2 | #define STYLE_H
3 |
4 | extern int sleep_alpha;
5 | extern int active_alpha;
6 | extern int sleep_alpha_deep;
7 | extern int active_alpha_deep;
8 |
9 | extern float sleep_color_ratio;
10 | extern float active_color_ratio;
11 |
12 | extern int light_alpha_start;
13 | extern int light_alpha_end;
14 |
15 | extern bool ShowRect;
16 | extern bool ShowSide;
17 | extern bool ShowLight;
18 |
19 | extern int icon_shadow_alpha;
20 | extern int icon_shadow_blur_radius;
21 |
22 | extern int unit_shadow_alpha;
23 | extern int unit_shadow_blur_radius;
24 |
25 | extern int unit_radius;
26 | extern int position_animation_time;
27 |
28 | extern bool enable_background_transparent;
29 | extern bool enable_background_blur;
30 | extern bool enable_light_track;
31 |
32 | extern bool enable_intime_repaint;
33 |
34 | extern bool enable_image_fill;
35 |
36 | extern int muilt_icon_default_type;
37 |
38 | extern double scale_fix_ratio;
39 |
40 | extern bool enable_lnk_redirect;
41 |
42 | #endif // STYLE_H
43 |
--------------------------------------------------------------------------------
/testBackgroud.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gitgitTrue/Sapphire-EnhancedDesktop/da26c11f3f8b52c869689fc88beed321a6aaeace/testBackgroud.jpg
--------------------------------------------------------------------------------
/weather.cpp:
--------------------------------------------------------------------------------
1 | #include "weather.h"
2 | #include "QWidget"
3 | #include"QProcess"
4 | #include "qaction.h"
5 | #include "qboxlayout.h"
6 | #include"SysFunctions.h"
7 | #include "qlabel.h"
8 | #include"QDebug"
9 | #include"QUrl"
10 | #include
11 | #include
12 | #include
13 | #include
14 | #include"QDesktopServices"
15 | #include"QTextCodec"
16 | #include "qpainter.h"
17 | #include"QGraphicsDropShadowEffect"
18 | Weather::Weather(QWidget *parent, int sizex, int sizey)
19 | : ED_Unit(parent,sizex,sizey)
20 | {
21 | type = Unit;
22 | wlayout=new QVBoxLayout(this);
23 | manager=new QNetworkAccessManager(this);
24 | temperatureLabel=new QLabel(this);
25 | weatherlabel=new QLabel(this);
26 | advicelabel=new QLabel(this);
27 | advicelabel->setWordWrap(true);
28 | wlayout->addWidget(temperatureLabel, 0, Qt::AlignHCenter);
29 | wlayout->addWidget(weatherlabel, 0, Qt::AlignHCenter);
30 | wlayout->addWidget(advicelabel, 0, Qt::AlignHCenter);
31 | connect(manager,&QNetworkAccessManager::finished,this,&Weather::handleWeatherResponse);
32 | addWeatherInfo("101010200");
33 | }
34 |
35 |
36 |
37 | void Weather::addWeatherInfo(QString citycode)
38 | {
39 | QUrl url("http://t.weather.itboy.net/api/weather/city/"+citycode);
40 | manager->get(QNetworkRequest(url));
41 | }
42 |
43 | void Weather::handleWeatherResponse(QNetworkReply *reply)
44 | {
45 | //qDebug()<<"success";
46 | int statuscode=reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
47 | //qDebug()<readAll();
49 | //qDebug()<setText("北京海淀区气温" + rootobj.value("data").toObject().value("wendu").toString() + " °C");
65 | weatherlabel->setText("空气污染:"+rootobj.value("data").toObject().value("quality").toString());
66 | advicelabel->setText("建议:"+rootobj.value("data").toObject().value("ganmao").toString());
67 |
68 | }
69 |
70 |
71 |
--------------------------------------------------------------------------------
/weather.h:
--------------------------------------------------------------------------------
1 | #ifndef WEATHER_H
2 | #define WEATHER_H
3 |
4 | #include
5 | #include"ed_unit.h"
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 |
15 | class Weather : public ED_Unit
16 | {
17 | Q_OBJECT
18 | public:
19 | explicit Weather():Weather(nullptr,1,1){};
20 | explicit Weather(QWidget *parent,int sizex=1,int sizey=1);
21 | QLabel *temperatureLabel;
22 | QLabel *weatherlabel;
23 | QLabel *advicelabel;
24 | QNetworkAccessManager *manager;
25 | QVBoxLayout *wlayout;
26 | void addWeatherInfo(QString citycode);
27 | void double_click_action() override;
28 | void parsejson(QByteArray& byteArray);
29 | private slots:
30 | void handleWeatherResponse(QNetworkReply *reply);
31 |
32 | };
33 | Q_DECLARE_METATYPE(Weather)
34 | #endif // WEATHER_H
35 |
--------------------------------------------------------------------------------