From efd14e44651554eff1343729e5805ddeeb213e92 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 6 Sep 2017 18:48:51 +0200 Subject: [PATCH 01/16] Fix correct indent style --- .../src/components/emoji/EmojiButton.qml | 36 ++++++++----- .../components/emoji/EmojiCategoryButton.qml | 48 +++++++++++------ .../src/components/emoji/EmojiPicker.qml | 51 ++++++++++++------- 3 files changed, 90 insertions(+), 45 deletions(-) diff --git a/retroshare-qml-app/src/components/emoji/EmojiButton.qml b/retroshare-qml-app/src/components/emoji/EmojiButton.qml index 3720d9f5c..34408b2e2 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiButton.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiButton.qml @@ -1,12 +1,14 @@ import QtQuick 2.7 import QtQuick.Controls.Styles 1.2 -Rectangle { +Rectangle +{ id: emojiButton property var fontName - Text { + Text + { id: emojiText color: "gray" text: qsTr(eCatText) @@ -17,17 +19,22 @@ Rectangle { state: "RELEASED" - states: [ - State { + states: + [ + State + { name: "PRESSED" - PropertyChanges { + PropertyChanges + { target: emojiText font.pixelSize: emojiButton.width - 10 } }, - State { + State + { name: "RELEASED" - PropertyChanges { + PropertyChanges + { target: emojiText font.pixelSize: emojiButton.width - 8 } @@ -35,20 +42,25 @@ Rectangle { ] - MouseArea { + MouseArea + { anchors.fill: parent hoverEnabled: true - onEntered: { + onEntered: + { emojiText.color = "black" } - onExited: { + onExited: + { emojiText.color = "gray" } - onPressedChanged: { + onPressedChanged: + { emojiButton.state = emojiButton.state == "PRESSED" ? "RELEASED" : "PRESSED" } - onClicked: { + onClicked: + { Qt.emojiClickedHandler(emojiText.text) } } diff --git a/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml b/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml index 12983cf5b..251d8f70e 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiCategoryButton.qml @@ -1,30 +1,37 @@ import QtQuick 2.7 import QtQuick.Controls.Styles 1.2 -Rectangle { +Rectangle +{ id: emojiCategoryButton property string categoryName property var fontName - function completedHandler() { + function completedHandler() + { categoryName = eCatName //initialize - if (parent.currSelEmojiButton === undefined) { + if (parent.currSelEmojiButton === undefined) + { clickedHandler() } } - function pressedHandler() { - if (state != "SELECTED") { + function pressedHandler() + { + if (state != "SELECTED") + { state = state == "PRESSED" ? "RELEASED" : "PRESSED" } } - function clickedHandler() { - if (parent.currSelEmojiButton !== undefined) { + function clickedHandler() + { + if (parent.currSelEmojiButton !== undefined) + { parent.currSelEmojiButton.state = "RELEASED" } @@ -34,7 +41,8 @@ Rectangle { } - Text { + Text + { id: emojiText color: "gray" text: qsTr(eCatText) @@ -45,31 +53,39 @@ Rectangle { state: "RELEASED" - states: [ - State { + states: + [ + State + { name: "PRESSED" - PropertyChanges { + PropertyChanges + { target: emojiText font.pixelSize: emojiCategoryButton.width - 10 } }, - State { + State + { name: "RELEASED" - PropertyChanges { + PropertyChanges + { target: emojiText font.pixelSize: emojiCategoryButton.width - 8 } }, - State { + State + { name: "SELECTED" - PropertyChanges { + PropertyChanges + { target: emojiCategoryButton color: "#ADD6FF" } } ] - MouseArea { + MouseArea + { anchors.fill: parent hoverEnabled: true onEntered: emojiText.color = "black" diff --git a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml index f99d8f444..20c1072d1 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml @@ -2,7 +2,8 @@ import QtQuick 2.7 import QtQuick.Controls 2.0 import "emoji.js" as EmojiJSON -Rectangle { +Rectangle +{ id: emojiPicker property EmojiCategoryButton currSelEmojiButton property variant emojiParsedJson @@ -12,23 +13,27 @@ Rectangle { property var rootFontName: theme.emojiFontName //displays all Emoji of one categroy by modifying the ListModel of emojiGrid - function categoryChangedHandler (newCategoryName){ + function categoryChangedHandler (newCategoryName) + { emojiByCategory.clear() - for (var i = 0; i < emojiParsedJson.emoji_by_category[newCategoryName].length; i++) { + for (var i = 0; i < emojiParsedJson.emoji_by_category[newCategoryName].length; i++) + { var elem = emojiParsedJson.emoji_by_category[newCategoryName][i] emojiByCategory.append({eCatName: newCategoryName, eCatText: elem}) } } //adds the clicked Emoji (and one ' ' if the previous character isn't an Emoji) to textArea - function emojiClickedHandler(selectedEmoji) { + function emojiClickedHandler(selectedEmoji) + { var strAppnd = "" var plainText = textArea.getText(0, textArea.length) if (plainText.length > 0) { var lastChar = plainText[plainText.length-1] - if ((lastChar !== ' ') && (lastChar.charCodeAt(0) < 255)) { + if ((lastChar !== ' ') && (lastChar.charCodeAt(0) < 255)) + { strAppnd = " " } } @@ -38,10 +43,12 @@ Rectangle { } //parses JSON, publishes button handlers and inits textArea - function completedHandler() { + function completedHandler() + { // emojiParsedJson = JSON.parse(EmojiJSON.emoji_json) emojiParsedJson = EmojiJSON.emoji_json - for (var i = 0; i < emojiParsedJson.emoji_categories.length; i++) { + for (var i = 0; i < emojiParsedJson.emoji_categories.length; i++) + { var elem = emojiParsedJson.emoji_categories[i] emojiCategoryButtons.append({eCatName: elem.name, eCatText: elem.emoji_unified}) } @@ -56,21 +63,25 @@ Rectangle { //checks if the previous character is an Emoji and adds a ' ' if that's the case //this is necessary, because Emoji use a bigger font-size, and that font-size is kept using without a ' ' - function keyPressedHandler(event) { + function keyPressedHandler(event) + { var testStr = textArea.getText(textArea.length-2, textArea.length) var ptrn = new RegExp("[\uD800-\uDBFF][\uDC00-\uDFFF]") - if ((event.key !== Qt.Key_Backspace) && (ptrn.test(testStr))) { + if ((event.key !== Qt.Key_Backspace) && (ptrn.test(testStr))) + { textArea.text += " " textArea.cursorPosition = textArea.length } } //all emoji of one category - ListModel { + ListModel + { id: emojiByCategory } - GridView { + GridView + { id: emojiGrid width: parent.width anchors.fill: parent @@ -78,7 +89,8 @@ Rectangle { cellWidth: buttonWidth; cellHeight: buttonWidth model: emojiByCategory - delegate: EmojiButton { + delegate: EmojiButton + { width: buttonWidth height: buttonWidth color: emojiPicker.color @@ -88,13 +100,15 @@ Rectangle { //seperator - Rectangle { + Rectangle + { color: emojiPicker.color anchors.bottom: parent.bottom width: parent.width height: buttonWidth } - Rectangle { + Rectangle + { color: "black" anchors.bottom: parent.bottom anchors.bottomMargin: buttonWidth @@ -103,14 +117,16 @@ Rectangle { } //emoji category selector - ListView { + ListView + { width: parent.width anchors.bottom: parent.bottom anchors.bottomMargin: buttonWidth orientation: ListView.Horizontal model: emojiCategoryButtons - delegate: EmojiCategoryButton { + delegate: EmojiCategoryButton + { width: buttonWidth height: buttonWidth color: emojiPicker.color @@ -118,7 +134,8 @@ Rectangle { } } - ListModel { + ListModel + { id: emojiCategoryButtons } From 9386657955881bbe0b6bf7b531dab6fc0b4ae911 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 6 Sep 2017 18:50:20 +0200 Subject: [PATCH 02/16] Fix horizontal scroll on category selection --- .../src/components/emoji/EmojiPicker.qml | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml index 20c1072d1..e30b84322 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml @@ -100,38 +100,37 @@ Rectangle //seperator + Rectangle + { + color: "black" + anchors.bottom: parent.bottom + anchors.bottomMargin: buttonWidth + width: parent.width + height: 1 + } Rectangle { color: emojiPicker.color anchors.bottom: parent.bottom width: parent.width height: buttonWidth - } - Rectangle - { - color: "black" - anchors.bottom: parent.bottom - anchors.bottomMargin: buttonWidth - width: parent.width - height: 1 - } - //emoji category selector - ListView - { - width: parent.width - anchors.bottom: parent.bottom - anchors.bottomMargin: buttonWidth - orientation: ListView.Horizontal - - model: emojiCategoryButtons - delegate: EmojiCategoryButton + //emoji category selector + ListView { - width: buttonWidth - height: buttonWidth - color: emojiPicker.color - fontName: rootFontName - } + width: parent.width + orientation: ListView.Horizontal + anchors.fill: parent + + model: emojiCategoryButtons + delegate: EmojiCategoryButton + { + width: buttonWidth + height: buttonWidth + color: emojiPicker.color + fontName: rootFontName + } + } } ListModel From cfe44be1287f5ad0f0db0d2efadc8d3e7117786a Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Wed, 6 Sep 2017 20:23:33 +0200 Subject: [PATCH 03/16] Fix close android keyboard when emoji menu is shown --- retroshare-qml-app/src/ChatView.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/retroshare-qml-app/src/ChatView.qml b/retroshare-qml-app/src/ChatView.qml index 8a814545b..e9d87ca6a 100644 --- a/retroshare-qml-app/src/ChatView.qml +++ b/retroshare-qml-app/src/ChatView.qml @@ -284,6 +284,7 @@ Item onClicked: { if (emojiPicker.state == "EMOJI_HIDDEN") { emojiPicker.state = "EMOJI_SHOWN" + Qt.inputMethod.hide(); } else { emojiPicker.state = "EMOJI_HIDDEN" } From f435fcda28d44e45cdd63f654e7b99a6312edd10 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Thu, 7 Sep 2017 17:59:53 +0200 Subject: [PATCH 04/16] Implement android layout --- .../src/components/emoji/EmojiPicker.qml | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml index e30b84322..7783eff69 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml @@ -10,6 +10,9 @@ Rectangle property int buttonWidth: 40 property TextArea textArea + property bool androidMode: true // On Desktop appears on top of text field, instead appears in place of virtual keyboard (under text field) + + property var rootFontName: theme.emojiFontName //displays all Emoji of one categroy by modifying the ListModel of emojiGrid @@ -84,9 +87,14 @@ Rectangle { id: emojiGrid width: parent.width - anchors.fill: parent - anchors.bottomMargin: buttonWidth - cellWidth: buttonWidth; cellHeight: buttonWidth + anchors.fill: parent + anchors + { + bottomMargin: if (!androidMode) buttonWidth + topMargin: if (androidMode) buttonWidth + } + + cellWidth: buttonWidth; cellHeight: buttonWidth model: emojiByCategory delegate: EmojiButton @@ -102,19 +110,30 @@ Rectangle //seperator Rectangle { - color: "black" - anchors.bottom: parent.bottom - anchors.bottomMargin: buttonWidth + color: "gray" + anchors + { + bottom: if (!androidMode) parent.bottom + top: if (androidMode) parent.top + bottomMargin: if (!androidMode) buttonWidth + topMargin: if (androidMode) buttonWidth + } + width: parent.width height: 1 } Rectangle { - color: emojiPicker.color - anchors.bottom: parent.bottom + color: emojiPicker.color width: parent.width height: buttonWidth + anchors + { + bottom: if (!androidMode) parent.bottom + top: if (androidMode) parent.top + } + //emoji category selector ListView { From d9804928dc080092fba4e7e184d86847b60a7e36 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Thu, 7 Sep 2017 18:13:29 +0200 Subject: [PATCH 05/16] Set emoji menu under inferior panel on android mode --- retroshare-qml-app/src/ChatView.qml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/ChatView.qml b/retroshare-qml-app/src/ChatView.qml index e9d87ca6a..aba028118 100644 --- a/retroshare-qml-app/src/ChatView.qml +++ b/retroshare-qml-app/src/ChatView.qml @@ -100,7 +100,7 @@ Item anchors.fill: parent anchors.topMargin: parent.height / 2 - anchors.bottomMargin: categorySelectorHeight + anchors.bottomMargin: if(!androidMode) categorySelectorHeight property int categorySelectorHeight: 50 @@ -114,6 +114,7 @@ Item name: "EMOJI_HIDDEN" PropertyChanges { target: emojiPicker; anchors.topMargin: parent.height } PropertyChanges { target: emojiPicker; anchors.bottomMargin: -1 } + PropertyChanges { target: emojiPicker; height: 0 } }, State { name: "EMOJI_SHOWN" @@ -132,7 +133,7 @@ Item id: inferiorPanel height: ( msgComposer.height > styles.height)? msgComposer.height: styles.height width: parent.width - anchors.bottom: parent.bottom + anchors.bottom: emojiPicker.androidMode ? emojiPicker.top : parent.bottom Rectangle { From bbd139ae0e2c2853a2a00f33ac1b80b943b9b92b Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Thu, 7 Sep 2017 18:33:57 +0200 Subject: [PATCH 06/16] Disable keyboard close when emojimenu button is pushed --- retroshare-qml-app/src/ChatView.qml | 1 - 1 file changed, 1 deletion(-) diff --git a/retroshare-qml-app/src/ChatView.qml b/retroshare-qml-app/src/ChatView.qml index aba028118..505637274 100644 --- a/retroshare-qml-app/src/ChatView.qml +++ b/retroshare-qml-app/src/ChatView.qml @@ -285,7 +285,6 @@ Item onClicked: { if (emojiPicker.state == "EMOJI_HIDDEN") { emojiPicker.state = "EMOJI_SHOWN" - Qt.inputMethod.hide(); } else { emojiPicker.state = "EMOJI_HIDDEN" } From 404469b0a7aa900ef7a0bb91319ac06e32bb44e3 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Thu, 7 Sep 2017 18:34:23 +0200 Subject: [PATCH 07/16] Set android mode on android os platforms --- retroshare-qml-app/src/components/emoji/EmojiPicker.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml index 7783eff69..844ba60b1 100644 --- a/retroshare-qml-app/src/components/emoji/EmojiPicker.qml +++ b/retroshare-qml-app/src/components/emoji/EmojiPicker.qml @@ -10,7 +10,7 @@ Rectangle property int buttonWidth: 40 property TextArea textArea - property bool androidMode: true // On Desktop appears on top of text field, instead appears in place of virtual keyboard (under text field) + property bool androidMode: Qt.platform.os === "android" // On Desktop appears on top of text field, instead appears in place of virtual keyboard (under text field) property var rootFontName: theme.emojiFontName From 335c1463e60b7687be9d8d7e1bf6320ac6d68ceb Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Thu, 7 Sep 2017 18:47:08 +0200 Subject: [PATCH 08/16] Open own contact details page when click your identity --- retroshare-qml-app/src/GxsIdentityDelegate.qml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/retroshare-qml-app/src/GxsIdentityDelegate.qml b/retroshare-qml-app/src/GxsIdentityDelegate.qml index 650cf6551..6bdbf2524 100644 --- a/retroshare-qml-app/src/GxsIdentityDelegate.qml +++ b/retroshare-qml-app/src/GxsIdentityDelegate.qml @@ -50,7 +50,14 @@ Item console.log("GxsIntentityDelegate onclicked:", model.name, model.gxs_id) contactsView.searching = false - if(model.own) contactsView.own_gxs_id = model.gxs_id + if(model.own) + { + contactsView.own_gxs_id = model.gxs_id + stackView.push( + "qrc:/ContactDetails.qml", + {md: ChatCache.contactsCache.getContactFromGxsId(model.gxs_id)}) + + } else { startDistantChat() From 75180f2a016ddc9eb0948a932a0d042a69cddd62 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Thu, 7 Sep 2017 20:30:08 +0200 Subject: [PATCH 09/16] Encode base64 via c++ code --- retroshare-qml-app/src/androidimagepicker.h | 60 ++++++++++++++++ retroshare-qml-app/src/components/Faces.qml | 79 +++++++++++---------- 2 files changed, 101 insertions(+), 38 deletions(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index ad5f0e302..4187489de 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -9,6 +9,8 @@ #include #include +#include "qpainter.h" + #ifdef __ANDROID__ # include @@ -60,7 +62,65 @@ public slots: qDebug() << "imageToBase64() encoded" ; + return encoded; + } + + static QString faceImage (QVariantList onloads, int size) + { + QImage result(size, size, QImage::Format_ARGB32_Premultiplied); + QPainter painter(&result); + + + int counter = 0; + for (QVariantList::iterator j = onloads.begin(); j != onloads.end(); j++) + { + QString path = (*j).toString(); + QImageReader reader; + reader.setFileName(path); + QImage image = reader.read(); + painter.drawImage(0, 0, image); // xi, yi is the position for imagei +// if (counter == 0) +// { +// base = QImage(bg.size(), QImage::Format_ARGB32_Premultiplied); +// qDebug() << "FIIIRST "; + +// } +// else +// { + +// } + qDebug() << "iterating through QVariantList "; + qDebug() << (*j).toString(); // Print QVariant + counter++; + } + painter.end(); + + // Transform image into PNG format + QByteArray ba; + QBuffer buffer( &ba ); + buffer.open( QIODevice::WriteOnly ); + result.save( &buffer, "png" ); + + // Get Based 64 image string + QString encoded = QString(ba.toBase64()); + + qDebug() << "@@@@@ encoded avatar " << encoded ; + return encoded; } + + QImage getImageFromPath (QString localPath) + { + qDebug() << "getImageFromPath() local path:" << localPath ; + + // Read the image + QImageReader reader; + reader.setFileName(localPath); + QImage image = reader.read(); + return image; + + } + + }; diff --git a/retroshare-qml-app/src/components/Faces.qml b/retroshare-qml-app/src/components/Faces.qml index f814ebb6d..ed60df314 100644 --- a/retroshare-qml-app/src/components/Faces.qml +++ b/retroshare-qml-app/src/components/Faces.qml @@ -19,43 +19,43 @@ Item visible: true } - Canvas - { - id: canvasAvatar - width: height - height: canvasSizes - visible: false +// Canvas +// { +// id: canvasAvatar +// width: height +// height: canvasSizes +// visible: false - renderStrategy: Canvas.Threaded; - renderTarget: Canvas.Image; +// renderStrategy: Canvas.Threaded; +// renderTarget: Canvas.Image; - property var images - property var callback +// property var images +// property var callback - onPaint: - { - var ctx = getContext("2d"); +// onPaint: +// { +// var ctx = getContext("2d"); - if (images) - { - for (y = 0 ; y< nPieces ; y++) - { - ctx.drawImage(images[y], 0, 0, iconSize, iconSize ) - } - } +// if (images) +// { +// for (y = 0 ; y< nPieces ; y++) +// { +// ctx.drawImage(images[y], 0, 0, iconSize, iconSize ) +// } +// } - } +// } - onPainted: - { - if (callback) - { - var data = toDataURL('image/png') - callback(data) - } - } - } +// onPainted: +// { +// if (callback) +// { +// var data = toDataURL('image/png') +// callback(data) +// } +// } +// } Component.onCompleted: { @@ -134,11 +134,14 @@ Item { var url = src(gender, i, data[i+1]) onloads.push(url) - canvasAvatar.loadImage(url) +// canvasAvatar.loadImage(url) } - canvasAvatar.images = onloads - canvasAvatar.callback = callback - canvasAvatar.requestPaint() +// canvasAvatar.images = onloads +// canvasAvatar.callback = callback + var datas = androidImagePicker.faceImage(onloads, iconSize) + console.log("@@@@@@@ url " , datas) + callback("data:image/png;base64,"+datas) +// canvasAvatar.requestPaint() } // Create the identicon @@ -156,17 +159,17 @@ Item { imageAvatar.source = data imageAvatar.visible = true - canvasAvatar.visible = false +// canvasAvatar.visible = false - canvasAvatar.height = 0 +// canvasAvatar.height = 0 imageAvatar.height = iconSize } else { - canvasAvatar.visible = true +// canvasAvatar.visible = true imageAvatar.visible = false - canvasAvatar.height = iconSize +// canvasAvatar.height = iconSize imageAvatar.height = 0 } From 1fdd190fb00c87719dffdbd3634b0a360d4af650 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Mon, 11 Sep 2017 16:27:16 +0200 Subject: [PATCH 10/16] Set correct qrc path --- retroshare-qml-app/src/androidimagepicker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index 4187489de..168e33bdf 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -74,7 +74,7 @@ public slots: int counter = 0; for (QVariantList::iterator j = onloads.begin(); j != onloads.end(); j++) { - QString path = (*j).toString(); + QString path = ":/"+(*j).toString(); QImageReader reader; reader.setFileName(path); QImage image = reader.read(); From cd2e18f27b6e83e3ac0aa9306667d487f431b6e2 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Mon, 11 Sep 2017 16:36:59 +0200 Subject: [PATCH 11/16] Use correct image size --- retroshare-qml-app/src/components/Faces.qml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/retroshare-qml-app/src/components/Faces.qml b/retroshare-qml-app/src/components/Faces.qml index ed60df314..723384219 100644 --- a/retroshare-qml-app/src/components/Faces.qml +++ b/retroshare-qml-app/src/components/Faces.qml @@ -138,9 +138,8 @@ Item } // canvasAvatar.images = onloads // canvasAvatar.callback = callback - var datas = androidImagePicker.faceImage(onloads, iconSize) - console.log("@@@@@@@ url " , datas) - callback("data:image/png;base64,"+datas) + var base64Image = androidImagePicker.faceImage(onloads, canvasSizes) + callback("data:image/png;base64,"+base64Image) // canvasAvatar.requestPaint() } From 4642f2ab2a8c97fd6148d3e9225f815c0a420774 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Mon, 11 Sep 2017 16:42:29 +0200 Subject: [PATCH 12/16] Clean code --- retroshare-qml-app/src/androidimagepicker.h | 27 +----------- retroshare-qml-app/src/components/Faces.qml | 48 +++++---------------- 2 files changed, 12 insertions(+), 63 deletions(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index 168e33bdf..89759edbc 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -79,18 +79,7 @@ public slots: reader.setFileName(path); QImage image = reader.read(); painter.drawImage(0, 0, image); // xi, yi is the position for imagei -// if (counter == 0) -// { -// base = QImage(bg.size(), QImage::Format_ARGB32_Premultiplied); -// qDebug() << "FIIIRST "; - -// } -// else -// { - -// } - qDebug() << "iterating through QVariantList "; - qDebug() << (*j).toString(); // Print QVariant + qDebug() << "Generating face Avatar from: " << (*j).toString(); // Print QVariant counter++; } painter.end(); @@ -104,23 +93,9 @@ public slots: // Get Based 64 image string QString encoded = QString(ba.toBase64()); - qDebug() << "@@@@@ encoded avatar " << encoded ; - return encoded; } - QImage getImageFromPath (QString localPath) - { - qDebug() << "getImageFromPath() local path:" << localPath ; - - // Read the image - QImageReader reader; - reader.setFileName(localPath); - QImage image = reader.read(); - return image; - - } - }; diff --git a/retroshare-qml-app/src/components/Faces.qml b/retroshare-qml-app/src/components/Faces.qml index 723384219..7a1b0d2a1 100644 --- a/retroshare-qml-app/src/components/Faces.qml +++ b/retroshare-qml-app/src/components/Faces.qml @@ -16,7 +16,6 @@ Item id: imageAvatar width: height height: iconSize - visible: true } // Canvas @@ -134,13 +133,9 @@ Item { var url = src(gender, i, data[i+1]) onloads.push(url) -// canvasAvatar.loadImage(url) } -// canvasAvatar.images = onloads -// canvasAvatar.callback = callback var base64Image = androidImagePicker.faceImage(onloads, canvasSizes) callback("data:image/png;base64,"+base64Image) -// canvasAvatar.requestPaint() } // Create the identicon @@ -148,32 +143,11 @@ Item { var iconId = [dataHex, iconSize]; var update = function(data) - { - // This conditions are for solve a bug on an Lg S3. - // On this device the toDataURL() is incompleted. - // So for see the complete avatar at least at first execution we'll show the canvas, - // instead of the image component. - // See issue: https://gitlab.com/angesoc/RetroShare/issues/37 - if (facesCache.iconCache[iconId]) - { - imageAvatar.source = data - imageAvatar.visible = true -// canvasAvatar.visible = false - -// canvasAvatar.height = 0 - imageAvatar.height = iconSize - } - else - { -// canvasAvatar.visible = true - imageAvatar.visible = false - -// canvasAvatar.height = iconSize - imageAvatar.height = 0 - } - - facesCache.iconCache[iconId] = data; - } + { + imageAvatar.source = data + imageAvatar.height = iconSize + facesCache.iconCache[iconId] = data; + } if (facesCache.iconCache.hasOwnProperty(iconId)) { @@ -186,13 +160,13 @@ Item else { var onImageGenerated = function(data) - { + { - facesCache.callbackCache[iconId].forEach(function(callback) - { - callback(data); - }) - } + facesCache.callbackCache[iconId].forEach(function(callback) + { + callback(data); + }) + } facesCache.callbackCache[iconId] = [update]; if (dataHex) From be7c6a966f2956f6289b6f8fc603dcebc0431ccb Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Mon, 11 Sep 2017 16:43:38 +0200 Subject: [PATCH 13/16] Refactor function name --- retroshare-qml-app/src/androidimagepicker.h | 2 +- retroshare-qml-app/src/components/Faces.qml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index 89759edbc..2de4aaabe 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -65,7 +65,7 @@ public slots: return encoded; } - static QString faceImage (QVariantList onloads, int size) + static QString base64FaceAvatarGenerator (QVariantList onloads, int size) { QImage result(size, size, QImage::Format_ARGB32_Premultiplied); QPainter painter(&result); diff --git a/retroshare-qml-app/src/components/Faces.qml b/retroshare-qml-app/src/components/Faces.qml index 7a1b0d2a1..ea4fe28dc 100644 --- a/retroshare-qml-app/src/components/Faces.qml +++ b/retroshare-qml-app/src/components/Faces.qml @@ -134,7 +134,7 @@ Item var url = src(gender, i, data[i+1]) onloads.push(url) } - var base64Image = androidImagePicker.faceImage(onloads, canvasSizes) + var base64Image = androidImagePicker.b64AvatarGen(onloads, canvasSizes) callback("data:image/png;base64,"+base64Image) } From 44ffdb97c59f0bc6b3b54e1b220257953e0dfc41 Mon Sep 17 00:00:00 2001 From: Angela Mazzurco Date: Mon, 11 Sep 2017 16:52:15 +0200 Subject: [PATCH 14/16] Refactor and delete repeated code --- retroshare-qml-app/src/androidimagepicker.h | 48 +++++++++------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/retroshare-qml-app/src/androidimagepicker.h b/retroshare-qml-app/src/androidimagepicker.h index 2de4aaabe..06ceade18 100644 --- a/retroshare-qml-app/src/androidimagepicker.h +++ b/retroshare-qml-app/src/androidimagepicker.h @@ -43,30 +43,19 @@ public slots: QString localPath = url.toLocalFile(); qDebug() << "imageToBase64() local path:" << localPath ; - - // Read the image - QImageReader reader; - reader.setFileName(localPath); - QImage image = reader.read(); + QImage image= getImage (localPath); image = image.scaled(96,96,Qt::KeepAspectRatio,Qt::SmoothTransformation); - // Transform image into PNG format - QByteArray ba; - QBuffer buffer( &ba ); - buffer.open( QIODevice::WriteOnly ); - image.save( &buffer, "png" ); + qDebug() << "imageToBase64() encoding" ; - // Get Based 64 image string - QString encoded = QString(ba.toBase64()); - - qDebug() << "imageToBase64() encoded" ; - - return encoded; + return imageToB64(image); } - static QString base64FaceAvatarGenerator (QVariantList onloads, int size) + static QString b64AvatarGen (QVariantList onloads, int size) { + qDebug() << "b64AvatarGen(): Generating face Avatar from"; + QImage result(size, size, QImage::Format_ARGB32_Premultiplied); QPainter painter(&result); @@ -74,27 +63,32 @@ public slots: int counter = 0; for (QVariantList::iterator j = onloads.begin(); j != onloads.end(); j++) { - QString path = ":/"+(*j).toString(); - QImageReader reader; - reader.setFileName(path); - QImage image = reader.read(); + QImage image = getImage (":/"+(*j).toString()); painter.drawImage(0, 0, image); // xi, yi is the position for imagei - qDebug() << "Generating face Avatar from: " << (*j).toString(); // Print QVariant counter++; } painter.end(); + return imageToB64(result); + } + + static QImage getImage (QString const& path) + { + QImageReader reader; + reader.setFileName(path); + return reader.read(); + } + + static QString imageToB64 (QImage image) + { // Transform image into PNG format QByteArray ba; QBuffer buffer( &ba ); buffer.open( QIODevice::WriteOnly ); - result.save( &buffer, "png" ); + image.save( &buffer, "png" ); // Get Based 64 image string - QString encoded = QString(ba.toBase64()); - - return encoded; - + return QString(ba.toBase64()); } From 9ba7b5cf4712c4d3041799e9ec45cae48af09377 Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sun, 8 Oct 2017 11:44:51 +0200 Subject: [PATCH 15/16] qml-app properly initialize ChatView.gxsInfo Use proper Qml empty object notation instead of string to inistalize property of type var as it is an object not a string, thus fixing the assiciated warning --- retroshare-qml-app/src/ChatView.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/retroshare-qml-app/src/ChatView.qml b/retroshare-qml-app/src/ChatView.qml index 505637274..07b81f9ad 100644 --- a/retroshare-qml-app/src/ChatView.qml +++ b/retroshare-qml-app/src/ChatView.qml @@ -28,7 +28,7 @@ Item { id: chatView property string chatId - property var gxsInfo: "" + property var gxsInfo: ({}) property int token: 0 property string objectName:"chatView" @@ -64,7 +64,7 @@ Item function changeState () { toolBar.state = "CHATVIEW" - gxsInfo= ChatCache.lastMessageCache.getGxsFromChatId(chatView.chatId) + gxsInfo = ChatCache.lastMessageCache.getGxsFromChatId(chatView.chatId) toolBar.gxsSource = gxsInfo.gxs toolBar.titleText = gxsInfo.name } From 69efa07224a35c0bc63b22751690d231087301cf Mon Sep 17 00:00:00 2001 From: Gioacchino Mazzurco Date: Sun, 8 Oct 2017 12:00:07 +0200 Subject: [PATCH 16/16] qml-app removed some dead code --- retroshare-qml-app/src/components/Faces.qml | 47 ++------------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/retroshare-qml-app/src/components/Faces.qml b/retroshare-qml-app/src/components/Faces.qml index ea4fe28dc..27ba5dab8 100644 --- a/retroshare-qml-app/src/components/Faces.qml +++ b/retroshare-qml-app/src/components/Faces.qml @@ -4,13 +4,11 @@ import "../" // Needed by ChatCache (where stores generated faces) Item { - id: faces property string hash property var facesCache: ChatCache.facesCache - Image { id: imageAvatar @@ -18,49 +16,10 @@ Item height: iconSize } -// Canvas -// { -// id: canvasAvatar -// width: height -// height: canvasSizes -// visible: false - -// renderStrategy: Canvas.Threaded; -// renderTarget: Canvas.Image; - -// property var images -// property var callback - - -// onPaint: -// { -// var ctx = getContext("2d"); - -// if (images) -// { -// for (y = 0 ; y< nPieces ; y++) -// { -// ctx.drawImage(images[y], 0, 0, iconSize, iconSize ) -// } -// } - -// } - -// onPainted: -// { -// if (callback) -// { -// var data = toDataURL('image/png') -// callback(data) -// } -// } -// } - - Component.onCompleted: - { - createFromHex(hash) - } + Component.onCompleted: createFromHex(hash) + /* TODO: Is there a reason why we are using var and not proper type for the + * following properties? */ property var facesPath: "/icons/faces/"