Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mahuifa
QMDemo
提交
33b5709c
Q
QMDemo
项目概览
mahuifa
/
QMDemo
通知
1
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
QMDemo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
33b5709c
编写于
8月 22, 2022
作者:
mahuifa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新功能:完成QTransformDemo部分功能
1、打印部分输出信息; 2、实现滑动条控制平移原点功能。
上级
00dda067
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
130 addition
and
30 deletion
+130
-30
PaintingDemo/TransformDemo/renderarea.cpp
PaintingDemo/TransformDemo/renderarea.cpp
+20
-1
PaintingDemo/TransformDemo/renderarea.h
PaintingDemo/TransformDemo/renderarea.h
+2
-1
PaintingDemo/TransformDemo/widget.cpp
PaintingDemo/TransformDemo/widget.cpp
+67
-12
PaintingDemo/TransformDemo/widget.h
PaintingDemo/TransformDemo/widget.h
+13
-1
PaintingDemo/TransformDemo/widget.ui
PaintingDemo/TransformDemo/widget.ui
+28
-15
未找到文件。
PaintingDemo/TransformDemo/renderarea.cpp
浏览文件 @
33b5709c
#include "renderarea.h"
#include <QDebug>
#include <qpainter.h>
RenderArea
::
RenderArea
(
QWidget
*
parent
)
:
QWidget
(
parent
)
...
...
@@ -8,6 +8,7 @@ RenderArea::RenderArea(QWidget *parent) : QWidget(parent)
this
->
setBackgroundRole
(
QPalette
::
Base
);
this
->
setAutoFillBackground
(
true
);
showData
();
}
RenderArea
::~
RenderArea
()
...
...
@@ -22,9 +23,27 @@ RenderArea::~RenderArea()
void
RenderArea
::
setTransform
(
const
QTransform
&
transform
)
{
m_transform
=
transform
;
showData
();
this
->
update
();
}
void
RenderArea
::
showData
()
{
qDebug
()
<<
"-----------------------打印信息-----------------------"
;
qDebug
()
<<
"矩阵元素:"
<<
QString
(
"[%1, %2, %3][%4, %5, %6][%7, %8, %9]"
)
.
arg
(
m_transform
.
m11
()).
arg
(
m_transform
.
m12
()).
arg
(
m_transform
.
m13
())
// 水平缩放、垂直剪切、水平投影
.
arg
(
m_transform
.
m21
()).
arg
(
m_transform
.
m22
()).
arg
(
m_transform
.
m23
())
// 水平剪切、垂直缩放、垂直投影
.
arg
(
m_transform
.
m31
()).
arg
(
m_transform
.
m32
()).
arg
(
m_transform
.
m33
());
// 水平平移、垂直平移、投影因子
qDebug
()
<<
"转换类型:"
<<
m_transform
.
type
();
qDebug
()
<<
"仿射变换:"
<<
m_transform
.
isAffine
();
qDebug
()
<<
"单位矩阵(TxNone):"
<<
m_transform
.
isIdentity
();
qDebug
()
<<
"矩阵可逆:"
<<
m_transform
.
isInvertible
();
qDebug
()
<<
"矩阵旋转:"
<<
m_transform
.
isRotating
();
qDebug
()
<<
"矩阵缩放:"
<<
m_transform
.
isScaling
();
qDebug
()
<<
"矩阵偏移:"
<<
m_transform
.
isTranslating
();
}
void
RenderArea
::
paintEvent
(
QPaintEvent
*
event
)
{
...
...
PaintingDemo/TransformDemo/renderarea.h
浏览文件 @
33b5709c
...
...
@@ -12,7 +12,8 @@ public:
void
setTransform
(
const
QTransform
&
transform
);
signals:
private:
void
showData
();
protected:
void
paintEvent
(
QPaintEvent
*
event
)
override
;
...
...
PaintingDemo/TransformDemo/widget.cpp
浏览文件 @
33b5709c
#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget
::
Widget
(
QWidget
*
parent
)
:
QWidget
(
parent
)
...
...
@@ -7,10 +8,11 @@ Widget::Widget(QWidget *parent)
{
ui
->
setupUi
(
this
);
m_transform
.
translate
(
50
,
50
);
m_transform
.
rotate
(
10
);
m_transform
.
scale
(
1
,
1.0
);
//
m_transform.translate(50, 50);
//
m_transform.rotate(10);
// m_transform.scale(0.5, 1
);
ui
->
renderArea
->
installEventFilter
(
this
);
}
Widget
::~
Widget
()
...
...
@@ -19,17 +21,70 @@ Widget::~Widget()
}
/**
* @brief 获取反转副本
* @param checked
* @brief 事件过滤器
* @param watched
* @param event
* @return
*/
void
Widget
::
on_checkBox_transform_clicked
(
bool
checked
)
bool
Widget
::
eventFilter
(
QObject
*
watched
,
QEvent
*
event
)
{
if
(
checked
)
if
(
watched
==
ui
->
renderArea
&&
event
->
type
()
==
QEvent
::
Resize
)
{
ui
->
renderArea
->
setTransform
(
m_transform
.
inverted
());
}
else
{
ui
->
renderArea
->
setTransform
(
m_transform
);
ui
->
horizontalSlider_origin
->
setMaximum
(
ui
->
renderArea
->
width
());
ui
->
verticalSlider_origin
->
setMaximum
(
ui
->
renderArea
->
height
());
ui
->
horizontalSlider_origin
->
setValue
(
0
);
ui
->
verticalSlider_origin
->
setValue
(
ui
->
renderArea
->
height
()
);
}
return
QWidget
::
eventFilter
(
watched
,
event
);
}
/**
* @brief 设置原始变换
*/
void
Widget
::
on_but_original_clicked
()
{
ui
->
renderArea
->
setTransform
(
m_transform
);
}
/**
* @brief 重置QTransform
*/
void
Widget
::
on_but_reset_clicked
()
{
m_transform
.
reset
();
ui
->
renderArea
->
setTransform
(
m_transform
);
}
/**
* @brief 获取反转副本
*/
void
Widget
::
on_but_transform_clicked
()
{
ui
->
renderArea
->
setTransform
(
m_transform
.
inverted
());
}
/**
* @brief 水平偏移原点
* @param value
*/
void
Widget
::
on_horizontalSlider_origin_valueChanged
(
int
value
)
{
static
int
pastValue
=
0
;
m_transform
.
translate
(
value
-
pastValue
,
0
);
// 由于QTransform设置时累加的,所以这里需要通过pastValue计算差值
pastValue
=
value
;
ui
->
renderArea
->
setTransform
(
m_transform
);
}
/**
* @brief 垂直偏移原点
* @param value
*/
void
Widget
::
on_verticalSlider_origin_valueChanged
(
int
value
)
{
static
int
pastValue
=
0
;
m_transform
.
translate
(
0
,
ui
->
verticalSlider_origin
->
maximum
()
-
value
-
pastValue
);
pastValue
=
ui
->
verticalSlider_origin
->
maximum
()
-
value
;
ui
->
renderArea
->
setTransform
(
m_transform
);
}
PaintingDemo/TransformDemo/widget.h
浏览文件 @
33b5709c
...
...
@@ -15,8 +15,20 @@ public:
Widget
(
QWidget
*
parent
=
nullptr
);
~
Widget
();
protected:
bool
eventFilter
(
QObject
*
watched
,
QEvent
*
event
)
override
;
private
slots
:
void
on_checkBox_transform_clicked
(
bool
checked
);
void
on_but_reset_clicked
();
void
on_but_transform_clicked
();
void
on_but_original_clicked
();
void
on_horizontalSlider_origin_valueChanged
(
int
value
);
void
on_verticalSlider_origin_valueChanged
(
int
value
);
private:
Ui
::
Widget
*
ui
;
...
...
PaintingDemo/TransformDemo/widget.ui
浏览文件 @
33b5709c
...
...
@@ -14,40 +14,53 @@
<string>
Widget
</string>
</property>
<layout
class=
"QGridLayout"
name=
"gridLayout"
>
<item
row=
"2"
column=
"1"
>
<widget
class=
"QSlider"
name=
"horizontalSlider_2"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
</widget>
</item>
<item
row=
"2"
column=
"3"
>
<widget
class=
"QDial"
name=
"dial"
/>
</item>
<item
row=
"1"
column=
"1"
colspan=
"3"
>
<widget
class=
"RenderArea"
name=
"renderArea"
native=
"true"
/>
</item>
<item
row=
"1"
column=
"0"
>
<widget
class=
"QSlider"
name=
"verticalSlider"
>
<widget
class=
"QSlider"
name=
"verticalSlider
_origin
"
>
<property
name=
"orientation"
>
<enum>
Qt::Vertical
</enum>
</property>
<property
name=
"tickPosition"
>
<enum>
QSlider::TicksBelow
</enum>
</property>
</widget>
</item>
<item
row=
"5"
column=
"2"
>
<widget
class=
"QPushButton"
name=
"but_reset"
>
<property
name=
"text"
>
<string>
重置
</string>
</property>
</widget>
</item>
<item
row=
"4"
column=
"2"
>
<widget
class=
"QPushButton"
name=
"but_transform"
>
<property
name=
"text"
>
<string>
反转
</string>
</property>
</widget>
</item>
<item
row=
"0"
column=
"1"
colspan=
"3"
>
<widget
class=
"QSlider"
name=
"horizontalSlider"
>
<widget
class=
"QSlider"
name=
"horizontalSlider
_origin
"
>
<property
name=
"orientation"
>
<enum>
Qt::Horizontal
</enum>
</property>
<property
name=
"tickPosition"
>
<enum>
QSlider::TicksBelow
</enum>
</property>
</widget>
</item>
<item
row=
"
2
"
column=
"2"
>
<widget
class=
"Q
CheckBox"
name=
"checkBox_transform
"
>
<item
row=
"
3
"
column=
"2"
>
<widget
class=
"Q
PushButton"
name=
"but_original
"
>
<property
name=
"text"
>
<string>
反转Transform
</string>
<string>
原始
</string>
</property>
</widget>
</item>
<item
row=
"2"
column=
"3"
rowspan=
"4"
>
<widget
class=
"QDial"
name=
"dial"
/>
</item>
</layout>
</widget>
<customwidgets>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录