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