comexpertise / plasma-kdeconnect-sms

Plasmoid for KDE Connect allowing SMS sending from your desktop
Other
18 stars 2 forks source link

[feature request] - Add to panel as icon #2

Open psifidotos opened 6 years ago

psifidotos commented 6 years ago

Fantastic plasmoid!!! :) keep it up!!!

comxd commented 6 years ago

Thanks! I agree too. It's planned in the roadmap :)

comxd commented 6 years ago

Fixed in the lastest commit, can you review?

psifidotos commented 6 years ago

just checked it...

the issue I have in my system is that kdeconnect icon isnt growing when the thickness of panel grows. Latte dock heuristics also didnt identify correctly the IconItem used in order to provide correctly its parabolic effect.

I replaced the CompactRepresentation.qml code completely with just the following and all the above issues were fixed:

import QtQuick 2.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore

PlasmaCore.IconItem {
    source: "kdeconnect"
    anchors.fill: parent
    active: mouseArea.containsMouse

    PlasmaCore.ToolTipArea {
        anchors.fill: parent
        icon: parent.source
        mainText: "Send SMS with KDEConnect"
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
        onClicked: plasmoid.expanded = !plasmoid.expanded
        hoverEnabled: true
    }
}
Zren commented 6 years ago

If you wish to have it the same height as other panel icon widgets, you might be interested in the default CompactRepresentation.

Notice how it'll cap out at units.iconSizeHints.panel when in a panel.

You don't appear to be doing anything special to the compact representation yet, so you could even just delete the Plasmoid.compactRepresentation: CompactRepresentation {} in main.qml, and it should automatically use the file linked above. It'll use the icon, tooltip based off the info in your metadata.desktop. If you want to change the tooltip text / icon, you can do it with Plasmoid.icon: "iconName" and Plasmoid.toolTipMainText: i18n("Send SMS with KDEConnect").

If you're ever interested in doing a "counter" overlay, check out what I did for todolist (copied from the default task manager widget).

comxd commented 6 years ago

Thanks you for feedbacks. Can you review this commit? https://github.com/comexpertise/plasma-kdeconnect-sms/commit/2e34f9de61c716242893c8fed8d2852b50fca5cb

you could even just delete the Plasmoid.compactRepresentation: CompactRepresentation {} in main.qml

If I delete this line the popup no longer appears

If you're ever interested in doing a "counter" overlay, check out what I did for todolist (copied from the default task manager widget).

Thank you I will study this

Zren commented 6 years ago

Plasmoid.toolTipMainText and Plasmoid.icon need to be attached to your main.qml object otherwise they're ignored. Eg:

diff --git a/plasmoid/contents/ui/main.qml b/plasmoid/contents/ui/main.qml
index 00330dc..736832f 100644
--- a/plasmoid/contents/ui/main.qml
+++ b/plasmoid/contents/ui/main.qml
@@ -14,7 +14,8 @@ import "../lib/"
 Item {
     id: root

-    Plasmoid.compactRepresentation: CompactRepresentation {}
+    Plasmoid.toolTipMainText: i18n("Send SMS with KDEConnect")
+
     Plasmoid.fullRepresentation: FullRepresentation {}

     Plasmoid.preferredRepresentation: MyComponents.isConstrained() ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation
diff --git a/plasmoid/metadata.desktop b/plasmoid/metadata.desktop
index c7016cb..edd64c6 100644
--- a/plasmoid/metadata.desktop
+++ b/plasmoid/metadata.desktop
@@ -2,6 +2,7 @@
 Encoding=UTF-8
 Name=KDEConnect SMS
 Comment=Plasmoid (KDE Plasma desktop) connected to KDEConnect allowing SMS sending from your desktop
+Icon=kdeconnect
 Type=Service

 X-KDE-ParentApp=

You also don't need to set Plasmoid.icon since it defaults to the icon set in the metadata.desktop. Assigning the icon in the metadata will also show up in the "add widget" menu.

However when testing this, I noticed that it does not in fact limit scaling the icon by default with the above code (weird).

2017-12-13___16-25-08

So you'll need to use:

import QtQuick 2.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.core 2.0 as PlasmaCore

// Based on: https://github.com/KDE/plasma-desktop/blob/master/desktoppackage/contents/applet/DefaultCompactRepresentation.qml
MouseArea {
    readonly property bool inPanel: (plasmoid.location == PlasmaCore.Types.TopEdge
        || plasmoid.location == PlasmaCore.Types.RightEdge
        || plasmoid.location == PlasmaCore.Types.BottomEdge
        || plasmoid.location == PlasmaCore.Types.LeftEdge)

    Layout.minimumWidth: {
        switch (plasmoid.formFactor) {
        case PlasmaCore.Types.Vertical:
            return 0;
        case PlasmaCore.Types.Horizontal:
            return height;
        default:
            return units.gridUnit * 3;
        }
    }

    Layout.minimumHeight: {
        switch (plasmoid.formFactor) {
        case PlasmaCore.Types.Vertical:
            return width;
        case PlasmaCore.Types.Horizontal:
            return 0;
        default:
            return units.gridUnit * 3;
        }
    }

    Layout.maximumWidth: inPanel ? units.iconSizeHints.panel : -1
    Layout.maximumHeight: inPanel ? units.iconSizeHints.panel : -1

    PlasmaCore.IconItem {
        id: icon
        anchors.fill: parent
        source: plasmoid.icon
    }

    onClicked: plasmoid.expanded = !plasmoid.expanded
}

2017-12-16___19-12-31

Zren commented 6 years ago

As you can tell in my first screenshot, I also noticed a bug in my "counter" overlay when it's in a very tall panel.

2017-12-13___16-25-08