1 /***************************************************************************
2 infobox.cpp - description
4 begin : Thu May 30 2002
5 copyright : (C) 2002 by Jason Harris
6 email : jharris@30doradus.org
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
28 //Initialize text dimension variables to 0
34 AnchorFlag
= AnchorNone
;
39 InfoBox::InfoBox( int x
, int y
, bool shade
, QString t1
, QString t2
, QString t3
) {
45 //Initialize text dimension variables to 0
51 AnchorFlag
= AnchorNone
;
55 InfoBox::InfoBox( QPoint pt
, bool shade
, QString t1
, QString t2
, QString t3
) {
61 //Initialize text dimension variables to 0
67 AnchorFlag
= AnchorNone
;
74 void InfoBox::setAnchorRight( const bool ar
) {
75 if ( ar
) setAnchorFlag( anchorFlag() | AnchorRight
);
76 else setAnchorFlag( anchorFlag() & ~AnchorRight
);
79 void InfoBox::setAnchorBottom( const bool ab
) {
80 if ( ab
) setAnchorFlag( anchorFlag() | AnchorBottom
);
81 else setAnchorFlag( anchorFlag() & ~AnchorBottom
);
84 bool InfoBox::toggleShade() {
88 emit
shaded( Shaded
);
92 void InfoBox::updateSize() {
93 int dh
= ShadedTextHeight
/2;
94 // kdDebug() << "Full=" << FullTextWidth + 2*padx() << "," << FullTextHeight - dh + 2*pady() << endl;
95 if ( Shaded
) resize( ShadedTextWidth
+ 2*padx(), ShadedTextHeight
- dh
+ 2*pady() );
96 else resize( FullTextWidth
+ 2*padx(), FullTextHeight
- dh
+ 2*pady() );
97 // kdDebug() << "Size=" << Size.width() << "," << Size.height() << endl;
100 bool InfoBox::constrain( QRect r
, bool inside
) {
102 //Place InfoBox within QRect r:
103 if ( x() < r
.x() ) move( r
.x(), y() );
104 if ( y() < r
.y() ) move( x(), r
.y() );
105 if ( x() + width() > r
.right() ) move( r
.right() - width(), y() );
106 if ( y() + height() > r
.bottom() ) move( x(), r
.bottom() - height() );
107 //The InfoBox is now within the bounds of QRect r, unless it is bigger than r.
108 //In that case, we cannot obey the constraint, but the current position is as
109 //close as we can get. Return false in this case.
110 if ( width() > r
.width() || height() > r
.height() ) return false;
114 //Place InfoBox outside QRect r. First, determine if InfoBox is within r:
115 // if ( rect().intersects( r ) ) {
116 //Move the InfoBox in all four directions until it no longer intersects r.
117 //Determine which displacement is shortest
123 void InfoBox::draw( QPainter
&p
, QColor BGColor
, unsigned int BGMode
) {
127 r
= p
.boundingRect( x(), y(), p
.window().width(), p
.window().height(), Qt::AlignCenter
, text1() );
128 ShadedTextWidth
= r
.width();
129 ShadedTextHeight
= r
.height();
132 h
= ShadedTextHeight
;
134 if ( !text2().isEmpty() ) {
135 r
= p
.boundingRect( x(), y(), p
.window().width(), p
.window().height(), Qt::AlignCenter
, text2() );
136 if ( r
.width() > w
) w
= r
.width();
140 if ( !text3().isEmpty() ) {
141 r
= p
.boundingRect( x(), y(), p
.window().width(), p
.window().height(), Qt::AlignCenter
, text3() );
142 if ( r
.width() > w
) w
= r
.width();
150 constrain( QRect( 0, 0, p
.window().width(), p
.window().height() ) );
152 //Draw the box boundary and the text
153 if ( BGMode
==1 ) p
.fillRect( x(), y(), width(), height(), QBrush( BGColor
, Dense4Pattern
) );
154 if ( BGMode
==2 ) p
.fillRect( x(), y(), width(), height(), QBrush( BGColor
) );
156 p
.drawText( x() + padx(), y() + ShadedTextHeight
/2 + pady(), text1() );
159 if ( !text2().isEmpty() ) p
.drawText( x() + padx(), y() + 3*ShadedTextHeight
/2 + pady(), text2() );
160 if ( !text3().isEmpty() ) p
.drawText( x() + padx(), y() + 5*ShadedTextHeight
/2 + pady(), text3() );
164 QRect
InfoBox::rect() const {
165 return QRect( pos(), size() );
168 void InfoBox::move( int x
, int y
) {
169 Pos
.setX( x
); Pos
.setY( y
); emit
moved( QPoint(x
,y
) );
172 void InfoBox::move( QPoint p
) {
173 move( p
.x(), p
.y() ); emit
moved( QPoint( p
.x(), p
.y() ) );
176 #include "infobox.moc"