00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
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
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
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
00095 if ( Shaded ) resize( ShadedTextWidth + 2*padx(), ShadedTextHeight - dh + 2*pady() );
00096 else resize( FullTextWidth + 2*padx(), FullTextHeight - dh + 2*pady() );
00097
00098 }
00099
00100 bool InfoBox::constrain( QRect r, bool inside ) {
00101 if ( inside ) {
00102
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
00108
00109
00110 if ( width() > r.width() || height() > r.height() ) return false;
00111 else return true;
00112 } else {
00113
00114
00115
00116
00117
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
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"