• 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
framesvgitem.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010 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 "framesvgitem.h"
21 
22 #include <QPainter>
23 
24 #include "kdebug.h"
25 
26 
27 namespace Plasma
28 {
29 
30 FrameSvgItemMargins::FrameSvgItemMargins(Plasma::FrameSvg *frameSvg, QObject *parent)
31  : QObject(parent),
32  m_frameSvg(frameSvg)
33 {
34  //kDebug() << "margins at: " << left() << top() << right() << bottom();
35  connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(update()));
36 }
37 
38 qreal FrameSvgItemMargins::left() const
39 {
40  return m_frameSvg->marginSize(LeftMargin);
41 }
42 
43 qreal FrameSvgItemMargins::top() const
44 {
45  return m_frameSvg->marginSize(TopMargin);
46 }
47 
48 qreal FrameSvgItemMargins::right() const
49 {
50  return m_frameSvg->marginSize(RightMargin);
51 }
52 
53 qreal FrameSvgItemMargins::bottom() const
54 {
55  return m_frameSvg->marginSize(BottomMargin);
56 }
57 
58 void FrameSvgItemMargins::update()
59 {
60  emit marginsChanged();
61 }
62 
63 FrameSvgItem::FrameSvgItem(QDeclarativeItem *parent)
64  : QDeclarativeItem(parent)
65 {
66  m_frameSvg = new Plasma::FrameSvg(this);
67  m_margins = new FrameSvgItemMargins(m_frameSvg, this);
68  setFlag(QGraphicsItem::ItemHasNoContents, false);
69  connect(m_frameSvg, SIGNAL(repaintNeeded()), this, SLOT(doUpdate()));
70 }
71 
72 
73 FrameSvgItem::~FrameSvgItem()
74 {
75 }
76 
77 void FrameSvgItem::setImagePath(const QString &path)
78 {
79  if (m_frameSvg->imagePath() == path) {
80  return;
81  }
82 
83  m_frameSvg->setImagePath(path);
84  m_frameSvg->setElementPrefix(m_prefix);
85 
86  if (implicitWidth() <= 0) {
87  setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin));
88  }
89 
90  if (implicitHeight() <= 0) {
91  setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin));
92  }
93 
94  emit imagePathChanged();
95  m_margins->update();
96  update();
97 }
98 
99 QString FrameSvgItem::imagePath() const
100 {
101  return m_frameSvg->imagePath();
102 }
103 
104 
105 void FrameSvgItem::setPrefix(const QString &prefix)
106 {
107  if (m_prefix == prefix) {
108  return;
109  }
110 
111  m_frameSvg->setElementPrefix(prefix);
112  m_prefix = prefix;
113 
114  if (implicitWidth() <= 0) {
115  setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin));
116  }
117 
118  if (implicitHeight() <= 0) {
119  setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin));
120  }
121 
122  emit prefixChanged();
123  m_margins->update();
124  update();
125 }
126 
127 QString FrameSvgItem::prefix() const
128 {
129  return m_prefix;
130 }
131 
132 FrameSvgItemMargins *FrameSvgItem::margins() const
133 {
134  return m_margins;
135 }
136 
137 void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders)
138 {
139  if (m_frameSvg->enabledBorders() == borders)
140  return;
141 
142  m_frameSvg->setEnabledBorders(borders);
143  emit enabledBordersChanged();
144 }
145 
146 Plasma::FrameSvg::EnabledBorders FrameSvgItem::enabledBorders() const
147 {
148  return m_frameSvg->enabledBorders();
149 }
150 
151 void FrameSvgItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
152 {
153  Q_UNUSED(option);
154  Q_UNUSED(widget);
155 
156  m_frameSvg->paintFrame(painter);
157 }
158 
159 void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
160  const QRectF &oldGeometry)
161 {
162  m_frameSvg->resizeFrame(newGeometry.size());
163  QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
164 }
165 
166 void FrameSvgItem::doUpdate()
167 {
168  if (implicitWidth() <= 0) {
169  setImplicitWidth(m_frameSvg->marginSize(Plasma::LeftMargin) + m_frameSvg->marginSize(Plasma::RightMargin));
170  }
171 
172  if (implicitHeight() <= 0) {
173  setImplicitHeight(m_frameSvg->marginSize(Plasma::TopMargin) + m_frameSvg->marginSize(Plasma::BottomMargin));
174  }
175 
176  update();
177 }
178 
179 void FrameSvgItem::setImplicitWidth(qreal width)
180 {
181  if (implicitWidth() == width) {
182  return;
183  }
184 
185  QDeclarativeItem::setImplicitWidth(width);
186 
187  emit implicitWidthChanged();
188 }
189 
190 qreal FrameSvgItem::implicitWidth() const
191 {
192  return QDeclarativeItem::implicitWidth();
193 }
194 
195 void FrameSvgItem::setImplicitHeight(qreal height)
196 {
197  if (implicitHeight() == height) {
198  return;
199  }
200 
201  QDeclarativeItem::setImplicitHeight(height);
202 
203  emit implicitHeightChanged();
204 }
205 
206 qreal FrameSvgItem::implicitHeight() const
207 {
208  return QDeclarativeItem::implicitHeight();
209 }
210 
211 } // Plasma namespace
212 
213 #include "framesvgitem.moc"
QDeclarativeItem::setImplicitWidth
void setImplicitWidth(qreal w)
Plasma::FrameSvgItemMargins::right
qreal right() const
QWidget
Plasma::FrameSvgItem::~FrameSvgItem
~FrameSvgItem()
Definition: framesvgitem.cpp:73
Plasma::FrameSvgItem::prefixChanged
void prefixChanged()
Plasma::FrameSvgItem::paint
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: framesvgitem.cpp:151
QGraphicsItem::setFlag
void setFlag(GraphicsItemFlag flag, bool enabled)
Plasma::FrameSvgItem::enabledBorders
Plasma::FrameSvg::EnabledBorders enabledBorders() const
Plasma::FrameSvgItemMargins::update
void update()
Definition: framesvgitem.cpp:58
Plasma::FrameSvgItem::prefix
QString prefix() const
QRectF::size
QSizeF size() const
Plasma::FrameSvgItem::setImagePath
void setImagePath(const QString &path)
Definition: framesvgitem.cpp:77
QDeclarativeItem::implicitHeight
qreal implicitHeight() const
QGraphicsItem::update
void update(const QRectF &rect)
Plasma::FrameSvgItemMargins
Definition: framesvgitem.h:31
Plasma::FrameSvgItemMargins::FrameSvgItemMargins
FrameSvgItemMargins(Plasma::FrameSvg *frameSvg, QObject *parent=0)
Definition: framesvgitem.cpp:30
QObject
Plasma::FrameSvgItem::geometryChanged
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
Definition: framesvgitem.cpp:159
QPainter
QString
Plasma::FrameSvgItem::FrameSvgItem
FrameSvgItem(QDeclarativeItem *parent=0)
Definition: framesvgitem.cpp:63
QDeclarativeItem::implicitWidth
qreal implicitWidth() const
Plasma::FrameSvgItem::enabledBordersChanged
void enabledBordersChanged()
Plasma::FrameSvgItem::implicitHeight
qreal implicitHeight() const
QDeclarativeItem::geometryChanged
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
Plasma::FrameSvgItem::margins
FrameSvgItemMargins * margins() const
Plasma::FrameSvgItem::setEnabledBorders
void setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders)
Definition: framesvgitem.cpp:137
Plasma::FrameSvgItem::implicitWidth
qreal implicitWidth() const
Plasma::FrameSvgItem::imagePath
QString imagePath() const
Plasma::FrameSvgItem::implicitHeightChanged
void implicitHeightChanged()
Plasma::FrameSvgItem::imagePathChanged
void imagePathChanged()
Plasma::FrameSvgItem::implicitWidthChanged
void implicitWidthChanged()
framesvgitem.h
Plasma::FrameSvgItem::setImplicitWidth
void setImplicitWidth(qreal width)
Definition: framesvgitem.cpp:179
QRectF
Plasma::FrameSvgItemMargins::marginsChanged
void marginsChanged()
QDeclarativeItem::setImplicitHeight
void setImplicitHeight(qreal h)
Plasma::FrameSvgItem::setImplicitHeight
void setImplicitHeight(qreal height)
Definition: framesvgitem.cpp:195
Plasma::FrameSvgItemMargins::left
qreal left() const
Plasma::FrameSvgItemMargins::top
qreal top() const
QStyleOptionGraphicsItem
QDeclarativeItem
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
Plasma::FrameSvgItemMargins::bottom
qreal bottom() const
Plasma::FrameSvgItem::setPrefix
void setPrefix(const QString &prefix)
Definition: framesvgitem.cpp:105
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