moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / infobox.h
blobffc4ddc9ca7e0227a6acc601a03e08bb00337300
1 /***************************************************************************
2 infobox.h - description
3 -------------------
4 begin : Thu May 30 2002
5 copyright : (C) 2002 by Jason Harris
6 email : jharris@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef INFOBOX_H
19 #define INFOBOX_H
21 #include <qobject.h>
22 #include <qpoint.h>
23 #include <qrect.h>
24 #include <qsize.h>
25 #include <qstring.h>
27 /**@class InfoBox
28 *InfoBoxencapsulates a lightweight floating "window" to be drawn directly
29 *on a pixmap. The window contains three lines of text, and it can
30 *be "shaded" to show only the top line. The window resizes itself
31 *automatically to contain the text within it.
32 *@author Jason Harris
33 *@version 1.0
36 class QPainter;
38 class InfoBox : public QObject {
39 Q_OBJECT
40 public:
41 /**default constructor. Creates an infobox with empty text string
42 *and default geometry
44 InfoBox();
46 /**General constructor. Specify The text string, x,y position and size.
47 *@param x the X-coordinate for the box
48 *@param y the Y-coordinate for the box
49 *@param t1 The first line of text
50 *@param t2 The second line of text
51 *@param t3 The third line of text
53 InfoBox( int x, int y, bool shade, QString t1="", QString t2="", QString t3="" );
55 /**General constructor. Specify The text string, x,y position and size.
56 *This behaves just like the above function. It differs only in the data types
57 *of its arguments.
58 *@param p The (x,y) position of the box
59 *@param t1 The first line of text
60 *@param t2 The second line of text
61 *@param t3 The third line of text
63 InfoBox( QPoint p, bool shade, QString t1="", QString t2="", QString t3="" );
65 /**Destructor (empty)*/
66 ~InfoBox();
68 /**Draw the InfoBox. First calls updateSize() and constrain() to make sure
69 *the box is onscreen and the correct size.
70 *@param p reference to the QPainter on which to draw the box
71 *@param BGColor the background color to be used
72 *@param BGMode the background mode (0=none; 1=semi-transparent; 2=opaque)
73 *@see InfoBox::updateSize()
74 *@see InfoBox::constrain()
76 void draw( QPainter &p, QColor BGColor, unsigned int BGMode );
78 /**Toggle the Shaded state of the box.
80 bool toggleShade();
82 /**Reset the x,y position. Check the edge anchors.
83 *@param x the new X-position
84 *@param y the new Y-position
86 void move( int x, int y );
88 /**Reset the x,y position. Check the edge anchors.
89 *This function behaves just like the above function. It differs
90 *only in the data type of its arguments.
91 *@param p the new (X,Y) position
93 void move( QPoint p );
95 /**Reset the width and height.
96 *@param w the new width
97 *@param h the new height
99 void resize( int w, int h ) { Size.setWidth( w ); Size.setHeight( h ); }
101 /**Reset the width and height. This function behaves just like the above
102 *function. It differs only in the data type of its arguments.
103 *@param s the new size
105 void resize( QSize s ) { Size.setWidth( s.width() ); Size.setHeight( s.height() ); }
107 /**Set the size of the box to fit the current displayed text */
108 void updateSize();
110 /**Make sure the InfoBox is inside (or outside) the QRect r.
111 *@return true if the function was able to obey the constraint.
112 *@param r the Rect which the box must lie completely inside/outside of.
113 *@param inside if TRUE (the default), the box must lie inside the rect r.
114 *Otherwise, the box must lie *outside* rect r.
116 bool constrain( QRect r, bool inside=true );
118 /**Reset the first text string
119 *@param newt the new text.
121 void setText1( QString newt ) { Text1 = newt; }
123 /**Reset the second text string
124 *@param newt the new text.
126 void setText2( QString newt ) { Text2 = newt; }
128 /**Reset the third text string
129 *@param newt the new text.
131 void setText3( QString newt ) { Text3 = newt; }
133 //temporarily, padx() and pady() simply return a constant
134 int padx() const { return 6; }
135 int pady() const { return 6; }
137 /**set the Visible flag according to the bool argument */
138 void setVisible( bool t ) { Visible = t; }
140 /**@return the X-position of the box*/
141 int x() const { return Pos.x(); }
143 /**@return the Y-position of the box*/
144 int y() const { return Pos.y(); }
146 /**@return the (X,Y) position of the box*/
147 QPoint pos() const { return Pos; }
149 /**@return the width of the box*/
150 int width() const { return Size.width(); }
152 /**@return the height of the box*/
153 int height() const { return Size.height(); }
155 /**@return the size of the box*/
156 QSize size() const { return Size; }
158 /**@return whether the box is visible */
159 bool isVisible() const { return Visible; }
161 /**@return the first line of text*/
162 QString text1() const { return Text1; }
164 /**@return the second line of text*/
165 QString text2() const { return Text2; }
167 /**@return the third line of text*/
168 QString text3() const { return Text3; }
170 /**@return the geometry of the box*/
171 QRect rect() const;
173 /**@return TRUE if the box is anchored to the right window edge*/
174 bool anchorRight() const { return ( AnchorFlag & AnchorRight ); }
176 /**@return TRUE if the box is anchored to the bottom window edge*/
177 bool anchorBottom() const { return ( AnchorFlag & AnchorBottom ); }
179 /**Set the box to be anchored to the right window edge*/
180 void setAnchorRight( const bool ar );
182 /**Set the box to be anchored to the bottom window edge*/
183 void setAnchorBottom( const bool ab );
185 /**@return the box's anchor flag bitmask.*/
186 int anchorFlag() const { return AnchorFlag; }
188 /**Set the box's anchor flag bitmask*/
189 void setAnchorFlag( const int af ) { AnchorFlag = af; }
191 enum AnchorType {
192 AnchorNone = 0x0000,
193 AnchorRight = 0x0001,
194 AnchorBottom = 0x0002,
195 AnchorBoth = AnchorRight | AnchorBottom
198 signals:
199 /**Signal emitted when the box is moved
200 *@param p the new (X,Y) position
201 *@see InfoBox::move()
203 void moved( QPoint p );
205 /**Signal emitted when the box's shaded-state is toggled
206 *@param s the new shaded state
207 *@see InfoBox::toggleShade()
209 void shaded( bool s );
211 private:
212 bool Shaded, Visible;
213 //TextWidth, TextHeight are the text dimensions when box is unshaded;
214 //TextWidth1, TextHeight1 are the text dimensions when the box is shaded.
215 int FullTextWidth, FullTextHeight;
216 int ShadedTextWidth, ShadedTextHeight;
217 int AnchorFlag;
218 QPoint Pos;
219 QSize Size;
220 QString Text1, Text2, Text3;
223 #endif