Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 1f01dcc9 authored by Marco Martin's avatar Marco Martin

remove old imagepalette

parent 0c0d2f25
......@@ -2,7 +2,6 @@ project(bigscreen)
set(bigscreen_SRCS
bigscreenplugin.cpp
imagepalette.cpp
)
add_library(bigscreenplugin SHARED ${bigscreen_SRCS})
......
......@@ -21,7 +21,6 @@
*/
#include "bigscreenplugin.h"
#include "imagepalette.h"
#include <QtQml>
......@@ -30,7 +29,6 @@ void BigScreenPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.mycroft.bigscreen"));
qmlRegisterType<ImagePalette>(uri, 1, 0, "ImagePalette");
qmlRegisterSingletonType(componentUrl(QStringLiteral("NavigationSoundEffects.qml")), uri, 1, 0, "NavigationSoundEffects");
}
......
This diff is collapsed.
/*
* Copyright 2020 Marco Martin <mart@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 2.010-1301, USA.
*/
#pragma once
#include <QObject>
#include <QColor>
#include <QImage>
#include <QQuickItem>
#include <QQuickItemGrabResult>
#include <QPointer>
#include <QQuickWindow>
#include <QFuture>
class QTimer;
struct ImageData {
struct colorStat {
QList<QRgb> colors;
QRgb centroid = 0;
qreal ratio = 0;
};
QList<QRgb> m_samples;
QList<colorStat> m_clusters;
QVariantList m_palette;
QColor m_dominant;
QColor m_suggestedContrast;
QColor m_mostSaturated;
QColor m_closestToBlack;
QColor m_closestToWhite;
};
class ImagePalette : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariant source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(QVariantList palette READ palette NOTIFY paletteChanged)
Q_PROPERTY(QColor suggestedContrast READ suggestedContrast NOTIFY suggestedContrastChanged)
Q_PROPERTY(QColor mostSaturated READ mostSaturated NOTIFY mostSaturatedChanged)
Q_PROPERTY(QColor closestToWhite READ closestToWhite NOTIFY closestToWhiteChanged)
Q_PROPERTY(QColor closestToBlack READ closestToBlack NOTIFY closestToBlackChanged)
public:
explicit ImagePalette(QObject* parent = nullptr);
~ImagePalette();
void setSource(const QVariant &source);
QVariant source() const;
void setSourceImage(const QImage &image);
QImage sourceImage() const;
void setSourceItem(QQuickItem *source);
QQuickItem *sourceItem() const;
Q_INVOKABLE void update();
QVariantList palette() const;
QColor suggestedContrast() const;
QColor mostSaturated() const;
QColor closestToWhite() const;
QColor closestToBlack() const;
Q_SIGNALS:
void sourceChanged();
void paletteChanged();
void suggestedContrastChanged();
void mostSaturatedChanged();
void closestToBlackChanged();
void closestToWhiteChanged();
private:
inline void positionColor(QRgb rgb, QList<ImageData::colorStat> &clusters);
ImageData generatePalette(const QImage &sourceImage);
// Arbitrary number that seems to work well
const int s_minimumSquareDistance = 32000;
QPointer<QQuickWindow> m_window;
QVariant m_source;
QPointer<QQuickItem> m_sourceItem;
QSharedPointer<QQuickItemGrabResult> m_grabResult;
QImage m_sourceImage;
QTimer *m_imageSyncTimer;
QFutureWatcher<ImageData> *m_futureImageData = nullptr;
ImageData m_imageData;
};
import QtQuick 2.12
import QtQuick.Layouts 1.4
import QtQuick.Controls 2.12 as Controls
import org.kde.kirigami 2.10 as Kirigami
import org.kde.mycroft.bigscreen 1.0 as BigScreen
RowLayout {
id: root
width: 500
height: 500
property var icons: ["desktop", "firefox", "vlc", "blender", "applications-games", "blinken", "adjustlevels", "adjustrgb", "cuttlefish", "folder-games", "applications-network", "multimedia-player", "applications-utilities", "accessories-dictionary", "calligraflow", "calligrakrita", "view-left-close","calligraauthor"]
property int i
BigScreen.ImagePalette {
id: palette
source: icon
}
BigScreen.ImagePalette {
id: imgPalette
source: image
}
ColumnLayout {
Rectangle {
Layout.preferredWidth: 200
Layout.preferredHeight: 200
z: -1
color: palette.suggestedContrast
Kirigami.Icon {
id: icon
anchors.centerIn: parent
width: 120
height: 120
source: "desktop"
}
}
Controls.Button {
text: "Next"
onClicked: {
i = (i+1)%icons.length
icon.source = icons[i]
palette.update()
}
}
Repeater {
model: palette.palette
delegate: Rectangle {
implicitWidth: 10 + 300 * modelData.ratio
implicitHeight: 30
color: modelData.color
}
}
}
Item {
Layout.preferredWidth: 500
Layout.preferredHeight: 500/(image.sourceSize.width/image.sourceSize.height)
Image {
id: image
source: "https://source.unsplash.com/random"
anchors.fill: parent
}
ColumnLayout {
Controls.Button {
text: "Grab"
onClicked: {
imgPalette.update()
}
}
Repeater {
model: imgPalette.palette
delegate: Rectangle {
implicitWidth: 10 + 300 * modelData.ratio
implicitHeight: 30
color: modelData.color
}
}
}
Rectangle {
width: 300
height: 150
color: imgPalette.closestToWhite
anchors {
bottom: parent.bottom
right: parent.right
}
Row {
anchors.centerIn: parent
Rectangle {
width: 10
height: 10
color: imgPalette.mostSaturated
}
Controls.Label {
text: "Lorem Ipsum dolor sit amet"
color: imgPalette.closestToBlack
}
}
}
}
}
......@@ -2,7 +2,7 @@
import QtQuick 2.12
import QtQuick.Layouts 1.4
import QtQuick.Controls 2.12 as Controls
import org.kde.kirigami 2.10 as Kirigami
import org.kde.kirigami 2.13 as Kirigami
import org.kde.mycroft.bigscreen 1.0 as BigScreen
Image {
......@@ -29,8 +29,8 @@ Image {
margins: 10
}
radius: 5
color: palette.suggestedContrast
BigScreen.ImagePalette {
color: palette.dominantContrast
Kirigami.ImageColors {
id: palette
source: modelData
}
......@@ -48,7 +48,10 @@ Image {
Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter
text: "Lorem"
color: 0.2126 * palette.suggestedContrast.r + 0.7152 * palette.suggestedContrast.g + 0.0722 * palette.suggestedContrast.b > 0.6 ? "black" : "white"
//color: 0.2126 * palette.suggestedContrast.r + 0.7152 * palette.suggestedContrast.g + 0.0722 * palette.suggestedContrast.b > 0.6 ? "black" : "white"
color: useColors
? Kirigami.ColorUtils.brightness(palette.dominantContrast) === Kirigami.ColorUtils.Light ? imagePalette.closestToBlack : imagePalette.closestToWhite
: PlasmaCore.ColorScope.textColor
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment