From f3cc7a259bb78929284aea21eaab4fca661c5205 Mon Sep 17 00:00:00 2001 From: SeeLook <945374+SeeLook@users.noreply.github.com> Date: Tue, 7 Feb 2017 12:12:45 +0100 Subject: [PATCH] Get rid of QtWidgets dependency, using QtGui instead, Tcolor-s routines moved from header to definition file, make compile under Win --- src/CMakeLists.txt | 4 +- src/libs/core/CMakeLists.txt | 9 +++- src/libs/core/music/tinstrument.cpp | 10 ++-- src/libs/core/tcolor.cpp | 37 +++++++++++++- src/libs/core/tcolor.h | 76 ++++++++++++++--------------- src/libs/core/tglobals.cpp | 2 +- src/libs/core/tinitcorelib.cpp | 12 +++-- src/libs/core/tinitcorelib.h | 8 +-- src/libs/core/ttickcolors.h | 3 +- src/main.cpp | 8 +-- 10 files changed, 104 insertions(+), 65 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2bf14a2b7..34b01f7f0 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -20,7 +20,7 @@ endif(Qt5Gui_FOUND) find_package(Qt5Qml REQUIRED) find_package(Qt5Quick REQUIRED) find_package(Qt5QuickControls2 REQUIRED) -find_package(Qt5Widgets REQUIRED) +find_package(Qt5Gui REQUIRED) find_package(Qt5PrintSupport REQUIRED) @@ -93,7 +93,7 @@ target_link_libraries(nootka NootkaCore # NootkaScore Qt5::Core - Qt5::Widgets + Qt5::Gui Qt5::Qml Qt5::Quick Qt5::QuickControls2 diff --git a/src/libs/core/CMakeLists.txt b/src/libs/core/CMakeLists.txt index 52335caf8..4dfef33c9 100644 --- a/src/libs/core/CMakeLists.txt +++ b/src/libs/core/CMakeLists.txt @@ -15,7 +15,7 @@ set(LIB_NOOTKACORE_SRC tglobals.cpp tnoofont.cpp tpath.cpp - tmtr.cpp +# tmtr.cpp tnootkaqml.cpp ttickcolors.cpp @@ -55,7 +55,12 @@ set(LIB_NOOTKACORE_SRC add_library(NootkaCore SHARED ${LIB_NOOTKACORE_SRC} ) -target_link_libraries(NootkaCore Qt5::Widgets) +target_link_libraries(NootkaCore + Qt5::Gui + Qt5::Qml + Qt5::Quick + Qt5::QuickControls2 + ) if(UNIX AND NOT APPLE) # Linux path for Nootka library diff --git a/src/libs/core/music/tinstrument.cpp b/src/libs/core/music/tinstrument.cpp index c050849b0..19ce64a72 100644 --- a/src/libs/core/music/tinstrument.cpp +++ b/src/libs/core/music/tinstrument.cpp @@ -17,18 +17,18 @@ ***************************************************************************/ #include "tinstrument.h" -#include <QApplication> +#include <QtGui/qguiapplication.h> QString instrumentToText(Einstrument instr) { if (instr == e_noInstrument) - return QApplication::translate("Einstrument", "other instrument"); + return QGuiApplication::translate("Einstrument", "other instrument"); if (instr == e_classicalGuitar) - return QApplication::translate("Einstrument", "Classical Guitar"); + return QGuiApplication::translate("Einstrument", "Classical Guitar"); if (instr == e_electricGuitar) - return QApplication::translate("Einstrument", "Electric Guitar"); + return QGuiApplication::translate("Einstrument", "Electric Guitar"); if (instr == e_bassGuitar) - return QApplication::translate("Einstrument", "Bass Guitar"); + return QGuiApplication::translate("Einstrument", "Bass Guitar"); return ""; } diff --git a/src/libs/core/tcolor.cpp b/src/libs/core/tcolor.cpp index 4fa82c208..77201e29b 100644 --- a/src/libs/core/tcolor.cpp +++ b/src/libs/core/tcolor.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2014 by Tomasz Bojczuk * + * Copyright (C) 2014-2017 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -17,6 +17,8 @@ ***************************************************************************/ #include "tcolor.h" +#include <QtGui/qpalette.h> + QColor Tcolor::shadow = Qt::gray; @@ -30,3 +32,36 @@ void Tcolor::setShadow(const QPalette& pal) { shadow = pal.shadow().color(); #endif } + + +QColor Tcolor::merge(const QColor& C1, const QColor& C2) { + qreal al = iV(C1.alpha()) + iV(C2.alpha() * (1 - iV(C1.alpha()))); + return QColor(((iV(C1.red()) * iV(C1.alpha()) + iV(C2.red()) * iV(C2.alpha()) * (1 - iV(C1.alpha()))) / al) * 255, + ((iV(C1.green()) * iV(C1.alpha()) + iV(C2.green()) * iV(C2.alpha()) * (1 - iV(C1.alpha()))) / al) * 255, + ((iV(C1.blue()) * iV(C1.alpha()) + iV(C2.blue()) * iV(C2.alpha()) * (1 - iV(C1.alpha()))) / al) * 255, + qMin(255, (int)(255 * al))); +} + + +QColor Tcolor::invert(const QColor& color) { + QColor C = color; + if (C.isValid()) + C.setRgb(qRgb(255 - C.red(), 255 - C.green(), 255 - C.blue())); + return C; +} + + +QString Tcolor::rgbaText(const QColor& color, const QString& styleTag) { + return QString(styleTag + "rgba(%1, %2, %3, %4);").arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha()); +} + + +QString Tcolor::bgTag(const QColor& color) { + if (color != -1 && color.alpha() > 0) + return rgbaText(color, "background-color:"); + else + return QString("background-color: transparent; "); +} + + + diff --git a/src/libs/core/tcolor.h b/src/libs/core/tcolor.h index a0c994199..c5996c2b8 100644 --- a/src/libs/core/tcolor.h +++ b/src/libs/core/tcolor.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2014 by Tomasz Bojczuk * + * Copyright (C) 2014-2017 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -19,9 +19,13 @@ #ifndef TCOLOR_H #define TCOLOR_H + #include <nootkacoreglobal.h> -#include <QColor> -#include <QWidget> +#include <QtGui/qcolor.h> + + +class QPalette; + /** * A set of static methods with some tweaks of color: @@ -34,47 +38,39 @@ class NOOTKACORE_EXPORT Tcolor { public: - /** Merge given colors. */ - static QColor merge(const QColor& C1, const QColor& C2) { - qreal al = iV(C1.alpha()) + iV(C2.alpha() * (1 - iV(C1.alpha()))); - return QColor(((iV(C1.red()) * iV(C1.alpha()) + iV(C2.red()) * iV(C2.alpha()) * (1 - iV(C1.alpha()))) / al) * 255, - ((iV(C1.green()) * iV(C1.alpha()) + iV(C2.green()) * iV(C2.alpha()) * (1 - iV(C1.alpha()))) / al) * 255, - ((iV(C1.blue()) * iV(C1.alpha()) + iV(C2.blue()) * iV(C2.alpha()) * (1 - iV(C1.alpha()))) / al) * 255, - qMin(255, (int)(255 * al))); -} - - /** Returns inverted copy of given color */ - static QColor invert(const QColor& color) { - QColor C = color; - if (C.isValid()) - C.setRgb(qRgb(255 - C.red(), 255 - C.green(), 255 - C.blue())); - return C; - } - - /** Returns css style tag with rgba values of color. - * - * @p styleTag rgba(red, green, blue, alpha); - */ - static QString rgbaText(const QColor& color, const QString& styleTag = "") { - return QString(styleTag + "rgba(%1, %2, %3, %4);"). - arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha()); - } - - /** Returns - * background-color: rgba(red, green, blue, alpha) */ - static QString bgTag(const QColor& color) { - if (color != -1 && color.alpha() > 0) - return rgbaText(color, "background-color:"); - else - return QString("background-color: transparent; "); - } - - /** Converts value (0 - 255) to (0.0 - 1.0) */ + + /** + * Merge given colors. + */ + static QColor merge(const QColor& C1, const QColor& C2); + + /** + * Returns inverted copy of given color + */ + static QColor invert(const QColor& color); + + /** + * Returns css style tag with rgba values of color. + * @p styleTag rgba(red, green, blue, alpha); + */ + static QString rgbaText(const QColor& color, const QString& styleTag = QString()); + + /** + * Returns + * background-color: rgba(red, green, blue, alpha) + */ + static QString bgTag(const QColor& color); + + /** + * Converts value (0 - 255) to (0.0 - 1.0) + */ static qreal iV(int ch) { return ch / 255.0; } static QColor shadow; - /** Sets default shadow color of tips */ + /** + * Sets default shadow color of tips + */ static void setShadow(const QPalette& pal); }; diff --git a/src/libs/core/tglobals.cpp b/src/libs/core/tglobals.cpp index 0316f7a16..1eab6f0ef 100755 --- a/src/libs/core/tglobals.cpp +++ b/src/libs/core/tglobals.cpp @@ -87,7 +87,7 @@ Tglobals::Tglobals(QObject* parent) : new TtouchParams; #if defined(Q_OS_WIN32) || defined(Q_OS_MAC) // I hate mess in Win registry - config = new QSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral("Nootka")), qApp->applicationName()); + config = new QSettings(QSettings::IniFormat, QSettings::UserScope, QStringLiteral("Nootka"), qApp->applicationName()); #else config = new QSettings(); #endif diff --git a/src/libs/core/tinitcorelib.cpp b/src/libs/core/tinitcorelib.cpp index 0b57a9bef..d368992c1 100644 --- a/src/libs/core/tinitcorelib.cpp +++ b/src/libs/core/tinitcorelib.cpp @@ -22,8 +22,9 @@ #include "tcolor.h" #include "tscoreparams.h" #include "tpath.h" -#include <QtWidgets/qapplication.h> -#include <QtWidgets/qmessagebox.h> +#include <QtGui/qguiapplication.h> +#include <QtGui/qpalette.h> +// #include <QtWidgets/qmessagebox.h> #include <QtCore/qtranslator.h> #include <QtCore/qlibraryinfo.h> #include <QtGui/qfontdatabase.h> @@ -75,7 +76,7 @@ bool initCoreLibrary() { } -void prepareTranslations(QApplication* a, QTranslator& qt, QTranslator& noo) { +void prepareTranslations(QGuiApplication* a, QTranslator& qt, QTranslator& noo) { if (!Tcore::gl()) return; @@ -112,12 +113,13 @@ void prepareTranslations(QApplication* a, QTranslator& qt, QTranslator& noo) { } -bool loadNootkaFont(QApplication* a) { +bool loadNootkaFont(QGuiApplication* a) { QFontDatabase fd; int fid = fd.addApplicationFont(Tpath::main + QLatin1String("fonts/nootka.ttf")); int fid2 = fd.addApplicationFont(Tpath::main + QLatin1String("fonts/Scorek.otf")); if (fid == -1 || fid2 == -1) { - QMessageBox::critical(0, QString(), a->translate("main", "<center>Can not load a font.<br>Try to install nootka.ttf manually.</center>")); + qDebug() << "Can not load Nootka fonts!"; +// QMessageBox::critical(0, QString(), a->translate("main", "<center>Can not load a font.<br>Try to install nootka.ttf manually.</center>")); return false; } return true; diff --git a/src/libs/core/tinitcorelib.h b/src/libs/core/tinitcorelib.h index 19b1e93ef..cda823480 100755 --- a/src/libs/core/tinitcorelib.h +++ b/src/libs/core/tinitcorelib.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2014-2016 by Tomasz Bojczuk * + * Copyright (C) 2014-2017 by Tomasz Bojczuk * * seelook@gmail.com * * * * This program is free software; you can redistribute it and/or modify * @@ -24,7 +24,7 @@ class QTranslator; -class QApplication; +class QGuiApplication; class QStyle; /** @@ -61,10 +61,10 @@ NOOTKACORE_EXPORT bool initCoreLibrary(); /** Loads translations files for appropriate language (system or user preferred) * Translator object has to be created before. */ -NOOTKACORE_EXPORT void prepareTranslations(QApplication* a, QTranslator& qt, QTranslator& noo); +NOOTKACORE_EXPORT void prepareTranslations(QGuiApplication* a, QTranslator& qt, QTranslator& noo); /** Checks nootka.ttf file and loads it. Returns true if successful. * libNootkaCore has to be initialized first by initCoreLibrary() */ -NOOTKACORE_EXPORT bool loadNootkaFont(QApplication* a); +NOOTKACORE_EXPORT bool loadNootkaFont(QGuiApplication* a); #endif // TINITCORELIB_H diff --git a/src/libs/core/ttickcolors.h b/src/libs/core/ttickcolors.h index d24f90d77..3b34f2ea0 100644 --- a/src/libs/core/ttickcolors.h +++ b/src/libs/core/ttickcolors.h @@ -20,12 +20,13 @@ #define TTICKCOLORS_H +#include "nootkacoreglobal.h" #include <QtCore/QObject> #include <QtGui/QColor> #include <QtCore/QDebug> -class TtickColors : public QObject +class NOOTKACORE_EXPORT TtickColors : public QObject { Q_OBJECT diff --git a/src/main.cpp b/src/main.cpp index 5dec9cee2..6f9fe5d40 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,7 +23,7 @@ #include <tinitcorelib.h> #include <tpath.h> #include <tmtr.h> -#include <QtWidgets/qapplication.h> +#include <QtGui/qguiapplication.h> #include <QtGui/qicon.h> #include <QtQml/qqmlapplicationengine.h> #include <QtQml/qqmlcontext.h> @@ -75,7 +75,7 @@ int main(int argc, char *argv[]) QTranslator qtTranslator; QTranslator nooTranslator; - QPointer<QApplication> a = 0; + QPointer<QGuiApplication> a = nullptr; QQmlApplicationEngine *e = nullptr; Tpath pathObj; TnootkaQML nooObj; @@ -93,8 +93,8 @@ int main(int argc, char *argv[]) } resetConfig = false; #endif - a = new QApplication(argc, argv); - Tmtr::init(a); + a = new QGuiApplication(argc, argv); +// Tmtr::init(a); gl = new Tglobals(); gl->path = Tglobals::getInstPath(qApp->applicationDirPath()); -- GitLab