equal
deleted
inserted
replaced
21 #include "hspageindicatoritem.h" |
21 #include "hspageindicatoritem.h" |
22 |
22 |
23 /*! |
23 /*! |
24 |
24 |
25 */ |
25 */ |
26 HsPageIndicator::HsPageIndicator(QGraphicsItem *parent) |
26 HsPageIndicator::HsPageIndicator(qreal spacing, QGraphicsItem *parent) |
27 : HbWidget(parent), |
27 : HbWidget(parent), |
28 mActiveItemIndex(-1) |
28 mActiveItemIndex(-1), |
|
29 mSpacing(spacing) |
29 { |
30 { |
30 } |
31 } |
31 |
32 |
32 /*! |
33 /*! |
33 |
34 |
44 { |
45 { |
45 qDeleteAll(mItems); |
46 qDeleteAll(mItems); |
46 mItems.clear(); |
47 mItems.clear(); |
47 mActiveItemIndex = -1; |
48 mActiveItemIndex = -1; |
48 |
49 |
49 if (itemCount < 1 || activeItemIndex < 0 || |
50 if (itemCount < 1 || activeItemIndex < 0 || |
50 itemCount <= activeItemIndex) { |
51 itemCount <= activeItemIndex) { |
51 return; |
52 return; |
52 } |
53 } |
53 |
54 |
54 for (int i = 0; i < itemCount; ++i) { |
55 for (int i = 0; i < itemCount; ++i) { |
55 mItems << new HsPageIndicatorItem(i == activeItemIndex); |
56 mItems << new HsPageIndicatorItem(i == activeItemIndex); |
56 } |
57 } |
57 mActiveItemIndex = activeItemIndex; |
58 mActiveItemIndex = activeItemIndex; |
58 layoutItems(); |
59 layoutItems(); |
59 } |
60 } |
60 |
61 |
61 /*! |
62 /*! |
62 |
63 |
63 */ |
64 */ |
64 int HsPageIndicator::itemCount() const |
65 int HsPageIndicator::itemCount() const |
65 { |
66 { |
78 mActiveItemIndex = activeItemIndex; |
79 mActiveItemIndex = activeItemIndex; |
79 for (int i = 0; i < mItems.count(); ++i) { |
80 for (int i = 0; i < mItems.count(); ++i) { |
80 mItems[i]->setActive(i == activeItemIndex); |
81 mItems[i]->setActive(i == activeItemIndex); |
81 } |
82 } |
82 } |
83 } |
83 |
84 |
84 /*! |
85 /*! |
85 |
86 |
86 */ |
87 */ |
87 int HsPageIndicator::activeItemIndex() const |
88 int HsPageIndicator::activeItemIndex() const |
88 { |
89 { |
105 |
106 |
106 /*! |
107 /*! |
107 |
108 |
108 */ |
109 */ |
109 void HsPageIndicator::removeItem(int activeItemIndex) |
110 void HsPageIndicator::removeItem(int activeItemIndex) |
110 { |
111 { |
111 if (activeItemIndex < 0 || itemCount() - 1 <= activeItemIndex) { |
112 if (activeItemIndex < 0 || itemCount() - 1 <= activeItemIndex) { |
112 return; |
113 return; |
113 } |
114 } |
114 |
115 |
115 delete mItems.last(); |
116 delete mItems.last(); |
131 */ |
132 */ |
132 void HsPageIndicator::layoutItems() |
133 void HsPageIndicator::layoutItems() |
133 { |
134 { |
134 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
135 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
135 layout->setContentsMargins(0, 0, 0, 0); |
136 layout->setContentsMargins(0, 0, 0, 0); |
136 layout->setSpacing(8); |
137 layout->setSpacing(mSpacing); |
137 layout->addStretch(); |
138 layout->addStretch(); |
138 foreach (HsPageIndicatorItem *item, mItems) { |
139 foreach (HsPageIndicatorItem *item, mItems) { |
139 item->setPreferredSize(preferredHeight(), preferredHeight()); |
140 item->setPreferredSize(preferredHeight(), preferredHeight()); |
140 layout->addItem(item); |
141 layout->addItem(item); |
141 } |
142 } |
142 layout->addStretch(); |
143 layout->addStretch(); |
143 setLayout(layout); |
144 setLayout(layout); |
144 } |
145 } |
|
146 |
|
147 /*! |
|
148 |
|
149 */ |
|
150 void HsPageIndicator::setSpacing(qreal spacing) |
|
151 { |
|
152 QGraphicsLinearLayout *linearLayout = static_cast<QGraphicsLinearLayout*>(layout()); |
|
153 if (linearLayout) { |
|
154 linearLayout->setSpacing(spacing); |
|
155 } |
|
156 } |