1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
22 #include <QVBoxLayout>
23 #define y2log_component "qt-ui"
24 #include <ycp/y2log.h>
30 #include "YQLogView.h"
31 #include "YQWidgetCaption.h"
34 YQLogView::YQLogView( YWidget * parent,
38 : QFrame( (QWidget *) parent->widgetRep() )
39 , YLogView( parent, label, visibleLines, maxLines )
42 QVBoxLayout* layout = new QVBoxLayout( this );
45 layout->setSpacing( YQWidgetSpacing );
46 layout->setMargin( YQWidgetMargin );
48 _caption = new YQWidgetCaption( this, label );
49 YUI_CHECK_NEW( _caption );
50 layout->addWidget( _caption );
52 _qt_text = new Q3MultiLineEdit( this );
53 YUI_CHECK_NEW( _qt_text );
54 layout->addWidget( _qt_text );
56 _qt_text->setReadOnly( true );
57 _qt_text->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
59 _caption->setBuddy( _qt_text );
63 YQLogView::~YQLogView()
70 YQLogView::displayLogText( const string & text )
72 _qt_text->setText( fromUTF8( text ) );
73 _qt_text->scrollToBottom();
78 YQLogView::setLabel( const string & label )
80 _caption->setText( label );
81 YLogView::setLabel( label );
87 YQLogView::setEnabled( bool enabled )
89 _caption->setEnabled( enabled );
90 _qt_text->setEnabled( enabled );
91 YWidget::setEnabled( enabled );
96 YQLogView::preferredWidth()
98 return max( 50, sizeHint().width() );
103 YQLogView::preferredHeight()
105 int hintHeight = visibleLines() * _qt_text->fontMetrics().lineSpacing();
106 hintHeight += _qt_text->style()->pixelMetric( QStyle::PM_ScrollBarExtent );
107 hintHeight += _qt_text->frameWidth() * 2;
109 if ( !_caption->isHidden() )
110 hintHeight += _caption->sizeHint().height();
112 return max( 80, hintHeight );
117 YQLogView::setSize( int newWidth, int newHeight )
119 resize( newWidth, newHeight );
124 YQLogView::setKeyboardFocus()
126 _qt_text->setFocus();
133 #include "YQLogView.moc"