00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "kdhorizontalline.h"
00042
00043 #include <tqstyle.h>
00044 #include <tqpainter.h>
00045 #ifdef TQT_ACCESSIBILITY_SUPPORT
00046 #include <tqaccessible.h>
00047 #endif
00048 #include <tqfontmetrics.h>
00049 #include <tqapplication.h>
00050
00051 KDHorizontalLine::KDHorizontalLine( TQWidget * parent, const char * name, WFlags f )
00052 : TQFrame( parent, name, f ),
00053 mAlign( TQt::AlignAuto ),
00054 mLenVisible( 0 )
00055 {
00056 TQFrame::setFrameStyle( HLine | Sunken );
00057 }
00058
00059 KDHorizontalLine::KDHorizontalLine( const TQString & title, TQWidget * parent, const char * name, WFlags f )
00060 : TQFrame( parent, name, f ),
00061 mAlign( TQt::AlignAuto ),
00062 mLenVisible( 0 )
00063 {
00064 TQFrame::setFrameStyle( HLine | Sunken );
00065 setTitle( title );
00066 }
00067
00068 KDHorizontalLine::~KDHorizontalLine() {}
00069
00070 void KDHorizontalLine::setFrameStyle( int style ) {
00071 TQFrame::setFrameStyle( ( style & ~MShape ) | HLine );
00072 }
00073
00074 void KDHorizontalLine::setTitle( const TQString & title ) {
00075 if ( mTitle == title )
00076 return;
00077 mTitle = title;
00078 calculateFrame();
00079 update();
00080 updateGeometry();
00081 #ifdef TQT_ACCESSIBILITY_SUPPORT
00082 TQAccessible::updateAccessibility( this, 0, TQAccessible::NameChanged );
00083 #endif
00084 }
00085
00086 void KDHorizontalLine::calculateFrame() {
00087 mLenVisible = mTitle.length();
00088 #if 0
00089 if ( mLenVisible ) {
00090 const TQFontMetrics fm = fontMetrics();
00091 while ( mLenVisible ) {
00092 const int tw = fm.width( mTitle, mLenVisible ) + 4*fm.width(TQChar(' '));
00093 if ( tw < width() )
00094 break;
00095 mLenVisible--;
00096 }
00097 qDebug( "mLenVisible = %d (of %d)", mLenVisible, mTitle.length() );
00098 if ( mLenVisible ) {
00099 TQRect r = rect();
00100 const int va = style().styleHint( TQStyle::SH_GroupBox_TextLabelVerticalAlignment, this );
00101 if( va & AlignVCenter )
00102 r.setTop( fm.height() / 2 );
00103 else if( va & AlignTop )
00104 r.setTop( fm.ascent() );
00105 setFrameRect( r );
00106 return;
00107 }
00108 }
00109
00110 setFrameRect( TQRect(0,0,0,0) );
00111 #endif
00112 }
00113
00114 TQSizePolicy KDHorizontalLine::sizePolicy() const {
00115 return TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed );
00116 }
00117
00118 TQSize KDHorizontalLine::sizeHint() const {
00119 return minimumSizeHint();
00120 }
00121
00122 TQSize KDHorizontalLine::minimumSizeHint() const {
00123 const int w = fontMetrics().width( mTitle, mLenVisible ) +
00124 fontMetrics().width( TQChar( ' ' ) );
00125 const int h = fontMetrics().height();
00126 return TQSize( TQMAX( w, indentHint() ), h ).expandedTo( tqApp->globalStrut() );
00127 }
00128
00129 void KDHorizontalLine::paintEvent( TQPaintEvent * e ) {
00130 TQPainter paint( this );
00131
00132 if ( mLenVisible ) {
00133 const TQFontMetrics & fm = paint.fontMetrics();
00134 const int h = fm.height();
00135 const int tw = fm.width( mTitle, mLenVisible ) + fm.width(TQChar(' '));
00136 int x;
00137 if ( mAlign & AlignHCenter )
00138 x = frameRect().width()/2 - tw/2;
00139 else if ( mAlign & AlignRight )
00140 x = frameRect().width() - tw;
00141 else if ( mAlign & AlignLeft )
00142 x = 0;
00143 else {
00144 if( TQApplication::reverseLayout() )
00145 x = frameRect().width() - tw;
00146 else
00147 x = 0;
00148 }
00149 TQRect r( x, 0, tw, h );
00150 int va = style().styleHint( TQStyle::SH_GroupBox_TextLabelVerticalAlignment, this );
00151 if ( va & AlignTop )
00152 r.moveBy( 0, fm.descent() );
00153 const TQColor pen( (TQRgb) style().styleHint( TQStyle::SH_GroupBox_TextLabelColor, this ) );
00154 if ( !style().styleHint( TQStyle::SH_UnderlineAccelerator, this ) )
00155 va |= NoAccel;
00156 style().drawItem( &paint, r, ShowPrefix | AlignHCenter | va, colorGroup(),
00157 isEnabled(), 0, mTitle, -1, ownPalette() ? 0 : &pen );
00158 paint.setClipRegion( e->region().subtract( r ) );
00159 }
00160 drawFrame( &paint );
00161 drawContents( &paint );
00162 }
00163
00164
00165 int KDHorizontalLine::indentHint() {
00166 return 30;
00167 }
00168
00169 #include "kdhorizontalline.moc"