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

kig

  • sources
  • kde-4.12
  • kdeedu
  • kig
  • objects
object_drawer.cc
Go to the documentation of this file.
1 // Copyright (C) 2003 Dominique Devriese <devriese@kde.org>
2 
3 // This program is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU General Public License
5 // as published by the Free Software Foundation; either version 2
6 // of the License, or (at your option) any later version.
7 
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17 
18 #include "object_drawer.h"
19 
20 #include "object_imp.h"
21 #include "../misc/kigpainter.h"
22 
23 #include <qpen.h>
24 #include <qnamespace.h>
25 #include <cassert>
26 
27 #include <kdebug.h>
28 
29 void ObjectDrawer::draw( const ObjectImp& imp, KigPainter& p, bool sel ) const
30 {
31  bool nv = p.getNightVision( );
32  if ( mshown || nv )
33  {
34  p.setBrushStyle( Qt::NoBrush );
35  p.setBrushColor( sel ? Qt::red : ( mshown?mcolor:Qt::gray ) );
36  p.setPen( QPen ( sel ? Qt::red : ( mshown?mcolor:Qt::gray ), 1) );
37  p.setWidth( mwidth );
38  p.setStyle( mstyle );
39  p.setPointStyle( mpointstyle );
40  p.setFont( mfont );
41  p.setSelected( sel );
42  imp.draw( p );
43  }
44 }
45 
46 bool ObjectDrawer::contains( const ObjectImp& imp, const Coordinate& pt, const KigWidget& w, bool nv ) const
47 {
48  bool shownornv = mshown || nv;
49  return shownornv && imp.contains( pt, mwidth, w );
50 }
51 
52 bool ObjectDrawer::shown( ) const
53 {
54  return mshown;
55 }
56 
57 QColor ObjectDrawer::color() const
58 {
59  return mcolor;
60 }
61 
62 ObjectDrawer* ObjectDrawer::getCopyShown( bool s ) const
63 {
64  ObjectDrawer* ret = new ObjectDrawer;
65  ret->mcolor = mcolor;
66  ret->mshown = s;
67  ret->mwidth = mwidth;
68  ret->mstyle = mstyle;
69  ret->mpointstyle = mpointstyle;
70  ret->mfont = mfont;
71  return ret;
72 }
73 
74 ObjectDrawer* ObjectDrawer::getCopyColor( const QColor& c ) const
75 {
76  ObjectDrawer* ret = new ObjectDrawer;
77  ret->mcolor = c;
78  ret->mshown = mshown;
79  ret->mwidth = mwidth;
80  ret->mstyle = mstyle;
81  ret->mpointstyle = mpointstyle;
82  ret->mfont = mfont;
83  return ret;
84 }
85 
86 ObjectDrawer* ObjectDrawer::getCopyWidth( int w ) const
87 {
88  ObjectDrawer* ret = new ObjectDrawer;
89  ret->mcolor = mcolor;
90  ret->mshown = mshown;
91  ret->mwidth = w;
92  ret->mstyle = mstyle;
93  ret->mpointstyle = mpointstyle;
94  ret->mfont = mfont;
95  return ret;
96 }
97 
98 ObjectDrawer* ObjectDrawer::getCopyStyle( Qt::PenStyle s ) const
99 {
100  ObjectDrawer* ret = new ObjectDrawer;
101  ret->mcolor = mcolor;
102  ret->mshown = mshown;
103  ret->mwidth = mwidth;
104  ret->mstyle = s;
105  ret->mpointstyle = mpointstyle;
106  ret->mfont = mfont;
107  return ret;
108 }
109 
110 ObjectDrawer* ObjectDrawer::getCopyPointStyle( int p ) const
111 {
112  ObjectDrawer* ret = new ObjectDrawer;
113  ret->mcolor = mcolor;
114  ret->mshown = mshown;
115  ret->mwidth = mwidth;
116  ret->mstyle = mstyle;
117  ret->mpointstyle = p;
118  ret->mfont = mfont;
119  return ret;
120 }
121 
122 ObjectDrawer* ObjectDrawer::getCopyFont( const QFont& f ) const
123 {
124  ObjectDrawer* ret = new ObjectDrawer;
125  ret->mcolor = mcolor;
126  ret->mshown = mshown;
127  ret->mwidth = mwidth;
128  ret->mstyle = mstyle;
129  ret->mpointstyle = mpointstyle;
130  ret->mfont = f;
131  return ret;
132 }
133 
134 int ObjectDrawer::width() const
135 {
136  return mwidth;
137 }
138 
139 Qt::PenStyle ObjectDrawer::style() const
140 {
141  return mstyle;
142 }
143 
144 int ObjectDrawer::pointStyle() const
145 {
146  return mpointstyle;
147 }
148 
149 QFont ObjectDrawer::font() const
150 {
151  return mfont;
152 }
153 
154 ObjectDrawer::ObjectDrawer( const QColor& color, int width, bool shown, Qt::PenStyle style, int pointStyle, const QFont& f )
155  : mcolor( color ), mshown( shown ), mwidth( width ), mstyle( style ), mpointstyle( pointStyle ), mfont( f )
156 {
157 }
158 
159 ObjectDrawer::ObjectDrawer()
160  : mcolor( Qt::blue ), mshown( true ), mwidth( -1 ), mstyle( Qt::SolidLine ), mpointstyle( 0 ), mfont( QFont() )
161 {
162 }
163 
164 bool ObjectDrawer::inRect( const ObjectImp& imp, const Rect& r, const KigWidget& w ) const
165 {
166  return mshown && imp.inRect( r, mwidth, w );
167 }
168 
169 int ObjectDrawer::pointStyleFromString( const QString& style )
170 {
171  if ( style == "Round" )
172  return 0;
173  else if ( style == "RoundEmpty" )
174  return 1;
175  else if ( style == "Rectangular" )
176  return 2;
177  else if ( style == "RectangularEmpty" )
178  return 3;
179  else if ( style == "Cross" )
180  return 4;
181  return 0;
182 }
183 
184 QString ObjectDrawer::pointStyleToString() const
185 {
186  if ( mpointstyle == 0 )
187  return "Round";
188  else if ( mpointstyle == 1 )
189  return "RoundEmpty";
190  else if ( mpointstyle == 2 )
191  return "Rectangular";
192  else if ( mpointstyle == 3 )
193  return "RectangularEmpty";
194  else if ( mpointstyle == 4 )
195  return "Cross";
196  assert( false );
197  return QString();
198 }
199 
200 Qt::PenStyle ObjectDrawer::styleFromString( const QString& style )
201 {
202  if ( style == "SolidLine" )
203  return Qt::SolidLine;
204  else if ( style == "DashLine" )
205  return Qt::DashLine;
206  else if ( style == "DotLine" )
207  return Qt::DotLine;
208  else if ( style == "DashDotLine" )
209  return Qt::DashDotLine;
210  else if ( style == "DashDotDotLine" )
211  return Qt::DashDotDotLine;
212  else return Qt::SolidLine;
213 }
214 
215 QString ObjectDrawer::styleToString() const
216 {
217  if ( mstyle == Qt::SolidLine )
218  return "SolidLine";
219  else if ( mstyle == Qt::DashLine )
220  return "DashLine";
221  else if ( mstyle == Qt::DotLine )
222  return "DotLine";
223  else if ( mstyle == Qt::DashDotLine )
224  return "DashDotLine";
225  else if ( mstyle == Qt::DashDotDotLine )
226  return "DashDotDotLine";
227  return "SolidLine";
228 }
object_imp.h
ObjectDrawer::getCopyShown
ObjectDrawer * getCopyShown(bool s) const
returns a new ObjectDrawer that is identical to this one, except that the shown state is set to s ...
Definition: object_drawer.cc:62
KigPainter::setPointStyle
void setPointStyle(int p)
Definition: kigpainter.cpp:239
KigPainter::setBrushColor
void setBrushColor(const QColor &c)
Definition: kigpainter.cpp:265
ObjectDrawer::pointStyleToString
QString pointStyleToString() const
return pointStyle transformed in a string
Definition: object_drawer.cc:184
object_drawer.h
ObjectDrawer::shown
bool shown() const
returns whether the object this ObjectDrawer is responsible for will be drawn or not.
Definition: object_drawer.cc:52
ObjectDrawer::font
QFont font() const
return the font
Definition: object_drawer.cc:149
Rect
This file is part of Kig, a KDE program for Interactive Geometry...
Definition: rect.h:34
ObjectDrawer::getCopyStyle
ObjectDrawer * getCopyStyle(Qt::PenStyle s) const
returns a new ObjectDrawer that is identical to this one, except that the PenStyle state is set to s ...
Definition: object_drawer.cc:98
ObjectDrawer::inRect
bool inRect(const ObjectImp &imp, const Rect &r, const KigWidget &w) const
returns whether the object imp is in the rectangle r .
Definition: object_drawer.cc:164
ObjectDrawer::draw
void draw(const ObjectImp &imp, KigPainter &p, bool selected) const
Draw the object imp on kigpainter p .
Definition: object_drawer.cc:29
ObjectDrawer::ObjectDrawer
ObjectDrawer()
Construct a new ObjectDrawer with a default color ( Qt::blue ), width ( -1 ), shown state ( true )...
Definition: object_drawer.cc:159
Coordinate
The Coordinate class is the basic class representing a 2D location by its x and y components...
Definition: coordinate.h:33
KigPainter::getNightVision
bool getNightVision() const
Definition: kigpainter.cpp:276
KigPainter
KigPainter is an extended QPainter.
Definition: kigpainter.h:51
KigPainter::setWidth
void setWidth(int c)
setting this to -1 means to use the default width for the object being drawn.
Definition: kigpainter.cpp:232
KigPainter::setSelected
void setSelected(bool selected)
Definition: kigpainter.cpp:286
KigPainter::setBrushStyle
void setBrushStyle(Qt::BrushStyle c)
Definition: kigpainter.cpp:259
ObjectDrawer::getCopyPointStyle
ObjectDrawer * getCopyPointStyle(int p) const
returns a new ObjectDrawer that is identical to this one, except that the pointStyle state is set to ...
Definition: object_drawer.cc:110
KigWidget
This class is the real widget showing the document.
Definition: kig_view.h:50
ObjectDrawer::getCopyColor
ObjectDrawer * getCopyColor(const QColor &c) const
returns a new ObjectDrawer that is identical to this one, except that the color is set to c ...
Definition: object_drawer.cc:74
ObjectDrawer::contains
bool contains(const ObjectImp &imp, const Coordinate &pt, const KigWidget &w, bool nv=false) const
returns whether the object imp contains coordinate p .
Definition: object_drawer.cc:46
ObjectImp::inRect
virtual bool inRect(const Rect &r, int width, const KigWidget &si) const =0
ObjectDrawer::width
int width() const
return the width of the object
Definition: object_drawer.cc:134
ObjectDrawer::pointStyleFromString
static int pointStyleFromString(const QString &style)
Note that this returns a valid point style in every case, even if the given style string is unknown...
Definition: object_drawer.cc:169
ObjectDrawer::styleToString
QString styleToString() const
return style transformed in a string
Definition: object_drawer.cc:215
ObjectDrawer
A class holding some information about how a certain object is drawn on the window.
Definition: object_drawer.h:47
ObjectDrawer::pointStyle
int pointStyle() const
return pointStyle for points
Definition: object_drawer.cc:144
KigPainter::setStyle
void setStyle(Qt::PenStyle c)
Definition: kigpainter.cpp:226
ObjectDrawer::styleFromString
static Qt::PenStyle styleFromString(const QString &style)
Note that this returns a valid style in every case, even if the given style string is unknown...
Definition: object_drawer.cc:200
KigPainter::setPen
void setPen(const QPen &p)
Definition: kigpainter.cpp:244
ObjectImp::draw
virtual void draw(KigPainter &p) const =0
ObjectImp::contains
virtual bool contains(const Coordinate &p, int width, const KigWidget &si) const =0
ObjectDrawer::color
QColor color() const
returns the color that the object will be drawn in
Definition: object_drawer.cc:57
ObjectDrawer::getCopyFont
ObjectDrawer * getCopyFont(const QFont &f) const
returns a new ObjectDrawer that is identical to this one, except that the font state is set to f ...
Definition: object_drawer.cc:122
ObjectImp
The ObjectImp class represents the behaviour of an object after it is calculated. ...
Definition: object_imp.h:226
ObjectDrawer::style
Qt::PenStyle style() const
return PenStyle for all objects except points
Definition: object_drawer.cc:139
KigPainter::setFont
void setFont(const QFont &f)
Definition: kigpainter.cpp:271
ObjectDrawer::getCopyWidth
ObjectDrawer * getCopyWidth(int w) const
returns a new ObjectDrawer that is identical to this one, except that the width is set to w ...
Definition: object_drawer.cc:86
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:35:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kig

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

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