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

Keeping currentIndex in sync with a GridView

Tags: None
(comma "," separated)
User avatar
Timmer
Registered Member
Posts
23
Karma
0
OS
I'm writing an activity switcher plasmoid. It displays the activity icon in a GridView. When you click the icon, it switches to the proper activity. I'd like the current activity to be highlighted, using the highlight property built into GridView. I've got it so that when I click, the highlight follows the click. But I cannot figure out how to get the GridView.currentIndex to stay in sync with the current activity (for example, on intial login, or switching activities with Win+Tab.).

(I am able to get the highlight to work by recreating the highlight box manually in my delegate, but then I lose the animation features from the GridView builtin, so I'd rather use that if possible)

It seems like the ActivityModel should have an onCurrentActivityChanged event that I could use, or a currentActivity property that returns the activity ID, but neither of those appears to exist. (actually, onCurrentActivityChanged exists - it's just private.)

I've copied what I believe to be the relevant code below:
Code: Select all
   
GridView {
   id: gridView
   ...
   model: activityTrayModel
   delegate: activityDelegateComponent
      
   highlight: Rectangle {
      id: highlightBackground
      color: theme.highlightColor
      opacity: 0.6
      radius: 3
   }
}

Activities.ActivityModel {
   id: activityTrayModel
   shownStates: "Running"
}


And my Delegate component
Code: Select all
MouseArea {
   id: wrapper
   property bool isExpanded: false
   
   PlasmaCore.IconItem {
      id: activityIcon
      source: iconSource
      anchors.horizontalCenter: parent.horizontalCenter
      
      PlasmaCore.ToolTipArea {
         id: toolTip
         anchors.fill: parent
         
         active: !isExpanded
         icon: icon
         mainText: name
      }
   }
   
   onClicked: {
      activityTrayModel.setCurrentActivity(id, function() {});
      gridView.currentIndex = index;
   }
}


Is there a way to get from where I am to where I want to go?


Timmer, proud to be a member of KDE forums since 2008-Nov.


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]