41 #include "kdhorizontalline.h"
44 #include <tqpainter.h>
45 #ifdef TQT_ACCESSIBILITY_SUPPORT
46 #include <tqaccessible.h>
48 #include <tqfontmetrics.h>
49 #include <tqapplication.h>
51 KDHorizontalLine::KDHorizontalLine( TQWidget * parent,
const char * name, WFlags f )
52 : TQFrame( parent, name, f ),
53 mAlign( TQt::AlignAuto ),
56 TQFrame::setFrameStyle( HLine | Sunken );
59 KDHorizontalLine::KDHorizontalLine(
const TQString & title, TQWidget * parent,
const char * name, WFlags f )
60 : TQFrame( parent, name, f ),
61 mAlign( TQt::AlignAuto ),
64 TQFrame::setFrameStyle( HLine | Sunken );
68 KDHorizontalLine::~KDHorizontalLine() {}
70 void KDHorizontalLine::setFrameStyle(
int style ) {
71 TQFrame::setFrameStyle( ( style & ~MShape ) | HLine );
74 void KDHorizontalLine::setTitle(
const TQString & title ) {
75 if ( mTitle == title )
81 #ifdef TQT_ACCESSIBILITY_SUPPORT
82 TQAccessible::updateAccessibility(
this, 0, TQAccessible::NameChanged );
86 void KDHorizontalLine::calculateFrame() {
87 mLenVisible = mTitle.length();
90 const TQFontMetrics fm = fontMetrics();
91 while ( mLenVisible ) {
92 const int tw = fm.width( mTitle, mLenVisible ) + 4*fm.width(TQChar(
' '));
97 tqDebug(
"mLenVisible = %d (of %d)", mLenVisible, mTitle.length() );
100 const int va = style().styleHint( TQStyle::SH_GroupBox_TextLabelVerticalAlignment,
this );
101 if( va & AlignVCenter )
102 r.setTop( fm.height() / 2 );
103 else if( va & AlignTop )
104 r.setTop( fm.ascent() );
110 setFrameRect( TQRect(0,0,0,0) );
114 TQSizePolicy KDHorizontalLine::sizePolicy()
const {
115 return TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Fixed );
118 TQSize KDHorizontalLine::sizeHint()
const {
119 return minimumSizeHint();
122 TQSize KDHorizontalLine::minimumSizeHint()
const {
123 const int w = fontMetrics().width( mTitle, mLenVisible ) +
124 fontMetrics().width( TQChar(
' ' ) );
125 const int h = fontMetrics().height();
126 return TQSize( TQMAX( w, indentHint() ), h ).expandedTo( tqApp->globalStrut() );
129 void KDHorizontalLine::paintEvent( TQPaintEvent * e ) {
130 TQPainter paint(
this );
133 const TQFontMetrics & fm = paint.fontMetrics();
134 const int h = fm.height();
135 const int tw = fm.width( mTitle, mLenVisible ) + fm.width(TQChar(
' '));
137 if ( mAlign & AlignHCenter )
138 x = frameRect().width()/2 - tw/2;
139 else if ( mAlign & AlignRight )
140 x = frameRect().width() - tw;
141 else if ( mAlign & AlignLeft )
144 if( TQApplication::reverseLayout() )
145 x = frameRect().width() - tw;
149 TQRect r( x, 0, tw, h );
150 int va = style().styleHint( TQStyle::SH_GroupBox_TextLabelVerticalAlignment,
this );
152 r.moveBy( 0, fm.descent() );
153 const TQColor pen( (TQRgb) style().styleHint( TQStyle::SH_GroupBox_TextLabelColor,
this ) );
154 if ( !style().styleHint( TQStyle::SH_UnderlineAccelerator,
this ) )
156 style().drawItem( &paint, r, ShowPrefix | AlignHCenter | va, colorGroup(),
157 isEnabled(), 0, mTitle, -1, ownPalette() ? 0 : &pen );
158 paint.setClipRegion( e->region().subtract( r ) );
161 drawContents( &paint );
165 int KDHorizontalLine::indentHint() {
169 #include "kdhorizontalline.moc"