28 #include <QVBoxLayout>
30 #define YUILogComponent "qt-ui"
31 #include <yui/YUILog.h>
37 #include "YQLogView.h"
38 #include "YQWidgetCaption.h"
42 const std::string & label,
45 : QFrame( (QWidget *) parent->widgetRep() )
46 , YLogView( parent, label, visibleLines, maxLines )
49 QVBoxLayout* layout =
new QVBoxLayout(
this );
52 layout->setSpacing( YQWidgetSpacing );
53 layout->setMargin( YQWidgetMargin );
56 YUI_CHECK_NEW( _caption );
57 layout->addWidget( _caption );
60 YUI_CHECK_NEW( _qt_text );
61 layout->addWidget( _qt_text );
63 _qt_text->setReadOnly(
true );
64 _qt_text->setAcceptRichText(
false );
65 _qt_text->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
67 _caption->setBuddy( _qt_text );
69 connect (_qt_text, &pclass(_qt_text)::resized,
this, &pclass(
this)::slotResize);
83 QScrollBar *sb = _qt_text->verticalScrollBar();
84 QString newString = fromUTF8( text );
86 bool atEnd = sb->value() == sb->maximum();
88 if (newString.startsWith(_lastText) && !_lastText.isEmpty() )
90 int position = _lastText.length();
93 if ( newString.mid( _lastText.length(), 1 ) == QString(
'\n') )
96 _qt_text->append( newString.mid( position) );
100 _qt_text->setPlainText( newString );
106 _qt_text->moveCursor( QTextCursor::End );
107 _qt_text->ensureCursorVisible();
108 sb->setValue( sb->maximum() );
111 _lastText = newString;
119 YLogView::setLabel( label );
127 _caption->setEnabled( enabled );
128 _qt_text->setEnabled( enabled );
129 YWidget::setEnabled( enabled );
136 return max( 50, sizeHint().width() );
143 int hintHeight = visibleLines() * _qt_text->fontMetrics().lineSpacing();
144 hintHeight += _qt_text->style()->pixelMetric( QStyle::PM_ScrollBarExtent );
145 hintHeight += _qt_text->frameWidth() * 2;
147 if ( !_caption->isHidden() )
148 hintHeight += _caption->sizeHint().height();
150 return max( 80, hintHeight );
154 YQLogView::slotResize()
156 QScrollBar *sb = _qt_text->verticalScrollBar();
158 bool atEnd = sb->value() == sb->maximum();
162 _qt_text->moveCursor( QTextCursor::End );
163 _qt_text->ensureCursorVisible();
164 sb->setValue( sb->maximum() );
171 resize( newWidth, newHeight );
178 _qt_text->setFocus();
185 #include "YQLogView.moc"
virtual void displayLogText(const std::string &text)
Display the part of the log text that should be displayed.
YQLogView(YWidget *parent, const std::string &label, int visibleLines, int maxLines)
Constructor.
virtual int preferredWidth()
Preferred width of the widget.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void setLabel(const std::string &label)
Set the label (the caption above the log text).
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual int preferredHeight()
Preferred height of the widget.
virtual ~YQLogView()
Destructor.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.