add qml library module.
This commit is contained in:
parent
7070777f80
commit
3a037be631
1
Examples/CMakeLists.txt
Normal file
1
Examples/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
add_subdirectory(FluentWindow)
|
19
Examples/FluentWindow/CMakeLists.txt
Normal file
19
Examples/FluentWindow/CMakeLists.txt
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||||
|
|
||||||
|
qt_standard_project_setup(REQUIRES 6.5)
|
||||||
|
|
||||||
|
add_executable(FluentWindow main.cpp)
|
||||||
|
|
||||||
|
qt_add_qml_module(FluentWindow
|
||||||
|
URI FluentWindow
|
||||||
|
VERSION 1.0
|
||||||
|
QML_FILES
|
||||||
|
qml/Main.qml
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(FluentWindow
|
||||||
|
PRIVATE Qt6::Quick
|
||||||
|
PRIVATE Universal
|
||||||
|
PRIVATE Fluent
|
||||||
|
PRIVATE Fluentplugin
|
||||||
|
)
|
15
Examples/FluentWindow/main.cpp
Normal file
15
Examples/FluentWindow/main.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "BoostLog.h"
|
||||||
|
#include "Rectangle.h"
|
||||||
|
#include <QGuiApplication>
|
||||||
|
#include <QQmlApplicationEngine>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
LOG(info) << "app start...";
|
||||||
|
QGuiApplication app(argc, argv);
|
||||||
|
QQmlApplicationEngine engine;
|
||||||
|
QObject::connect(
|
||||||
|
&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); },
|
||||||
|
Qt::QueuedConnection);
|
||||||
|
engine.loadFromModule("FluentWindow", "Main");
|
||||||
|
return app.exec();
|
||||||
|
}
|
14
Examples/FluentWindow/qml/Main.qml
Normal file
14
Examples/FluentWindow/qml/Main.qml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import QtQuick
|
||||||
|
import Fluent as Fluent
|
||||||
|
|
||||||
|
Window {
|
||||||
|
width: 640
|
||||||
|
height: 480
|
||||||
|
visible: true
|
||||||
|
title: qsTr("FluentWindow")
|
||||||
|
|
||||||
|
Fluent.Rectangle {
|
||||||
|
width: 100
|
||||||
|
height: 100
|
||||||
|
}
|
||||||
|
}
|
25
Fluent/CMakeLists.txt
Normal file
25
Fluent/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Gui Quick)
|
||||||
|
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Quick)
|
||||||
|
|
||||||
|
qt_standard_project_setup(REQUIRES 6.5)
|
||||||
|
|
||||||
|
add_library(Fluent
|
||||||
|
AsyncEvent.h
|
||||||
|
QClassStdStream.h QClassStdStream.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
qt_add_qml_module(Fluent
|
||||||
|
URI Fluent
|
||||||
|
VERSION 1.0
|
||||||
|
SOURCES
|
||||||
|
Rectangle.h Rectangle.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(Fluent
|
||||||
|
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(Fluent
|
||||||
|
PUBLIC Qt${QT_VERSION_MAJOR}::Gui
|
||||||
|
PRIVATE Qt${QT_VERSION_MAJOR}::Quick
|
||||||
|
)
|
30
Fluent/Rectangle.cpp
Normal file
30
Fluent/Rectangle.cpp
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#include "Rectangle.h"
|
||||||
|
#include <QPainter>
|
||||||
|
#include <QPainterPath>
|
||||||
|
|
||||||
|
Rectangle::Rectangle(QQuickItem *parent) : QQuickPaintedItem{parent} {
|
||||||
|
}
|
||||||
|
|
||||||
|
void Rectangle::paint(QPainter *painter) {
|
||||||
|
if (m_radius.size() < 4) return;
|
||||||
|
painter->save();
|
||||||
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
|
QPainterPath path;
|
||||||
|
QRectF rect = boundingRect();
|
||||||
|
path.moveTo(rect.bottomRight() - QPointF(0, m_radius[2]));
|
||||||
|
path.lineTo(rect.topRight() + QPointF(0, m_radius[1]));
|
||||||
|
path.arcTo(QRectF(QPointF(rect.topRight() - QPointF(m_radius[1] * 2, 0)), QSize(m_radius[1] * 2, m_radius[1] * 2)),
|
||||||
|
0, 90);
|
||||||
|
path.lineTo(rect.topLeft() + QPointF(m_radius[0], 0));
|
||||||
|
path.arcTo(QRectF(QPointF(rect.topLeft()), QSize(m_radius[0] * 2, m_radius[0] * 2)), 90, 90);
|
||||||
|
path.lineTo(rect.bottomLeft() - QPointF(0, m_radius[3]));
|
||||||
|
path.arcTo(
|
||||||
|
QRectF(QPointF(rect.bottomLeft() - QPointF(0, m_radius[3] * 2)), QSize(m_radius[3] * 2, m_radius[3] * 2)), 180,
|
||||||
|
90);
|
||||||
|
path.lineTo(rect.bottomRight() - QPointF(m_radius[2], 0));
|
||||||
|
path.arcTo(QRectF(QPointF(rect.bottomRight() - QPointF(m_radius[2] * 2, m_radius[2] * 2)),
|
||||||
|
QSize(m_radius[2] * 2, m_radius[2] * 2)),
|
||||||
|
270, 90);
|
||||||
|
painter->fillPath(path, m_color);
|
||||||
|
painter->restore();
|
||||||
|
}
|
20
Fluent/Rectangle.h
Normal file
20
Fluent/Rectangle.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#ifndef RECTANGLE_H
|
||||||
|
#define RECTANGLE_H
|
||||||
|
|
||||||
|
#include <QQmlEngine>
|
||||||
|
#include <QQuickPaintedItem>
|
||||||
|
|
||||||
|
class Rectangle : public QQuickPaintedItem {
|
||||||
|
Q_OBJECT
|
||||||
|
QML_ELEMENT
|
||||||
|
public:
|
||||||
|
explicit Rectangle(QQuickItem *parent = nullptr);
|
||||||
|
|
||||||
|
void paint(QPainter *painter) final;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QColor m_color;
|
||||||
|
QList<int> m_radius;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RECTANGLE_H
|
4
Fluent/qml/Text.qml
Normal file
4
Fluent/qml/Text.qml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import QtQuick
|
||||||
|
|
||||||
|
Item {
|
||||||
|
}
|
@ -1,17 +0,0 @@
|
|||||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Gui)
|
|
||||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui)
|
|
||||||
|
|
||||||
set(CMAKE_AUTOMOC ON)
|
|
||||||
|
|
||||||
add_library(QtComponets
|
|
||||||
AsyncEvent.h
|
|
||||||
QClassStdStream.h QClassStdStream.cpp
|
|
||||||
)
|
|
||||||
|
|
||||||
target_include_directories(QtComponets
|
|
||||||
INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(QtComponets
|
|
||||||
PUBLIC Qt${QT_VERSION_MAJOR}::Gui
|
|
||||||
)
|
|
Loading…
Reference in New Issue
Block a user