summaryrefslogtreecommitdiffstats
path: root/kig/objects/object_drawer.h
blob: 6206522e2382df9137f8ecfd7af8af248704e6a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (C)  2003  Dominique Devriese <[email protected]>

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
// 02110-1301, USA.

#ifndef KIG_OBJECTS_OBJECT_DRAWER_H
#define KIG_OBJECTS_OBJECT_DRAWER_H

#include <tqcolor.h>
#include <tqnamespace.h>

class ObjectImp;
class KigPainter;
class Coordinate;
class KigWidget;
class Rect;

/**
 * A class holding some information about how a certain object is
 * drawn on the window.
 *
 * An ObjectDrawer is used by an ObjectHolder to keep information
 * about how to draw an ObjectImp on the window.  It is really nothing
 * more than a struct with some convenience methods.  It does not have
 * any virtual methods, or have any complex semantics.  It keeps
 * information like the thickness of an object, its color, and whether
 * or not it is hidden.
 *
 * \note The default width of an object depends on its type.  E.g. A
 * point is by default drawn at width 5, a line at width 1.
 * Therefore, there is a special width -1, which means "the default
 * width for this object".
 */
class ObjectDrawer
{
  TQColor mcolor;
  bool mshown;
  int mwidth;
  Qt::PenStyle mstyle;
  int mpointstyle;
public:
  /**
   * Construct a new ObjectDrawer with a default color ( Qt::blue ),
   * width ( -1 ), shown state ( true ), PenStyle ( Qt::SolidLine ),
   * and pointstyle ( 0 )
   */
  ObjectDrawer();
  ObjectDrawer( const TQColor& color, int width = -1, bool shown = true, Qt::PenStyle = Qt::SolidLine, int pointStyle = 0 );
  /**
   * Draw the object \p imp on kigpainter \p p .  If \p selected is true, it is
   * drawn in red, otherwise in its normal color.
   */
  void draw( const ObjectImp& imp, KigPainter& p, bool selected ) const;
  /**
   * returns whether the object \p imp contains coordinate \p p . This is
   * dependent on whether it is shown ( when it will never contain
   * anything ), and on its width..
   */
  bool contains( const ObjectImp& imp, const Coordinate& pt, const KigWidget& w, bool nv = false ) const;
  /**
   * returns whether the object \p imp is in the rectangle \p r . This is
   * dependent on whether it is shown and on its width..
   */
  bool inRect( const ObjectImp& imp, const Rect& r, const KigWidget& w ) const;

  /**
   * returns whether the object this ObjectDrawer is responsible for
   * will be drawn or not..
   */
  bool shown() const;
  /**
   * returns the color that the object will be drawn in
   */
  TQColor color() const;
  /**
   * return the width of the object
   */
  int width() const;
  /**
   * return PenStyle for all objects except points
   */
  Qt::PenStyle style() const;
  /**
   * return pointStyle for points
   */
  int pointStyle() const;
  /**
   * return pointStyle trasnformed in a string
   */
  TQString pointStyleToString() const;
  /**
   * return style trasnformed in a string
   */
  TQString styleToString() const;
  /**
   * returns a new ObjectDrawer that is identical to this one.. except
   * that the shown state is set to \p s ..
   */
  ObjectDrawer* getCopyShown( bool s ) const;
  /**
   * returns a new ObjectDrawer that is identical to this one.. except
   * that the color is set to \p c ..
   */
  ObjectDrawer* getCopyColor( const TQColor& c ) const;
  /**
   * returns a new ObjectDrawer that is identical to this one.. except
   * that the width is set to \p w ..
   */
  ObjectDrawer* getCopyWidth( int w ) const;
  /**
   * returns a new ObjectDrawer that is identical to this one.. except
   * that the PenStyle state is set to \p s ..
   */
  ObjectDrawer* getCopyStyle( Qt::PenStyle s ) const;
  /**
   * returns a new ObjectDrawer that is identical to this one.. except
   * that the pointStyle state is set to \p p ..
   */
  ObjectDrawer* getCopyPointStyle( int p ) const;
  /**
   * Note that this returns a valid point style in every case, even if
   * the given \p style string is unknown. In that case it returns a
   * default value.
   */
  static int pointStyleFromString( const TQString& style );
  /**
   * Note that this returns a valid style in every case, even if the
   * given \p style string is unknown. In that case it returns a default
   * value.
   */
  static Qt::PenStyle styleFromString( const TQString& style );
};

#endif