Skip to content

Commit 071e96e

Browse files
committed
Add QmlInvertedImage
1 parent 5372a4d commit 071e96e

File tree

8 files changed

+99
-1
lines changed

8 files changed

+99
-1
lines changed

QmlInvertedImage/1.png

40.5 KB
Loading

QmlInvertedImage/QmlInvertedImage.pro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlInvertedImage/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
11+
int main(int argc, char *argv[])
12+
{
13+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
14+
QGuiApplication app(argc, argv);
15+
16+
QQmlApplicationEngine engine;
17+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
18+
19+
return app.exec();
20+
}

QmlInvertedImage/main.qml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.0
10+
import QtGraphicalEffects 1.0
11+
12+
ApplicationWindow {
13+
visible: true
14+
width: 400
15+
height: 320
16+
title: qsTr("Qml倒影")
17+
color: "#AAAAAA"
18+
19+
Image {
20+
id: img
21+
width: 128
22+
height: 128
23+
anchors.top: parent.top
24+
anchors.topMargin: 16
25+
anchors.horizontalCenter: parent.horizontalCenter
26+
source: "qrc:/1.png"
27+
28+
ShaderEffect {
29+
height: parent.height
30+
width: parent.width
31+
anchors.top: parent.bottom
32+
anchors.left: parent.left
33+
34+
property variant source: img
35+
property size sourceSize: Qt.size(0.5 / img.width, 0.5 / img.height)
36+
37+
fragmentShader: "
38+
varying highp vec2 qt_TexCoord0;
39+
uniform lowp sampler2D source;
40+
uniform lowp vec2 sourceSize;
41+
uniform lowp float qt_Opacity;
42+
void main() {
43+
lowp vec2 tc = qt_TexCoord0 * vec2(1, -1) + vec2(0, 1);
44+
lowp vec4 col = 0.25 * (texture2D(source, tc + sourceSize)
45+
+ texture2D(source, tc- sourceSize)
46+
+ texture2D(source, tc + sourceSize * vec2(1, -1))
47+
+ texture2D(source, tc + sourceSize * vec2(-1, 1))
48+
);
49+
gl_FragColor = col * qt_Opacity * (1.0 - qt_TexCoord0.y) * 0.5;
50+
}"
51+
}
52+
}
53+
}

QmlInvertedImage/qml.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>1.png</file>
5+
</qresource>
6+
</RCC>

QmlInvertedImage/show.jpg

15.9 KB
Loading

QtQuickExamples.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ SUBDIRS += QmlWinExtras
3535
SUBDIRS += QmlCalendar
3636
SUBDIRS += QmlCanvasText
3737
SUBDIRS += QmlKey
38-
SUBDIRS += QmlLoader
38+
SUBDIRS += QmlLoader
39+
SUBDIRS += QmlInvertedImage

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,8 @@ QmlLoader: QmlLoader
162162

163163
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlLoader/show.gif?raw=true)
164164

165+
166+
QmlInvertedImage: Qml倒影
167+
168+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlInvertedImage/show.jpg?raw=true)
169+

0 commit comments

Comments
 (0)