This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Specific question on submenus in qml

Tags: None
(comma "," separated)
cgiannakidis
Registered Member
Posts
7
Karma
0
OS
I am working on a widget that is a menu (like "apple menu") for my own use.The most part of it is ready except the "Recent Items" menuitem .
Is there a way to make a submenu that displays the recent files when I hover over this.Is there any tutorial on that subject ?
Any help will be appreciated.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
Hi!

You can parse the file ~/.local/share/recently-used.xbel to get recent applications and documents in XML if not disabled by the user. I don't know any tutorials, but if you use the C++-Backend, you can use the QXmlStreamReader Class to read it.
cgiannakidis
Registered Member
Posts
7
Karma
0
OS
Hi.
Sorry for delayed reply.
I am not using c++ backend.I am new on coding on qml.
If you want to give me a help, there is the code https://gist.github.com/cgiannakidis70/ ... 39cea5d5c6 .

Thanks in advance.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
Afaik you cannot do this in pure QML. You can try to reuse the kickoff/kicker-part. Have a look at /usr/share/plasma/plasmoids/org.kde.plasma.kickoff/contents/ui/ and the implementation of the RecentlyUsedView using org.kde.plasma.private.kicker.
cgiannakidis
Registered Member
Posts
7
Karma
0
OS
Hi.
Thanks for the reply . I will work on it later.
By the way as you can see in the code above (post #3), I can not create a submenu .I am using "ListView" for menuitems but I think that it is not the proper way or I am using it the wrong way.Any suggestions for submenu creation will be appreciated.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
You could use the QML Menu with Actions. Using actions has the advantage of not being bound to a visible item. So you can bind an action to a shortcut, menu, button, etc. to handle multiple occurences.
Code: Select all
Menu {
    Action { text: "one" }
    Menu {
        title: "SubMenu"
        Action { text: "Sub one" }
        Action { text: "Sub two" }
    }
}

See QML Menu.
cgiannakidis
Registered Member
Posts
7
Karma
0
OS
Thanks for the suggestion.After studying the "Kicker" code I 've managed to complete the submenu "recent items" task.
I've ended up using ColumnLayout with ListDelegate items.This is roughly the hierarchy of the code:
Code: Select all
         Item {
             id: root
             .............
             Menu {
                 id: recentItemsSubMenu
                 ..............
              }
             ColumnLayout {
                 id: column
                 ...............
                 ListDelegate {
                      id: .........
                      onClicked: {                 
                           recentItemsSubMenu.open()                       
                      }
                 }
                 ................
             }
          }


The problem now is that the menu opens where the mouse pointer is but I want to open on a certain point on the screen.I used also the
Code: Select all
 popup(x,y)
method, where x, and y are the desired point on the screen but does not work. On the contrary the ListDelegate item moves and not the menu.Is there any idea how to fix this?
Thanks again for your help.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
The popup-coordinates are relative to its parent not to the underlying screen(s). But I really do not know how to handle this. I normally don't touch positions as the user expects them being at a specific point, e.g. where right-clicked. You also have to handle the case when the mouse is outside of your popup to not automatically close it. You can test this behaviour in Plasma using the «focus follows mouse» policy in the system settings. I do switch focus only by moving the mouse which will surely close the popup in your approach.
cgiannakidis
Registered Member
Posts
7
Karma
0
OS
Hi.
I finally wrote the code again from scratch, and now I am using only MouseArea and Menu .It seems that all are working fine except that I lost the panel icon.What I mean is that when I use
Code: Select all
Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation
the Plasmoid icon vanishes from panel.When I use
Code: Select all
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
the icon is on the panel but there is a strange behavior.An area appears when I click the plasmoid icon and when I click inside the area appears the menu .A snippet of the code is below:
Code: Select all
import QtQuick 2.15
import QtQuick.Layouts 1.15
import Qt.labs.platform 1.1
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kcoreaddons 1.0 as KCoreAddons // kuser
import org.kde.kquickcontrolsaddons 2.0 // kcmshell
import org.kde.taskmanager 0.1 as TaskManager

import org.kde.plasma.private.appmenu 1.0 as AppMenuPrivate
import org.kde.plasma.private.kicker 0.1 as Kicker

MouseArea {
    id: root
    onClicked: { appleMenu.open(root, appleMenu) }
    Plasmoid.preferredRepresentation: Plasmoid.fullRepresentation

    Menu {
                id: appleMenu       
                minimumWidth: 400
               
               
                MenuItem { ................
                ...................................................
                }
         }
}

Any idea on what might be the problem?
Thanks again.
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
Did you provide a layout for both representations? Your code should catch the switch from compact to full representation and handle the plasmoid different. Did you upload the new code for testing?
cgiannakidis
Registered Member
Posts
7
Karma
0
OS
Hi.
Here is the main.qml: https://gist.github.com/cgiannakidis70/ ... b051fd2ee5
I am confused and I dont know how to move on.
Any help will be appreciated
koffeinfriedhof
Registered Member
Posts
608
Karma
4
OS
You have to provide a fullRepresantation which is almost your current main.qml and compactRepresentation for the icon. See https://techbase.kde.org/Development/Tutorials/Plasma5/QML2/GettingStarted for a minimal example.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]