moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kstars / kstars / infoboxes.h
blob15010683d487f801f46634bfb4706406dfcaf341
1 /***************************************************************************
2 infoboxes.h - description
3 -------------------
4 begin : Wed Jun 5 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 INFOBOXES_H
19 #define INFOBOXES_H
21 #include <qobject.h>
22 #include <qcolor.h>
23 #include <qevent.h>
24 #include <qpoint.h>
25 #include <kdebug.h>
27 #include "infobox.h"
29 /**@class InfoBoxes
30 *Infoboxes manages the three infobox objects which are drawn on the Skymap.
31 *Each Infobox is a member variable in Infoboxes. Infoboxes handles user
32 *interactions with the boxes, and makes sure they do not overlap each other or
33 *move outside the bounds of the SkyMap.
34 *@short Infoboxes encapsulates and manages the three Infobox objects
35 *@author Jason Harris
36 *@version 1.0
39 class QPainter;
40 class GeoLocation;
41 class SkyPoint;
42 class dms;
43 class InfoBox;
44 class KStarsDateTime;
46 class InfoBoxes : public QObject {
47 Q_OBJECT
48 public:
49 /**Constructor. Create three infoboxes and place them in the skymap.
50 *@param w The width of the region in which the boxes can be drawn
51 *(typically the width of the SkyMap)
52 *@param h The height of the region in which the boxes can be drawn
53 *(typically the height of the SkyMap)
54 *@param tx the x-position of the Time infobox
55 *@param ty the y-position of the Time infobox
56 *@param gx the x-position of the Geographic infobox
57 *@param gy the y-position of the Geographic infobox
58 *@param fx the x-position of the Focus-object infobox
59 *@param fy the y-position of the Focus-object infobox
60 *@param colorText The foreground color for infoboxes
61 *@param colorGrab The foreground color for infoboxes, while they are
62 *"grabbed" by the user
63 *@param colorText The background color for infoboxes
65 InfoBoxes( int w, int h,
66 int tx=0, int ty=0, bool tshade=false,
67 int gx=0, int gy=600, bool gshade=false,
68 int fx=600, int fy=0, bool fshade=false,
69 QColor colorText=QColor("white"),
70 QColor colorGrab=QColor("red"),
71 QColor colorBG=QColor("black") );
73 /**Constructor. Create three infoboxes and place them in the skymap.
74 *Differs from the above function only in the types of its arguments.
75 *@param w The width of the region in which the boxes can be drawn
76 *(typically the width of the SkyMap)
77 *@param h The height of the region in which the boxes can be drawn
78 *(typically the height of the SkyMap)
79 *@param tp the position of the Time infobox
80 *@param gp the position of the Geographic infobox
81 *@param fp the position of the Focus-object infobox
82 *@param colorText The foreground color for infoboxes
83 *@param colorGrab The foreground color for infoboxes, while they are
84 *"grabbed" by the user
85 *@param colorText The background color for infoboxes
87 InfoBoxes( int w, int h,
88 QPoint tp, bool tshade,
89 QPoint gp, bool gshade,
90 QPoint fp, bool fshade,
91 QColor colorText=QColor("white"),
92 QColor colorGrab=QColor("red"),
93 QColor colorBG=QColor("black") );
95 /**Destructor (empty)*/
96 ~InfoBoxes();
98 /**@return pointer to the Time infobox*/
99 InfoBox *timeBox() { return TimeBox; }
100 /**@return pointer to the Geographic infobox*/
101 InfoBox *geoBox() { return GeoBox; }
102 /**@return pointer to the Focus-object infobox*/
103 InfoBox *focusBox() { return FocusBox; }
105 /**Resets the width and height parameters. These usually reflect the size
106 *of the Skymap widget (Skymap::resizeEvent() calls this function).
107 *Will also reposition the infoboxes to fit the new size. Infoboxes
108 *that were along an edge will remain along the edge.
109 *@param w The new width
110 *@param h The new height
112 void resize( int w, int h );
114 /**@return the width of the region containing the infoboxes (usually the
115 *width of the Skymap)
117 int width() const { return Width; }
119 /**@return the height of the region containing the infoboxes (usually the
120 *height of the Skymap)
122 int height() const { return Height; }
124 /**Draw the boxes on a Qpainter object (representing the SkyMap).
125 *@param p The QPainter on which to draw the boxes.
126 *@param FGColor The foreground color (Pen color) to use when drawing boxes.
127 *@param grabColor The foreground color to use if the box is "grabbed" by the user.
128 *@param BGColor The background color (brush color) to use
129 *@param BGMode: 0=no BG fill; 1=transparent BG fill; 2=Opaque BG fill.
131 void drawBoxes( QPainter &p, QColor FGColor=QColor("white"),
132 QColor grabColor=QColor("red"), QColor BGColor=QColor("black"),
133 unsigned int BGMode=0 );
135 /**Determine whether a mouse click occurred inside one of the infoboxes.
136 *Also, set the internal variable GrabBox to indicate which box was grabbed.
137 *Finally, set the internal variable GrabPos to record the relative position of the
138 *mouse cursor inside the box (we hold this position constant while dragging).
139 *@param e The mouse event to check (it's a mousePressEvent)
140 *@return true if the mouse press occurred inside one of the infoboxes.
142 bool grabBox( QMouseEvent *e );
144 /**Set the internal variable GrabBox to 0, indicating that no box is currently
145 *grabbed. Also determine if any box should be anchored to an edge. (This
146 *is called by SkyMap::mouseReleaseEvent() )
147 *@return true if a box was grabbed in the first place; otherwise, return false.
149 bool unGrabBox();
151 /**Move the Grabbed box around by keeping the relative position of the mouse cursor
152 *to the box position equal to GrabPos. (this is called by SkyMap::mouseMoveEvent() ).
153 *Once the box has been moved, we call fixCollisions() to make sure the boxes don't
154 *overlap or exceed the SkyMap boundaries.
155 *@param e The mouse event which contains the new mouse cursor position
156 *@return false if no box is grabbed; otherwise, moves the grabbed box and returns true.
158 bool dragBox( QMouseEvent *e );
160 /**Toggle the shade-state of the infobox in which the user double-clicked.
161 *After shading the box, call fixCollisions() on the other two boxes.
162 *(This is called by SkyMap::mouseDoubleClickEvent() )
163 *@param e the mouse event containing the position of the double-click.
164 *@return false if the double-click was not inside any box; otherwise shade the
165 *target box and return true.
167 bool shadeBox( QMouseEvent *e );
169 /**Make sure the target Infobox lies within the SkyMap boundaries, and that it does
170 *not overlap with the other two Infoboxes. If an overlap is detected, the target
171 *box does a test-displacement each direction until there is no overlap (or the
172 *SkyMap boundary is reached). The target box is then moved in the direction that
173 *required the smallest displacement to remove the overlap.
174 *@param target the infobox which should be tested for collisions.
175 *@return false if the box collisions could not be resolved; otherwise, returns true.
177 bool fixCollisions( InfoBox *target );
179 /**@return true if the collection of infoboxes is visible (i.e., not hidden).
181 bool isVisible() { return Visible; }
183 public slots:
184 /**Set whether the Infoboxes should be drawn, according to the bool argument.
185 *This is the visibility setting for all three boxes. Each individual box
186 *also has its own Visible parameter. A box is only drawn if both
187 *Infoboxes::Visible /and/ Infobox::Visible are true.
188 *@param t If true, the Infoboxes will be drawn.
190 void setVisible( bool t ) { Visible = t; }
192 /**Call the TimeBox's setVisible() function.
193 *@param t The bool parameter to send
195 void showTimeBox( bool t ) { TimeBox->setVisible( t ); }
197 /**Call the GeoBox's setVisible() function.
198 *@param t The bool parameter to send
200 void showGeoBox( bool t ) { GeoBox->setVisible( t ); }
202 /**Call the FocusBox's setVisible() function.
203 *@param t The bool parameter to send
205 void showFocusBox( bool t ) { FocusBox->setVisible( t ); }
207 /**Update the TimeBox strings according to the arguments.
208 *The arguments are date/time objects; this function converts them to
209 *strings and displays them in the TimeBox.
210 *@param ut The Universal Time date/time object
211 *@param lt The Local Time date/time object
212 *@param lst The Sidereal Time object
213 *@return true if values have changed
215 bool timeChanged( const KStarsDateTime &ut, const KStarsDateTime &lt, dms *lst );
217 /**Update the GeoBox strings according to the argument.
218 *@param geo The Geographic Location (we get the name, longitude and latitude from this)
219 *@return true if values have changed
221 bool geoChanged(const GeoLocation *geo);
223 /**Update the FocusBox coordinates strings according to the argument.
224 *@param p the SkyPoint object from which we get the coordinates.
225 *@return true if values have changed
227 bool focusCoordChanged(const SkyPoint *p);
229 /**Update the FocusBox name string according to the argument.
230 *@param n The object name
231 *@return true if values have changed
233 bool focusObjChanged(const QString &n);
235 /**Check if boxes are anchored with bottom or right border.
236 @param resetToDefault reset all borders of boxes to false before checking borders.
238 void checkBorders(bool resetToDefault=true);
240 private:
241 int Width, Height;
242 int GrabbedBox;
243 bool Visible;
244 const QColor boxColor, grabColor, bgColor;
245 QPoint GrabPos;
246 InfoBox *GeoBox, *FocusBox, *TimeBox;
249 #endif