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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
/* This file is part of KCachegrind.
Copyright (C) 2002, 2003 Josef Weidendorfer <Josef.Weidendorfer@gmx.de>
Adapted for the needs of kdesvn by Rajko Albrecht <ral@alwins-world.de>
KCachegrind 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, version 2.
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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/**
* A Widget for visualizing hierarchical metrics as areas.
* The API is similar to TQListView.
*
* This file defines the following classes:
* DrawParams, RectDrawing, TreeMapItem, TreeMapWidget
*
* DrawParams/RectDrawing allows reusing of TreeMap drawing
* functions in other widgets.
*/
#ifndef DRAWPARAMS_H
#define DRAWPARAMS_H
#include <tqstring.h>
#include <tqwidget.h>
#include <tqpixmap.h>
#include <tqptrlist.h>
#include <tqvaluevector.h>
#include <tqcolor.h>
#include <tqapplication.h>
#include <tqstringlist.h>
class TQPopupMenu;
class TQString;
class KConfigGroup;
/**
* Drawing parameters for an object.
* A Helper Interface for RectDrawing.
*/
class DrawParams
{
public:
/**
* Positions for drawing into a rectangle.
*
* The specified position assumes no rotation.
* If there is more than one text for one position, it is put
* nearer to the center of the item.
*
* Drawing at top positions cuts free space from top,
* drawing at bottom positions cuts from bottom.
* Default usually gives positions clockwise according to field number.
*/
enum Position { TopLeft, TopCenter, TopRight,
BottomLeft, BottomCenter, BottomRight,
Default, Unknown};
// no constructor as this is an abstract class
virtual ~DrawParams() {}
virtual TQString text(int) const = 0;
virtual TQPixmap pixmap(int) const = 0;
virtual Position position(int) const = 0;
// 0: no limit, negative: leave at least -maxLines() free
virtual int maxLines(int) const { return 0; }
virtual int fieldCount() const { return 0; }
virtual TQColor backColor() const { return TQt::white; }
virtual const TQFont& font() const = 0;
virtual bool selected() const { return false; }
virtual bool current() const { return false; }
virtual bool shaded() const { return true; }
virtual bool rotated() const { return false; }
virtual bool drawFrame() const { return true; }
};
/*
* DrawParam with attributes stored
*/
class StoredDrawParams: public DrawParams
{
public:
StoredDrawParams();
StoredDrawParams(TQColor c,
bool selected = false, bool current = false);
// getters
TQString text(int) const;
TQPixmap pixmap(int) const;
Position position(int) const;
int maxLines(int) const;
int fieldCount() const { return _field.size(); }
TQColor backColor() const { return _backColor; }
bool selected() const { return _selected; }
bool current() const { return _current; }
bool shaded() const { return _shaded; }
bool rotated() const { return _rotated; }
bool drawFrame() const { return _drawFrame; }
const TQFont& font() const;
// attribute setters
void setField(int f, TQString t, TQPixmap pm = TQPixmap(),
Position p = Default, int maxLines = 0);
void setText(int f, TQString);
void setPixmap(int f, TQPixmap);
void setPosition(int f, Position);
void setMaxLines(int f, int);
void setBackColor(TQColor c) { _backColor = c; }
void setSelected(bool b) { _selected = b; }
void setCurrent(bool b) { _current = b; }
void setShaded(bool b) { _shaded = b; }
void setRotated(bool b) { _rotated = b; }
void drawFrame(bool b) { _drawFrame = b; }
protected:
TQColor _backColor;
bool _selected :1;
bool _current :1;
bool _shaded :1;
bool _rotated :1;
bool _drawFrame :1;
private:
// resize field array if needed to allow to access field <f>
void ensureField(int f);
struct Field {
TQString text;
TQPixmap pix;
Position pos;
int maxLines;
};
TQValueVector<Field> _field;
};
/* State for drawing on a rectangle.
*
* Following drawing functions are provided:
* - background drawing with shading and 3D frame
* - successive pixmap/text drawing at various positions with wrap-around
* optimized for minimal space usage (e.g. if a text is drawn at top right
* after text on top left, the same line is used if space allows)
*
*/
class RectDrawing
{
public:
RectDrawing(TQRect);
~RectDrawing();
// The default DrawParams object used.
DrawParams* drawParams();
// we take control over the given object (i.e. delete at destruction)
void setDrawParams(DrawParams*);
// draw on a given TQPainter, use this class as info provider per default
void drawBack(TQPainter*, DrawParams* dp = 0);
/* Draw field at position() from pixmap()/text() with maxLines().
* Returns true if something was drawn
*/
bool drawField(TQPainter*, int f, DrawParams* dp = 0);
// resets rectangle for free space
void setRect(TQRect);
// Returns the rectangle area still free of text/pixmaps after
// a number of drawText() calls.
TQRect remainingRect(DrawParams* dp = 0);
private:
int _usedTopLeft, _usedTopCenter, _usedTopRight;
int _usedBottomLeft, _usedBottomCenter, _usedBottomRight;
TQRect _rect;
// temporary
int _fontHeight;
TQFontMetrics* _fm;
DrawParams* _dp;
};
#endif
|