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

marble

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