diff -r 000000000000 -r 4a5361db8937 logsui/logsapp/src/logspageindicator.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/logsui/logsapp/src/logspageindicator.cpp Tue May 04 12:39:37 2010 +0300 @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include + +#include "logspageindicator.h" +#include "logspageindicatoritem.h" + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +LogsPageIndicator::LogsPageIndicator(QGraphicsItem *parent) + : HbWidget(parent), + mActiveItemIndex(-1) +{ +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +LogsPageIndicator::~LogsPageIndicator() +{ + qDeleteAll(mItems); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void LogsPageIndicator::initialize(int itemCount, int activeItemIndex) +{ + qDeleteAll(mItems); + mItems.clear(); + mActiveItemIndex = -1; + + if (itemCount < 1 || activeItemIndex < 0 || + itemCount <= activeItemIndex) { + return; + } + + for (int i = 0; i < itemCount; ++i) { + mItems << new LogsPageIndicatorItem(i == activeItemIndex); + } + mActiveItemIndex = activeItemIndex; + layoutItems(); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +int LogsPageIndicator::itemCount() const +{ + return mItems.count(); +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void LogsPageIndicator::setActiveItemIndex(int activeItemIndex) +{ + if (activeItemIndex < 0 || itemCount() <= activeItemIndex) { + return; + } + + mActiveItemIndex = activeItemIndex; + for (int i = 0; i < mItems.count(); ++i) { + mItems[i]->setActive(i == activeItemIndex); + } +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +int LogsPageIndicator::activeItemIndex() const +{ + return mActiveItemIndex; +} + +// ----------------------------------------------------------------------------- +// +// ----------------------------------------------------------------------------- +// +void LogsPageIndicator::layoutItems() +{ + QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; + layout->setContentsMargins(0, 0, 0, 0); + layout->addStretch(); + foreach (LogsPageIndicatorItem *item, mItems) { + layout->addItem(item); + } + layout->addStretch(); + setLayout(layout); +}