2009-12-27 23:16:11 +01:00
|
|
|
/*
|
|
|
|
Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
#include "stackedlayout.h"
|
|
|
|
|
|
|
|
#include <QGraphicsWidget>
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
|
|
StackedLayout::StackedLayout(QGraphicsLayoutItem *parent)
|
|
|
|
: QGraphicsLayout(parent), m_currentWidgetIndex(-1)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
StackedLayout::~StackedLayout()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackedLayout::setGeometry(const QRectF &rect)
|
|
|
|
{
|
|
|
|
QGraphicsLayout::setGeometry(rect);
|
|
|
|
|
|
|
|
for(int i = 0; i < items.size(); i++) {
|
|
|
|
itemAt(i)->setGeometry(rect);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF StackedLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
|
|
{
|
|
|
|
Q_UNUSED(which);
|
|
|
|
Q_UNUSED(constraint);
|
|
|
|
|
|
|
|
qreal left, top, right, bottom;
|
|
|
|
getContentsMargins(&left, &top, &right, &bottom);
|
|
|
|
|
2010-01-17 07:05:54 +01:00
|
|
|
if (m_currentWidgetIndex <= 0 || !itemAt(m_currentWidgetIndex)) {
|
|
|
|
return QSizeF();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF currentWidgetSize = itemAt(m_currentWidgetIndex)->effectiveSizeHint(which, constraint);
|
2009-10-22 22:17:07 +02:00
|
|
|
|
|
|
|
return QSizeF( left + right + currentWidgetSize.width(), right + bottom + currentWidgetSize.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
int StackedLayout::count() const
|
|
|
|
{
|
|
|
|
return items.count();
|
|
|
|
}
|
|
|
|
|
|
|
|
QGraphicsLayoutItem *StackedLayout::itemAt(int i) const
|
|
|
|
{
|
|
|
|
return items.at(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackedLayout::insertWidget(QGraphicsLayoutItem *item, int pos)
|
|
|
|
{
|
|
|
|
if(!pos && (m_currentWidgetIndex == -1)) {
|
|
|
|
m_currentWidgetIndex = 0;
|
|
|
|
} else {
|
|
|
|
item->graphicsItem()->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
items.insert(pos, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackedLayout::addWidget(QGraphicsLayoutItem *item)
|
|
|
|
{
|
|
|
|
insertWidget(item, items.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackedLayout::removeAt(int index)
|
|
|
|
{
|
|
|
|
items.removeAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StackedLayout::setCurrentWidgetIndex(qint32 index)
|
|
|
|
{
|
|
|
|
QGraphicsItem *currentWidget = itemAt(m_currentWidgetIndex)->graphicsItem();
|
|
|
|
QGraphicsItem *hidenWidget = itemAt(index)->graphicsItem();
|
|
|
|
|
|
|
|
currentWidget->hide();
|
|
|
|
hidenWidget->show();
|
|
|
|
|
|
|
|
m_currentWidgetIndex = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint32 StackedLayout::currentWidgetIndex() const
|
|
|
|
{
|
|
|
|
return m_currentWidgetIndex;
|
|
|
|
}
|