From 8dfeac448e2040247e13d7fa083c903aa75b9ed4 Mon Sep 17 00:00:00 2001 From: johanneshilden Date: Fri, 29 Sep 2017 00:28:08 +0300 Subject: [PATCH] Fix resource mess --- components/lib/qtmaterialtheme.cpp | 9 ++++++++- components/lib/qtmaterialtheme.h | 3 +++ components/resources.qrc | 5 ++++- examples/examples.pro | 6 ++++-- examples/examples.qrc | 5 +++++ examples/main.cpp | 2 ++ examples/mainwindow.cpp | 7 +++++-- examples/resources.qrc | 5 ----- 8 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 examples/examples.qrc delete mode 100644 examples/resources.qrc diff --git a/components/lib/qtmaterialtheme.cpp b/components/lib/qtmaterialtheme.cpp index d8de25d..725c954 100644 --- a/components/lib/qtmaterialtheme.cpp +++ b/components/lib/qtmaterialtheme.cpp @@ -1,8 +1,10 @@ #include "lib/qtmaterialtheme.h" #include "lib/qtmaterialtheme_p.h" +#include +#include #include -/*! +/*!material * \class QtMaterialThemePrivate * \internal */ @@ -150,3 +152,8 @@ void QtMaterialTheme::setColor(const QString &key, Material::Color color) d->colors.insert(key, palette[color]); } + +QIcon QtMaterialTheme::icon(QString category, QString icon) +{ + return QIcon(":/icons/icons/" % category % "/svg/production/ic_" % icon % "_24px.svg"); +} diff --git a/components/lib/qtmaterialtheme.h b/components/lib/qtmaterialtheme.h index c1210e4..fe4a11c 100644 --- a/components/lib/qtmaterialtheme.h +++ b/components/lib/qtmaterialtheme.h @@ -4,6 +4,7 @@ #include #include #include +#include namespace Material { @@ -330,6 +331,8 @@ public: void setColor(const QString &key, const QColor &color); void setColor(const QString &key, Material::Color color); + static QIcon icon(QString category, QString icon); + protected: const QScopedPointer d_ptr; diff --git a/components/resources.qrc b/components/resources.qrc index 7831d70..bf99339 100644 --- a/components/resources.qrc +++ b/components/resources.qrc @@ -1,5 +1,5 @@ - + ../fonts/Roboto/Roboto-Black.ttf ../fonts/Roboto/Roboto-Bold.ttf ../fonts/Roboto/Roboto-Medium.ttf @@ -7,4 +7,7 @@ ../fonts/Roboto/Roboto-Light.ttf ../fonts/Roboto/Roboto-Thin.ttf + + icons/communication/svg/production/ic_message_24px.svg + diff --git a/examples/examples.pro b/examples/examples.pro index 812ce56..c9c9857 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,8 +1,10 @@ QT += core gui widgets TEMPLATE = app SOURCES = mainwindow.cpp main.cpp -HEADERS = mainwindow.h +HEADERS = mainwindow.h LIBS += ../components/libcomponents.a INCLUDEPATH += ../components/ TARGET = ../examples-exe -RESOURCES += resources.qrc + +RESOURCES += \ + examples.qrc diff --git a/examples/examples.qrc b/examples/examples.qrc new file mode 100644 index 0000000..ba0747d --- /dev/null +++ b/examples/examples.qrc @@ -0,0 +1,5 @@ + + + assets/uxceo-128.jpg + + diff --git a/examples/main.cpp b/examples/main.cpp index e41b03d..38f8761 100644 --- a/examples/main.cpp +++ b/examples/main.cpp @@ -6,6 +6,8 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); + Q_INIT_RESOURCE(resources); + MainWindow window; window.show(); diff --git a/examples/mainwindow.cpp b/examples/mainwindow.cpp index 4e6f08f..4da74d9 100644 --- a/examples/mainwindow.cpp +++ b/examples/mainwindow.cpp @@ -1,14 +1,17 @@ #include "mainwindow.h" #include +#include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { QtMaterialAvatar *avatars[3]; - avatars[0] = new QtMaterialAvatar(QImage("../qt-material-widgets/examples/assets/uxceo-128.jpg")); + avatars[0] = new QtMaterialAvatar(QImage(":/images/assets/uxceo-128.jpg")); avatars[1] = new QtMaterialAvatar('W'); - avatars[2] = new QtMaterialAvatar(QIcon(":/icons/assets/ic_message_24px.svg")); + avatars[2] = new QtMaterialAvatar(QIcon(QtMaterialTheme::icon("communication", "message"))); QWidget *widget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; diff --git a/examples/resources.qrc b/examples/resources.qrc deleted file mode 100644 index 4bed9d1..0000000 --- a/examples/resources.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - assets/ic_message_24px.svg - -