anatolyk82 / ShaderTransitionView

A QML plugin which provides an easy way to apply different transitions between two QML views by using shaders.
18 stars 7 forks source link

Shader Transition View

This is a small QML plugin which provides an easy way to apply different transitions between two QML views in your Qt/QML application.

To learn more about the project visit wiki pages.

This short video can show some of those transitions. ScreenShot

There is a demo application which shows how ShaderTransitionView actually works. The app can be found here.

STView

STView is a QML element which provides a stack-based navigation model with different animation effects between two views.

Import statement: import ShaderTransitionView 1.0

Properties:

Methods:

Signals:

Transitions

ShaderTransitionView.EffectWIND

Options:


ShaderTransitionView.EffectVERTICALWIND

Options:


ShaderTransitionView.EffectCIRCLEOPEN

Options:


ShaderTransitionView.EffectPINWHEEL

Options:


ShaderTransitionView.EffectDIRECTIONALWIPE

Options:


ShaderTransitionView.EffectRADIALWIPE

Options:

Read more...


ShaderTransitionView.EffectPIXELIZE

Options:


ShaderTransitionView.EffectFLIP

Options:


ShaderTransitionView.EffectFOLD

Options:


ShaderTransitionView.EffectDOORWAY

Options:

Read more...


ShaderTransitionView.EffectFADECOLOR

Options:


ShaderTransitionView.EffectMORPH

Options:


ShaderTransitionView.EffectPOLKADOTS

Options:

Read more...


ShaderTransitionView.EffectSQUEEZE

Options:

Read more...


ShaderTransitionView.EffectHORIZONTALSLIDE

Options:


ShaderTransitionView.EffectVERTICALSLIDE

Options:


ShaderTransitionView.EffectCROSSZOOM

Options:

Read more...


ShaderTransitionView.EffectSWIRL

Options:

Read more...


ShaderTransitionView.EffectLINEARBLUR

Options:

Read more...


ShaderTransitionView.EffectSWAP

Options:

Read more...


ShaderTransitionView.EffectCROSSHATCH

Options:

Read more...


How to use it

The video above shows that the content of QML pages can be various. It doesn't matter whether a QML page has maps or any interactive element such as Button or ListView for instance or maybe it's just a static picture. Let's have a look how to use the plugin in QML:

import QtQuick 2.5
import QtQuick.Window 2.2
import ShaderTransitionView 1.0

Window {
    visible: true
    width: 1000
    height: 600

    STView {
        id: view
        anchors.fill: parent
        duration: 700
        transition: ShaderTransitionView.EffectFADECOLOR
        transitionOptions: { "color": Qt.vector3d(0.0, 0.0, 0.0) }
    }

    Component.onCompleted: {
        specialView.push( "PageExample1.qml" )
    }
}

We created a new window and filled it by STView. By calling the method push(...) in Component.onCompleted in such a way specialView.push( "PageExample1.qml" ) we put a QML page PageExample1.qml into the stack so the page PageExample1.qml will be displayed when the window appears. Next time when we want to change the current view by the next one, we need to call the same method push(...) or we there is one more similar method pushItem(...) in STView which puts the next view represented as QQmlComponent. Here is another example:

import QtQuick 2.5
import QtQuick.Window 2.2
import ShaderTransitionView 1.0

Window {
    visible: true
    width: 1000
    height: 600

    Component {
      id: componentPage2
      MyPage2 {
        id: myPage2
        onBackPressed: {
          stView.transitionOptions = { "forward":false }
          stView.pop()
        }
        onNextPressed: {
          stView.transitionOptions = { "forward":true }
          stView.pushItem( componentPage3 )
        }
      }
    }

    Component {
      id: componentPage3
      MyPage3 {
        id: myPage3
        onBackPressed: {
          stView.transitionOptions = { "forward":false }
          stView.pop()
        }
      }
    }

    STView {
        id: stView
        anchors.fill: parent
        duration: 700
        transition: ShaderTransitionView.EffectWIND
        transitionOptions: { "size": 0.3 }
    }

    Component.onCompleted: {
        stView.push( "PageExample1.qml" )
    }
}

Here we have two additional pages MyPage2{...} and MyPage3{...} represented as QML components. They will be loaded when we call the method pushItem(...) If our pages emit signals backPressed() and nextPressed() we can define handlers and put/remove pages into/from the stack. This example also shows that we can put any different options for transition every time when we put or remove pages. For the button "Back" we can change direction of unfolding animation.

  stView.transitionOptions = { "forward":false }
  stView.pop()

The method pop() removes the current page from the stack and displays the previous one. If we want to go to the next page we will do very similar actions but instead removing a page from the stack we need to put it into the stack by calling push(...) or pushItem(...).

  stView.transitionOptions = { "forward":true }
  stView.pushItem( componentPage3 )

Transitions and options for each transition can be changed during navigation through the stack.

An experiment

Experimentally I made similar effects with video as a source. On the video below it's possible to see how it works. ScreenShot