Reply
Thread Tools
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#1
Hi all,

I'm having problems making a cover action work. Here's my current code;

Code:
import QtQuick 2.4
import Sailfish.Silica 1.0

CoverBackground {
    CoverPlaceholder {
        id: coverPlaceholder
        text: "National Rail"
        icon.source: "../images/harbour-nationalrail.png"
    }
    CoverActionList {
        CoverAction {
            iconSource: "image://theme/icon-cover-search"
            onTriggered: Qt.resolvedUrl("Search.qml")
        }
    }
}
Quite simple, I just want to click the search icon on the cover and open the Search page of my app.......so, what am I missing here?

file hierarchy;

CoverPage - /usr/share/harbour-nationalrail/qml/cover/CoverPage.qml
Other pages - /usr/share/harbour-nationalrail/qml/pages/Search.qml

Thanks,

p.s. courteous answers only please
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..

Last edited by Markkyboy; 2017-09-11 at 01:00. Reason: Cover action (Solved)
 

The Following 3 Users Say Thank You to Markkyboy For This Useful Post:
merlin1991's Avatar
Posts: 125 | Thanked: 1,142 times | Joined on Feb 2010 @ Austria
#2
It's been a while since I did this and there might be better ways nowadays, but here I go:

Since you didn't describe you actual situation (except it doesn't work) and atm I can't test the sample, have some pointers:

If you don't see your coveraction, CoverActionList has an enabled property (boolean).

onTriggered is called/executed when you touch the action, calling the resolved string of your qml file ofc won't do anything.

Instead call a function that does all the heavy lifting of changing application state, so basically:

Code:
import QtQuick 2.4
import Sailfish.Silica 1.0

CoverBackground {
    CoverPlaceholder {
        id: coverPlaceholder
        text: "National Rail"
        icon.source: "../images/harbour-nationalrail.png"
    }
    CoverActionList {
        CoverAction {
            iconSource: "image://theme/icon-cover-search"
            onTriggered: showSearch()
        }
    }

    function showSearch() {
        pageStack.push(Qt.resolvedUrl("Search.qml"))
        appWindow.activate()
    }
}
appWindow is the id of your ApplicationWindow, you can play with the parameters of pageStack.push to get the desired effect ie. no transition to the new page, see https://sailfishos.org/develop/docs/...l/#push-method
__________________
"Fog is neither water nor air, it's something between." Merlin
 

The Following 9 Users Say Thank You to merlin1991 For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#3
Okay, progress!, I now have a working shortcut on my cover, with extended thanks to Merlin1991, as initially, I couldn't make his code work at all, that is until I moved CoverPage.qml into the pages directory and removed cover directory completely, then with one minor change to Merlin's code ('appWindow' to 'window') and now I have a basic cover action, but......

A few little problems with the now working shortcut, firstly, I get a glimpse of the first page of the app as the Search page is spawned from cover and if I minimise the spawned search page and go back to the cover, tap the search icon, then another search page is spawned on to the stack, making 2 search pages.....?

So, how to stop the glimpse of the first page as Search page spawns and how to prevent the stacking up of search pages with each tap on the cover shortcut?

Here's the working code;

Code:
import QtQuick 2.4
import Sailfish.Silica 1.0

CoverBackground {
    id: cover
    CoverPlaceholder {
        id: coverPlaceholder
        text: "National Rail"
        icon.source: "../images/harbour-nationalrail.png"
    }
    CoverActionList {
        CoverAction {
            iconSource: "image://theme/icon-cover-search"
            onTriggered: showSearch()

            function showSearch() {
                pageStack.push(Qt.resolvedUrl("Search.qml"))
                window.activate();
            }
        }
    }
}
More progress: I've stopped the glimpse of the first page when search is spawning from cover action, just a minor change to the onTriggered portion of the code while also removing the 'function' call;

Code:
CoverBackground {
    id: cover
    CoverPlaceholder {
        id: coverPlaceholder
        text: "National Rail"
        icon.source: "../images/harbour-nationalrail.png"
    }
    CoverActionList {
        CoverAction {
            iconSource: "image://theme/icon-cover-search"
            onTriggered: {
                window.activate()
                pageStack.push("Search.qml", {}, PageStackAction.Immediate)
            }
        }
    }
}
Now to prevent search from spawning more than once!
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..

Last edited by Markkyboy; 2017-09-10 at 12:05.
 

The Following 2 Users Say Thank You to Markkyboy For This Useful Post:
Markkyboy's Avatar
Posts: 433 | Thanked: 727 times | Joined on Oct 2012 @ Costa Blanca, Espaņa
#4
Sorted, I now have 2 cover actions working as expected. While it may not be the most eloquent way of doing it, it works nonetheless. Only a single instance of each cover action now occurs

The working code is as follows;

Code:
import QtQuick 2.0
import Sailfish.Silica 1.0

CoverBackground {
    CoverPlaceholder {
        text: "Live Departure Boards"
        icon.source: "../images/harbour-nationalrail.png"
    }
    CoverActionList {
        CoverAction {
            iconSource: "image://theme/icon-cover-search"
            onTriggered: {
                pageStack.navigateBack(PageStackAction.Immediate)
                pageStack.push('Search.qml')
                pageStack.navigateForward(PageStackAction.Immediate)
                activate()
            }
        }
Thanks to Merlin1991 for getting it all rolling
__________________
..oO(Don't just sit there standing around, pick up a shovel and sweep up!)Oo..

Last edited by Markkyboy; 2017-09-11 at 09:17. Reason: Changed a minor detail; 'pageStack.pushAttached' to 'pageStack.push'
 

The Following 5 Users Say Thank You to Markkyboy For This Useful Post:
Posts: 1,746 | Thanked: 1,832 times | Joined on Dec 2010
#5
hey man. I can't seem to reply to your DM shoot me over your email if you don't mind and I'll message you there
 

The Following 2 Users Say Thank You to m4r0v3r For This Useful Post:
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 20:00.