mirror of
https://github.com/QuasarApp/ViewSolutions.git
synced 2025-04-26 17:54:41 +00:00
added support imageProviders for colorpicker of qml
This commit is contained in:
parent
55222dab05
commit
2e1cbba442
@ -1,6 +1,6 @@
|
||||
import QtQuick 2.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
|
||||
import ViewSolutionsModule 1.0
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import QtQuick 2.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
|
||||
import ViewSolutionsModule 1.0
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import QtQuick 2.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
|
||||
import ViewSolutionsModule 1.0
|
||||
|
||||
|
@ -9,11 +9,11 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
import QtQuick 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick.Controls.Universal 2.14
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
import QtQuick.Controls.Universal 2.15
|
||||
|
||||
ApplicationWindow {
|
||||
id: window
|
||||
|
@ -1,8 +1,8 @@
|
||||
import QtQuick 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick.Controls.Universal 2.14
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
import QtQuick.Controls.Universal 2.15
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
@ -1,13 +1,14 @@
|
||||
import QtQuick 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick.Controls.Universal 2.14
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
import QtQuick.Controls.Universal 2.15
|
||||
|
||||
Item {
|
||||
id: delegateItem
|
||||
|
||||
property string source: ""
|
||||
property alias imageSource: image
|
||||
property var background: Rectangle {
|
||||
border.color: "black"
|
||||
anchors.fill: parent
|
||||
|
@ -1,15 +1,26 @@
|
||||
import QtQuick 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick.Controls.Universal 2.14
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
import QtQuick.Controls.Universal 2.15
|
||||
import QtGraphicalEffects 1.14
|
||||
|
||||
|
||||
ViewPortPage {
|
||||
id: root
|
||||
|
||||
Connections {
|
||||
target: imageSource
|
||||
|
||||
onStatusChanged: {
|
||||
if (imageSource.status === Image.Ready) {
|
||||
bacground.color = colorPicker.pick(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
id: bacground
|
||||
color: colorPicker.pick(source)
|
||||
radius: 16
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import QtQuick 2.14
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Layouts 1.14
|
||||
import QtQuick.Controls 2.14
|
||||
import QtQuick.Controls.Material 2.14
|
||||
import QtQuick.Controls.Universal 2.14
|
||||
import QtQuick.Controls 2.15
|
||||
import QtQuick.Controls.Material 2.15
|
||||
import QtQuick.Controls.Universal 2.15
|
||||
import QtGraphicalEffects 1.14
|
||||
|
||||
|
||||
|
@ -1,4 +1,7 @@
|
||||
#include "qmlcolorpicker.h"
|
||||
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickAsyncImageProvider>
|
||||
namespace ViewSolutions {
|
||||
|
||||
QMLColorPicker::QMLColorPicker(QObject *parent) :
|
||||
@ -12,6 +15,56 @@ QMLColorPicker *ViewSolutions::QMLColorPicker::instance() {
|
||||
}
|
||||
|
||||
QColor QMLColorPicker::pick(const QString &img) const {
|
||||
|
||||
if (img.left(6) == "image:") {
|
||||
int urlBegin = img.indexOf('/', 8);
|
||||
QString id = img.mid(8, urlBegin - 8);
|
||||
|
||||
if (!_engine)
|
||||
return {};
|
||||
|
||||
QQuickImageProvider* provider = dynamic_cast<QQuickImageProvider*>(_engine->imageProvider(id));
|
||||
|
||||
if (!provider) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QString url = img.mid(urlBegin + 1);
|
||||
|
||||
if (provider->imageType() & QQmlImageProviderBase::ImageResponse) {
|
||||
auto async = static_cast<QQuickAsyncImageProvider*>(provider);
|
||||
auto textureFacrory = async->requestImageResponse(url, {})->textureFactory();
|
||||
|
||||
if (!textureFacrory) {
|
||||
return {};
|
||||
}
|
||||
|
||||
QColor responce = ColorPicker::pick(textureFacrory->image());
|
||||
|
||||
delete textureFacrory;
|
||||
|
||||
return responce;
|
||||
}
|
||||
|
||||
if (provider->imageType() & QQmlImageProviderBase::Texture) {
|
||||
return ColorPicker::pick(provider->requestTexture(url, nullptr, {})->image());
|
||||
}
|
||||
|
||||
if (provider->imageType() & QQmlImageProviderBase::Pixmap) {
|
||||
return ColorPicker::pick(provider->requestPixmap(url, nullptr, {}).toImage());
|
||||
}
|
||||
|
||||
if (provider->imageType() & QQmlImageProviderBase::Image) {
|
||||
return ColorPicker::pick(provider->requestImage(url, nullptr, {}));
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
return ColorPicker::pick(img);
|
||||
}
|
||||
|
||||
void QMLColorPicker::setEngine(QQmlApplicationEngine *engine) {
|
||||
_engine = engine;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@
|
||||
#include "colorpicker.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QQmlApplicationEngine;
|
||||
namespace ViewSolutions {
|
||||
|
||||
/**
|
||||
@ -14,18 +16,27 @@ class LOGINVIEW_EXPORT QMLColorPicker : public QObject, private ColorPicker
|
||||
public:
|
||||
explicit QMLColorPicker(QObject *parent = nullptr);
|
||||
/**
|
||||
* @brief instance
|
||||
* @brief instance This method return instance object of the QMLColorPicker setvice.
|
||||
* @return static instance of this ColorPicker
|
||||
*/
|
||||
static QMLColorPicker* instance();
|
||||
|
||||
/**
|
||||
* @brief pick - this is override function for qml
|
||||
* @param img - path to image
|
||||
* @brief pick This is override function for qml
|
||||
* @param img This is path to image
|
||||
* @return General color of image
|
||||
*/
|
||||
Q_INVOKABLE QColor pick(const QString &img) const;
|
||||
|
||||
/**
|
||||
* @brief setEngine This method set qml engine for working with image providers.
|
||||
* @param engine This is new engine.
|
||||
*/
|
||||
void setEngine(QQmlApplicationEngine *engine);
|
||||
|
||||
private:
|
||||
|
||||
QQmlApplicationEngine *_engine = nullptr;
|
||||
};
|
||||
}
|
||||
#endif // QMLCOLORPICKER_H
|
||||
|
@ -17,7 +17,10 @@ bool init(QQmlApplicationEngine *engine) {
|
||||
|
||||
engine->addImportPath(":/");
|
||||
|
||||
root->setContextProperty("colorPicker", QMLColorPicker::instance());
|
||||
auto picker = QMLColorPicker::instance();
|
||||
picker->setEngine(engine);
|
||||
|
||||
root->setContextProperty("colorPicker", picker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user