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

Plasma

  • 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
23StackedLayout::StackedLayout(QGraphicsLayoutItem *parent)
24 : QObject(0),
25 QGraphicsLayout(parent),
26 m_currentWidgetIndex(-1)
27{
28}
29
30StackedLayout::~StackedLayout()
31{
32}
33
34void 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
45QSizeF 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
62int StackedLayout::count() const
63{
64 return items.count();
65}
66
67QGraphicsLayoutItem *StackedLayout::itemAt(int i) const
68{
69 return items.at(i);
70}
71
72void 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
84void StackedLayout::addWidget(QGraphicsLayoutItem *item)
85{
86 insertWidget(item, items.size());
87}
88
89void StackedLayout::removeAt(int index)
90{
91 items.removeAt(index);
92}
93
94void 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
105qint32 StackedLayout::currentWidgetIndex() const
106{
107 return m_currentWidgetIndex;
108}
QGraphicsLayout
QObject
StackedLayout::currentWidgetIndex
qint32 currentWidgetIndex() const
Definition: stackedlayout.cpp:105
StackedLayout::setGeometry
void setGeometry(const QRectF &rect)
Definition: stackedlayout.cpp:34
StackedLayout::insertWidget
void insertWidget(QGraphicsLayoutItem *item, int pos)
Definition: stackedlayout.cpp:72
StackedLayout::~StackedLayout
~StackedLayout()
Definition: stackedlayout.cpp:30
StackedLayout::addWidget
void addWidget(QGraphicsLayoutItem *item)
Definition: stackedlayout.cpp:84
StackedLayout::removeAt
void removeAt(int index)
Definition: stackedlayout.cpp:89
StackedLayout::itemAt
QGraphicsLayoutItem * itemAt(int i) const
Definition: stackedlayout.cpp:67
StackedLayout::setCurrentWidgetIndex
void setCurrentWidgetIndex(qint32 index)
Definition: stackedlayout.cpp:94
StackedLayout::sizeHint
QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Definition: stackedlayout.cpp:45
StackedLayout::StackedLayout
StackedLayout(QGraphicsLayoutItem *parent=0)
Definition: stackedlayout.cpp:23
StackedLayout::count
int count() const
Definition: stackedlayout.cpp:62
stackedlayout.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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