StarMenu: custom QML component plugin
(Lildeimos -) |
(Lildeimos -) |
||
| Line 26: | Line 26: | ||
== Usage == | == Usage == | ||
| − | '''Note for Harmattan:''' .pro must contains this: | + | '''Note for Harmattan:''' |
| + | .pro must contains this: | ||
| + | <code java> | ||
contains(MEEGO_EDITION,harmattan) { | contains(MEEGO_EDITION,harmattan) { | ||
DEFINES += MEEGO_EDITION_HARMATTAN | DEFINES += MEEGO_EDITION_HARMATTAN | ||
QT += dbus | QT += dbus | ||
} | } | ||
| + | </code> | ||
'''To compile and install the plugin, just do:''' | '''To compile and install the plugin, just do:''' | ||
| Line 49: | Line 52: | ||
Then in the main.cpp include the headers: | Then in the main.cpp include the headers: | ||
<code java> | <code java> | ||
| − | + | #include "starmenu.h" | |
| − | + | #include "staritem.h" | |
</code> | </code> | ||
| Line 56: | Line 59: | ||
<code java> | <code java> | ||
| − | + | qmlRegisterType<StarMenu>("StarMenu", 1, 0, "StarMenu"); | |
| − | + | qmlRegisterType<StarItem>("StarMenu", 1, 0, "StarItem"); | |
</code> | </code> | ||
then, in your .qml file, you will be able to: | then, in your .qml file, you will be able to: | ||
<code java> | <code java> | ||
| − | + | import StarMenu 1.0 | |
</code> | </code> | ||
Revision as of 19:48, 25 March 2012
This article introduces StarMenu, a QML pop up menu that animates menu elements to align them around a central star.
Article Metadata
Tested with
Compatibility
Article
Contents |
Introduction
The StarMenu is a pop up menu that can be raised by clicking or tapping on an area defined like using MouseArea component. The StarMenu's menu items are defined using StarItems. This plugin is been developed with Qt 4.7.4 and tested on linux, Nokia N900, Nokia C7-00, Nokia N950 and Android Galaxy tab GT-7310 (with Necesistas ).
Usage
Note for Harmattan: .pro must contains this:
contains(MEEGO_EDITION,harmattan) {
DEFINES += MEEGO_EDITION_HARMATTAN
QT += dbus
}
To compile and install the plugin, just do:
qmake
make
make install
then in your .qml you will need to
import com.starMenu 1.0
To compile within your project: copy staritem.* and starmenu.* in your project directory and add them to the .pro file. Then in the main.cpp include the headers:
#include "starmenu.h"
#include "staritem.h"
and before setSource() or setMainQmlFile() register the component with:
qmlRegisterType<StarMenu>("StarMenu", 1, 0, "StarMenu");
qmlRegisterType<StarItem>("StarMenu", 1, 0, "StarItem");
then, in your .qml file, you will be able to:
import StarMenu 1.0
The StarMenu component displays a contextual menu in a declarative user interface.
StarMenu is hidden by default and opens in response to a user action. The purpose of StarMenu is to manage all StarItem childs. By default they are arrange in a circle shape and, in the center of it, it is painted a star polygon shape with as many spikes as the number of StarItems. It can be visible or not by setting the boolean starCenterVisible property. The circle shape amplitude is given by {{Icode|radiusH} and {{Icode|radiusV} properties. Clicking on the center of the current menu, will close it and goes back to parent. It's possible to click on the center of the first menu to close all. visualParent property is used to bind the close menu action to a specified item, so, instead of clicking on center of {{Icode|StarMenu}, it's possible to set {{Icode|visualParent} to the main window and close menu everywhere on the screen. When using {{Icode|visualParent}, it come handy the {{Icode|color} property to set a transparent color to the clickable area to close the menu. Changing StarItem visible property, makes all {{Icode|StarItem}s position recalculated with only visible items.
It is possible to bind animations to StarItems. When a StarMenu is raised, the StarItems circle shape has the center located by the mouse click (or tap) position and their opacity, rotation, x, y property are set to 0. By doing this:
StarItem {
[...]
Behavior on x { NumberAnimation { duration: 1500; easing.type: Easing.OutBounce } }
Behavior on y { NumberAnimation { duration: 1500; easing.type: Easing.OutBounce } }
Behavior on opacity { NumberAnimation { duration: 2200; easing.type: Easing.OutBounce } }
StarItems are animated from center to their final position.
StarMenu has also a delayChangePos property. For example, when it is set to 100, the animation of the second StarItem is started after 100 ms, the third after 200 ms and so on. StarItem has also a delayChangePos property and if it is set, it take priority over the StarMenu delayChangePos property.
StarItems can also contain any other component instead Image component used in these examples:
StarItem {
width: 320; height: 240
scale: 0.3
zoomHoverValue: 1
Behavior on scale { NumberAnimation { duration: 500; easing.type: Easing.OutQuad } }
Column {
Button { text: "Hello Qt" }
Switch { }
RadioButton { }
}
}
StarItemss can be arranged in a spiral shape, in a grid shape or in a line shape. StarMenu shape property could have the following values:
- StarMenu.ShapeCircle (default value)
- StarMenu.ShapeGrid
- StarMenu.ShapeSpiral
- StarMenu.ShapeLine
Rows in grid shape are arranged centered by the mouse click and are spaced by spacingH and spacingV properties with columns count defined by {{Icode|columns} property. Spiral shape takes care of startingRadius value to start drawing StarItems and radiusIncrement property to shape the spiral. Line shape has a startingAngle, radiusIncrement and startingRadius properties.
StarMenu has the center where user clicks. This centerproperty can be defined everywhere in scene coordinates by setting center property.
Properties & signals
StarMenu
Properties
- center: point
- color: color
- columns: int
- delayChangePos: int
- open: bool
- radiusH: qreal
- radiusV: qreal
- rotation: qreal
- radiusIncrement: qreal
- shape: enumeration
- spacingH: qreal
- spacingV: qreal
- startingAngle: qreal
- starCenterVisible: bool
- startingRadius: qreal
- useParentMenuCenter: bool
- visualParent: Item
Signals
- StarMenu::starMenuOpening()
- StarMenu::starMenuClosing()
StarItem
Properties
- zoomHoverValue: qreal
- delayChangePos: int
Signals
- StarItem::hoverItem()
- StarItem::leaveItem()
- StarItem::clicked()

