ViewSolutions
1.0.100.30ae2aa
View solutions of qml for quasarapp projects
Toggle main menu visibility
Loading...
Searching...
No Matches
qmlcolorpicker.cpp
Go to the documentation of this file.
1
2
//#
3
//# Copyright (C) 2020-2025 QuasarApp.
4
//# Distributed under the GPLv3 software license, see the accompanying
5
//# Everyone is permitted to copy and distribute verbatim copies
6
//# of this license document, but changing it is not allowed.
7
//#
8
9
#include "
qmlcolorpicker.h
"
10
11
#include <QQmlApplicationEngine>
12
#include <QQuickAsyncImageProvider>
13
namespace
ViewSolutions
{
14
15
QMLColorPicker::QMLColorPicker
(QObject *parent) :
16
QObject(parent) {
17
18
}
19
20
QColor
QMLColorPicker::pick
(
const
QString &img)
const
{
21
22
if
(img.left(6) ==
"image:"
) {
23
int
urlBegin = img.indexOf(
'/'
, 8);
24
QString
id
= img.mid(8, urlBegin - 8);
25
26
if
(
auto
eng =
engine
()) {
27
QQuickImageProvider* provider =
dynamic_cast<
QQuickImageProvider*
>
(eng->imageProvider(
id
));
28
29
if
(!provider) {
30
return
{};
31
}
32
33
QString url = img.mid(urlBegin + 1);
34
35
if
(provider->imageType() & QQmlImageProviderBase::ImageResponse) {
36
auto
async =
static_cast<
QQuickAsyncImageProvider*
>
(provider);
37
auto
textureFacrory = async->requestImageResponse(url, {})->textureFactory();
38
39
if
(!textureFacrory) {
40
return
{};
41
}
42
43
QColor responce =
ColorPicker::pick
(textureFacrory->image());
44
45
delete
textureFacrory;
46
47
return
responce;
48
}
49
50
if
(provider->imageType() == QQmlImageProviderBase::Texture) {
51
return
ColorPicker::pick
(provider->requestTexture(url,
nullptr
, {})->image());
52
}
53
54
if
(provider->imageType() == QQmlImageProviderBase::Pixmap) {
55
return
ColorPicker::pick
(provider->requestPixmap(url,
nullptr
, {}).toImage());
56
}
57
58
if
(provider->imageType() == QQmlImageProviderBase::Image) {
59
return
ColorPicker::pick
(provider->requestImage(url,
nullptr
, {}));
60
}
61
62
return
{};
63
}
64
65
}
66
67
return
ColorPicker::pick
(img);
68
}
69
70
QString
QMLColorPicker::modelId
()
const
{
71
return
"ColorPicker"
;
72
}
73
74
}
ViewSolutions::ColorPicker::pick
QColor pick(int x, int y, const QImage &img) const
pick Get color from point.
Definition
colorpicker.cpp:19
ViewSolutions::QMLColorPicker::QMLColorPicker
QMLColorPicker(QObject *parent=nullptr)
Definition
qmlcolorpicker.cpp:15
ViewSolutions::QMLColorPicker::modelId
QString modelId() const override
modelId This method returns the model id of the QMLColorPicker.
Definition
qmlcolorpicker.cpp:70
ViewSolutions::QMLColorPicker::pick
Q_INVOKABLE QColor pick(const QString &img) const
pick This is override function for qml.
Definition
qmlcolorpicker.cpp:20
ViewSolutions::iModel::engine
QQmlEngine * engine() const
engine returns qml engine.
Definition
imodel.cpp:19
ViewSolutions
The ViewSolutions namespace.
Definition
avatargenerator.cpp:14
qmlcolorpicker.h
ViewSolutions
src
qmlcolorpicker.cpp
Generated by
1.18.0