|
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 <QGraphicsLinearLayout> |
|
19 |
|
20 #include "logspageindicator.h" |
|
21 #include "logspageindicatoritem.h" |
|
22 |
|
23 // ----------------------------------------------------------------------------- |
|
24 // |
|
25 // ----------------------------------------------------------------------------- |
|
26 // |
|
27 LogsPageIndicator::LogsPageIndicator(QGraphicsItem *parent) |
|
28 : HbWidget(parent), |
|
29 mActiveItemIndex(-1) |
|
30 { |
|
31 } |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 // ----------------------------------------------------------------------------- |
|
36 // |
|
37 LogsPageIndicator::~LogsPageIndicator() |
|
38 { |
|
39 qDeleteAll(mItems); |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 void LogsPageIndicator::initialize(int itemCount, int activeItemIndex) |
|
47 { |
|
48 qDeleteAll(mItems); |
|
49 mItems.clear(); |
|
50 mActiveItemIndex = -1; |
|
51 |
|
52 if (itemCount < 1 || activeItemIndex < 0 || |
|
53 itemCount <= activeItemIndex) { |
|
54 return; |
|
55 } |
|
56 |
|
57 for (int i = 0; i < itemCount; ++i) { |
|
58 mItems << new LogsPageIndicatorItem(i == activeItemIndex); |
|
59 } |
|
60 mActiveItemIndex = activeItemIndex; |
|
61 layoutItems(); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 // ----------------------------------------------------------------------------- |
|
67 // |
|
68 int LogsPageIndicator::itemCount() const |
|
69 { |
|
70 return mItems.count(); |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 void LogsPageIndicator::setActiveItemIndex(int activeItemIndex) |
|
78 { |
|
79 if (activeItemIndex < 0 || itemCount() <= activeItemIndex) { |
|
80 return; |
|
81 } |
|
82 |
|
83 mActiveItemIndex = activeItemIndex; |
|
84 for (int i = 0; i < mItems.count(); ++i) { |
|
85 mItems[i]->setActive(i == activeItemIndex); |
|
86 } |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 int LogsPageIndicator::activeItemIndex() const |
|
94 { |
|
95 return mActiveItemIndex; |
|
96 } |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 void LogsPageIndicator::layoutItems() |
|
103 { |
|
104 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
|
105 layout->setContentsMargins(0, 0, 0, 0); |
|
106 layout->addStretch(); |
|
107 foreach (LogsPageIndicatorItem *item, mItems) { |
|
108 layout->addItem(item); |
|
109 } |
|
110 layout->addStretch(); |
|
111 setLayout(layout); |
|
112 } |