1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
22 #include <q3multilineedit.h>
23 #include <QVBoxLayout>
24 #define y2log_component "qt-ui"
25 #include <ycp/y2log.h>
31 #include "YQLogView.h"
32 #include "YQWidgetCaption.h"
35 YQLogView::YQLogView( YWidget * parent,
39 : QFrame( (QWidget *) parent->widgetRep() )
40 , YLogView( parent, label, visibleLines, maxLines )
43 QVBoxLayout* layout = new QVBoxLayout( this );
46 layout->setSpacing( YQWidgetSpacing );
47 layout->setMargin( YQWidgetMargin );
49 _caption = new YQWidgetCaption( this, label );
50 YUI_CHECK_NEW( _caption );
51 layout->addWidget( _caption );
53 _qt_text = new Q3MultiLineEdit( this );
54 YUI_CHECK_NEW( _qt_text );
55 layout->addWidget( _qt_text );
57 _qt_text->setReadOnly( true );
58 _qt_text->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
60 _caption->setBuddy( _qt_text );
64 YQLogView::~YQLogView()
71 YQLogView::displayLogText( const string & text )
73 _qt_text->setText( fromUTF8( text ) );
74 _qt_text->scrollToBottom();
79 YQLogView::setLabel( const string & label )
81 _caption->setText( label );
82 YLogView::setLabel( label );
88 YQLogView::setEnabled( bool enabled )
90 _caption->setEnabled( enabled );
91 _qt_text->setEnabled( enabled );
92 YWidget::setEnabled( enabled );
97 YQLogView::preferredWidth()
99 return max( 50, sizeHint().width() );
104 YQLogView::preferredHeight()
106 int hintHeight = visibleLines() * _qt_text->fontMetrics().lineSpacing();
107 hintHeight += _qt_text->style()->pixelMetric( QStyle::PM_ScrollBarExtent );
108 hintHeight += _qt_text->frameWidth() * 2;
110 if ( !_caption->isHidden() )
111 hintHeight += _caption->sizeHint().height();
113 return max( 80, hintHeight );
118 YQLogView::setSize( int newWidth, int newHeight )
120 resize( newWidth, newHeight );
125 YQLogView::setKeyboardFocus()
127 _qt_text->setFocus();
134 #include "YQLogView.moc"