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

Plasma

  • sources
  • kde-4.14
  • kdelibs
  • plasma
  • animations
stackedlayout.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 Igor Trindade Oliveira <igor.oliveira@indt.org.br>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Lesser General Public License for more details.
13 
14  You should have received a copy of the GNU Lesser General Public
15  License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include "stackedlayout.h"
19 
20 #include <QGraphicsWidget>
21 #include <QDebug>
22 
23 StackedLayout::StackedLayout(QGraphicsLayoutItem *parent)
24  : QObject(0),
25  QGraphicsLayout(parent),
26  m_currentWidgetIndex(-1)
27 {
28 }
29 
30 StackedLayout::~StackedLayout()
31 {
32 }
33 
34 void StackedLayout::setGeometry(const QRectF &rect)
35 {
36  QGraphicsLayout::setGeometry(rect);
37 
38  const QRectF effectiveRect = geometry();
39 
40  for(int i = 0; i < items.size(); i++) {
41  itemAt(i)->setGeometry(effectiveRect);
42  }
43 }
44 
45 QSizeF StackedLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
46 {
47  Q_UNUSED(which);
48  Q_UNUSED(constraint);
49 
50  qreal left, top, right, bottom;
51  getContentsMargins(&left, &top, &right, &bottom);
52 
53  if (m_currentWidgetIndex <= 0 || !itemAt(m_currentWidgetIndex)) {
54  return QSizeF();
55  }
56 
57  QSizeF currentWidgetSize = itemAt(m_currentWidgetIndex)->effectiveSizeHint(which, constraint);
58 
59  return QSizeF( left + right + currentWidgetSize.width(), right + bottom + currentWidgetSize.height());
60 }
61 
62 int StackedLayout::count() const
63 {
64  return items.count();
65 }
66 
67 QGraphicsLayoutItem *StackedLayout::itemAt(int i) const
68 {
69  return items.at(i);
70 }
71 
72 void StackedLayout::insertWidget(QGraphicsLayoutItem *item, int pos)
73 {
74  if(!pos && (m_currentWidgetIndex == -1)) {
75  m_currentWidgetIndex = 0;
76  } else {
77  item->graphicsItem()->hide();
78  }
79 
80  items.insert(pos, item);
81  activate();
82 }
83 
84 void StackedLayout::addWidget(QGraphicsLayoutItem *item)
85 {
86  insertWidget(item, items.size());
87 }
88 
89 void StackedLayout::removeAt(int index)
90 {
91  items.removeAt(index);
92 }
93 
94 void StackedLayout::setCurrentWidgetIndex(qint32 index)
95 {
96  QGraphicsItem *currentWidget = itemAt(m_currentWidgetIndex)->graphicsItem();
97  QGraphicsItem *hiddenWidget = itemAt(index)->graphicsItem();
98 
99  currentWidget->hide();
100  hiddenWidget->show();
101 
102  m_currentWidgetIndex = index;
103 }
104 
105 qint32 StackedLayout::currentWidgetIndex() const
106 {
107  return m_currentWidgetIndex;
108 }
StackedLayout::removeAt
void removeAt(int index)
Definition: stackedlayout.cpp:89
QGraphicsLayout::activate
void activate()
StackedLayout::addWidget
void addWidget(QGraphicsLayoutItem *item)
Definition: stackedlayout.cpp:84
QGraphicsLayoutItem::geometry
QRectF geometry() const
StackedLayout::setGeometry
void setGeometry(const QRectF &rect)
Definition: stackedlayout.cpp:34
StackedLayout::itemAt
QGraphicsLayoutItem * itemAt(int i) const
Definition: stackedlayout.cpp:67
QGraphicsLayoutItem::graphicsItem
QGraphicsItem * graphicsItem() const
QList::at
const T & at(int i) const
StackedLayout::sizeHint
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Definition: stackedlayout.cpp:45
QList::removeAt
void removeAt(int i)
QGraphicsItem
QGraphicsItem::hide
void hide()
stackedlayout.h
QList::size
int size() const
StackedLayout::insertWidget
void insertWidget(QGraphicsLayoutItem *item, int pos)
Definition: stackedlayout.cpp:72
QList::count
int count(const T &value) const
QObject
StackedLayout::StackedLayout
StackedLayout(QGraphicsLayoutItem *parent=0)
Definition: stackedlayout.cpp:23
StackedLayout::~StackedLayout
~StackedLayout()
Definition: stackedlayout.cpp:30
QGraphicsLayoutItem::effectiveSizeHint
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint) const
QGraphicsLayout::getContentsMargins
virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
StackedLayout::currentWidgetIndex
qint32 currentWidgetIndex() const
Definition: stackedlayout.cpp:105
StackedLayout::setCurrentWidgetIndex
void setCurrentWidgetIndex(qint32 index)
Definition: stackedlayout.cpp:94
QSizeF
QList::insert
void insert(int i, const T &value)
QRectF
QGraphicsLayout
QGraphicsItem::show
void show()
QSizeF::height
qreal height() const
StackedLayout::count
int count() const
Definition: stackedlayout.cpp:62
QSizeF::width
qreal width() const
QGraphicsLayoutItem
QGraphicsLayoutItem::setGeometry
virtual void setGeometry(const QRectF &rect)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:23:12 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Plasma

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal