|
1 /* |
|
2 * Copyright (c) 2010 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: Another view for test application. |
|
15 * |
|
16 */ |
|
17 #include <qgraphicslinearlayout.h> |
|
18 #include <qgraphicssceneresizeevent> |
|
19 #include <hbaction.h> |
|
20 #include <hbinstance.h> |
|
21 #include <hblabel.h> |
|
22 #include <hbmainwindow.h> |
|
23 #include "hgtestview.h" |
|
24 #include "trace.h" |
|
25 |
|
26 HgTestView::HgTestView(const QString &title1, const QString &title2, const QPixmap &pixmap, QGraphicsItem *parent) : |
|
27 HbView(parent), mPixmap(pixmap) |
|
28 { |
|
29 FUNC_LOG; |
|
30 |
|
31 QList<HbMainWindow *> mainWindows = hbInstance->allMainWindows(); |
|
32 if (mainWindows.count() > 0) |
|
33 { |
|
34 HbMainWindow *primaryWindow = mainWindows[0]; |
|
35 |
|
36 setTitle(primaryWindow->currentView()->title()); |
|
37 setItemVisible(Hb::AllItems, true); // ensure that all needed view items stay visible |
|
38 |
|
39 // set view as parent because action will be removed on view exit |
|
40 mBackAction = new HbAction(Hb::BackAction, this); |
|
41 primaryWindow->addSoftKeyAction(Hb::SecondarySoftKey, mBackAction); |
|
42 connect(mBackAction, SIGNAL(triggered()), SLOT(closeView())); |
|
43 |
|
44 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical); |
|
45 HANDLE_ERROR_NULL(layout); |
|
46 if (layout) |
|
47 { |
|
48 HbLabel *title1Label = new HbLabel(title1); |
|
49 title1Label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
|
50 layout->addItem(title1Label); |
|
51 |
|
52 HbLabel *title2Label = new HbLabel(title2); |
|
53 title2Label->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
|
54 layout->addItem(title2Label); |
|
55 |
|
56 mIconLabel = new HbLabel; |
|
57 HANDLE_ERROR_NULL(mIconLabel); |
|
58 if (mIconLabel) |
|
59 { |
|
60 mIconLabel->setIcon(HbIcon(mPixmap)); |
|
61 mIconLabel->setAlignment(Qt::AlignHCenter|Qt::AlignVCenter); |
|
62 layout->addItem(mIconLabel); |
|
63 } |
|
64 setLayout(layout); |
|
65 } |
|
66 } |
|
67 } |
|
68 |
|
69 void HgTestView::closeView() |
|
70 { |
|
71 FUNC_LOG; |
|
72 |
|
73 QList<HbMainWindow *> mainWindows = hbInstance->allMainWindows(); |
|
74 if (mainWindows.count() > 0) |
|
75 { |
|
76 HbMainWindow *primaryWindow = mainWindows[0]; |
|
77 primaryWindow->removeView(this); |
|
78 primaryWindow->setViewSwitchingEnabled(true); |
|
79 primaryWindow->removeSoftKeyAction(Hb::SecondarySoftKey, mBackAction); // restores original action |
|
80 } |
|
81 delete this; // ownership transferred back from HbMainWindow |
|
82 } |
|
83 |
|
84 void HgTestView::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
85 { |
|
86 FUNC_LOG; |
|
87 |
|
88 if (mIconLabel && event) |
|
89 { |
|
90 QSize iconSize(event->newSize().width()-5, event->newSize().height()-20); |
|
91 mIconLabel->setIcon(HbIcon(mPixmap.scaled(iconSize, Qt::KeepAspectRatio))); |
|
92 } |
|
93 } |
|
94 |