• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kstars

infobox.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           infobox.cpp  -  description
00003                              -------------------
00004     begin                : Thu May 30 2002
00005     copyright            : (C) 2002 by Jason Harris
00006     email                : jharris@30doradus.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include <kdebug.h>
00019 #include <qpainter.h>
00020 
00021 #include "infobox.h"
00022 
00023 InfoBox::InfoBox(){
00024     setText1( "" );
00025     setText2( "" );
00026     setText3( "" );
00027     move( 0, 0 );
00028 //Initialize text dimension variables to 0
00029     FullTextWidth  = 0;
00030     FullTextHeight = 0;
00031     ShadedTextWidth  = 0;
00032     ShadedTextHeight = 0;
00033 
00034     AnchorFlag = AnchorNone;
00035     Visible = true;
00036     Shaded = false;
00037 }
00038 
00039 InfoBox::InfoBox( int x, int y, bool shade, QString t1, QString t2, QString t3 ) {
00040     setText1( t1 );
00041     setText2( t2 );
00042     setText3( t3 );
00043     move( x, y );
00044     Shaded = shade;
00045 //Initialize text dimension variables to 0
00046     FullTextWidth  = 0;
00047     FullTextHeight = 0;
00048     ShadedTextWidth  = 0;
00049     ShadedTextHeight = 0;
00050 
00051     AnchorFlag = AnchorNone;
00052     Visible = true;
00053 }
00054 
00055 InfoBox::InfoBox( QPoint pt, bool shade, QString t1, QString t2, QString t3 ) {
00056     setText1( t1 );
00057     setText2( t2 );
00058     setText3( t3 );
00059     move( pt );
00060     Shaded = shade;
00061 //Initialize text dimension variables to 0
00062     FullTextWidth  = 0;
00063     FullTextHeight = 0;
00064     ShadedTextWidth  = 0;
00065     ShadedTextHeight = 0;
00066 
00067     AnchorFlag = AnchorNone;
00068     Visible = true;
00069 }
00070 
00071 InfoBox::~InfoBox(){
00072 }
00073 
00074 void InfoBox::setAnchorRight( const bool ar ) {
00075     if ( ar ) setAnchorFlag( anchorFlag() | AnchorRight  );
00076     else      setAnchorFlag( anchorFlag() & ~AnchorRight );
00077 }
00078 
00079 void InfoBox::setAnchorBottom( const bool ab ) {
00080     if ( ab ) setAnchorFlag( anchorFlag() | AnchorBottom  );
00081     else      setAnchorFlag( anchorFlag() & ~AnchorBottom );
00082 }
00083 
00084 bool InfoBox::toggleShade() {
00085     Shaded = !Shaded;
00086     updateSize();
00087 
00088     emit shaded( Shaded );
00089     return Shaded;
00090 }
00091 
00092 void InfoBox::updateSize() {
00093     int dh = ShadedTextHeight/2;
00094 //  kdDebug() << "Full=" << FullTextWidth + 2*padx() << "," << FullTextHeight - dh + 2*pady() << endl;
00095     if ( Shaded ) resize( ShadedTextWidth + 2*padx(), ShadedTextHeight - dh + 2*pady() );
00096     else resize( FullTextWidth + 2*padx(), FullTextHeight - dh + 2*pady() );
00097 //  kdDebug() << "Size=" << Size.width() << "," << Size.height() << endl;
00098 }
00099 
00100 bool InfoBox::constrain( QRect r, bool inside ) {
00101     if ( inside ) {
00102         //Place InfoBox within QRect r:
00103         if ( x() < r.x() ) move( r.x(), y() );
00104         if ( y() < r.y() ) move( x(), r.y() );
00105         if ( x() + width() > r.right() ) move( r.right() - width(), y() );
00106         if ( y() + height() > r.bottom() ) move( x(), r.bottom() - height() );
00107         //The InfoBox is now within the bounds of QRect r, unless it is bigger than r.
00108         //In that case, we cannot obey the constraint, but the current position is as
00109         //close as we can get.  Return false in this case.
00110         if ( width() > r.width() || height() > r.height() ) return false;
00111         else return true;
00112     } else {
00113 //FIXME...
00114         //Place InfoBox outside QRect r.  First, determine if InfoBox is within r:
00115 //      if ( rect().intersects( r ) ) {
00116             //Move the InfoBox in all four directions until it no longer intersects r.
00117             //Determine which displacement is shortest
00118             //
00119         return false;
00120     }
00121 }
00122 
00123 void InfoBox::draw( QPainter &p, QColor BGColor, unsigned int BGMode ) {
00124     QRect r;
00125     int w,h;
00126 
00127     r = p.boundingRect( x(), y(), p.window().width(), p.window().height(), Qt::AlignCenter, text1() );
00128     ShadedTextWidth  = r.width();
00129     ShadedTextHeight = r.height();
00130 
00131     w = ShadedTextWidth;
00132     h = ShadedTextHeight;
00133 
00134     if ( !text2().isEmpty() ) {
00135         r = p.boundingRect( x(), y(), p.window().width(), p.window().height(), Qt::AlignCenter, text2() );
00136         if ( r.width() > w ) w = r.width();
00137         h += r.height();
00138     }
00139 
00140     if ( !text3().isEmpty() ) {
00141         r = p.boundingRect( x(), y(), p.window().width(), p.window().height(), Qt::AlignCenter, text3() );
00142         if ( r.width() > w ) w = r.width();
00143         h += r.height();
00144     }
00145 
00146     FullTextWidth = w;
00147     FullTextHeight = h;
00148 
00149     updateSize();
00150     constrain( QRect( 0, 0, p.window().width(), p.window().height() ) );
00151 
00152 //Draw the box boundary and the text
00153     if ( BGMode==1 ) p.fillRect( x(), y(), width(), height(), QBrush( BGColor, Dense4Pattern ) );
00154     if ( BGMode==2 ) p.fillRect( x(), y(), width(), height(), QBrush( BGColor ) );
00155 
00156     p.drawText( x() + padx(), y() + ShadedTextHeight/2 + pady(), text1() );
00157 
00158     if ( !Shaded ) {
00159         if ( !text2().isEmpty() ) p.drawText( x() + padx(), y() + 3*ShadedTextHeight/2 + pady(), text2() );
00160         if ( !text3().isEmpty() ) p.drawText( x() + padx(), y() + 5*ShadedTextHeight/2 + pady(), text3() );
00161     }
00162 }
00163 
00164 QRect InfoBox::rect() const {
00165     return QRect( pos(), size() );
00166 }
00167 
00168 void InfoBox::move( int x, int y ) {
00169     Pos.setX( x ); Pos.setY( y ); emit moved( QPoint(x,y) );
00170 }
00171 
00172 void InfoBox::move( QPoint p ) {
00173     move( p.x(), p.y() ); emit moved( QPoint( p.x(), p.y() ) );
00174 }
00175 
00176 #include "infobox.moc"

kstars

Skip menu "kstars"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • keduca
  • kstars
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal