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

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • src
  • lib
  • marble
  • graphicsview
FrameGraphicsItem.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2009 Bastian Holst <bastianholst@gmx.de>
9 //
10 
11 // Self
12 #include "FrameGraphicsItem.h"
13 #include "FrameGraphicsItem_p.h"
14 
15 // Marble
16 #include "MarbleDebug.h"
17 
18 // Qt
19 #include <QSizeF>
20 #include <QPainter>
21 #include <QPixmapCache>
22 #include <QMargins>
23 #include <qdrawutil.h>
24 
25 using namespace Marble;
26 
27 FrameGraphicsItem::FrameGraphicsItem( MarbleGraphicsItem *parent )
28  : ScreenGraphicsItem( parent ),
29  d( new FrameGraphicsItemPrivate( this ) )
30 {
31 }
32 
33 FrameGraphicsItem::~FrameGraphicsItem()
34 {
35  delete d;
36 }
37 
38 FrameGraphicsItem::FrameType FrameGraphicsItem::frame() const
39 {
40  return d->m_frame;
41 }
42 
43 void FrameGraphicsItem::setFrame( FrameType type )
44 {
45  d->m_frame = type;
46  setPadding( padding() );
47 }
48 
49 qreal FrameGraphicsItem::margin() const
50 {
51  return d->m_margin;
52 }
53 
54 void FrameGraphicsItem::setMargin( qreal margin )
55 {
56  d->m_margin = margin;
57  d->updateSize();
58  update();
59 }
60 
61 qreal FrameGraphicsItem::marginTop() const
62 {
63  return d->m_marginTop;
64 }
65 
66 void FrameGraphicsItem::setMarginTop( qreal marginTop )
67 {
68  d->m_marginTop = marginTop;
69  d->updateSize();
70  update();
71 }
72 
73 qreal FrameGraphicsItem::marginBottom() const
74 {
75  return d->m_marginBottom;
76 }
77 
78 void FrameGraphicsItem::setMarginBottom( qreal marginBottom )
79 {
80  d->m_marginBottom = marginBottom;
81  d->updateSize();
82  update();
83 }
84 
85 qreal FrameGraphicsItem::marginLeft() const
86 {
87  return d->m_marginLeft;
88 }
89 
90 void FrameGraphicsItem::setMarginLeft( qreal marginLeft )
91 {
92  d->m_marginLeft = marginLeft;
93  d->updateSize();
94  update();
95 }
96 
97 qreal FrameGraphicsItem::marginRight() const
98 {
99  return d->m_marginRight;
100 }
101 
102 void FrameGraphicsItem::setMarginRight( qreal marginRight )
103 {
104  d->m_marginRight = marginRight;
105  d->updateSize();
106  update();
107 }
108 
109 qreal FrameGraphicsItem::borderWidth() const
110 {
111  return d->m_borderWidth;
112 }
113 
114 void FrameGraphicsItem::setBorderWidth( qreal width )
115 {
116  d->m_borderWidth = width;
117  d->updateSize();
118  update();
119 }
120 
121 qreal FrameGraphicsItem::padding() const
122 {
123  return d->m_padding;
124 }
125 
126 void FrameGraphicsItem::setPadding( qreal width )
127 {
128  if ( width >= 0 ) {
129  d->m_padding = width;
130  d->updateSize();
131  }
132 }
133 
134 QBrush FrameGraphicsItem::borderBrush() const
135 {
136  return d->m_borderBrush;
137 }
138 
139 void FrameGraphicsItem::setBorderBrush( const QBrush &brush )
140 {
141  d->m_borderBrush = brush;
142  update();
143 }
144 
145 Qt::PenStyle FrameGraphicsItem::borderStyle () const
146 {
147  return d->m_borderStyle;
148 }
149 
150 void FrameGraphicsItem::setBorderStyle( Qt::PenStyle style )
151 {
152  d->m_borderStyle = style;
153  update();
154 }
155 
156 QBrush FrameGraphicsItem::background() const
157 {
158  return d->m_backgroundBrush;
159 }
160 
161 void FrameGraphicsItem::setBackground( const QBrush &background )
162 {
163  d->m_backgroundBrush = background;
164  update();
165 }
166 
167 QRectF FrameGraphicsItem::contentRect() const
168 {
169  qreal marginTop = ( d->m_marginTop == 0.0 ) ? d->m_margin : d->m_marginTop;
170  qreal marginLeft = ( d->m_marginLeft == 0.0 ) ? d->m_margin : d->m_marginLeft;
171 
172  QRectF contentRect = QRectF( marginLeft + d->m_padding,
173  marginTop + d->m_padding,
174  d->m_contentSize.width(),
175  d->m_contentSize.height() );
176 
177  return contentRect;
178 }
179 
180 QSizeF FrameGraphicsItem::contentSize() const
181 {
182  return d->m_contentSize;
183 }
184 
185 QRectF FrameGraphicsItem::paintedRect() const
186 {
187  qreal marginTop = ( d->m_marginTop == 0.0 ) ? d->m_margin : d->m_marginTop;
188  qreal marginBottom = ( d->m_marginBottom == 0.0 ) ? d->m_margin : d->m_marginBottom;
189  qreal marginLeft = ( d->m_marginLeft == 0.0 ) ? d->m_margin : d->m_marginLeft;
190  qreal marginRight = ( d->m_marginRight == 0.0 ) ? d->m_margin : d->m_marginRight;
191 
192  QSizeF size = this->size();
193 
194  QRectF paintedRect = QRectF( marginLeft, marginTop,
195  size.width() - ( marginLeft + marginRight ),
196  size.height() - ( marginTop + marginBottom ) );
197  return paintedRect;
198 }
199 
200 void FrameGraphicsItem::setContentSize( const QSizeF& size )
201 {
202  d->m_contentSize = size;
203  d->updateSize();
204 }
205 
206 QPainterPath FrameGraphicsItem::backgroundShape() const
207 {
208  QPainterPath path;
209  if ( d->m_frame == RectFrame || d->m_frame == ShadowFrame ) {
210  QRectF renderedRect = paintedRect();
211  path.addRect( QRectF( 0.0, 0.0, renderedRect.size().width(), renderedRect.size().height() ) );
212  }
213  else if ( d->m_frame == RoundedRectFrame ) {
214  QSizeF paintedSize = paintedRect().size();
215  path.addRoundedRect( QRectF( 0.0, 0.0, paintedSize.width() - 1, paintedSize.height() - 1 ),
216  6, 6 );
217  }
218  return path;
219 }
220 
221 void FrameGraphicsItem::paintBackground( QPainter *painter )
222 {
223  painter->save();
224  painter->setPen( QPen( d->m_borderBrush, d->m_borderWidth, d->m_borderStyle ) );
225  painter->setBrush( d->m_backgroundBrush );
226  painter->drawPath( backgroundShape() );
227 
228  painter->restore();
229 }
230 
231 void FrameGraphicsItem::paint( QPainter *painter )
232 {
233  painter->save();
234 
235  // Needs to be done here cause we don't want the margin translation
236  if ( frame() == ShadowFrame )
237  {
238  QPixmap shadow;
239  if ( !QPixmapCache::find( "marble/frames/shadowframe.png", shadow ) ) {
240  shadow = QPixmap( ":/marble/frames/shadowframe.png" );
241  QPixmapCache::insert( "marble/frames/shadowframe.png", shadow );
242  }
243  qDrawBorderPixmap( painter, QRect( QPoint( 0, 0 ), size().toSize() ),
244  QMargins( 10, 10, 10, 10 ), shadow );
245  }
246 
247  painter->translate( paintedRect().topLeft() );
248  paintBackground( painter );
249  painter->translate( d->m_padding, d->m_padding );
250  paintContent( painter );
251  painter->restore();
252 }
253 
254 void FrameGraphicsItem::paintContent( QPainter *painter )
255 {
256  Q_UNUSED( painter )
257 }
Marble::FrameGraphicsItem::margin
qreal margin() const
Returns the margin of the item.
Definition: FrameGraphicsItem.cpp:49
Marble::FrameGraphicsItem::paint
virtual void paint(QPainter *painter)
This function won't be reimplemented in most cases.
Definition: FrameGraphicsItem.cpp:231
Marble::FrameGraphicsItemPrivate
Definition: FrameGraphicsItem_p.h:25
Marble::FrameGraphicsItem::borderWidth
qreal borderWidth() const
Returns the border width of the item.
Definition: FrameGraphicsItem.cpp:109
Marble::FrameGraphicsItem::setBorderStyle
void setBorderStyle(Qt::PenStyle style)
Change the style of the border.
Definition: FrameGraphicsItem.cpp:150
Marble::FrameGraphicsItemPrivate::m_marginTop
qreal m_marginTop
Definition: FrameGraphicsItem_p.h:66
Marble::FrameGraphicsItemPrivate::m_marginBottom
qreal m_marginBottom
Definition: FrameGraphicsItem_p.h:67
Marble::FrameGraphicsItem::setMarginTop
void setMarginTop(qreal marginTop)
Set the top margin of the item.
Definition: FrameGraphicsItem.cpp:66
Marble::FrameGraphicsItem::marginLeft
qreal marginLeft() const
Returns the left margin of the item.
Definition: FrameGraphicsItem.cpp:85
QRectF::size
QSizeF size() const
QPainterPath::addRoundedRect
void addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode)
Marble::FrameGraphicsItem::contentSize
QSizeF contentSize() const
Returns the size of the content of the MarbleGraphicsItem.
Definition: FrameGraphicsItem.cpp:180
QPainter::save
void save()
Marble::FrameGraphicsItem::setBackground
void setBackground(const QBrush &background)
Changes the background brush of the item.
Definition: FrameGraphicsItem.cpp:161
Marble::FrameGraphicsItem::setMarginLeft
void setMarginLeft(qreal marginLeft)
Set the left margin of the item.
Definition: FrameGraphicsItem.cpp:90
Marble::FrameGraphicsItem::borderStyle
Qt::PenStyle borderStyle() const
Returns the style of the border.
Definition: FrameGraphicsItem.cpp:145
QBrush
Marble::MarbleGraphicsItem::size
QSizeF size() const
Returns the size of the item.
Definition: MarbleGraphicsItem.cpp:136
QPoint
Marble::FrameGraphicsItemPrivate::m_marginLeft
qreal m_marginLeft
Definition: FrameGraphicsItem_p.h:68
Marble::FrameGraphicsItem::setMargin
void setMargin(qreal margin)
Sets the margin of the item.
Definition: FrameGraphicsItem.cpp:54
MarbleDebug.h
Marble::FrameGraphicsItemPrivate::m_borderBrush
QBrush m_borderBrush
Definition: FrameGraphicsItem_p.h:75
FrameGraphicsItem.h
QRect
Marble::FrameGraphicsItemPrivate::m_marginRight
qreal m_marginRight
Definition: FrameGraphicsItem_p.h:69
Marble::FrameGraphicsItem::setBorderBrush
void setBorderBrush(const QBrush &brush)
Change the brush of the border.
Definition: FrameGraphicsItem.cpp:139
Marble::FrameGraphicsItem::paintBackground
virtual void paintBackground(QPainter *painter)
Paints the background.
Definition: FrameGraphicsItem.cpp:221
Marble::FrameGraphicsItem::RoundedRectFrame
Definition: FrameGraphicsItem.h:31
Marble::FrameGraphicsItem::paintedRect
QRectF paintedRect() const
Definition: FrameGraphicsItem.cpp:185
FrameGraphicsItem_p.h
Marble::FrameGraphicsItem::background
QBrush background() const
Returns the background brush of the item.
Definition: FrameGraphicsItem.cpp:156
QPainter::setPen
void setPen(const QColor &color)
QPainter
Marble::FrameGraphicsItem::contentRect
QRectF contentRect() const
Returns the rect of the content in item coordinates.
Definition: FrameGraphicsItem.cpp:167
Marble::FrameGraphicsItemPrivate::m_contentSize
QSizeF m_contentSize
Definition: FrameGraphicsItem_p.h:62
QPainterPath::addRect
void addRect(const QRectF &rectangle)
Marble::MarbleGraphicsItem
Definition: MarbleGraphicsItem.h:34
QPainter::setBrush
void setBrush(const QBrush &brush)
Marble::FrameGraphicsItem::setMarginRight
void setMarginRight(qreal marginRight)
Set the right margin of the item.
Definition: FrameGraphicsItem.cpp:102
Marble::FrameGraphicsItem::padding
qreal padding() const
Returns the padding of the item.
Definition: FrameGraphicsItem.cpp:121
QPixmap
Marble::FrameGraphicsItem::marginRight
qreal marginRight() const
Returns the right margin of the item.
Definition: FrameGraphicsItem.cpp:97
Marble::FrameGraphicsItem::ShadowFrame
Definition: FrameGraphicsItem.h:32
Marble::FrameGraphicsItem::FrameType
FrameType
Definition: FrameGraphicsItem.h:28
QPainter::restore
void restore()
Marble::FrameGraphicsItemPrivate::m_margin
qreal m_margin
Definition: FrameGraphicsItem_p.h:65
QPainterPath
Marble::FrameGraphicsItem::marginTop
qreal marginTop() const
Returns the top margin of the item.
Definition: FrameGraphicsItem.cpp:61
QPainter::drawPath
void drawPath(const QPainterPath &path)
Marble::FrameGraphicsItem::marginBottom
qreal marginBottom() const
Returns the bottom margin of the item.
Definition: FrameGraphicsItem.cpp:73
QSizeF
Marble::FrameGraphicsItemPrivate::m_backgroundBrush
QBrush m_backgroundBrush
Definition: FrameGraphicsItem_p.h:77
Marble::FrameGraphicsItemPrivate::m_borderWidth
qreal m_borderWidth
Definition: FrameGraphicsItem_p.h:74
Marble::FrameGraphicsItem::borderBrush
QBrush borderBrush() const
Returns the brush of the border.
Definition: FrameGraphicsItem.cpp:134
QRectF
Marble::FrameGraphicsItem::setMarginBottom
void setMarginBottom(qreal marginBottom)
Set the bottom margin of the item.
Definition: FrameGraphicsItem.cpp:78
QMargins
Marble::FrameGraphicsItemPrivate::m_borderStyle
Qt::PenStyle m_borderStyle
Definition: FrameGraphicsItem_p.h:76
QPixmapCache::find
QPixmap * find(const QString &key)
Marble::ScreenGraphicsItem
Definition: ScreenGraphicsItem.h:30
Marble::FrameGraphicsItem::setFrame
void setFrame(FrameType type)
Sets the type of the Frame.
Definition: FrameGraphicsItem.cpp:43
Marble::FrameGraphicsItem::frame
FrameType frame() const
Returns the type of the frame.
Definition: FrameGraphicsItem.cpp:38
QPainter::translate
void translate(const QPointF &offset)
Marble::MarbleGraphicsItem::update
void update()
Marks the item and all parent items as invalid.
Definition: MarbleGraphicsItem.cpp:167
QPen
Marble::FrameGraphicsItem::paintContent
virtual void paintContent(QPainter *painter)
Here the items paint their content.
Definition: FrameGraphicsItem.cpp:254
Marble::FrameGraphicsItem::setBorderWidth
void setBorderWidth(qreal width)
Set the border width of the item.
Definition: FrameGraphicsItem.cpp:114
Marble::FrameGraphicsItemPrivate::updateSize
void updateSize()
Definition: FrameGraphicsItem_p.h:46
Marble::FrameGraphicsItem::FrameGraphicsItem
FrameGraphicsItem(MarbleGraphicsItem *parent=0)
Definition: FrameGraphicsItem.cpp:27
Marble::FrameGraphicsItem::backgroundShape
virtual QPainterPath backgroundShape() const
Returns the shape of the background.
Definition: FrameGraphicsItem.cpp:206
QSizeF::height
qreal height() const
QPixmapCache::insert
bool insert(const QString &key, const QPixmap &pixmap)
Marble::FrameGraphicsItemPrivate::m_padding
qreal m_padding
Definition: FrameGraphicsItem_p.h:71
Marble::FrameGraphicsItem::RectFrame
Definition: FrameGraphicsItem.h:30
Marble::FrameGraphicsItem::setPadding
void setPadding(qreal width)
Set the padding of the item.
Definition: FrameGraphicsItem.cpp:126
Marble::FrameGraphicsItem::setContentSize
void setContentSize(const QSizeF &size)
Sets the size of the content of the item.
Definition: FrameGraphicsItem.cpp:200
Marble::FrameGraphicsItem::~FrameGraphicsItem
virtual ~FrameGraphicsItem()
Definition: FrameGraphicsItem.cpp:33
QSizeF::width
qreal width() const
Marble::FrameGraphicsItemPrivate::m_frame
FrameGraphicsItem::FrameType m_frame
Definition: FrameGraphicsItem_p.h:61
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

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

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

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