diff options
Diffstat (limited to 'examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider')
6 files changed, 330 insertions, 0 deletions
diff --git a/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/CMakeLists.txt b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/CMakeLists.txt new file mode 100644 index 0000000..9e62cda --- /dev/null +++ b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/CMakeLists.txt @@ -0,0 +1,32 @@ +# There are a number of options to qt_add_qml_module that start with capital NO. +# The most prominent NO option is probably NO_GENERATE_PLUGIN_SOURCE. +# Unfortunately image providers still need to be configured per QML engine. +# Therefore, if you bundle an image provider in your QML module, you need to implement +# the QQmlEngineExtensionPlugin::initializeEngine() method. +# This, in turn, makes it necessary to write your own plugin. +# In this example the plugin is in the QtButtonImageProvider class. + +qt_add_qml_module(qtbuttonimageproviderplugin + URI "DeviceUtilities.QtButtonImageProvider" + VERSION 1.0 + PLUGIN_TARGET qtbuttonimageproviderplugin + NO_PLUGIN_OPTIONAL + NO_GENERATE_PLUGIN_SOURCE + CLASS_NAME QtButtonImageProviderPlugin + SOURCES + plugin.cpp plugin_p.h + qtbuttonimageprovider.cpp qtbuttonimageprovider.h + QML_FILES + "QtButton.qml" +) + +target_link_libraries(qtbuttonimageproviderplugin PRIVATE + Qt::Quick +) + +install(TARGETS qtbuttonimageproviderplugin + DESTINATION "${INSTALL_EXAMPLEDIR}/DeviceUtilities/QtButtonImageProvider" +) +install(FILES $<TARGET_FILE_DIR:qtbuttonimageproviderplugin>/qmldir + DESTINATION "${INSTALL_EXAMPLEDIR}/DeviceUtilities/QtButtonImageProvider" +) diff --git a/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/QtButton.qml b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/QtButton.qml new file mode 100644 index 0000000..60e16ff --- /dev/null +++ b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/QtButton.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $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$ +** +****************************************************************************/ +import QtQuick +import DeviceUtilities.SettingsUI + +Image { + id: root + source: "image://QtButton/" + cutSize + "/" + fillColor + "/" + borderColor + sourceSize: Qt.size(width, height) + property string state: "enabled" + property int cutSize: 10 + property color fillColor: Globals.buttonGreenColor + property color borderColor: mouseArea.pressed ? Globals.buttonActiveColor : Globals.buttonGreenColor + property alias text: buttonText.text + property alias fontFamily: buttonText.font.family + signal clicked() + + width: buttonText.contentWidth + cutSize * 4 + + MouseArea { + id: mouseArea + anchors.fill: parent + onClicked: root.clicked() + } + Text { + id: buttonText + anchors.fill: parent + verticalAlignment: Text.AlignVCenter + horizontalAlignment: Text.AlignHCenter + font.pixelSize: parent.height * 0.65 + //font.family: Globals.appFont + color: "white" + } +} diff --git a/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/plugin.cpp b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/plugin.cpp new file mode 100644 index 0000000..30ede2a --- /dev/null +++ b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/plugin.cpp @@ -0,0 +1,29 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $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 "plugin_p.h" diff --git a/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/plugin_p.h b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/plugin_p.h new file mode 100644 index 0000000..96f64ad --- /dev/null +++ b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/plugin_p.h @@ -0,0 +1,62 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $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 QTBUTTONIMAGEPROVIDERQMLPLUGIN_H +#define QTBUTTONIMAGEPROVIDERQMLPLUGIN_H + +#include "qtbuttonimageprovider.h" +#include <qqmlextensionplugin.h> + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists for the convenience +// of other Qt classes. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +QT_BEGIN_NAMESPACE + +class QtButtonImageProviderQmlPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid) + +public: + void initializeEngine(QQmlEngine *engine, const char *uri) final + { + Q_UNUSED(uri); + engine->addImageProvider("QtButton", new QtButtonImageProvider); + } +}; + +QT_END_NAMESPACE +#endif //QTBUTTONIMAGEPROVIDERQMLPLUGIN_H diff --git a/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/qtbuttonimageprovider.cpp b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/qtbuttonimageprovider.cpp new file mode 100644 index 0000000..65566a5 --- /dev/null +++ b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/qtbuttonimageprovider.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $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 <QImage> +#include <QPainter> +#include <QPainterPath> + +#include "qtbuttonimageprovider.h" + +QtButtonImageProvider::QtButtonImageProvider() + : QQuickImageProvider(QQuickImageProvider::Pixmap) +{ +} + +QPixmap QtButtonImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) +{ + bool ok = false; + + QStringList params = id.split("/"); + + int cutSize = params.at(0).toInt(&ok); + + if (!ok) + cutSize = 10; + + QColor fillColor; + QColor borderColor; + + if (params.length() > 1) { + fillColor = QColor(params.at(1)); + } + + if (params.length() > 2) + borderColor = QColor(params.at(2)); + + if (!fillColor.isValid()) + fillColor = "#00eb00"; + + if (!borderColor.isValid()) + borderColor ="white"; + + int width = 100; + int height = 50; + + if (size) + *size = QSize(requestedSize.width(), requestedSize.height()); + + QPixmap pixmap(requestedSize.width() > 0 ? requestedSize.width() : width, + requestedSize.height() > 0 ? requestedSize.height() : height); + pixmap.fill(Qt::transparent); + + QPainter painter(&pixmap); + const qreal borderPenWidth = 2; + QPen borderPen(QBrush(borderColor), borderPenWidth); + borderPen.setJoinStyle(Qt::MiterJoin); + painter.setRenderHint(QPainter::Antialiasing, true); + painter.setPen(borderPen); + painter.setBrush(fillColor); + + QPainterPath path; + qreal top = borderPenWidth - 1; + qreal left = borderPenWidth - 1; + qreal bottom = pixmap.height() - borderPenWidth; + qreal right = pixmap.width() - borderPenWidth; + path.moveTo(left + cutSize, top); + path.lineTo(right, top); + path.lineTo(right, bottom - cutSize); + path.lineTo(right - cutSize, bottom); + path.lineTo(left, bottom); + path.lineTo(left, top + cutSize); + path.lineTo(left + cutSize, top); + painter.drawPath(path); + + return pixmap; +} diff --git a/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/qtbuttonimageprovider.h b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/qtbuttonimageprovider.h new file mode 100644 index 0000000..94f410e --- /dev/null +++ b/examples/deviceutilities/settingsuiapp/DeviceUtilities/QtButtonImageProvider/qtbuttonimageprovider.h @@ -0,0 +1,47 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Device Utilities module of the Qt Toolkit. +** +** $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 QTBUTTONIMAGEPROVIDER_H +#define QTBUTTONIMAGEPROVIDER_H + +#include <QQuickImageProvider> +#include <QPixmap> + +class QtButtonImageProvider : public QQuickImageProvider +{ +public: + QtButtonImageProvider(); + + QPixmap requestPixmap(const QString &id, QSize *size, const QSize &requestedSize) override; + + void setCutSize(int size) { m_cutSize = size; } +private: + int m_cutSize; +}; + +#endif // QTBUTTONIMAGEPROVIDER_H |