• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

Plasma

stackedlayout.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Lesser General Public
00006     License as published by the Free Software Foundation; either
00007     version 2.1 of the License, or (at your option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00016 */
00017 
00018 #include "stackedlayout.h"
00019 
00020 #include <QGraphicsWidget>
00021 #include <QDebug>
00022 
00023 StackedLayout::StackedLayout(QGraphicsLayoutItem *parent)
00024     : QObject(0),
00025       QGraphicsLayout(parent),
00026       m_currentWidgetIndex(-1)
00027 {
00028 }
00029 
00030 StackedLayout::~StackedLayout()
00031 {
00032 }
00033 
00034 void StackedLayout::setGeometry(const QRectF &rect)
00035 {
00036     QGraphicsLayout::setGeometry(rect);
00037 
00038     const QRectF effectiveRect = geometry();
00039 
00040     for(int i = 0; i < items.size(); i++) {
00041         itemAt(i)->setGeometry(effectiveRect);
00042     }
00043 }
00044 
00045 QSizeF StackedLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
00046 {
00047     Q_UNUSED(which);
00048     Q_UNUSED(constraint);
00049 
00050     qreal left, top, right, bottom;
00051     getContentsMargins(&left, &top, &right, &bottom);
00052 
00053     if (m_currentWidgetIndex <= 0 || !itemAt(m_currentWidgetIndex)) {
00054         return QSizeF();
00055     }
00056 
00057     QSizeF currentWidgetSize = itemAt(m_currentWidgetIndex)->effectiveSizeHint(which, constraint);
00058 
00059     return QSizeF( left + right + currentWidgetSize.width(), right + bottom + currentWidgetSize.height());
00060 }
00061 
00062 int StackedLayout::count() const
00063 {
00064     return items.count();
00065 }
00066 
00067 QGraphicsLayoutItem *StackedLayout::itemAt(int i) const
00068 {
00069     return items.at(i);
00070 }
00071 
00072 void StackedLayout::insertWidget(QGraphicsLayoutItem *item, int pos)
00073 {
00074     if(!pos && (m_currentWidgetIndex == -1)) {
00075         m_currentWidgetIndex = 0;
00076     } else {
00077         item->graphicsItem()->hide();
00078     }
00079 
00080     items.insert(pos, item);
00081     activate();
00082 }
00083 
00084 void StackedLayout::addWidget(QGraphicsLayoutItem *item)
00085 {
00086     insertWidget(item, items.size());
00087 }
00088 
00089 void StackedLayout::removeAt(int index)
00090 {
00091     items.removeAt(index);
00092 }
00093 
00094 void StackedLayout::setCurrentWidgetIndex(qint32 index)
00095 {
00096     QGraphicsItem *currentWidget = itemAt(m_currentWidgetIndex)->graphicsItem();
00097     QGraphicsItem *hiddenWidget = itemAt(index)->graphicsItem();
00098 
00099     currentWidget->hide();
00100     hiddenWidget->show();
00101 
00102     m_currentWidgetIndex = index;
00103 }
00104 
00105 qint32 StackedLayout::currentWidgetIndex() const
00106 {
00107     return m_currentWidgetIndex;
00108 }

Plasma

Skip menu "Plasma"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal