maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   SailfishOS (https://talk.maemo.org/forumdisplay.php?f=52)
-   -   Cover action (Solved) (https://talk.maemo.org/showthread.php?t=99795)

Markkyboy 2017-09-06 19:49

Cover action (Solved)
 
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 :D

merlin1991 2017-09-06 21:23

Re: Cover action
 
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

Markkyboy 2017-09-09 18:38

Re: Cover action
 
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! :)

Markkyboy 2017-09-11 00:55

Re: Cover action (Solved)
 
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 :)

m4r0v3r 2017-10-11 10:20

Re: Cover action (Solved)
 
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 :)


All times are GMT. The time now is 22:23.

vBulletin® Version 3.8.8