Skip to content

Commit

Permalink
WIP real plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinBriza committed Sep 29, 2023
1 parent c43a413 commit 366fe0e
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ add_subdirectory(modules/Lith/UI)
add_subdirectory(modules/Lith/Core)
add_subdirectory(app)

add_dependencies(Lith LithStyleplugin LithUIplugin LithCoreplugin)
add_dependencies(Lith LithStyle LithUIplugin LithCoreplugin)

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
install(FILES ${CMAKE_SOURCE_DIR}/dist/linux/app.lith.Lith.appdata.xml DESTINATION share/metainfo)
Expand Down
3 changes: 1 addition & 2 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ target_link_libraries(Lith PRIVATE
LithAssets
LithCore
LithUI
LithStyle
QCoro6::Coro
Qt::Gui
Qt::GuiPrivate
Expand Down Expand Up @@ -68,7 +67,7 @@ if (PLUGIN_TARGET_TYPE STREQUAL STATIC_LIBRARY)
target_link_libraries(Lith PRIVATE
LithCoreplugin
LithUIplugin
LithStyleplugin
LithStyle
)
endif()

Expand Down
1 change: 0 additions & 1 deletion app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ int main(int argc, char* argv[]) {
font.setHintingPreference(QFont::PreferNoHinting);
font.setStyleHint(QFont::Monospace);
app.setFont(font);
app.setFont(font, "monospace");

// Start the engine
engine.load(QUrl(QLatin1String("qrc:/qt/qml/App/main.qml")));
Expand Down
20 changes: 12 additions & 8 deletions modules/Lith/Style/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ set_source_files_properties(LithPalette.qml PROPERTIES

set(LITHSTYLE_SOURCES
constants.cpp constants.h
lithstyle.h lithstyle.cpp
liththeme.h liththeme.cpp
lith_styleplugin.cpp
)

qt_add_library(LithStyle
${LITHSTYLE_SOURCES}
)
qt_add_qml_module(LithStyle
URI Lith.Style
VERSION 1.0
DEPENDENCIES
QtQuick/auto
CLASS_NAME Lith_StylePlugin
PLUGIN_TARGET LithStyle
NO_PLUGIN_OPTIONAL
NO_GENERATE_PLUGIN_SOURCE
SOURCES ${LITHSTYLE_SOURCES}
QML_FILES ${LITHSTYLE_QML}
)
qt_import_qml_plugins(LithStyle)
Expand All @@ -39,10 +46,10 @@ target_link_libraries(LithStyle PRIVATE
QCoro6::Coro
Qt6::Gui
Qt6::Quick
Qt::QuickControls2
Qt::QuickControls2 Qt::QuickControls2Private
Qt::QuickLayouts
Qt::QuickDialogs2
Qt::QuickTemplates2
Qt::QuickTemplates2 Qt::QuickTemplates2Private
)

target_include_directories(LithStyle PRIVATE
Expand All @@ -54,9 +61,6 @@ target_include_directories(LithStyle PRIVATE
)

install(TARGETS LithStyle
LIBRARY DESTINATION ${LITH_INSTALL_LIBDIR}
)
install(TARGETS LithStyleplugin
LIBRARY DESTINATION ${LITH_INSTALL_MODULEDIR}/Lith/Style/
)
install(FILES
Expand Down
38 changes: 38 additions & 0 deletions modules/Lith/Style/lith_styleplugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "lithstyle.h"
#include "liththeme.h"

#include <QtQuickControls2/private/qquickstyleplugin_p.h>
#include <QtQuickTemplates2/private/qquicktheme_p.h>

extern void qml_register_types_Lith_Style();
Q_GHS_KEEP_REFERENCE(qml_register_types_Lith_Style);

class Lith_StylePlugin : public QQuickStylePlugin {
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)

public:
Lith_StylePlugin(QObject* parent = nullptr);

QString name() const override;
void initializeTheme(QQuickTheme* theme) override;

LithTheme theme;
};

Lith_StylePlugin::Lith_StylePlugin(QObject* parent)
: QQuickStylePlugin(parent) {
volatile auto registration = &qml_register_types_Lith_Style;
Q_UNUSED(registration);
}

QString Lith_StylePlugin::name() const {
return QStringLiteral("Lith.Style");
}

void Lith_StylePlugin::initializeTheme(QQuickTheme* theme) {
LithStyle::initialize();
this->theme.initialize(theme);
}

#include "lith_styleplugin.moc"
18 changes: 18 additions & 0 deletions modules/Lith/Style/lithstyle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "lithstyle.h"

Border::Border(LithStyle* parent)
: QObject(parent) {
}


QColor LithStyle::frameBorderColor() const {
return m_frameBorderColor;
}

void LithStyle::setFrameBorderColor(const QColor& newFrameBorderColor) {
if (m_frameBorderColor == newFrameBorderColor) {
return;
}
m_frameBorderColor = newFrameBorderColor;
emit paletteChanged();
}
60 changes: 60 additions & 0 deletions modules/Lith/Style/lithstyle.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#ifndef LITHSTYLE_H
#define LITHSTYLE_H

#include "common.h"

#include <QQmlEngine>
#include <QtQuickControls2/qquickattachedpropertypropagator.h>
#include <QtQuick/private/qquickpalette_p.h>

#include <QColor>

class LithStyle;

class Border : public QObject {
Q_OBJECT
PROPERTY(qreal, width, 0.0)
PROPERTY(QColor, color, Qt::transparent)
public:
Border(LithStyle* parent);
};

class Theme : public QQuickPalette {
Q_OBJECT
public:
using QQuickPalette::QQuickPalette;
};

class LithStyle : public QQuickAttachedPropertyPropagator {
Q_OBJECT
QML_NAMED_ELEMENT(LithStyle)
QML_ATTACHED(LithStyle)
QML_UNCREATABLE("")

PROPERTY_PTR(Border, border, new Border(this))
PROPERTY(QColor, backgroundColor, Qt::transparent)

Q_PROPERTY(QColor frameBorderColor READ frameBorderColor NOTIFY paletteChanged)
public:
explicit LithStyle(QObject* parent = nullptr)
: QQuickAttachedPropertyPropagator(parent) {
}

static LithStyle* qmlAttachedProperties(QObject* object) {
return new LithStyle(object);
}

static void initialize() {
}

QColor frameBorderColor() const;
void setFrameBorderColor(const QColor& newFrameBorderColor);

signals:
void paletteChanged();

private:
QColor m_frameBorderColor = {255, 0, 0};
};

#endif // LITHSTYLE_H
32 changes: 32 additions & 0 deletions modules/Lith/Style/liththeme.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "liththeme.h"
#include <QtQuickTemplates2/private/qquicktheme_p.h>
#include <QFontInfo>

void LithTheme::initialize(QQuickTheme* theme) {
qCritical() << "HYR" << theme << theme->font(QQuickTheme::Scope::System);
QFont systemFont;
QFont groupBoxTitleFont;
QFont tabButtonFont;
theme->setUsePlatformPalette(false);
theme->setPalette(QQuickTheme::System, QPalette(Qt::red));

const QFont font(QLatin1String("Segoe UI"));
if (QFontInfo(font).family() == QLatin1String("Segoe UI")) {
const QStringList families {font.family()};
systemFont.setFamilies(families);
groupBoxTitleFont.setFamilies(families);
tabButtonFont.setFamilies(families);
}

systemFont.setPixelSize(15);
theme->setFont(QQuickTheme::System, systemFont);

groupBoxTitleFont.setPixelSize(15);
groupBoxTitleFont.setWeight(QFont::DemiBold);
theme->setFont(QQuickTheme::GroupBox, groupBoxTitleFont);

tabButtonFont.setPixelSize(24);
tabButtonFont.setWeight(QFont::Light);
theme->setFont(QQuickTheme::TabBar, tabButtonFont);
theme->setFont(QQuickTheme::Label, tabButtonFont);
}
12 changes: 12 additions & 0 deletions modules/Lith/Style/liththeme.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef LITHTHEME_H
#define LITHTHEME_H


class QQuickTheme;

class LithTheme {
public:
static void initialize(QQuickTheme* theme);
};

#endif // LITHTHEME_H

0 comments on commit 366fe0e

Please sign in to comment.