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

liblancelot

  • sources
  • kde-4.14
  • workspace
  • kdeplasma-addons
  • libs
  • lancelot
  • layouts
CardLayout.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007, 2008, 2009, 2010 Ivan Cukic <ivan.cukic(at)kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser/Library General Public License version 2,
6  * or (at your option) any later version, as published by the Free
7  * Software Foundation
8  *
9  * This program 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
12  * GNU Lesser/Library General Public License for more details
13  *
14  * You should have received a copy of the GNU Lesser/Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
20 #include "CardLayout.h"
21 
22 #include <QGraphicsScene>
23 
24 #include <Plasma/Plasma>
25 
26 namespace Lancelot
27 {
28 
29 class CardLayout::Private {
30 public:
31  Private(CardLayout * parent)
32  : shown(NULL), q(parent)
33  {
34  }
35 
36  void relayout()
37  {
38  QRectF g = q->geometry();
39 
40  foreach (QGraphicsLayoutItem * l, items) {
41  l->setGeometry(g);
42  }
43 
44  foreach (QGraphicsWidget * l, widgets) {
45  l->setVisible(true);
46  l->setGeometry(g);
47  if (shown != l) {
48  l->setVisible(false);
49  }
50  }
51  }
52 
53  void removeItem(QGraphicsLayoutItem * item)
54  {
55  items.removeAll(item);
56  QMutableMapIterator<QString, QGraphicsWidget *> i(widgets);
57  while (i.hasNext()) {
58  i.next();
59  if ((QGraphicsLayoutItem *)i.value() == item) {
60  i.remove();
61  }
62  }
63  }
64 
65  void removeItem(const QString & id)
66  {
67  widgets.remove(id);
68  }
69 
70  QList < QGraphicsLayoutItem * > items;
71  QMap < QString, QGraphicsWidget * > widgets;
72  QGraphicsWidget * shown;
73  QGraphicsItem * parentItem;
74  CardLayout * q;
75 };
76 
77 CardLayout::CardLayout(QGraphicsLayoutItem * parent)
78  : QGraphicsLayout(parent), d(new Private(this))
79 {
80 }
81 
82 CardLayout::~CardLayout()
83 {
84  delete d;
85 }
86 
87 QSizeF CardLayout::sizeHint(Qt::SizeHint which,
88  const QSizeF & constraint) const
89 {
90  QSizeF size = QSizeF(0, 0);
91 
92  foreach (QGraphicsLayoutItem * l, d->items) {
93  size = size.expandedTo(l->effectiveSizeHint(which, constraint));
94  }
95 
96  foreach (QGraphicsWidget * l, d->widgets) {
97  size = size.expandedTo(l->effectiveSizeHint(which, constraint));
98  }
99 
100  return size;
101 }
102 
103 void CardLayout::addItem(QGraphicsLayoutItem * item)
104 {
105  if (!d->items.contains(item)) {
106  d->items.append(item);
107  }
108 }
109 
110 void CardLayout::addItem(QGraphicsWidget * widget, const QString & id)
111 {
112  if (widget) {
113  d->widgets[id] = widget;
114  widget->hide();
115  } else {
116  d->removeItem(id);
117  }
118 }
119 
120 int CardLayout::count() const
121 {
122  return d->items.size() + d->widgets.size();
123 }
124 
125 QGraphicsLayoutItem * CardLayout::itemAt(int i) const
126 {
127  if (i < d->items.size()) {
128  return d->items[i];
129  } else {
130  i -= d->items.size();
131  foreach (QGraphicsWidget * l, d->widgets) {
132  if (0 == i--) {
133  return (QGraphicsLayoutItem *)l;
134  }
135  }
136  }
137  return NULL;
138 }
139 
140 void CardLayout::removeAt(int i)
141 {
142  d->removeItem(itemAt(i));
143 }
144 
145 void CardLayout::showCard(const QString & id)
146 {
147  if (!d->widgets.contains(id)) return;
148  if (d->shown == d->widgets[id]) return;
149  if (d->shown) {
150  d->shown->setVisible(false);
151  }
152  d->shown = d->widgets[id];
153  d->shown->setGeometry(geometry());
154  d->shown->setVisible(true);
155 }
156 
157 void CardLayout::hideAll()
158 {
159  if (!d->shown) return;
160  d->shown->setVisible(false);
161  d->shown = NULL;
162 }
163 
164 void CardLayout::setGeometry(const QRectF & rect)
165 {
166  QGraphicsLayout::setGeometry(rect);
167  d->relayout();
168 }
169 
170 } // namespace Lancelot
171 
QMutableMapIterator
Lancelot::CardLayout::showCard
void showCard(const QString &id)
Shows the item specified by id, and hides all other items.
Definition: CardLayout.cpp:145
QGraphicsLayoutItem::geometry
QRectF geometry() const
Lancelot::CardLayout::setGeometry
L_Override void setGeometry(const QRectF &rect)
Definition: CardLayout.cpp:164
QMap< QString, QGraphicsWidget * >
Lancelot::CardLayout::itemAt
L_Override QGraphicsLayoutItem * itemAt(int i) const
Definition: CardLayout.cpp:125
QSizeF::expandedTo
QSizeF expandedTo(const QSizeF &otherSize) const
QGraphicsItem
QGraphicsItem::hide
void hide()
Lancelot::CardLayout::CardLayout
CardLayout(QGraphicsLayoutItem *parent=0)
Creates a new Lancelot::CardLayout.
Definition: CardLayout.cpp:77
Lancelot::CardLayout::removeAt
L_Override void removeAt(int index)
Definition: CardLayout.cpp:140
Lancelot::CardLayout::~CardLayout
virtual ~CardLayout()
Destroys this Lancelot::CardLayout.
Definition: CardLayout.cpp:82
QGraphicsLayoutItem::effectiveSizeHint
QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint) const
Lancelot::CardLayout::sizeHint
L_Override QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Definition: CardLayout.cpp:87
QGraphicsWidget
QString
QList< QGraphicsLayoutItem * >
CardLayout.h
QSizeF
QRectF
Lancelot::CardLayout::count
L_Override int count() const
Definition: CardLayout.cpp:120
Lancelot::CardLayout::hideAll
void hideAll()
Hides all items that can be hidden.
Definition: CardLayout.cpp:157
QGraphicsItem::setVisible
void setVisible(bool visible)
QGraphicsLayout
Lancelot::CardLayout::addItem
void addItem(QGraphicsLayoutItem *item)
Adds a QGraphicsLayoutItem to this layout.
Definition: CardLayout.cpp:103
QObject::parent
QObject * parent() const
QGraphicsWidget::setGeometry
virtual void setGeometry(const QRectF &rect)
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:43:01 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

liblancelot

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

workspace API Reference

Skip menu "workspace API Reference"
  • kdeplasma-addons
  •       GroupingDesktop
  •     liblancelot

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