1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
22 #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 QTextEdit( 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 QScrollBar *sb = _qt_text->verticalScrollBar();
75 sb->setValue( sb->maximum() );
80 YQLogView::setLabel( const string & label )
82 _caption->setText( label );
83 YLogView::setLabel( label );
89 YQLogView::setEnabled( bool enabled )
91 _caption->setEnabled( enabled );
92 _qt_text->setEnabled( enabled );
93 YWidget::setEnabled( enabled );
98 YQLogView::preferredWidth()
100 return max( 50, sizeHint().width() );
105 YQLogView::preferredHeight()
107 int hintHeight = visibleLines() * _qt_text->fontMetrics().lineSpacing();
108 hintHeight += _qt_text->style()->pixelMetric( QStyle::PM_ScrollBarExtent );
109 hintHeight += _qt_text->frameWidth() * 2;
111 if ( !_caption->isHidden() )
112 hintHeight += _caption->sizeHint().height();
114 return max( 80, hintHeight );
119 YQLogView::setSize( int newWidth, int newHeight )
121 resize( newWidth, newHeight );
126 YQLogView::setKeyboardFocus()
128 _qt_text->setFocus();
135 #include "YQLogView.moc"