62
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include <QList>
|
|
19 |
#include <QGraphicsGridLayout>
|
|
20 |
|
|
21 |
#include <hbaction.h>
|
|
22 |
#include <hbcommonnote.h>
|
|
23 |
#include <hbinstance.h>
|
|
24 |
#include <hblabel.h>
|
|
25 |
#include <hblineedit.h>
|
|
26 |
#include <hbmainwindow.h>
|
|
27 |
#include <hbmenu.h>
|
|
28 |
#include <hbpushbutton.h>
|
|
29 |
#include <hbtoolbar.h>
|
|
30 |
|
|
31 |
#include "toolbarview.h"
|
|
32 |
|
|
33 |
ToolbarView::ToolbarView() :
|
|
34 |
HbView(),
|
|
35 |
portraitOrientation(true),
|
|
36 |
mirrored(false),
|
|
37 |
orientationChangeAction(0),
|
|
38 |
mirroringChangeAction(0)
|
|
39 |
{
|
|
40 |
//setIcon(HbIcon(":/toolbardemo/toolbar"));
|
|
41 |
setTitle("Toolbar demo view");
|
|
42 |
|
|
43 |
QGraphicsGridLayout *layout = new QGraphicsGridLayout();
|
|
44 |
|
|
45 |
QSizePolicy policy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
|
46 |
|
|
47 |
HbLabel *textLabel = new HbLabel("Text:", this);
|
|
48 |
textLabel->setSizePolicy(policy);
|
|
49 |
textLabel->setObjectName("textLabel");
|
|
50 |
layout->addItem(textLabel, 0, 0);
|
|
51 |
|
|
52 |
textLineEdit = new HbLineEdit("button text", this);
|
|
53 |
textLineEdit->setSizePolicy(policy);
|
|
54 |
textLineEdit->setObjectName("textLineEdit");
|
|
55 |
layout->addItem(textLineEdit, 0, 1);
|
|
56 |
|
|
57 |
HbLabel *tooltipLabel = new HbLabel("Tooltip:", this);
|
|
58 |
tooltipLabel->setSizePolicy(policy);
|
|
59 |
tooltipLabel->setObjectName("tooltipLabel");
|
|
60 |
layout->addItem(tooltipLabel, 1, 0);
|
|
61 |
|
|
62 |
tooltipLineEdit = new HbLineEdit("tooltip text", this);
|
|
63 |
tooltipLineEdit->setSizePolicy(policy);
|
|
64 |
tooltipLineEdit->setObjectName("tooltipLineEdit");
|
|
65 |
layout->addItem(tooltipLineEdit, 1, 1);
|
|
66 |
|
|
67 |
HbPushButton *addButton = new HbPushButton("Add", this);
|
|
68 |
addButton->setSizePolicy(policy);
|
|
69 |
addButton->setObjectName("add");
|
|
70 |
layout->addItem(addButton, 2, 0, 1, 2);
|
|
71 |
connect(addButton, SIGNAL(clicked()), this, SLOT(toolbarDemoSlot()));
|
|
72 |
|
|
73 |
HbPushButton *clearButton = new HbPushButton("Clear", this);
|
|
74 |
clearButton->setSizePolicy(policy);
|
|
75 |
clearButton->setObjectName("clear");
|
|
76 |
layout->addItem(clearButton, 3, 0, 1, 2);
|
|
77 |
connect(clearButton, SIGNAL(clicked()), this, SLOT(toolbarDemoSlot()));
|
|
78 |
|
|
79 |
HbPushButton *showButton = new HbPushButton("Show", this);
|
|
80 |
showButton->setSizePolicy(policy);
|
|
81 |
showButton->setObjectName("show");
|
|
82 |
layout->addItem(showButton, 4, 0, 1, 2);
|
|
83 |
connect(showButton, SIGNAL(clicked()), this, SLOT(toolbarDemoSlot()));
|
|
84 |
|
|
85 |
HbPushButton *hideButton = new HbPushButton("Hide", this);
|
|
86 |
hideButton->setSizePolicy(policy);
|
|
87 |
hideButton->setObjectName("hide");
|
|
88 |
layout->addItem(hideButton, 5, 0, 1, 2);
|
|
89 |
connect(hideButton, SIGNAL(clicked()), this, SLOT(toolbarDemoSlot()));
|
|
90 |
|
|
91 |
HbLabel *indexLabel = new HbLabel("Index:", this);
|
|
92 |
indexLabel->setSizePolicy(policy);
|
|
93 |
indexLabel->setObjectName("indexLabel");
|
|
94 |
layout->addItem(indexLabel, 6, 0);
|
|
95 |
|
|
96 |
indexLineEdit = new HbLineEdit("0", this);
|
|
97 |
indexLineEdit->setSizePolicy(policy);
|
|
98 |
indexLineEdit->setObjectName("indexLineEdit");
|
|
99 |
layout->addItem(indexLineEdit, 6, 1);
|
|
100 |
|
|
101 |
HbPushButton *insertButton = new HbPushButton("Insert", this);
|
|
102 |
insertButton->setSizePolicy(policy);
|
|
103 |
insertButton->setObjectName("insert");
|
|
104 |
layout->addItem(insertButton, 7, 0, 1, 2);
|
|
105 |
connect(insertButton, SIGNAL(clicked()), this, SLOT(toolbarDemoSlot()));
|
|
106 |
|
|
107 |
HbPushButton *removeButton = new HbPushButton("Remove", this);
|
|
108 |
removeButton->setSizePolicy(policy);
|
|
109 |
removeButton->setObjectName("remove");
|
|
110 |
layout->addItem(removeButton, 8, 0, 1, 2);
|
|
111 |
connect(removeButton, SIGNAL(clicked()), this, SLOT(toolbarDemoSlot()));
|
|
112 |
|
|
113 |
HbPushButton *iconButton = new HbPushButton("Icon", this);
|
|
114 |
iconButton->setSizePolicy(policy);
|
|
115 |
iconButton->setObjectName("icon");
|
|
116 |
layout->addItem(iconButton, 9, 0, 1, 2);
|
|
117 |
connect(iconButton, SIGNAL(clicked()), this, SLOT(toolbarDemoSlot()));
|
|
118 |
|
|
119 |
setLayout(layout);
|
|
120 |
|
|
121 |
if (orientationChangeAction) {
|
|
122 |
menu()->addAction(orientationChangeAction);
|
|
123 |
} else {
|
|
124 |
orientationChangeAction = menu()->addAction( "Change to landscape (auto)" );
|
|
125 |
connect(orientationChangeAction, SIGNAL(triggered()), this, SLOT(changeOrientation()));
|
|
126 |
}
|
|
127 |
|
|
128 |
if (mirroringChangeAction) {
|
|
129 |
menu()->addAction(mirroringChangeAction);
|
|
130 |
} else {
|
|
131 |
mirroringChangeAction = menu()->addAction( "Turn mirroring on" );
|
|
132 |
connect(mirroringChangeAction, SIGNAL(triggered()), this, SLOT(changeMirroring()));
|
|
133 |
}
|
|
134 |
|
|
135 |
HbMenu *prtOrMenu = menu()->addMenu( "Set orientation" );
|
|
136 |
prtOrMenu->addAction( "Vertical" );
|
|
137 |
prtOrMenu->addAction( "Horizontal" );
|
|
138 |
|
|
139 |
connect(prtOrMenu, SIGNAL(triggered(HbAction*)), this, SLOT(setOrientation(HbAction*)));
|
|
140 |
|
|
141 |
HbAction* unsetor = menu()->addAction( "Unset orientation" );
|
|
142 |
connect(unsetor, SIGNAL(triggered()), this, SLOT(unsetOrientation()));
|
|
143 |
}
|
|
144 |
|
|
145 |
ToolbarView::~ToolbarView()
|
|
146 |
{
|
|
147 |
}
|
|
148 |
|
|
149 |
int ToolbarView::selectedIndex(bool& ok)
|
|
150 |
{
|
|
151 |
ok = true;
|
|
152 |
bool valid = false;
|
|
153 |
QString str = indexLineEdit->text();
|
|
154 |
int value = str.toInt(&valid, 10);
|
|
155 |
if (!valid && !value) {
|
|
156 |
ok = false;
|
|
157 |
}
|
|
158 |
return value;
|
|
159 |
}
|
|
160 |
|
|
161 |
void ToolbarView::toolbarDemoSlot()
|
|
162 |
{
|
|
163 |
QString objectName = QObject::sender()->objectName();
|
|
164 |
if (objectName == "add") {
|
|
165 |
toolBar()->show();
|
|
166 |
HbAction *action = new HbAction();
|
|
167 |
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonTriggered()));
|
|
168 |
action->setText(textLineEdit->text());
|
|
169 |
action->setToolTip(tooltipLineEdit->text());
|
|
170 |
action->setIcon(HbIcon(":/toolbardemo/homer.jpg"));
|
|
171 |
toolBar()->addAction(action);
|
|
172 |
} else if (objectName == "clear") {
|
|
173 |
toolBar()->clearActions();
|
|
174 |
} else if (objectName == "show") {
|
|
175 |
toolBar()->show();
|
|
176 |
} else if (objectName == "hide") {
|
|
177 |
toolBar()->hide();
|
|
178 |
} else if (objectName == "insert") {
|
|
179 |
bool ok;
|
|
180 |
int index = selectedIndex(ok);
|
|
181 |
|
|
182 |
if (ok) {
|
|
183 |
toolBar()->show();
|
|
184 |
HbAction *action = new HbAction();
|
|
185 |
connect(action, SIGNAL(triggered()), this, SLOT(toolButtonTriggered()));
|
|
186 |
action->setText(textLineEdit->text());
|
|
187 |
action->setToolTip(tooltipLineEdit->text());
|
|
188 |
action->setIcon(HbIcon(":/toolbardemo/homer.jpg"));
|
|
189 |
|
|
190 |
HbAction* before = NULL;
|
|
191 |
if ( index >= 0 && index < toolBar()->actions().count() ) {
|
|
192 |
before = (HbAction*)toolBar()->actions()[index];
|
|
193 |
}
|
|
194 |
toolBar()->insertAction(before,action);
|
|
195 |
}
|
|
196 |
} else if (objectName == "remove") {
|
|
197 |
bool ok;
|
|
198 |
int index = selectedIndex(ok);
|
|
199 |
if (ok && index >= 0 && index < toolBar()->actions().count()) {
|
|
200 |
toolBar()->removeAction(toolBar()->actions()[index]);
|
|
201 |
}
|
|
202 |
} else if (objectName == "icon") {
|
|
203 |
bool ok;
|
|
204 |
int index = selectedIndex(ok);
|
|
205 |
if (ok && index >= 0 && index < toolBar()->actions().count()) {
|
|
206 |
HbAction* action = (HbAction*)toolBar()->actions()[index];
|
|
207 |
action->setIcon(HbIcon(":/toolbardemo/barney.gif"));
|
|
208 |
}
|
|
209 |
}
|
|
210 |
}
|
|
211 |
|
|
212 |
void ToolbarView::toolButtonTriggered()
|
|
213 |
{
|
|
214 |
HbAction *triggeredAction = static_cast<HbAction*>(sender());
|
|
215 |
HbCommonNote *note = new HbCommonNote(triggeredAction->text(), HbCommonNote::InformationNoteType);
|
|
216 |
note->setAttribute(Qt::WA_DeleteOnClose);
|
|
217 |
//note->setUnfadedItems(Hb::ToolBarItem);
|
|
218 |
note->setUnfadedItems(Hb::AllItems);
|
|
219 |
}
|
|
220 |
|
|
221 |
void ToolbarView::changeOrientation()
|
|
222 |
{
|
|
223 |
portraitOrientation = !portraitOrientation;
|
|
224 |
|
|
225 |
if (portraitOrientation) {
|
|
226 |
orientationChangeAction->setText("Change to landscape (auto)");
|
|
227 |
} else {
|
|
228 |
orientationChangeAction->setText("Change to portrait (auto)");
|
|
229 |
}
|
|
230 |
|
|
231 |
// Change application's orientation
|
|
232 |
hbInstance->setOrientation(portraitOrientation? Qt::Vertical : Qt::Horizontal);
|
|
233 |
}
|
|
234 |
|
|
235 |
void ToolbarView::changeMirroring()
|
|
236 |
{
|
|
237 |
mirrored = !mirrored;
|
|
238 |
|
|
239 |
if (mirrored) {
|
|
240 |
mirroringChangeAction->setText("Turn mirroring off");
|
|
241 |
} else {
|
|
242 |
mirroringChangeAction->setText("Turn mirroring on");
|
|
243 |
}
|
|
244 |
|
|
245 |
if (mirrored) {
|
|
246 |
hbInstance->primaryWindow()->setLayoutDirection(Qt::RightToLeft);
|
|
247 |
} else {
|
|
248 |
hbInstance->primaryWindow()->setLayoutDirection(Qt::LeftToRight);
|
|
249 |
}
|
|
250 |
}
|
|
251 |
|
|
252 |
void ToolbarView::setOrientation( HbAction* action )
|
|
253 |
{
|
|
254 |
if ( action->text() == "Vertical" ){
|
|
255 |
toolBar()->setOrientation( Qt::Vertical );
|
|
256 |
} else if ( action->text() == "Horizontal" ) {
|
|
257 |
toolBar()->setOrientation( Qt::Horizontal );
|
|
258 |
}
|
|
259 |
}
|
|
260 |
|
|
261 |
void ToolbarView::unsetOrientation()
|
|
262 |
{
|
|
263 |
toolBar()->unsetOrientation();
|
|
264 |
}
|