From 3a037be631c934321aae6a1a476fd4c73c7a13b7 Mon Sep 17 00:00:00 2001 From: amass <168062547@qq.com> Date: Tue, 20 Aug 2024 23:58:02 +0800 Subject: [PATCH] add qml library module. --- Examples/CMakeLists.txt | 1 + Examples/FluentWindow/CMakeLists.txt | 19 +++++++++++++ Examples/FluentWindow/main.cpp | 15 +++++++++++ Examples/FluentWindow/qml/Main.qml | 14 ++++++++++ {QtComponets => Fluent}/AsyncEvent.h | 0 Fluent/CMakeLists.txt | 25 +++++++++++++++++ {QtComponets => Fluent}/QClassStdStream.cpp | 0 {QtComponets => Fluent}/QClassStdStream.h | 0 Fluent/Rectangle.cpp | 30 +++++++++++++++++++++ Fluent/Rectangle.h | 20 ++++++++++++++ Fluent/qml/Text.qml | 4 +++ QtComponets/CMakeLists.txt | 17 ------------ 12 files changed, 128 insertions(+), 17 deletions(-) create mode 100644 Examples/CMakeLists.txt create mode 100644 Examples/FluentWindow/CMakeLists.txt create mode 100644 Examples/FluentWindow/main.cpp create mode 100644 Examples/FluentWindow/qml/Main.qml rename {QtComponets => Fluent}/AsyncEvent.h (100%) create mode 100644 Fluent/CMakeLists.txt rename {QtComponets => Fluent}/QClassStdStream.cpp (100%) rename {QtComponets => Fluent}/QClassStdStream.h (100%) create mode 100644 Fluent/Rectangle.cpp create mode 100644 Fluent/Rectangle.h create mode 100644 Fluent/qml/Text.qml delete mode 100644 QtComponets/CMakeLists.txt diff --git a/Examples/CMakeLists.txt b/Examples/CMakeLists.txt new file mode 100644 index 0000000..a66e4a0 --- /dev/null +++ b/Examples/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(FluentWindow) diff --git a/Examples/FluentWindow/CMakeLists.txt b/Examples/FluentWindow/CMakeLists.txt new file mode 100644 index 0000000..2d5068e --- /dev/null +++ b/Examples/FluentWindow/CMakeLists.txt @@ -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 +) diff --git a/Examples/FluentWindow/main.cpp b/Examples/FluentWindow/main.cpp new file mode 100644 index 0000000..3f98da5 --- /dev/null +++ b/Examples/FluentWindow/main.cpp @@ -0,0 +1,15 @@ +#include "BoostLog.h" +#include "Rectangle.h" +#include +#include + +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(); +} diff --git a/Examples/FluentWindow/qml/Main.qml b/Examples/FluentWindow/qml/Main.qml new file mode 100644 index 0000000..b299bed --- /dev/null +++ b/Examples/FluentWindow/qml/Main.qml @@ -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 + } +} diff --git a/QtComponets/AsyncEvent.h b/Fluent/AsyncEvent.h similarity index 100% rename from QtComponets/AsyncEvent.h rename to Fluent/AsyncEvent.h diff --git a/Fluent/CMakeLists.txt b/Fluent/CMakeLists.txt new file mode 100644 index 0000000..43bceab --- /dev/null +++ b/Fluent/CMakeLists.txt @@ -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 +) diff --git a/QtComponets/QClassStdStream.cpp b/Fluent/QClassStdStream.cpp similarity index 100% rename from QtComponets/QClassStdStream.cpp rename to Fluent/QClassStdStream.cpp diff --git a/QtComponets/QClassStdStream.h b/Fluent/QClassStdStream.h similarity index 100% rename from QtComponets/QClassStdStream.h rename to Fluent/QClassStdStream.h diff --git a/Fluent/Rectangle.cpp b/Fluent/Rectangle.cpp new file mode 100644 index 0000000..fa8d6f8 --- /dev/null +++ b/Fluent/Rectangle.cpp @@ -0,0 +1,30 @@ +#include "Rectangle.h" +#include +#include + +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(); +} diff --git a/Fluent/Rectangle.h b/Fluent/Rectangle.h new file mode 100644 index 0000000..3e229b6 --- /dev/null +++ b/Fluent/Rectangle.h @@ -0,0 +1,20 @@ +#ifndef RECTANGLE_H +#define RECTANGLE_H + +#include +#include + +class Rectangle : public QQuickPaintedItem { + Q_OBJECT + QML_ELEMENT +public: + explicit Rectangle(QQuickItem *parent = nullptr); + + void paint(QPainter *painter) final; + +private: + QColor m_color; + QList m_radius; +}; + +#endif // RECTANGLE_H diff --git a/Fluent/qml/Text.qml b/Fluent/qml/Text.qml new file mode 100644 index 0000000..8f788db --- /dev/null +++ b/Fluent/qml/Text.qml @@ -0,0 +1,4 @@ +import QtQuick + +Item { +} diff --git a/QtComponets/CMakeLists.txt b/QtComponets/CMakeLists.txt deleted file mode 100644 index 299d400..0000000 --- a/QtComponets/CMakeLists.txt +++ /dev/null @@ -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 -)