45 #ifdef QT_ACCESSIBILITY_SUPPORT
46 #include <QAccessible>
48 #include <QFontMetrics>
49 #include <QApplication>
50 #include <QPaintEvent>
54 mAlign( Qt::AlignLeft ),
57 setObjectName( QLatin1String(name) );
58 QFrame::setFrameStyle( HLine | Sunken );
63 mAlign( Qt::AlignLeft ),
66 setObjectName( QLatin1String(name) );
67 QFrame::setFrameStyle( HLine | Sunken );
74 QFrame::setFrameStyle( ( style & ~Shape_Mask ) | HLine );
78 if ( mTitle == title )
84 #ifdef QT_ACCESSIBILITY_SUPPORT
85 QAccessible::updateAccessibility(
this, 0, QAccessible::NameChanged );
89 void KDHorizontalLine::calculateFrame() {
90 mLenVisible = mTitle.length();
93 const QFontMetrics fm = fontMetrics();
94 while ( mLenVisible ) {
95 const int tw = fm.width( mTitle, mLenVisible ) + 4*fm.width(QChar(
' '));
100 qDebug(
"mLenVisible = %d (of %d)", mLenVisible, mTitle.length() );
103 const int va = style().styleHint( QStyle::SH_GroupBox_TextLabelVerticalAlignment,
this );
104 if( va & Qt::AlignVCenter )
105 r.setTop( fm.height() / 2 );
106 else if( va & Qt::AlignTop )
107 r.setTop( fm.ascent() );
113 setFrameRect( QRect(0,0,0,0) );
118 return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed );
126 const int w = fontMetrics().width( mTitle, mLenVisible ) +
127 fontMetrics().width( QLatin1Char(
' ' ) );
128 const int h = fontMetrics().height();
129 return QSize( qMax( w,
indentHint() ), h ).expandedTo( qApp->globalStrut() );
133 QPainter paint(
this );
136 const QFontMetrics & fm = paint.fontMetrics();
137 const int h = fm.height();
138 const int tw = fm.width( mTitle, mLenVisible ) + fm.width(QLatin1Char(
' '));
140 if ( mAlign & Qt::AlignHCenter )
141 x = frameRect().width()/2 - tw/2;
142 else if ( mAlign & Qt::AlignRight )
143 x = frameRect().width() - tw;
144 else if ( mAlign & Qt::AlignLeft )
147 if( QApplication::isRightToLeft() )
148 x = frameRect().width() - tw;
152 QRect r( x, 0, tw, h );
153 int va = style()->styleHint( QStyle::SH_GroupBox_TextLabelVerticalAlignment, 0,
this );
154 if ( va & Qt::AlignTop )
155 r.translate( 0, fm.descent() );
156 const QColor pen( (QRgb) style()->styleHint( QStyle::SH_GroupBox_TextLabelColor, 0,
this ) );
157 if ( !style()->styleHint( QStyle::SH_UnderlineShortcut, 0,
this ) )
158 va |= Qt::TextHideMnemonic;
159 style()->drawItemText( &paint, r, Qt::TextShowMnemonic | Qt::AlignHCenter | va, palette(),
160 isEnabled(), mTitle );
161 paint.setClipRegion( e->region().subtract( r ) );
171 #include "kdhorizontalline.moc"
QSize minimumSizeHint() const
KDHorizontalLine(QWidget *parent=0, const char *name=0, Qt::WindowFlags f=0)
virtual void setTitle(const QString &title)
void paintEvent(QPaintEvent *)
void setFrameStyle(int style)
QSizePolicy sizePolicy() const