]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQLogView.cc
- Don't create layouts with parent. Qt 4.x automatically reparents
[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 #include <QScrollBar>
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 QTextEdit( 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     QScrollBar *sb = _qt_text->verticalScrollBar();
75     sb->setValue( sb->maximum() );
76 }
77
78
79 void
80 YQLogView::setLabel( const string & label )
81 {
82     _caption->setText( label );
83     YLogView::setLabel( label );
84 }
85
86
87
88 void
89 YQLogView::setEnabled( bool enabled )
90 {
91     _caption->setEnabled( enabled );
92     _qt_text->setEnabled( enabled );
93     YWidget::setEnabled( enabled );
94 }
95
96
97 int
98 YQLogView::preferredWidth()
99 {
100     return max( 50, sizeHint().width() );
101 }
102
103
104 int
105 YQLogView::preferredHeight()
106 {
107     int hintHeight       = visibleLines() * _qt_text->fontMetrics().lineSpacing();
108     hintHeight          += _qt_text->style()->pixelMetric( QStyle::PM_ScrollBarExtent );
109     hintHeight          += _qt_text->frameWidth() * 2;
110
111     if ( !_caption->isHidden() )
112         hintHeight      +=  _caption->sizeHint().height();
113
114     return max( 80, hintHeight );
115 }
116
117
118 void
119 YQLogView::setSize( int newWidth, int newHeight )
120 {
121     resize( newWidth, newHeight );
122 }
123
124
125 bool
126 YQLogView::setKeyboardFocus()
127 {
128     _qt_text->setFocus();
129
130     return true;
131 }
132
133
134
135 #include "YQLogView.moc"
136