Skip to content

Commit 643a0e9

Browse files
committed
[feature|optimize]支持自由截图按C键复制颜色值;重构自由截图相关代码
1 parent fccae91 commit 643a0e9

File tree

12 files changed

+959
-286
lines changed

12 files changed

+959
-286
lines changed

SmartScreenSnapper/SmartScreenSnapper.pro

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ SOURCES += \
2121
src/aboutdialog.cpp \
2222
src/application.cpp \
2323
src/const.cpp \
24+
src/freesnap/freesnapgraphicsview.cpp \
25+
src/freesnap/freesnaprect.cpp \
26+
src/freesnap/freesnapscene.cpp \
2427
src/freesnapdialog.cpp \
2528
src/gif-h/gif.cpp \
2629
src/gifdialog.cpp \
@@ -42,6 +45,9 @@ HEADERS += \
4245
src/aboutdialog.h \
4346
src/application.h \
4447
src/const.h \
48+
src/freesnap/freesnapgraphicsview.h \
49+
src/freesnap/freesnaprect.h \
50+
src/freesnap/freesnapscene.h \
4551
src/freesnapdialog.h \
4652
src/gif-h/gif.h \
4753
src/gifdialog.h \

SmartScreenSnapper/SmartScreenSnapper.pro.user

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.11.1, 2022-08-20T14:32:08. -->
3+
<!-- Written by QtCreator 4.11.1, 2022-10-03T20:44:18. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
@@ -67,7 +67,7 @@
6767
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.14.2 MinGW 32-bit</value>
6868
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.14.2 MinGW 32-bit</value>
6969
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5142.win32_mingw73_kit</value>
70-
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">1</value>
70+
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
7171
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
7272
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
7373
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
@@ -299,7 +299,7 @@
299299
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
300300
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
301301
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
302-
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/C++/SmartScreenSnapper/build_MinGW_32_bit-Release</value>
302+
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/C++/SmartScreenSnapper/build-SmartScreenSnapper-Desktop_Qt_5_14_2_MinGW_32_bit-Debug</value>
303303
</valuemap>
304304
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
305305
</valuemap>
@@ -542,7 +542,7 @@
542542
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
543543
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
544544
<value type="QString" key="RunConfiguration.WorkingDirectory"></value>
545-
<value type="QString" key="RunConfiguration.WorkingDirectory.default">E:/C++/SmartScreenSnapper/build_MinGW_64_bit-Debug</value>
545+
<value type="QString" key="RunConfiguration.WorkingDirectory.default"></value>
546546
</valuemap>
547547
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
548548
</valuemap>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "freesnapgraphicsview.h"
2+
3+
#include <QMouseEvent>
4+
5+
FreeSnapGraphicsView::FreeSnapGraphicsView(QWidget *parent) :
6+
QGraphicsView(parent),
7+
ignoreMouseEvent(false)
8+
{
9+
setMouseTracking(true);
10+
}
11+
12+
void FreeSnapGraphicsView::setIgnoreMouseEvent(bool ignore)
13+
{
14+
ignoreMouseEvent = ignore;
15+
}
16+
17+
void FreeSnapGraphicsView::mousePressEvent(QMouseEvent *event)
18+
{
19+
if (ignoreMouseEvent) event->ignore();
20+
}
21+
22+
void FreeSnapGraphicsView::mouseReleaseEvent(QMouseEvent *event)
23+
{
24+
if (ignoreMouseEvent) event->ignore();
25+
}
26+
27+
void FreeSnapGraphicsView::mouseMoveEvent(QMouseEvent *event)
28+
{
29+
if (ignoreMouseEvent) event->ignore();
30+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#ifndef FREESNAPGRAPHICSVIEW_H
2+
#define FREESNAPGRAPHICSVIEW_H
3+
4+
#include <QGraphicsView>
5+
6+
class FreeSnapGraphicsView : public QGraphicsView
7+
{
8+
public:
9+
FreeSnapGraphicsView(QWidget *parent = nullptr);
10+
11+
void setIgnoreMouseEvent(bool ignore);
12+
13+
private:
14+
bool ignoreMouseEvent;
15+
16+
protected:
17+
void mousePressEvent(QMouseEvent *event);
18+
void mouseReleaseEvent(QMouseEvent *event);
19+
void mouseMoveEvent(QMouseEvent *event);
20+
};
21+
22+
#endif // FREESNAPGRAPHICSVIEW_H
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "freesnaprect.h"
2+
#include <QMouseEvent>
3+
4+
FreeSnapRect::FreeSnapRect(QWidget* parent, Qt::WindowFlags f) : QFrame(parent)
5+
{
6+
setMouseTracking(true);
7+
}
8+
9+
void FreeSnapRect::mouseMoveEvent(QMouseEvent *event)
10+
{
11+
emit mouseMove(event->pos());
12+
QWidget::mouseMoveEvent(event);
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef FREESNAPRECT_H
2+
#define FREESNAPRECT_H
3+
4+
#include <QFrame>
5+
6+
class FreeSnapRect : public QFrame
7+
{
8+
Q_OBJECT
9+
10+
signals:
11+
void mouseMove(QPoint p);
12+
13+
public:
14+
FreeSnapRect(QWidget* parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags());
15+
16+
protected:
17+
void mouseMoveEvent(QMouseEvent *event);
18+
};
19+
20+
#endif // FREESNAPRECT_H
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "freesnapscene.h"
2+
3+
#include <QDebug>
4+
#include <QtMath>
5+
#include <QGraphicsSceneMouseEvent>
6+
7+
FreeSnapScene::FreeSnapScene(QObject *parent) :
8+
QGraphicsScene(parent)
9+
{
10+
11+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef FREESNAPSCENE_H
2+
#define FREESNAPSCENE_H
3+
4+
#include <QGraphicsScene>
5+
6+
7+
class FreeSnapScene : public QGraphicsScene
8+
{
9+
Q_OBJECT
10+
public:
11+
FreeSnapScene(QObject *parent = nullptr);
12+
13+
};
14+
15+
#endif // FREESNAPSCENE_H

0 commit comments

Comments
 (0)