add qml library module.

This commit is contained in:
amass 2024-08-20 23:58:02 +08:00
parent 7070777f80
commit 3a037be631
12 changed files with 128 additions and 17 deletions

1
Examples/CMakeLists.txt Normal file
View File

@ -0,0 +1 @@
add_subdirectory(FluentWindow)

View 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
)

View 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();
}

View 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
View 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
View 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
View 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
View File

@ -0,0 +1,4 @@
import QtQuick
Item {
}

View File

@ -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
)