• 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
  • widgets
Panel.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 "Panel.h"
21 #include "BasicWidget.h"
22 
23 #include <Plasma/FrameSvg>
24 
25 namespace Lancelot
26 {
27 
28 class Panel::Private {
29 public:
30  Private(QIcon icon, QString title, Panel * parent)
31  : layoutItem(NULL),
32  hasTitle(!title.isEmpty()),
33  titleWidget(icon, title, "", parent),
34  q(parent)
35  {
36  init();
37  }
38 
39  Private(QString title, Panel * parent)
40  : layoutItem(NULL),
41  hasTitle(!title.isEmpty()),
42  titleWidget(title, "", parent),
43  q(parent)
44  {
45  init();
46  }
47 
48  Private(Panel * parent)
49  : layoutItem(NULL),
50  hasTitle(false),
51  titleWidget("", "", parent),
52  q(parent)
53  {
54  init();
55  }
56 
57  ~Private()
58  {
59  }
60 
61  void init()
62  {
63  showingTitle = hasTitle;
64  titleWidget.setIconSize(QSize(16, 16));
65  titleWidget.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
66  titleWidget.setEnabled(false);
67  invalidate();
68  }
69 
70  void invalidate()
71  {
72  QRectF rect = QRectF(QPointF(), q->size());
73  if (q->group() && q->group()->backgroundSvg()) {
74  rect.setTop(q->group()->backgroundSvg()->marginSize(Plasma::TopMargin));
75  rect.setLeft(q->group()->backgroundSvg()->marginSize(Plasma::LeftMargin));
76  rect.setWidth(rect.width() - q->group()->backgroundSvg()->marginSize(Plasma::RightMargin));
77  rect.setHeight(rect.height() - q->group()->backgroundSvg()->marginSize(Plasma::BottomMargin));
78  }
79 
80  if (!showingTitle || !hasTitle) {
81  titleWidget.hide();
82  if (layoutItem) {
83  layoutItem->setGeometry(rect);
84  }
85  } else {
86  qreal h = rect.height();
87 
88  titleWidget.show();
89  rect.setHeight(32);
90  titleWidget.setGeometry(rect);
91 
92  rect.setTop(32);
93  rect.setHeight(h - 32);
94 
95  if (layoutItem) {
96  layoutItem->setGeometry(rect);
97  }
98  }
99  }
100 
101  QGraphicsLayoutItem * layoutItem;
102  bool hasTitle;
103  bool showingTitle;
104 
105  BasicWidget titleWidget;
106  Panel * q;
107 };
108 
109 Panel::Panel(QIcon icon, QString title, QGraphicsItem * parent)
110  : Widget(parent), d(new Private(icon, title, this))
111 {
112  setGroupByName("Panel");
113 }
114 
115 Panel::Panel(QString title, QGraphicsItem * parent)
116  : Widget(parent), d(new Private(title, this))
117 {
118  setGroupByName("Panel");
119 }
120 
121 Panel::Panel(QGraphicsItem * parent)
122  : Widget(parent), d(new Private(this))
123 {
124  setGroupByName("Panel");
125 }
126 
127 Panel::~Panel()
128 {
129  delete d;
130 }
131 
132 qreal Panel::borderSize(Plasma::MarginEdge edge) const
133 {
134  if (!(group()) || !(group()->backgroundSvg())) {
135  return 0;
136  }
137  return group()->backgroundSvg()->marginSize(edge);
138 }
139 
140 void Panel::setTitle(const QString & title)
141 {
142  d->hasTitle = (title != "");
143  d->titleWidget.setTitle(title);
144 }
145 
146 QString Panel::title() const
147 {
148  return d->titleWidget.title();
149 }
150 
151 void Panel::setIcon(QIcon icon)
152 {
153  d->titleWidget.setIcon(icon);
154 }
155 
156 QIcon Panel::icon() const
157 {
158  return d->titleWidget.icon();
159 }
160 
161 void Panel::setIconSize(QSize size)
162 {
163  d->titleWidget.setIconSize(size);
164 }
165 
166 QSize Panel::iconSize() const
167 {
168  return d->titleWidget.iconSize();
169 }
170 
171 void Panel::setShowingTitle(bool value)
172 {
173  d->showingTitle = value;
174  d->titleWidget.setVisible(value);
175 }
176 
177 bool Panel::isShowingTitle() const
178 {
179  return d->showingTitle;
180 }
181 
182 void Panel::resizeEvent(QGraphicsSceneResizeEvent * event)
183 {
184  Widget::resizeEvent(event);
185  d->invalidate();
186 }
187 
188 void Panel::setGroup(Group * g)
189 {
190  Widget::setGroup(g);
191  d->titleWidget.setGroupByName(group()->name() + "-Title");
192 }
193 
194 void Panel::setLayoutItem(QGraphicsLayoutItem * layoutItem)
195 {
196  d->layoutItem = layoutItem;
197  d->invalidate();
198 }
199 
200 QGraphicsLayoutItem * Panel::layoutItem() const
201 {
202  return d->layoutItem;
203 }
204 
205 QSizeF Panel::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
206 {
207  QSizeF result = QSizeF();
208 
209  // TODO: Count the header as well
210 
211  if (!d->layoutItem) {
212  switch (which) {
213  case Qt::MinimumSize:
214  result = QSizeF();
215  break;
216  case Qt::MaximumSize:
217  result = MAX_WIDGET_SIZE;
218  break;
219  default:
220  result = QSizeF(100, 100);
221  }
222  } else {
223  result = d->layoutItem->effectiveSizeHint(which, constraint);
224  }
225  if (constraint.isValid()) {
226  result = result.boundedTo(constraint);
227  }
228  return result;
229 }
230 
231 
232 } // namespace Lancelot
233 
Lancelot::Widget::group
Group * group() const
Returns this widget's group.
Lancelot::Widget::setGroupByName
virtual void setGroupByName(const QString &groupName)
Sets this widget's group by group name.
Definition: Widget.cpp:134
Lancelot::Panel::setIconSize
void setIconSize(QSize size)
Sets icon size of this Lancelot::Panel.
Definition: Panel.cpp:161
Lancelot::Panel::~Panel
virtual ~Panel()
Destroys Lancelot::Panel.
Definition: Panel.cpp:127
Panel.h
Lancelot::Panel::setShowingTitle
void setShowingTitle(bool value)
Sets whether the title is shown.
Definition: Panel.cpp:171
BasicWidget.h
QSizeF::isValid
bool isValid() const
Lancelot::Panel::setGroup
L_Override void setGroup(Group *group=NULL)
Sets this widget's group.
Definition: Panel.cpp:188
Lancelot::Widget::setGroup
virtual void setGroup(Group *group=NULL)
Sets this widget's group.
Definition: Widget.cpp:139
QGraphicsItem
MAX_WIDGET_SIZE
#define MAX_WIDGET_SIZE
Definition: lancelot.h:45
Lancelot::Group::backgroundSvg
Plasma::FrameSvg * backgroundSvg() const
Background SVG image is one of the common properties, so a direct function that accesses it is provid...
Definition: Global.cpp:199
Lancelot::Panel::borderSize
qreal borderSize(Plasma::MarginEdge edge) const
Definition: Panel.cpp:132
QRectF::setLeft
void setLeft(qreal x)
QRectF::setHeight
void setHeight(qreal height)
QPointF
Lancelot::Panel::setLayoutItem
void setLayoutItem(QGraphicsLayoutItem *layoutItem)
Sets the layout item for the components in case the panel should contain more than one item at a time...
Definition: Panel.cpp:194
QObject::name
const char * name() const
Lancelot::Widget
Base class for Widgets that want to use Lancelot framework.
Definition: Widget.h:37
Lancelot::Group
Represents a group of object.
Definition: Global.h:63
Lancelot::Panel::setIcon
void setIcon(QIcon icon)
Sets icon of this Lancelot::Panel.
Definition: Panel.cpp:151
QString
QSizeF::boundedTo
QSizeF boundedTo(const QSizeF &otherSize) const
QGraphicsSceneResizeEvent
Lancelot::Panel::setTitle
void setTitle(const QString &title)
Sets title of this Lancelot::Panel.
Definition: Panel.cpp:140
QSize
Lancelot::Panel::sizeHint
L_Override QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
Definition: Panel.cpp:205
Lancelot::Panel::Panel
Panel(QString title, QGraphicsItem *parent=0)
Creates a new Lancelot::Widget.
Definition: Panel.cpp:109
Lancelot::Panel::isShowingTitle
bool isShowingTitle() const
Definition: Panel.cpp:177
Lancelot::Panel::resizeEvent
L_Override void resizeEvent(QGraphicsSceneResizeEvent *event)
Definition: Panel.cpp:182
QRectF::width
qreal width() const
Lancelot::Panel::icon
QIcon icon() const
QSizeF
QRectF
QRectF::setTop
void setTop(qreal y)
QRectF::setWidth
void setWidth(qreal width)
Lancelot::Panel::layoutItem
QGraphicsLayoutItem * layoutItem() const
Definition: Panel.cpp:200
QGraphicsWidget::rect
QRectF rect() const
Lancelot::Panel::title
QString title() const
QRectF::height
qreal height() const
Lancelot::Panel::iconSize
QSize iconSize() const
QObject::parent
QObject * parent() const
QGraphicsWidget::resizeEvent
virtual void resizeEvent(QGraphicsSceneResizeEvent *event)
QGraphicsLayoutItem
QIcon
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