• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kde-runtime API Reference
  • KDE Home
  • Contact Us
 

PlasmaCore

  • sources
  • kde-4.14
  • kde-runtime
  • plasma
  • declarativeimports
  • core
declarativeitemcontainer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Marco Martin <mart@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2, or
7  * (at your option) any later version.
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 General Public License for more details
13  *
14  * You should have received a copy of the GNU 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 "declarativeitemcontainer_p.h"
21 
22 #include <KDebug>
23 
24 DeclarativeItemContainer::DeclarativeItemContainer(QGraphicsItem *parent)
25  : QGraphicsWidget(parent)
26 {
27 }
28 
29 DeclarativeItemContainer::~DeclarativeItemContainer()
30 {
31 }
32 
33 void DeclarativeItemContainer::setDeclarativeItem(QDeclarativeItem *item, bool reparent)
34 {
35  if (m_declarativeItem) {
36  disconnect(m_declarativeItem.data(), 0, this, 0);
37  }
38 
39  setMinimumWidth(item->implicitWidth());
40  setMinimumHeight(item->implicitHeight());
41 
42  resize(item->width(), item->height());
43 
44  m_declarativeItem = item;
45  if (reparent) {
46  static_cast<QGraphicsItem *>(item)->setParentItem(this);
47  }
48 
49  connect(m_declarativeItem.data(), SIGNAL(widthChanged()), this, SLOT(widthChanged()));
50  connect(m_declarativeItem.data(), SIGNAL(heightChanged()), this, SLOT(heightChanged()));
51 
52  qreal minimumWidth = -1;
53  qreal minimumHeight = -1;
54  qreal maximumWidth = -1;
55  qreal maximumHeight = -1;
56  qreal preferredWidth = -1;
57  qreal preferredHeight = -1;
58 
59 
60  if (item->metaObject()->indexOfProperty("minimumWidth") >= 0 ) {
61  minimumWidth = item->property("minimumWidth").toReal();
62  QObject::connect(item, SIGNAL(minimumWidthChanged()), this, SLOT(minimumWidthChanged()));
63  }
64 
65  if (item->metaObject()->indexOfProperty("minimumHeight") >= 0 ) {
66  minimumHeight = item->property("minimumHeight").toReal();
67  QObject::connect(item, SIGNAL(minimumHeightChanged()), this, SLOT(minimumHeightChanged()));
68  }
69 
70  if (item->metaObject()->indexOfProperty("maximumWidth") >= 0 ) {
71  maximumWidth = item->property("maximumWidth").toReal();
72  QObject::connect(item, SIGNAL(maximumWidthChanged()), this, SLOT(maximumWidthChanged()));
73  }
74 
75  if (item->metaObject()->indexOfProperty("maximumHeight") >= 0 ) {
76  maximumHeight = item->property("maximumHeight").toReal();
77  QObject::connect(item, SIGNAL(maximumHeightChanged()), this, SLOT(maximumHeightChanged()));
78  }
79 
80  if (item->metaObject()->indexOfProperty("preferredWidth") >= 0 ) {
81  preferredWidth = item->property("preferredWidth").toReal();
82  QObject::connect(item, SIGNAL(preferredWidthChanged()), this, SLOT(preferredWidthChanged()));
83  }
84 
85  if (item->metaObject()->indexOfProperty("preferredHeight") >= 0 ) {
86  preferredHeight = item->property("preferredHeight").toReal();
87  QObject::connect(item, SIGNAL(preferredHeightChanged()), this, SLOT(preferredHeightChanged()));
88  }
89 
90  if (minimumWidth > 0 && minimumHeight > 0) {
91  setMinimumSize(minimumWidth, minimumHeight);
92  } else {
93  setMinimumSize(-1, -1);
94  }
95 
96  if (maximumWidth > 0 && maximumHeight > 0) {
97  setMaximumSize(maximumWidth, maximumHeight);
98  } else {
99  setMaximumSize(-1, -1);
100  }
101 
102  if (preferredWidth > 0 && preferredHeight > 0) {
103  setPreferredSize(preferredWidth, preferredHeight);
104  } else {
105  setPreferredSize(-1, -1);
106  }
107 }
108 
109 QDeclarativeItem *DeclarativeItemContainer::declarativeItem() const
110 {
111  return m_declarativeItem.data();
112 }
113 
114 void DeclarativeItemContainer::resizeEvent(QGraphicsSceneResizeEvent *event)
115 {
116  if (m_declarativeItem) {
117  m_declarativeItem.data()->setProperty("width", event->newSize().width());
118  m_declarativeItem.data()->setProperty("height", event->newSize().height());
119  }
120 }
121 
122 void DeclarativeItemContainer::mousePressEvent(QGraphicsSceneMouseEvent *event)
123 {
124  event->ignore();
125 }
126 
127 void DeclarativeItemContainer::widthChanged()
128 {
129  if (!m_declarativeItem) {
130  return;
131  }
132 
133  QSizeF newSize(size());
134  newSize.setWidth(m_declarativeItem.data()->width());
135  resize(newSize);
136 }
137 
138 void DeclarativeItemContainer::heightChanged()
139 {
140  if (!m_declarativeItem) {
141  return;
142  }
143 
144  QSizeF newSize(size());
145  newSize.setHeight(m_declarativeItem.data()->height());
146  resize(newSize);
147 }
148 
149 
150 void DeclarativeItemContainer::minimumWidthChanged()
151 {
152  qreal minimumWidth = m_declarativeItem.data()->property("minimumWidth").toReal();
153  setMinimumWidth(minimumWidth);
154 }
155 
156 void DeclarativeItemContainer::minimumHeightChanged()
157 {
158  qreal minimumHeight = m_declarativeItem.data()->property("minimumHeight").toReal();
159  setMinimumHeight(minimumHeight);
160 }
161 
162 void DeclarativeItemContainer::maximumWidthChanged()
163 {
164  qreal maximumWidth = m_declarativeItem.data()->property("maximumWidth").toReal();
165  setMaximumWidth(maximumWidth);
166 }
167 
168 void DeclarativeItemContainer::maximumHeightChanged()
169 {
170  qreal maximumHeight = m_declarativeItem.data()->property("maximumHeight").toReal();
171  setMaximumHeight(maximumHeight);
172 }
173 
174 void DeclarativeItemContainer::preferredWidthChanged()
175 {
176  qreal preferredWidth = m_declarativeItem.data()->property("preferredWidth").toReal();
177  setPreferredWidth(preferredWidth);
178 }
179 
180 void DeclarativeItemContainer::preferredHeightChanged()
181 {
182  qreal preferredHeight = m_declarativeItem.data()->property("preferredHeight").toReal();
183  setPreferredHeight(preferredHeight);
184 }
185 
186 #include "declarativeitemcontainer_p.moc"
QGraphicsLayoutItem::preferredWidth
qreal preferredWidth() const
QGraphicsLayoutItem::setMinimumWidth
void setMinimumWidth(qreal width)
QGraphicsLayoutItem::minimumHeight
qreal minimumHeight() const
DeclarativeItemContainer::setDeclarativeItem
void setDeclarativeItem(QDeclarativeItem *item, bool reparent=true)
Definition: declarativeitemcontainer.cpp:33
QGraphicsLayoutItem::minimumWidth
qreal minimumWidth() const
DeclarativeItemContainer::minimumHeightChanged
void minimumHeightChanged()
Definition: declarativeitemcontainer.cpp:156
QGraphicsLayoutItem::setMinimumSize
void setMinimumSize(const QSizeF &size)
QGraphicsLayoutItem::setMaximumHeight
void setMaximumHeight(qreal height)
QGraphicsItem::setParentItem
void setParentItem(QGraphicsItem *newParent)
DeclarativeItemContainer::minimumWidthChanged
void minimumWidthChanged()
Definition: declarativeitemcontainer.cpp:150
QGraphicsLayoutItem::preferredHeight
qreal preferredHeight() const
DeclarativeItemContainer::~DeclarativeItemContainer
~DeclarativeItemContainer()
Definition: declarativeitemcontainer.cpp:29
DeclarativeItemContainer::maximumHeightChanged
void maximumHeightChanged()
Definition: declarativeitemcontainer.cpp:168
DeclarativeItemContainer::DeclarativeItemContainer
DeclarativeItemContainer(QGraphicsItem *parent=0)
Definition: declarativeitemcontainer.cpp:24
QGraphicsLayoutItem::setMinimumHeight
void setMinimumHeight(qreal height)
QGraphicsLayoutItem::setPreferredHeight
void setPreferredHeight(qreal height)
QObject::metaObject
virtual const QMetaObject * metaObject() const
QWeakPointer::data
T * data() const
QGraphicsItem
QDeclarativeItem::implicitHeight
implicitHeight
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
QGraphicsWidget::resize
void resize(const QSizeF &size)
QGraphicsLayoutItem::maximumHeight
qreal maximumHeight() const
QObject::property
QVariant property(const char *name) const
QGraphicsLayoutItem::setPreferredWidth
void setPreferredWidth(qreal width)
QGraphicsSceneMouseEvent
QSizeF::setWidth
void setWidth(qreal width)
QGraphicsWidget
QDeclarativeItem::implicitWidth
implicitWidth
QGraphicsSceneResizeEvent
DeclarativeItemContainer::declarativeItem
QDeclarativeItem * declarativeItem() const
Definition: declarativeitemcontainer.cpp:109
DeclarativeItemContainer::preferredHeightChanged
void preferredHeightChanged()
Definition: declarativeitemcontainer.cpp:180
QMetaObject::indexOfProperty
int indexOfProperty(const char *name) const
QGraphicsLayoutItem::setMaximumSize
void setMaximumSize(const QSizeF &size)
DeclarativeItemContainer::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: declarativeitemcontainer.cpp:122
DeclarativeItemContainer::maximumWidthChanged
void maximumWidthChanged()
Definition: declarativeitemcontainer.cpp:162
QSizeF
DeclarativeItemContainer::resizeEvent
void resizeEvent(QGraphicsSceneResizeEvent *event)
Definition: declarativeitemcontainer.cpp:114
QGraphicsLayoutItem::setPreferredSize
void setPreferredSize(const QSizeF &size)
QGraphicsLayoutItem::maximumWidth
qreal maximumWidth() const
declarativeitemcontainer_p.h
QGraphicsLayoutItem::setMaximumWidth
void setMaximumWidth(qreal width)
QDeclarativeItem
DeclarativeItemContainer::widthChanged
void widthChanged()
Definition: declarativeitemcontainer.cpp:127
QVariant::toReal
qreal toReal(bool *ok) const
QSizeF::height
qreal height() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
DeclarativeItemContainer::heightChanged
void heightChanged()
Definition: declarativeitemcontainer.cpp:138
QSizeF::setHeight
void setHeight(qreal height)
QGraphicsSceneResizeEvent::newSize
QSizeF newSize() const
QSizeF::width
qreal width() const
DeclarativeItemContainer::preferredWidthChanged
void preferredWidthChanged()
Definition: declarativeitemcontainer.cpp:174
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:08:28 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

PlasmaCore

Skip menu "PlasmaCore"
  • Main Page
  • Namespace List
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kde-runtime API Reference

Skip menu "kde-runtime API Reference"
  • KCMShell
  • KNotify
  • Plasma Runtime
  •     PlasmaCore
  •     DragAndDrop
  •     PlasmaComponents
  •     PlasmaExtraComponents
  •     QtExtraComponents

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