Home · All Classes · Main Classes · Deprecated |
MeeGo Touch provides an easy way to integrate immediate feedback into graphical applications. The concept is based on the Qt's signal/slot architecture and the standard theme principles of Linux systems, and it is therefore easy to understand and deploy.
A mobile device can support several means for feedback, for example, audio speaker, vibra or piezo actuators. Input feedback facilitates the use of graphical controls on the touch screen by providing feedback which is similar to physical buttons. MeeGo Touch offers low latency input feedback which is important for the usability of the product.
The feedbacks are identified by name. For instance, if a user touches a button on the screen, "press" feedback is played or if a selected check box is pressed, "press-off" feedback is played. The feedbacks are played by a daemon (meegofeedbackd) that is invisible for the developers. Different types of feedback methods can be provided by different hardware:
MFeedback class provides an interface to send playback requests from a MeeGo Touch application to the feedback daemon. In practice, when a feedback-related signal is emitted, it should be translated into a feedback name and sent to the feedback daemon through the MFeedback class. The MFeedback class only forwards the feedback name to the feedback daemon, it does not know anything about the source of the signal which triggered the event and the feedback name is not validated at MeeGo Touch level. The feedback daemon receives the feedback name, validates it in the context of the current theme and the application name and plays the corresponding vibra/audio feedback if there is any. If multiple feedbacks (for example, audio and vibra) are available for the same name, they are played simultaneously.
For more information on the location of the feedback files in themes, see section Feedbacks in Theme directory structure Theme directory structure.
Typically, a feedback directory can contain two files: vibra.ivt and audio.wav.
Some principles are followed in the theme logic:
The feedbacks can be played on three different volume levels. This is a global setting of the feedback daemon, but the feedbacks should be prepared for. The PulseAudio (audio) backend of the daemon sets the appropriate playback volume from a config file so nothing needs to be done in PulseAudio case. The vibra backend checks the vibra.ivt for three timeline effects named "low", "medium" and "high", referring to low, medium and high volume levels. If there are no correctly named timeline effects in the effect file, the first effect is used (its type does not matter in this case).
This section only describes the feedback-specific syntax. Thus, it is recommended that you read first the Styling Styling section of the MeeGo Touch documentation.
A CSS file is associated with an application to describe the style of the widgets. For an application named "example" and a theme named "base", it is located in /usr/share/themes/base/meegotouch/example/style/example.css. The widgets in the applications can be styled at class-level (for example, for every button in an application) or at object/instance level (for one specific button in the application). The following is a brief overview of style sheets:
The following real-life examples illustrate the principles above. If a style is specific to every instance of a class, it must be written as follows:
MButtonStyle { }
Object instances can be referred by their name. The style data of a button named "SendButton" (an instance of an MButton):
MButtonStyle#SendButton { }
If multiple instances of several classes (MButton, MTextEdit) are named with the same name "CommonElements", they can be styled with:
#CommonElements { }
In the following example, "huge-feedback" is specified for the "press" event of an MButton widget instance with the object name "SignInButton":
MButtonStyle#SignInButton { press-feedback: huge-feedback; }
The equivalent source code with this example:
// Create a button MButton* button = new MButton(); .... // Create a "huge-feedback" feedback MFeedback* feedback = new MFeedback("huge-feedback"); // Connect the press event of the button to play the "huge-feedback". connect(button, SIGNAL(press()), feedback, SLOT(play()));
As shown above, the styling rules are written between the curly brackets.
MFeedback class is a thin convenience class used to easily play input feedbacks.
Play the input feedback manually:
feedback->play();
Connect a signal to the feedback:
connect(button, SIGNAL(pressed()), feedback, SLOT(play()));
MFeedback::play("press");
Behind the scenes the feedback event is forwarded to the feedback daemon and the audio/vibra feedback is played as soon as possible.
The following application simply plays a feedback called "press".
app.pro:
TEMPLATE = app CONFIG += meegotouch SOURCES += main.cpp
main.cpp:
#include <MApplication> #include <MFeedback> int main(int argc, char* argv[]) { MApplication app(argc, argv); // Process some initial events in the event queue app.processEvents(); // Request the press feedback MFeedback::play("press"); // Be sure that the request is processed app.processEvents(); }
The following application creates a window and places a button (MButton) in the window. The default press and release feedbacks are used automatically. Feedback named "press" is played when button is pressed and feedback named "release" is played when the button is released. These "press" and "release" feedback files are loaded from the current theme.
app.pro:
TEMPLATE = app CONFIG += meegotouch SOURCES += main.cpp
main.cpp:
#include <MApplication> #include <MApplicationWindow> #include <MApplicationPage> #include <MButton> int main(int argc, char* argv[]) { // Create an application with a button MApplication app(argc, argv); MApplicationPage* page = new MApplicationPage(); MApplicationWindow* window = new MApplicationWindow(); MButton* button = new MButton("Hello World"); // Show the UI page->setCentralWidget(button); window->show(); page->appear(window); // Enter the main loop app.exec(); // Clean up delete window; }
The following application creates a window and places a "Hello world!" button in the window. The default input feedback support is switched off by forcing the usage of the motif style, but the press feedback is connected to the pressed signal of the button manually. If any argument is passed to the application, the feedback is not connected to the signal.
app.pro:
TEMPLATE = app CONFIG += meegotouch SOURCES += main.cpp
main.cpp:
#include <QApplication> #include <QMotifStyle> #include <QPushButton> #include <MComponentData> #include <MFeedback> int main(int argc, char* argv[]) { // Create an application with a button QApplication app(argc, argv); QPushButton* button = new QPushButton("Hello World"); // An MComponentData instance is needed for the MeeGo related Qt extensions. MComponentData mTData(argc, argv); // Force the motif style to switch off the automatic input feedback support QApplication::setStyle(new QMotifStyle); // Show the UI button->show(); // Get the press feedback MFeedback* feedback = new MFeedback("press"); // Switch off the press feedback if arguments are passed if (argc == 1) // Connect the press event to the "press" feedback button->connect(button, SIGNAL(pressed()), feedback, SLOT(play())); // Enter the main loop app.exec(); // Clean up delete feedback; }
The MWidget has limited support for haptic feedback, the press and the release events of the derived widgets can be styled by default. To add more stylable feedback events, the following steps should be followed:
class MyWidgetStyle : public MWidgetStyle { Q_OBJECT M_STYLE(MyWidgetStyle) M_STYLE_ATTRIBUTE(MFeedback, gestureFeedback, GestureFeedback) };
MyWidgetStyle { gesture-feedback: gesture-click; }
// Connect a signal to play the gesture feedback effect connect(this, SIGNAL(customGesture()), &style()->gestureFeedback(), SLOT(play())); ... // Gesture effect played manually style()->gestureFeedback().play();
In this use case the application name is "app". To change the "press" feedback to an application-specific custom feedback (regardless of the selected theme):
This use case creates an application which places a normal MButton named "NormalButton" in a window and the style sheet overrides the default "press" feedback of the press feedback with the "press-on" feedback. The app.css file must be placed in the usr/share/themes/base/meegotouch/app/style directory.
app.css:
MButtonStyle#NormalButton { press-feedback: press-on; }
app.pro:
TEMPLATE = app CONFIG += meegotouch SOURCES += main.cpp
main.cpp:
#include <MApplication> #include <MApplicationWindow> #include <MApplicationPage> #include <MButton> int main(int argc, char* argv[]) { // Create an application with a button MApplication app(argc, argv); MApplicationPage* page = new MApplicationPage(); MApplicationWindow* window = new MApplicationWindow(); MButton* button = new MButton("Hello World"); button->setStyleName("NormalButton"); // Show the UI page->setCentralWidget(button); window->show(); page->appear(window); // Enter the main loop app.exec(); // Clean up delete window; }
Copyright © 2010 Nokia Corporation | MeeGo Touch |