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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
/***************************************************************************
infobox.h - description
-------------------
begin : Thu May 30 2002
copyright : (C) 2002 by Jason Harris
email : jharris@30doradus.org
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
#ifndef INFOBOX_H
#define INFOBOX_H
#include <tqobject.h>
#include <tqpoint.h>
#include <tqrect.h>
#include <tqsize.h>
#include <tqstring.h>
/**@class InfoBox
*InfoBoxencapsulates a lightweight floating "window" to be drawn directly
*on a pixmap. The window tqcontains three lines of text, and it can
*be "shaded" to show only the top line. The window resizes itself
*automatically to contain the text within it.
*@author Jason Harris
*@version 1.0
*/
class TQPainter;
class InfoBox : public TQObject {
Q_OBJECT
public:
/**default constructor. Creates an infobox with empty text string
*and default tqgeometry
*/
InfoBox();
/**General constructor. Specify The text string, x,y position and size.
*@param x the X-coordinate for the box
*@param y the Y-coordinate for the box
*@param shade if TRUE, apply text shading as well
*@param t1 The first line of text
*@param t2 The second line of text
*@param t3 The third line of text
*/
InfoBox( int x, int y, bool shade, TQString t1="", TQString t2="", TQString t3="" );
/**General constructor. Specify The text string, x,y position and size.
*This behaves just like the above function. It differs only in the data types
*of its arguments.
*@param p The (x,y) position of the box
*@param shade if TRUE, apply text shading as well
*@param t1 The first line of text
*@param t2 The second line of text
*@param t3 The third line of text
*/
InfoBox( TQPoint p, bool shade, TQString t1="", TQString t2="", TQString t3="" );
/**Destructor (empty)*/
~InfoBox();
/**Draw the InfoBox. First calls updateSize() and constrain() to make sure
*the box is onscreen and the correct size.
*@param p reference to the TQPainter on which to draw the box
*@param BGColor the background color to be used
*@param BGMode the background mode (0=none; 1=semi-transparent; 2=opaque)
*@see InfoBox::updateSize()
*@see InfoBox::constrain()
*/
void draw( TQPainter &p, TQColor BGColor, unsigned int BGMode );
/**Toggle the Shaded state of the box.
*/
bool toggleShade();
/**Reset the x,y position. Check the edge anchors.
*@param x the new X-position
*@param y the new Y-position
*/
void move( int x, int y );
/**Reset the x,y position. Check the edge anchors.
*This function behaves just like the above function. It differs
*only in the data type of its arguments.
*@param p the new (X,Y) position
*/
void move( TQPoint p );
/**Reset the width and height.
*@param w the new width
*@param h the new height
*/
void resize( int w, int h ) { Size.setWidth( w ); Size.setHeight( h ); }
/**Reset the width and height. This function behaves just like the above
*function. It differs only in the data type of its arguments.
*@param s the new size
*/
void resize( TQSize s ) { Size.setWidth( s.width() ); Size.setHeight( s.height() ); }
/**Set the size of the box to fit the current displayed text */
void updateSize();
/**Make sure the InfoBox is inside (or outside) the TQRect r.
*@return true if the function was able to obey the constraint.
*@param r the Rect which the box must lie completely inside/outside of.
*@param inside if TRUE (the default), the box must lie inside the rect r.
*Otherwise, the box must lie *outside* rect r.
*/
bool constrain( TQRect r, bool inside=true );
/**Reset the first text string
*@param newt the new text.
*/
void setText1( TQString newt ) { Text1 = newt; }
/**Reset the second text string
*@param newt the new text.
*/
void setText2( TQString newt ) { Text2 = newt; }
/**Reset the third text string
*@param newt the new text.
*/
void setText3( TQString newt ) { Text3 = newt; }
//temporarily, padx() and pady() simply return a constant
int padx() const { return 6; }
int pady() const { return 6; }
/**set the Visible flag according to the bool argument */
void setVisible( bool t ) { Visible = t; }
/**@return the X-position of the box*/
int x() const { return Pos.x(); }
/**@return the Y-position of the box*/
int y() const { return Pos.y(); }
/**@return the (X,Y) position of the box*/
TQPoint pos() const { return Pos; }
/**@return the width of the box*/
int width() const { return Size.width(); }
/**@return the height of the box*/
int height() const { return Size.height(); }
/**@return the size of the box*/
TQSize size() const { return Size; }
/**@return whether the box is visible */
bool isVisible() const { return Visible; }
/**@return the first line of text*/
TQString text1() const { return Text1; }
/**@return the second line of text*/
TQString text2() const { return Text2; }
/**@return the third line of text*/
TQString text3() const { return Text3; }
/**@return the tqgeometry of the box*/
TQRect rect() const;
/**@return TRUE if the box is anchored to the right window edge*/
bool anchorRight() const { return ( AnchorFlag & AnchorRight ); }
/**@return TRUE if the box is anchored to the bottom window edge*/
bool anchorBottom() const { return ( AnchorFlag & AnchorBottom ); }
/**Set the box to be anchored to the right window edge*/
void setAnchorRight( const bool ar );
/**Set the box to be anchored to the bottom window edge*/
void setAnchorBottom( const bool ab );
/**@return the box's anchor flag bitqmask.*/
int anchorFlag() const { return AnchorFlag; }
/**Set the box's anchor flag bitqmask*/
void setAnchorFlag( const int af ) { AnchorFlag = af; }
enum AnchorType {
AnchorNone = 0x0000,
AnchorRight = 0x0001,
AnchorBottom = 0x0002,
AnchorBoth = AnchorRight | AnchorBottom
};
signals:
/**Signal emitted when the box is moved
*@param p the new (X,Y) position
*@see InfoBox::move()
*/
void moved( TQPoint p );
/**Signal emitted when the box's shaded-state is toggled
*@param s the new shaded state
*@see InfoBox::toggleShade()
*/
void shaded( bool s );
private:
bool Shaded, Visible;
//TextWidth, TextHeight are the text dimensions when box is unshaded;
//TextWidth1, TextHeight1 are the text dimensions when the box is shaded.
int FullTextWidth, FullTextHeight;
int ShadedTextWidth, ShadedTextHeight;
int AnchorFlag;
TQPoint Pos;
TQSize Size;
TQString Text1, Text2, Text3;
};
#endif
|