28 #include <QVBoxLayout>
30 #define YUILogComponent "qt-ui"
31 #include <yui/YUILog.h>
35 #include "YQLogView.h"
36 #include "YQWidgetCaption.h"
46 : QFrame( (QWidget *) parent->widgetRep() )
47 , YLogView( parent, label, visibleLines, maxLines )
50 QVBoxLayout* layout =
new QVBoxLayout(
this );
53 layout->setSpacing( YQWidgetSpacing );
54 layout->setMargin( YQWidgetMargin );
57 YUI_CHECK_NEW( _caption );
58 layout->addWidget( _caption );
61 YUI_CHECK_NEW( _qt_text );
62 layout->addWidget( _qt_text );
64 _qt_text->setReadOnly(
true );
65 _qt_text->setAcceptRichText(
false );
66 _qt_text->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
68 _caption->setBuddy( _qt_text );
70 connect (_qt_text, &pclass(_qt_text)::resized,
this, &pclass(
this)::slotResize);
84 QScrollBar *sb = _qt_text->verticalScrollBar();
85 QString newString = fromUTF8( text );
87 if (newString == _lastText)
90 bool atEnd = sb->value() == sb->maximum();
92 if (newString.startsWith(_lastText) && !_lastText.isEmpty() )
94 int position = _lastText.length();
97 if ( newString.mid( _lastText.length(), 1 ) == QString(
'\n') )
100 _qt_text->append( newString.mid( position) );
104 _qt_text->setPlainText( newString );
110 _qt_text->moveCursor( QTextCursor::End );
111 _qt_text->ensureCursorVisible();
112 sb->setValue( sb->maximum() );
115 _lastText = newString;
123 YLogView::setLabel( label );
130 _caption->setEnabled( enabled );
131 _qt_text->setEnabled( enabled );
132 YWidget::setEnabled( enabled );
139 return std::max( 50, sizeHint().width() );
146 int hintHeight = visibleLines() * _qt_text->fontMetrics().lineSpacing();
147 hintHeight += _qt_text->style()->pixelMetric( QStyle::PM_ScrollBarExtent );
148 hintHeight += _qt_text->frameWidth() * 2;
150 if ( !_caption->isHidden() )
151 hintHeight += _caption->sizeHint().height();
153 return std::max( 80, hintHeight );
158 YQLogView::slotResize()
160 QScrollBar *sb = _qt_text->verticalScrollBar();
162 bool atEnd = sb->value() == sb->maximum();
166 _qt_text->moveCursor( QTextCursor::End );
167 _qt_text->ensureCursorVisible();
168 sb->setValue( sb->maximum() );
176 resize( newWidth, newHeight );
183 _qt_text->setFocus();
YQLogView(YWidget *parent, const std::string &label, int visibleLines, int maxLines)
Constructor.
virtual void displayLogText(const std::string &text)
Display the part of the log text that should be displayed.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual int preferredHeight()
Preferred height of the widget.
virtual ~YQLogView()
Destructor.
virtual void setLabel(const std::string &label)
Set the label (the caption above the log text).
virtual int preferredWidth()
Preferred width of the widget.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.