Skip to content

added icon overlay #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ViewSolutions/src/ViewSolutionsModule/ActivityPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ Control {
// shows the back button with text
property bool buttonBack: true

// shows the header of the ActivityProcessor (if is it not to abble atomaticaly)
property bool headerVisible: true


// shows close button on the ActivityProcessor header
property bool closeButton: true
// attach to this property link to ActivityProcessor (if is it not to abble atomaticaly)
property var activityProcessorLink: null
property var activityProcessorLink: (parent && parent.link)? parent.link: null

// emit this signal when you finish work on this page. The ActivityProcessor will inoke pop method.
signal finish();
Expand Down
5 changes: 4 additions & 1 deletion ViewSolutions/src/ViewSolutionsModule/ActivityProcessor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Page {

header: ActivityProcessorHeader {
id: headerView
visible: root.enableHeader
visible: root.enableHeader && stackView.currentItem && stackView.currentItem.headerVisible
title: {
if (root.enableHeader && stackView.currentItem && stackView.currentItem.title) {
return stackView.currentItem.title
Expand All @@ -50,6 +50,8 @@ Page {
contentItem: StackView {
id: stackView

property var link : root

Connections {
target: (stackView.currentItem && stackView.currentItem.finish)? stackView.currentItem : null

Expand Down Expand Up @@ -194,6 +196,7 @@ Page {
&& typeof(callback) === "function") {
activity.activityCallBack = callback;
}

return activity;

} else if (component.status === Component.Error) {
Expand Down
70 changes: 70 additions & 0 deletions ViewSolutions/src/ViewSolutionsModule/DragDelegate.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//#
//# Copyright (C) 2025-2025 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#


import QtQuick
import QtQuick.Controls
import QtQuick.Layouts

Control {
id: root

/// The content this is content data of the draging
property alias dragingContent: data.contentItem
property var mimeData: null

/// The draging area this is the area where the draging will be dropped
required property var dragingArea

signal draged()
signal clicked(var mouse)

contentItem: Control {
id: delegate

Drag.active: activeDragArea.drag.active
Drag.hotSpot.x: activeDragArea.width / 2
Drag.hotSpot.y: activeDragArea.height / 2
Drag.source: activeDragArea
Drag.mimeData: root.mimeData

states: [
State {
when: delegate.Drag.active
ParentChange {
target: delegate
parent: dragingArea
}
}
]

MouseArea {
id: activeDragArea
anchors.fill: parent
drag.target: parent

drag.onActiveChanged: {
if (drag.active) {
root.draged()
dragingArea.opacity *= 0.5
} else {
dragingArea.opacity *= 2
}
parent.Drag.drop();
}
onClicked: root.clicked(mouse)
}

implicitHeight: data.implicitHeight
implicitWidth: data.implicitWidth
Control {
id: data
anchors.fill: parent

}
}
}
29 changes: 29 additions & 0 deletions ViewSolutions/src/ViewSolutionsModule/IconOverlay.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//#
//# Copyright (C) 2025-2025 QuasarApp.
//# Distributed under the lgplv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#


import QtQuick
import QtQuick.Controls
import QtQuick.Effects

Control {
id: root
property alias source: image.source
property alias color: effect.colorizationColor
property alias colorization: effect.colorization

contentItem: Image {
id: image

MultiEffect {
id: effect
anchors.fill: image
colorization: 1

}
}
}
36 changes: 21 additions & 15 deletions ViewSolutions/src/ViewSolutionsModule/ImageView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@ AbstractButton {
property string toolTip: ""

property color textColor: Material.foreground

property alias textVisible: content.visible
property color backgroundColor: Material.background
property color selectedColor: Material.accent
property color hoverColor: Material.accent
property alias contentData: content.contentItem

Connections {
target: sourceImg

function onStatusChanged(status) {
if (status === Image.Ready) {
root.backgroundColor = colorPicker.pick(source);
root.backgroundColor = colorPicker.pick(root.source);
}
}
}
Expand All @@ -50,7 +51,6 @@ AbstractButton {
contentItem: Control {
id: privateData
property int rootMinSize: Math.min(root.height, root.width)
bottomPadding : 8
property real rx : 0
property real ry : 0
property real rz : 0
Expand Down Expand Up @@ -106,15 +106,14 @@ AbstractButton {
}

contentItem: ColumnLayout {
spacing: 8

spacing: 0

MultiEffect {
id: imgEffect
Layout.fillWidth: true
Layout.fillHeight: true

source: Image {
source: Image {
id: sourceImg
source: root.source

Expand All @@ -135,26 +134,33 @@ AbstractButton {

Rectangle {
color: "Black"

anchors.bottom: parent.bottom
height: 20
width: parent.width
visible: content.visible
}
}
}
}


Label {
text: root.text
visible: text.length
Control {
id: content
Layout.fillWidth: true
color: root.textColor
font: root.font
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
padding: 8

contentItem: Label {
text: root.text
visible: text.length
Layout.fillWidth: true
color: root.textColor
font: root.font
wrapMode: Text.WordWrap
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter

}
}

}

transform: [
Expand Down
2 changes: 2 additions & 0 deletions ViewSolutions/src/ViewSolutionsModule/qmldir
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ ViewPortPage 1.0 ViewPortPage.qml
ViewPortGradientPage 1.0 ViewPortGradientPage.qml
ViewPortStaticPage 1.0 ViewPortStaticPage.qml
ViewPortStaticGradientPage 1.0 ViewPortStaticGradientPage.qml
IconOverlay 1.0 IconOverlay.qml
DragDelegate 1.0 DragDelegate.qml
2 changes: 2 additions & 0 deletions ViewSolutions/src/ViewSolutionsResources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<file>ViewSolutionsModule/ActivityProcessorHeader.qml</file>
<file>ViewSolutionsModule/ActivityProcessor.qml</file>
<file>ViewSolutionsModule/ActivityPage.qml</file>
<file>ViewSolutionsModule/IconOverlay.qml</file>
<file>ViewSolutionsModule/DragDelegate.qml</file>
</qresource>
<qresource prefix="/img"/>
</RCC>
73 changes: 73 additions & 0 deletions ViewSolutions/src/avatargenerator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//#
//# Copyright (C) 2025-2025 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#


#include "avatargenerator.h"

#include <QFontMetrics>
#include <QPainter>

namespace ViewSolutions {

AvatarGenerator::AvatarGenerator() {}

bool AvatarGenerator::generateDefaultAvatar(QImage &result,
const QString &nickName,
const QFont &font,
const QColor &color) const {

const int size = std::max(std::max(result.width(), result.height()), 256);


QBrush solidBrush = QBrush(color);
if (!color.isValid()) {
auto mainColor = QColor(qHash(nickName + "red") % 250,
qHash(nickName + "green") % 250,
qHash(nickName + "blue") % 250);

// radnom dark
auto secondColor = QColor(qHash(nickName + "red dark") % 50,
qHash(nickName + "green dark") % 50,
qHash(nickName + "blue dark") % 50);

QLinearGradient g(0.0, 0.0, 0.0, size);
g.setColorAt(0, mainColor);
g.setColorAt(1, secondColor);

solidBrush = QBrush(g);
}

QImage image(size, size, QImage::Format_ARGB32);
image.fill(Qt::transparent);

QPainter painter(&image);
painter.setRenderHint(QPainter::Antialiasing);


painter.setBrush(solidBrush);
painter.setPen(Qt::NoPen);
painter.drawEllipse(0, 0, size, size);

QString firstLetter = nickName.left(1).toUpper();
QFont currentFont = font;
currentFont.setPixelSize( size / 2);
painter.setPen(QColor(Qt::white));
QFontMetrics metrics(currentFont);
painter.setFont(currentFont);

int textWidth = metrics.horizontalAdvance(firstLetter);
int textHeight = metrics.height();
int x = (size - textWidth) / 2;
int y = (size + textHeight / 2) / 1.9;
painter.drawText(x, y, firstLetter);

result = image;

return true;
}

}
42 changes: 42 additions & 0 deletions ViewSolutions/src/avatargenerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//#
//# Copyright (C) 2025-2025 QuasarApp.
//# Distributed under the GPLv3 software license, see the accompanying
//# Everyone is permitted to copy and distribute verbatim copies
//# of this license document, but changing it is not allowed.
//#



#ifndef AVATARGENERATOR_H
#define AVATARGENERATOR_H

#include <QImage>

namespace ViewSolutions {

/**
* @brief The AvatarGenerator class contains function for create default users avatars.
*
*/
class AvatarGenerator
{
public:
AvatarGenerator();

/**
* @brief generateDefaultAvatar generates default avatar.
* This function generate Ellipse with 2 first letters of user name.
* Size of image depends of result image size, but if it smaller the 256 px will use 256 px.
* @param result - result image
* @param nickName - user name
* @param font - font for text
* @param color - color of text - if not sets by default will be used random color
*/
bool generateDefaultAvatar(QImage &result, const QString &nickName,
const QFont& font, const QColor& color = {}) const;


};

}
#endif // AVATARGENERATOR_H
6 changes: 3 additions & 3 deletions ViewSolutions/src/qmlcolorpicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ QColor QMLColorPicker::pick(const QString &img) const {
return responce;
}

if (provider->imageType() & QQmlImageProviderBase::Texture) {
if (provider->imageType() == QQmlImageProviderBase::Texture) {
return ColorPicker::pick(provider->requestTexture(url, nullptr, {})->image());
}

if (provider->imageType() & QQmlImageProviderBase::Pixmap) {
if (provider->imageType() == QQmlImageProviderBase::Pixmap) {
return ColorPicker::pick(provider->requestPixmap(url, nullptr, {}).toImage());
}

if (provider->imageType() & QQmlImageProviderBase::Image) {
if (provider->imageType() == QQmlImageProviderBase::Image) {
return ColorPicker::pick(provider->requestImage(url, nullptr, {}));
}

Expand Down
2 changes: 0 additions & 2 deletions ViewSolutions/src/viewsolutions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ QSharedPointer<ModelStorage> init(QQmlApplicationEngine *engine) {

qRegisterMetaType<VariantListModel>("VariantListModel");



return storage;
}
}