summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNorwegian Rock Cat <qt-info@nokia.com>2009-07-03 16:21:43 +0200
committerNorwegian Rock Cat <qt-info@nokia.com>2009-07-03 16:21:43 +0200
commit7742ac13cccee6c90fdfe65bea10c89f73a0671a (patch)
tree1cf1841d61444a9be43a2f58593ad540ce4cb219
parentbf5b58abe2e1fab83298db38f16011e41f31c14c (diff)
Factor this out into it's own function.
-rw-r--r--src/qtsegmentcontrol.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/qtsegmentcontrol.cpp b/src/qtsegmentcontrol.cpp
index 8092252..6f98332 100644
--- a/src/qtsegmentcontrol.cpp
+++ b/src/qtsegmentcontrol.cpp
@@ -161,6 +161,7 @@ public:
void layoutSegments();
void postUpdate(int index = -1, bool geoToo = false);
+ QtStyleOptionSegmentControlSegment::SegmentPosition segmentPositionForIndex(int i);
QtSegmentControl *q;
QtSegmentControl::SelectionBehavior selectionBehavior;
@@ -173,6 +174,17 @@ public:
inline bool indexOK(int index) { return index >= 0 && index < segments.count(); }
};
+QtStyleOptionSegmentControlSegment::SegmentPosition QtSegmentControlPrivate::segmentPositionForIndex(int segment)
+{
+ if (segments.count() <= 1)
+ return QtStyleOptionSegmentControlSegment::OnlyOneSegment;
+ if (segment == 0)
+ return QtStyleOptionSegmentControlSegment::Beginning;
+ if (segment == segments.count() - 1)
+ return QtStyleOptionSegmentControlSegment::End;
+ return QtStyleOptionSegmentControlSegment::Middle;
+}
+
void QtSegmentControlPrivate::layoutSegments()
{
if (!layoutDirty)
@@ -507,16 +519,7 @@ void QtSegmentControl::initStyleOption(int segment, QStyleOption *option) const
if (QtStyleOptionSegmentControlSegment *sgi = static_cast<QtStyleOptionSegmentControlSegment *>(option)) {
sgi->iconSize = d->iconSize;
const SegmentInfo &segmentInfo = d->segments[segment];
- if (d->segments.count() == 1) {
- sgi->position = QtStyleOptionSegmentControlSegment::OnlyOneSegment;
- } else if (segment == 0) {
- sgi->position = QtStyleOptionSegmentControlSegment::Beginning;
- } else if (segment == d->segments.count() - 1) {
- sgi->position = QtStyleOptionSegmentControlSegment::End;
- } else {
- sgi->position = QtStyleOptionSegmentControlSegment::Middle;
- }
-
+ sgi->position = d->segmentPositionForIndex(segment);
if (segmentInfo.selected)
sgi->state |= QStyle::State_Selected;
if (!segmentInfo.enabled)