]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQLogView.cc
follow the widget state - for reference: you don't
[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 <q3multilineedit.h>
23 #include <QVBoxLayout>
24 #define y2log_component "qt-ui"
25 #include <ycp/y2log.h>
26
27 using std::max;
28
29 #include "utf8.h"
30 #include "YQUI.h"
31 #include "YQLogView.h"
32 #include "YQWidgetCaption.h"
33
34
35 YQLogView::YQLogView( YWidget *         parent,
36                       const string &    label,
37                       int               visibleLines,
38                       int               maxLines )
39     : QFrame( (QWidget *) parent->widgetRep() )
40     , YLogView( parent, label, visibleLines, maxLines )
41 {
42     setWidgetRep( this );
43     QVBoxLayout* layout = new QVBoxLayout( this );
44     setLayout( layout );
45
46     layout->setSpacing( YQWidgetSpacing );
47     layout->setMargin( YQWidgetMargin );
48
49     _caption = new YQWidgetCaption( this, label );
50     YUI_CHECK_NEW( _caption );
51     layout->addWidget( _caption );
52
53     _qt_text = new Q3MultiLineEdit( this );
54     YUI_CHECK_NEW( _qt_text );
55     layout->addWidget( _qt_text );
56
57     _qt_text->setReadOnly( true );
58     _qt_text->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
59
60     _caption->setBuddy( _qt_text );
61 }
62
63
64 YQLogView::~YQLogView()
65 {
66     // NOP
67 }
68
69
70 void
71 YQLogView::displayLogText( const string & text )
72 {
73     _qt_text->setText( fromUTF8( text ) );
74     _qt_text->scrollToBottom();
75 }
76
77
78 void
79 YQLogView::setLabel( const string & label )
80 {
81     _caption->setText( label );
82     YLogView::setLabel( label );
83 }
84
85
86
87 void
88 YQLogView::setEnabled( bool enabled )
89 {
90     _caption->setEnabled( enabled );
91     _qt_text->setEnabled( enabled );
92     YWidget::setEnabled( enabled );
93 }
94
95
96 int
97 YQLogView::preferredWidth()
98 {
99     return max( 50, sizeHint().width() );
100 }
101
102
103 int
104 YQLogView::preferredHeight()
105 {
106     int hintHeight       = visibleLines() * _qt_text->fontMetrics().lineSpacing();
107     hintHeight          += _qt_text->style()->pixelMetric( QStyle::PM_ScrollBarExtent );
108     hintHeight          += _qt_text->frameWidth() * 2;
109
110     if ( _caption->isShown() )
111         hintHeight      +=  _caption->sizeHint().height();
112
113     return max( 80, hintHeight );
114 }
115
116
117 void
118 YQLogView::setSize( int newWidth, int newHeight )
119 {
120     resize( newWidth, newHeight );
121 }
122
123
124 bool
125 YQLogView::setKeyboardFocus()
126 {
127     _qt_text->setFocus();
128
129     return true;
130 }
131
132
133
134 #include "YQLogView.moc"
135