]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQLogView.cc
27680f78f0a336febce916b1988fc76773ce1b6b
[duncan/yast2-qt4.git] / src / YQLogView.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQLogView.cc
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #include <qlabel.h>
21 #include <qstyle.h>
22 #include <qmultilineedit.h>
23 #define y2log_component "qt-ui"
24 #include <ycp/y2log.h>
25
26 using std::max;
27
28 #include "utf8.h"
29 #include "YQUI.h"
30 #include "YQLogView.h"
31 #include "YQWidgetCaption.h"
32
33
34 YQLogView::YQLogView( YWidget *         parent,
35                       const string &    label,
36                       int               visibleLines,
37                       int               maxLines )
38     : QVBox( (QWidget *) parent->widgetRep() )
39     , YLogView( parent, label, visibleLines, maxLines )
40 {
41     setWidgetRep( this );
42
43     setSpacing( YQWidgetSpacing );
44     setMargin( YQWidgetMargin );
45
46     _caption = new YQWidgetCaption( this, label );
47     YUI_CHECK_NEW( _caption );
48
49     _qt_text = new QMultiLineEdit( this );
50     YUI_CHECK_NEW( _qt_text );
51
52     _qt_text->setReadOnly( true );
53     _qt_text->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
54
55     _caption->setBuddy( _qt_text );
56 }
57
58
59 YQLogView::~YQLogView()
60 {
61     // NOP
62 }
63
64
65 void
66 YQLogView::displayLogText( const string & text )
67 {
68     _qt_text->setText( fromUTF8( text ) );
69     _qt_text->scrollToBottom();
70 }
71
72
73 void
74 YQLogView::setLabel( const string & label )
75 {
76     _caption->setText( label );
77     YLogView::setLabel( label );
78 }
79
80
81
82 void
83 YQLogView::setEnabled( bool enabled )
84 {
85     _caption->setEnabled( enabled );
86     _qt_text->setEnabled( enabled );
87     YWidget::setEnabled( enabled );
88 }
89
90
91 int
92 YQLogView::preferredWidth()
93 {
94     return max( 50, sizeHint().width() );
95 }
96
97
98 int
99 YQLogView::preferredHeight()
100 {
101     int hintHeight       = visibleLines() * _qt_text->fontMetrics().lineSpacing();
102     hintHeight          += _qt_text->style().scrollBarExtent().height();
103     hintHeight          += _qt_text->frameWidth() * 2;
104
105     if ( _caption->isShown() )
106         hintHeight      +=  _caption->sizeHint().height();
107
108     return max( 80, hintHeight );
109 }
110
111
112 void
113 YQLogView::setSize( int newWidth, int newHeight )
114 {
115     resize( newWidth, newHeight );
116 }
117
118
119 bool
120 YQLogView::setKeyboardFocus()
121 {
122     _qt_text->setFocus();
123
124     return true;
125 }
126
127
128
129 #include "YQLogView.moc"
130