diff options
author | Lasse Räihä <lasse.raiha@qt.io> | 2017-09-21 14:44:43 +0300 |
---|---|---|
committer | Sami Nurmenniemi <sami.nurmenniemi@qt.io> | 2017-11-22 10:42:41 +0000 |
commit | c0a91aab1a5e5ac4a0e6effcd410e43bd8b6cc16 (patch) | |
tree | 60c54024bfbab4f5ef31aa684b2562aea6648259 /src | |
parent | d2ec2dc7034c31e3602003b55d5f2a2c98983651 (diff) |
Launcher update
Task-number: QTBUG-63091
Done-with: Juho Annunen <juho.annunen@qt.io>
Change-Id: I4395becf8539e95ab3fa90b03e71565a2d087398
Reviewed-by: Kari Oikarinen <kari.oikarinen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/applicationsettings.cpp | 8 | ||||
-rw-r--r-- | src/applicationsettings.h | 6 | ||||
-rw-r--r-- | src/circularindicator.cpp | 241 | ||||
-rw-r--r-- | src/circularindicator.h | 99 | ||||
-rw-r--r-- | src/engine.cpp | 20 | ||||
-rw-r--r-- | src/engine.h | 13 | ||||
-rw-r--r-- | src/imageproviders.cpp | 155 | ||||
-rw-r--r-- | src/imageproviders.h | 55 | ||||
-rw-r--r-- | src/main.cpp | 37 | ||||
-rw-r--r-- | src/settingsmanager.cpp | 80 | ||||
-rw-r--r-- | src/settingsmanager.h | 63 |
11 files changed, 725 insertions, 52 deletions
diff --git a/src/applicationsettings.cpp b/src/applicationsettings.cpp index 4fe7473..2811213 100644 --- a/src/applicationsettings.cpp +++ b/src/applicationsettings.cpp @@ -34,7 +34,6 @@ ApplicationSettings::ApplicationSettings(QObject *parent) : QObject(parent) , m_mainFile(QUrl(QStringLiteral("qrc:///qml/Main.qml"))) , m_appsRoot("/data/user/qt") - , m_isBootAnimationEnabled(true) , m_isShowFPSEnabled(false) { } @@ -44,11 +43,6 @@ QString ApplicationSettings::appsRoot() const return m_appsRoot; } -bool ApplicationSettings::isBootAnimationEnabled() const -{ - return m_isBootAnimationEnabled; -} - bool ApplicationSettings::isShowFPSEnabled() const { return m_isShowFPSEnabled; @@ -64,8 +58,6 @@ bool ApplicationSettings::parseCommandLineArguments() } else if (args.at(i) == QStringLiteral("--applications-root")) { ++i; m_appsRoot = args.at(i); - } else if (args.at(i) == QStringLiteral("--no-boot-animation")) { - m_isBootAnimationEnabled = false; } else if (args.at(i) == QStringLiteral("--show-fps")) { m_isShowFPSEnabled = true; } else if (args.at(i) == QStringLiteral("-h") diff --git a/src/applicationsettings.h b/src/applicationsettings.h index 6b63c75..70e22c3 100644 --- a/src/applicationsettings.h +++ b/src/applicationsettings.h @@ -38,30 +38,24 @@ class ApplicationSettings : public QObject Q_OBJECT Q_PROPERTY(QUrl mainFile READ mainFile NOTIFY mainFileChanged) Q_PROPERTY(QString appsRoot READ appsRoot NOTIFY appsRootChanged) - Q_PROPERTY(bool isBootAnimationEnabled READ isBootAnimationEnabled NOTIFY isBootAnimationEnabledChanged) Q_PROPERTY(bool isShowFPSEnabled READ isShowFPSEnabled NOTIFY isShowFPSEnabledChanged) public: explicit ApplicationSettings(QObject *parent = 0); QUrl mainFile() const; QString appsRoot() const; - bool isBootAnimationEnabled() const; bool isShowFPSEnabled() const; bool parseCommandLineArguments(); - - signals: void mainFileChanged(QUrl newFile); void appsRootChanged(QString appRoot); - void isBootAnimationEnabledChanged(bool isEnabled); void isShowFPSEnabledChanged(bool isEnabled); private: QUrl m_mainFile; QString m_appsRoot; - bool m_isBootAnimationEnabled; bool m_isShowFPSEnabled; }; diff --git a/src/circularindicator.cpp b/src/circularindicator.cpp new file mode 100644 index 0000000..a3ec477 --- /dev/null +++ b/src/circularindicator.cpp @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "circularindicator.h" + +CircularIndicator::CircularIndicator(QQuickItem *parent) + : QQuickPaintedItem(parent) + , mStartAngle(0) + , mEndAngle(360) + , mMinimumValue(0.0) + , mMaximumValue(360.0) + , mValue(0.0) + , mLineWidth(10) + , mProgressColor(QColor(255, 0, 0)) + , mBackgroundColor(QColor(240, 240, 240)) + , mPadding(1) +{ +} + +CircularIndicator::~CircularIndicator() +{ +} + +int CircularIndicator::startAngle() const +{ + return mStartAngle; +} + +void CircularIndicator::setStartAngle(int angle) +{ + if (angle == mStartAngle) + return; + + mStartAngle = angle; + emit startAngleChanged(mStartAngle); + update(); +} + +int CircularIndicator::endAngle() const +{ + return mEndAngle; +} + +void CircularIndicator::setEndAngle(int angle) +{ + if (angle == mEndAngle) + return; + + mEndAngle = angle; + emit endAngleChanged(mEndAngle); + update(); +} + +qreal CircularIndicator::minimumValue() const +{ + return mMinimumValue; +} + +void CircularIndicator::setMinimumValue(qreal value) +{ + if (qFuzzyCompare(value, mMinimumValue)) + return; + + if (value > mMaximumValue) { + qWarning() << this << "\nMinimum value can't exceed maximum value."; + return; + } + + mMinimumValue = value; + emit minimumValueChanged(mMinimumValue); + update(); +} + +qreal CircularIndicator::maximumValue() const +{ + return mMaximumValue; +} + +void CircularIndicator::setMaximumValue(qreal value) +{ + if (qFuzzyCompare(value, mMaximumValue)) + return; + + if (value < mMinimumValue) { + qWarning() << this << "\nMaximum value can't be less than minimum value."; + return; + } + + mMaximumValue = value; + emit maximumValueChanged(value); + update(); +} + +qreal CircularIndicator::value() const +{ + return mValue; +} + +void CircularIndicator::setValue(qreal value) +{ + if (qFuzzyCompare(value, mValue)) + return; + + if (value < mMinimumValue) { + qWarning() << this << "\nValue can't be less than minimum value."; + return; + } + + if (value > mMaximumValue) { + qWarning() << this << "\nValue can't exceed maximum value."; + return; + } + + mValue = value; + emit valueChanged(mValue); + update(); +} + +int CircularIndicator::lineWidth() const +{ + return mLineWidth; +} + +void CircularIndicator::setLineWidth(int width) +{ + if (width == mLineWidth) + return; + + mLineWidth = width; + emit lineWidthChanged(mLineWidth); + update(); +} + +QColor CircularIndicator::progressColor() const +{ + return mProgressColor; +} + +void CircularIndicator::setProgressColor(QColor color) +{ + if (color == mProgressColor) + return; + + mProgressColor = color; + emit progressColorChanged(mProgressColor); + update(); +} + +QColor CircularIndicator::backgroundColor() const +{ + return mBackgroundColor; +} + +void CircularIndicator::setBackgroundColor(QColor color) +{ + if (color == mBackgroundColor) + return; + + mBackgroundColor = color; + emit backgroundColorChanged(mBackgroundColor); + update(); +} + +int CircularIndicator::padding() const +{ + return mPadding; +} + +void CircularIndicator::setPadding(int padding) +{ + if (padding == mPadding) + return; + + mPadding = padding; + emit paddingChanged(mPadding); + update(); +} + +void CircularIndicator::paint(QPainter *painter) +{ + painter->setRenderHint(QPainter::Antialiasing); + + int indicatorSize = qMin(width(), height()) - mPadding * 2 - mLineWidth; + + if (indicatorSize <= 0) + return; + + QRect indicatorRect(width() / 2 - indicatorSize / 2, + height() / 2 - indicatorSize / 2, + indicatorSize, + indicatorSize); + + QPen pen; + pen.setCapStyle(Qt::FlatCap); + pen.setWidth(mLineWidth); + pen.setColor(mBackgroundColor); + painter->setPen(pen); + + int endAngle = (qAbs(mEndAngle) > 360) ? mEndAngle % 360 : mEndAngle; + + // See http://doc.qt.io/qt-5/qpainter.html#drawArc for details + int minimumAngle = (90 - mStartAngle) * 16; + int maximumAngle = (90 - endAngle) * 16 - minimumAngle; + + painter->drawArc(indicatorRect, 0, 360 * 16); + + if (qFuzzyCompare(mValue, mMinimumValue)) + return; + + pen.setColor(mProgressColor); + painter->setPen(pen); + + int currentAngle = ((mValue - mMinimumValue) / (mMaximumValue - mMinimumValue)) * maximumAngle; + + painter->drawArc(indicatorRect, minimumAngle, currentAngle); +} diff --git a/src/circularindicator.h b/src/circularindicator.h new file mode 100644 index 0000000..f9adcdc --- /dev/null +++ b/src/circularindicator.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CIRCULARINDICATOR_H +#define CIRCULARINDICATOR_H + +#include <QQuickPaintedItem> +#include <QPainter> + +class CircularIndicator : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(int startAngle READ startAngle WRITE setStartAngle NOTIFY startAngleChanged) + Q_PROPERTY(int endAngle READ endAngle WRITE setEndAngle NOTIFY endAngleChanged) + Q_PROPERTY(qreal minimumValue READ minimumValue WRITE setMinimumValue NOTIFY minimumValueChanged) + Q_PROPERTY(qreal maximumValue READ maximumValue WRITE setMaximumValue NOTIFY maximumValueChanged) + Q_PROPERTY(qreal value READ value WRITE setValue NOTIFY valueChanged) + Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth NOTIFY lineWidthChanged) + Q_PROPERTY(QColor progressColor READ progressColor WRITE setProgressColor NOTIFY progressColorChanged) + Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged) + Q_PROPERTY(int padding READ padding WRITE setPadding NOTIFY paddingChanged) + +public: + CircularIndicator(QQuickItem *parent = 0); + ~CircularIndicator(); + + int startAngle() const; + int endAngle() const; + qreal minimumValue() const; + qreal maximumValue() const; + qreal value() const; + int lineWidth() const; + QColor progressColor() const; + QColor backgroundColor() const; + int padding() const; + +public slots: + void setStartAngle(int angle); + void setEndAngle(int angle); + void setMinimumValue(qreal value); + void setMaximumValue(qreal value); + void setValue(qreal value); + void setLineWidth(int width); + void setProgressColor(QColor color); + void setBackgroundColor(QColor color); + void setPadding(int padding); + +signals: + void startAngleChanged(int); + void endAngleChanged(int); + void minimumValueChanged(qreal); + void maximumValueChanged(qreal); + void valueChanged(qreal); + void lineWidthChanged(int); + void progressColorChanged(QColor); + void backgroundColorChanged(QColor); + void paddingChanged(int); + +protected: + void paint(QPainter *painter); + +private: + int mStartAngle; + int mEndAngle; + qreal mMinimumValue; + qreal mMaximumValue; + qreal mValue; + int mLineWidth; + QColor mProgressColor; + QColor mBackgroundColor; + int mPadding; +}; + +#endif // CIRCULARINDICATOR_H diff --git a/src/engine.cpp b/src/engine.cpp index e37cf57..b30e75a 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -42,7 +42,6 @@ #include <QQuickWindow> -#define ENGINE_STATE_BOOTING QStringLiteral("booting") #define ENGINE_STATE_RUNNING QStringLiteral("running") #define ENGINE_STATE_SETTINGS QStringLiteral("settings") @@ -57,10 +56,9 @@ Engine::Engine(QQuickItem *parent) , m_intro_done(false) , m_apps_ready(false) , m_fps_enabled(false) - , m_bootAnimationEnabled(true) , m_glAvailable(true) { - m_state = ENGINE_STATE_BOOTING; + m_state = ENGINE_STATE_RUNNING; QScreen *screen = QGuiApplication::primaryScreen(); m_screenSize = screen->size(); @@ -117,16 +115,6 @@ void Engine::setState(const QString &state) emit stateChanged(m_state); } - -void Engine::setBootAnimationEnabled(bool enabled) -{ - if (m_bootAnimationEnabled == enabled) - return; - - m_bootAnimationEnabled = enabled; - emit bootAnimationEnabledChanged(enabled); -} - int Engine::titleBarSize() const { return int(QGuiApplication::primaryScreen()->physicalDotsPerInch() / 2.54f); @@ -180,7 +168,7 @@ bool Engine::fileExists(const QUrl &fileName) return file.exists(); } -void Engine::launchApplication(const QUrl &path, const QString &mainFile, const QString &name) +void Engine::launchApplication(const QUrl &path, const QString &mainFile, const QString &name, const QString &desc) { // only launch apps when in the homescreen... if (m_state != QStringLiteral("running")) @@ -189,9 +177,11 @@ void Engine::launchApplication(const QUrl &path, const QString &mainFile, const m_applicationMain = m_applicationUrl = path; m_applicationMain.setPath(path.path() + "/" + mainFile); m_applicationName = name; + m_applicationDescription = desc; emit applicationUrlChanged(m_applicationUrl); emit applicationMainChanged(m_applicationMain); emit applicationNameChanged(m_applicationName); + emit applicationDescriptionChanged(m_applicationName); setState(ENGINE_STATE_APPLAUNCHING); } @@ -201,9 +191,11 @@ void Engine::closeApplication() m_applicationMain = m_applicationUrl = QUrl(); m_applicationName = QString(); + m_applicationDescription = QString(); emit applicationUrlChanged(m_applicationUrl); emit applicationMainChanged(m_applicationMain); emit applicationNameChanged(m_applicationName); + emit applicationDescriptionChanged(m_applicationName); setState(ENGINE_STATE_RUNNING); } diff --git a/src/engine.h b/src/engine.h index d327f29..ac8a202 100644 --- a/src/engine.h +++ b/src/engine.h @@ -45,11 +45,10 @@ class Engine : public QQuickItem Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged) - Q_PROPERTY(bool bootAnimationEnabled READ isBootAnimationEnabled WRITE setBootAnimationEnabled NOTIFY bootAnimationEnabledChanged) - Q_PROPERTY(QUrl applicationMain READ applicationMain NOTIFY applicationMainChanged) Q_PROPERTY(QUrl applicationUrl READ applicationUrl NOTIFY applicationUrlChanged) Q_PROPERTY(QString applicationName READ applicationName NOTIFY applicationNameChanged) + Q_PROPERTY(QString applicationDescription READ applicationDescription NOTIFY applicationDescriptionChanged) Q_PROPERTY(bool fpsEnabled READ isFpsEnabled WRITE setFpsEnabled NOTIFY fpsEnabledChanged) Q_PROPERTY(qreal fps READ fps NOTIFY fpsChanged) @@ -69,14 +68,12 @@ public: qreal fps() const { return m_fps; } - bool isBootAnimationEnabled() const { return m_bootAnimationEnabled; } - void setBootAnimationEnabled(bool enabled); - QString qtVersion() const { return QT_VERSION_STR; } QUrl applicationUrl() const { return m_applicationUrl; } QUrl applicationMain() const { return m_applicationMain; } QString applicationName() const { return m_applicationName; } + QString applicationDescription() const { return m_applicationDescription; } Q_INVOKABLE QUrl fromUserInput(const QString& userInput) { return QUrl::fromUserInput(userInput); } Q_INVOKABLE int sensibleButtonSize() const; @@ -98,7 +95,7 @@ signals: void applicationUrlChanged(const QUrl &applicationUrl); void applicationMainChanged(const QUrl &applicationMain); void applicationNameChanged(const QString &applicationName); - void bootAnimationEnabledChanged(bool enabled); + void applicationDescriptionChanged(const QString &applicationName); void fpsChanged(qreal fps); void fpsEnabledChanged(bool enabled); void glAvailableChanged(bool available); @@ -107,7 +104,7 @@ public slots: void markApplicationsModelReady() { m_apps_ready = true; updateReadyness(); } void markIntroAnimationDone() { m_intro_done = true; updateReadyness(); } - void launchApplication(const QUrl &location, const QString &mainFile, const QString &name); + void launchApplication(const QUrl &location, const QString &mainFile, const QString &name, const QString &desc); void closeApplication(); void setFps(qreal fps); @@ -126,6 +123,7 @@ private: QUrl m_applicationUrl; QUrl m_applicationMain; QString m_applicationName; + QString m_applicationDescription; QSize m_screenSize; qreal m_dpcm; @@ -137,7 +135,6 @@ private: uint m_intro_done : 1; uint m_apps_ready : 1; uint m_fps_enabled : 1; - uint m_bootAnimationEnabled : 1; bool m_glAvailable; }; diff --git a/src/imageproviders.cpp b/src/imageproviders.cpp new file mode 100644 index 0000000..1fef429 --- /dev/null +++ b/src/imageproviders.cpp @@ -0,0 +1,155 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "imageproviders.h" + +#include <QImage> +#include <QPixmap> +#include <QPen> +#include <QBrush> +#include <QPainter> +#include <QLinearGradient> + +static const int CORNER_CUTSIZE = 20; +static const int BORDERSIZE = 3; + +void cutEdges(QImage &image, int cutSize) +{ + if (!image.isNull()) { + const int w = image.width()-1; + const int h = image.height()-1; + if (w >= cutSize && h >= cutSize) { + for (int y=0; y <= cutSize; y++) { + for (int x=0; x <= (cutSize - y); x++) { + image.setPixelColor(x, y, QColor(Qt::transparent)); + image.setPixelColor(w - x, h - y, QColor(Qt::transparent)); + } + } + } + } +} + +void drawBorders(QPainter& painter, int w, int h, int cutSize, const QColor &color) +{ + QPen pen; + pen.setCosmetic(true); + pen.setWidth(3); + pen.setColor(color); + + painter.setPen(pen); + painter.setBrush(Qt::NoBrush); + + QPainterPath path; + path.moveTo(cutSize + 1, 1); + path.lineTo(w - 1, 1); + path.lineTo(w - 1, h - cutSize - 1); + path.lineTo(w - cutSize - 1, h - 1); + path.lineTo(1, h - 1); + path.lineTo(1, cutSize + 1); + path.lineTo(cutSize + 1, 1); + path.closeSubpath(); + painter.drawPath(path); +} + +QtImageProvider::QtImageProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) +{ +} + +QPixmap QtImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) +{ + Q_UNUSED(size); + Q_UNUSED(requestedSize); + + QString idd = id; + idd.remove("file://"); + + QImage image(idd); + if (!image.isNull()) { + image = image.copy(BORDERSIZE, BORDERSIZE, image.width() - BORDERSIZE * 2, image.height() - BORDERSIZE * 2) + .convertToFormat(QImage::Format_ARGB32); + cutEdges(image, CORNER_CUTSIZE); + } + + return QPixmap::fromImage(image); +} + +QtSquareImageProvider::QtSquareImageProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) +{ +} + +QPixmap QtSquareImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) +{ + Q_UNUSED(size); + Q_UNUSED(requestedSize); + + QString idd = id; + idd.remove("file://"); + + QImage image(idd); + if (!image.isNull()) { + const int min = qMin(image.width(), image.height()); + image = image.copy(BORDERSIZE, BORDERSIZE, min - BORDERSIZE * 2, min - BORDERSIZE * 2) + .scaled(requestedSize.width(), requestedSize.height()) + .convertToFormat(QImage::Format_ARGB32); + cutEdges(image, CORNER_CUTSIZE); + } + + return QPixmap::fromImage(image); +} + +QtImageMaskProvider::QtImageMaskProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) +{ +} + +QPixmap QtImageMaskProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) +{ + Q_UNUSED(size); + + if (requestedSize.width() <= 0) + return QPixmap(1, 1); + + QImage image(requestedSize.width(), requestedSize.height(), QImage::Format_ARGB32); + image.fill(Qt::transparent); + + QPainter p(&image); + + if (id.contains("hover")) { + QRect r = image.rect().adjusted(1, 1, -1, -1); + QLinearGradient gradient(r.topLeft(), r.bottomRight()); + gradient.setColorAt(0, Qt::transparent); + gradient.setColorAt(1, QColor("#9941cd52")); + p.fillRect(r, gradient); + } + + if (id.contains("namebox")) + p.fillRect(QRectF(0, image.height() * 0.65, image.width(), image.height() * 0.35), QBrush(QColor("#99000000"))); + + cutEdges(image, CORNER_CUTSIZE); + drawBorders(p, image.width(), image.height(), CORNER_CUTSIZE, QColor("#41cd52")); + return QPixmap::fromImage(image); +} diff --git a/src/imageproviders.h b/src/imageproviders.h new file mode 100644 index 0000000..89ac6d1 --- /dev/null +++ b/src/imageproviders.h @@ -0,0 +1,55 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef IMAGEPROVIDERS_H +#define IMAGEPROVIDERS_H + +#include <QQuickImageProvider> + + +class QtImageProvider : public QQuickImageProvider +{ +public: + QtImageProvider(); + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); +}; + +class QtSquareImageProvider : public QQuickImageProvider +{ +public: + QtSquareImageProvider(); + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); +}; + +class QtImageMaskProvider : public QQuickImageProvider +{ +public: + QtImageMaskProvider(); + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize); +}; +#endif // IMAGEPROVIDERS_H diff --git a/src/main.cpp b/src/main.cpp index 55281cc..ac9e66b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -44,6 +44,9 @@ #include "engine.h" #include "applicationsmodel.h" #include "applicationsettings.h" +#include "settingsmanager.h" +#include "imageproviders.h" +#include "circularindicator.h" void displayHelp(const char *appName) { @@ -53,7 +56,6 @@ void displayHelp(const char *appName) "Options:\n" " --main-file [qml-file] Launches an alternative QML file\n" " --applications-root [path] Specify a different applications root\n" - " --no-boot-animation Disable startup animation\n" " --show-fps Show FPS\n" , appName ); @@ -61,10 +63,9 @@ void displayHelp(const char *appName) int main(int argc, char **argv) { - QApplication app(argc, argv); + qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); - //Use Flat style for Qt Quick Controls by default - qputenv("QT_QUICK_CONTROLS_STYLE", "Flat"); + QApplication app(argc, argv); #if defined(USE_QTWEBENGINE) // This is currently needed by all QtWebEngine applications using the HW accelerated QQuickWebView. @@ -73,16 +74,11 @@ int main(int argc, char **argv) QtWebEngine::initialize(); #endif - QString fontName = QStringLiteral("/system/lib/fonts/DejaVuSans.ttf"); - if (QFile::exists(fontName)) { - QFontDatabase::addApplicationFont(fontName); - QFont font("DejaVu Sans"); - QGuiApplication::setFont(font); - } else { - QFont font; - font.setStyleHint(QFont::SansSerif); - QGuiApplication::setFont(font); - } + QFontDatabase::addApplicationFont(":/qml/fonts/TitilliumWeb-Light.ttf"); + QFontDatabase::addApplicationFont(":/qml/fonts/TitilliumWeb-Regular.ttf"); + QFontDatabase::addApplicationFont(":/qml/fonts/TitilliumWeb-SemiBold.ttf"); + QFontDatabase::addApplicationFont(":/qml/fonts/TitilliumWeb-Bold.ttf"); + QFontDatabase::addApplicationFont(":/qml/fonts/TitilliumWeb-Black.ttf"); ApplicationSettings applicationSettings; @@ -93,17 +89,26 @@ int main(int argc, char **argv) qDebug() << "Main File:" << applicationSettings.mainFile(); qDebug() << "Applications Root:" << applicationSettings.appsRoot(); - qDebug() << "Boot Animation:" << (applicationSettings.isBootAnimationEnabled() ? "yes" : "no"); qDebug() << "Show FPS:" << (applicationSettings.isShowFPSEnabled() ? "yes" : "no"); qmlRegisterType<ApplicationsModel>("com.qtcompany.B2QtLauncher", 1, 0, "LauncherApplicationsModel"); qmlRegisterType<Engine>("com.qtcompany.B2QtLauncher", 1, 0, "LauncherEngine"); + qmlRegisterType<CircularIndicator>("Circle", 1, 0, "CircularIndicator"); QQmlApplicationEngine engine; + SettingsManager settings; + QtImageProvider imageProvider; + QtSquareImageProvider squareImageProvider; + QtImageMaskProvider imageMaskProvider; + + engine.addImageProvider("QtImage", &imageProvider); + engine.addImageProvider("QtSquareImage", &squareImageProvider); + engine.addImageProvider("QtImageMask", &imageMaskProvider); + engine.rootContext()->setContextProperty("globalSettings", &settings); engine.rootContext()->setContextProperty("applicationSettings", &applicationSettings); engine.rootContext()->setContextProperty("qpa_platform", qGuiApp->platformName()); engine.load(applicationSettings.mainFile()); - app.exec(); + return app.exec(); } diff --git a/src/settingsmanager.cpp b/src/settingsmanager.cpp new file mode 100644 index 0000000..a5f2160 --- /dev/null +++ b/src/settingsmanager.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "settingsmanager.h" + +SettingsManager::SettingsManager(QObject *parent) : + QObject(parent), + m_settings("The Qt Company", "Qt Demo Launcher") +{ +} + +SettingsManager::~SettingsManager() +{ + m_settings.sync(); +} + +QVariant SettingsManager::getValue(const QString &key, const QVariant &defaultValue) +{ + return m_settings.value(key, defaultValue); +} + +void SettingsManager::setValue(const QString &key, const QVariant &value) +{ + m_settings.setValue(key, value); + m_settings.sync(); +} + + +bool SettingsManager::gridSelected() +{ + return getValue("gridSelected", false).toBool(); +} + +void SettingsManager::setGridSelected(bool enabled) +{ + if (gridSelected() == enabled) + return; + + setValue("gridSelected", enabled); + emit gridSelectedChanged(enabled); +} + +bool SettingsManager::mouseSelected() +{ + return getValue("mouseSelected", false).toBool(); +} + +void SettingsManager::setMouseSelected(bool enabled) +{ + if (mouseSelected() == enabled) + return; + + setValue("mouseSelected", enabled); + emit mouseSelectedChanged(enabled); +} diff --git a/src/settingsmanager.h b/src/settingsmanager.h new file mode 100644 index 0000000..f54ac77 --- /dev/null +++ b/src/settingsmanager.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt for Device Creation. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef SETTINGSMANAGER_H +#define SETTINGSMANAGER_H + +#include <QObject> +#include <QSettings> + +class SettingsManager : public QObject +{ + Q_OBJECT +public: + explicit SettingsManager(QObject *parent = 0); + ~SettingsManager(); + + Q_INVOKABLE QVariant getValue(const QString& key, const QVariant &defaultValue); + Q_INVOKABLE void setValue(const QString& key, const QVariant &value); + + Q_PROPERTY(bool gridSelected READ gridSelected WRITE setGridSelected NOTIFY gridSelectedChanged) + + bool gridSelected(); + void setGridSelected(bool enabled); + + Q_PROPERTY (bool mouseSelected READ mouseSelected WRITE setMouseSelected NOTIFY mouseSelectedChanged) + + bool mouseSelected(); + void setMouseSelected(bool enabled); + +signals: + void gridSelectedChanged(bool enabled); + void mouseSelectedChanged(bool enabled); + +private: + QSettings m_settings; +}; + +#endif // SETTINGSMANAGER_H |