|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbCore module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include <QApplication> |
|
27 #include <QHash> |
|
28 |
|
29 #include "hbsoftkeygroup_p.h" |
|
30 #include "hbsoftkey_p.h" |
|
31 #include "hbaction.h" |
|
32 #include "hbnamespace_p.h" |
|
33 |
|
34 class HbSoftKeyGroupPrivate : public QObject |
|
35 { |
|
36 Q_OBJECT |
|
37 public: |
|
38 HbSoftKeyGroupPrivate(HbSoftKeyGroup *group); |
|
39 |
|
40 QHash<HbPrivate::SoftKeyId, HbSoftKey *> mSoftKeys; |
|
41 HbSoftKeyGroup *q; |
|
42 HbAction *mDefaultSecondaryAction; |
|
43 |
|
44 private slots: |
|
45 void launchMenu(); |
|
46 }; |
|
47 |
|
48 HbSoftKeyGroupPrivate::HbSoftKeyGroupPrivate(HbSoftKeyGroup *group) |
|
49 : q(group), mDefaultSecondaryAction(0) |
|
50 { |
|
51 } |
|
52 |
|
53 void HbSoftKeyGroupPrivate::launchMenu() |
|
54 { |
|
55 // only the primary softkey is connected so it is safe to assume |
|
56 // the sender is q->primary |
|
57 emit q->launchMenu(mSoftKeys.value(HbPrivate::PrimarySoftKey)->scenePos()); |
|
58 |
|
59 } |
|
60 |
|
61 /* |
|
62 \class HbSoftKeyGroup |
|
63 \brief HbSoftKeyGroup manages soft keys. |
|
64 |
|
65 HbSoftKeyGroup creates and manages soft keys. HbSoftKeyGroup |
|
66 also provides access to individual soft keys. In the default |
|
67 constructor it creates primary, secondary and middle softkeys. |
|
68 |
|
69 Typically the softkey group is created by \a HbDecoratorGroup. |
|
70 The softkey group is accessible via HbDecoratorGroup::indicatorGroup(). |
|
71 |
|
72 A brief example of how to use this class: |
|
73 \code |
|
74 HbSoftKeyGroup *softkeys = decorators->softKeyGroup(); |
|
75 HbSoftKey *primary = softkeys->softKey(HbPrivate::PrimarySoftKey); |
|
76 \endcode |
|
77 |
|
78 \sa HbDecoratorGroup |
|
79 */ |
|
80 |
|
81 |
|
82 /* |
|
83 Default constructor. |
|
84 Creates PrimarySoftkey, SecondarySoftkey and MiddleSoftkey named |
|
85 "primary", "secondary" and "middle" respectively. Primary softkey |
|
86 connects \a launchMenu() slot and secondary to \a quit() slot. |
|
87 */ |
|
88 HbSoftKeyGroup::HbSoftKeyGroup(QObject *parent) |
|
89 : QObject(parent), d(new HbSoftKeyGroupPrivate(this)) |
|
90 { |
|
91 HbSoftKey* secondary = new HbSoftKey(HbPrivate::SecondarySoftKey); |
|
92 |
|
93 // add default quit action to secondary softkey |
|
94 d->mDefaultSecondaryAction = new HbAction(Hb::QuitNaviAction,this); |
|
95 d->mDefaultSecondaryAction->setText("Quit"); |
|
96 connect(d->mDefaultSecondaryAction, SIGNAL(triggered()), qApp, SLOT(quit())); |
|
97 secondary->addAction(d->mDefaultSecondaryAction); |
|
98 |
|
99 d->mSoftKeys.insert(HbPrivate::SecondarySoftKey, secondary); |
|
100 |
|
101 // Create primary and middle soft keys only for non-touch |
|
102 if (!HbDeviceProfile::current().touch()) { |
|
103 HbSoftKey* primary = new HbSoftKey(HbPrivate::PrimarySoftKey); |
|
104 // add default launch menu action to primary softkey |
|
105 HbAction *action = new HbAction(this); |
|
106 action->setText("Options"); |
|
107 connect(action, SIGNAL(triggered()), d, SLOT(launchMenu())); |
|
108 primary->addAction(action); |
|
109 d->mSoftKeys.insert(HbPrivate::PrimarySoftKey, primary); |
|
110 |
|
111 HbSoftKey* middle = new HbSoftKey(HbPrivate::MiddleSoftKey); |
|
112 d->mSoftKeys.insert(HbPrivate::MiddleSoftKey, middle); |
|
113 } |
|
114 } |
|
115 |
|
116 /* |
|
117 Destructs the softkey group. |
|
118 */ |
|
119 HbSoftKeyGroup::~HbSoftKeyGroup() |
|
120 { |
|
121 delete d; |
|
122 } |
|
123 |
|
124 /* |
|
125 Returns a list of all soft keys. |
|
126 |
|
127 \sa HbSoftKey |
|
128 */ |
|
129 QList<HbSoftKey *> HbSoftKeyGroup::softKeys() const |
|
130 { |
|
131 return d->mSoftKeys.values(); |
|
132 } |
|
133 |
|
134 /* |
|
135 Returns the standard soft \a key. |
|
136 |
|
137 \sa HbPrivate::SoftKeyId, HbSoftKey |
|
138 */ |
|
139 HbSoftKey *HbSoftKeyGroup::softKey(HbPrivate::SoftKeyId key) const |
|
140 { |
|
141 return d->mSoftKeys.value(key); |
|
142 } |
|
143 |
|
144 /*! |
|
145 Returns the default action for the secondary softkey (typically |
|
146 an action to quit the application). |
|
147 */ |
|
148 HbAction *HbSoftKeyGroup::defaultSecondaryAction() const |
|
149 { |
|
150 return d->mDefaultSecondaryAction; |
|
151 } |
|
152 |
|
153 #include "hbsoftkeygroup.moc" |