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 if (newString == _lastText)
89 bool atEnd = sb->value() == sb->maximum();
91 if (newString.startsWith(_lastText) && !_lastText.isEmpty() )
93 int position = _lastText.length();
96 if ( newString.mid( _lastText.length(), 1 ) == QString(
'\n') )
99 _qt_text->append( newString.mid( position) );
103 _qt_text->setPlainText( newString );
109 _qt_text->moveCursor( QTextCursor::End );
110 _qt_text->ensureCursorVisible();
111 sb->setValue( sb->maximum() );
114 _lastText = newString;
122 YLogView::setLabel( label );
130 _caption->setEnabled( enabled );
131 _qt_text->setEnabled( enabled );
132 YWidget::setEnabled( enabled );
139 return 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 max( 80, hintHeight );
157 YQLogView::slotResize()
159 QScrollBar *sb = _qt_text->verticalScrollBar();
161 bool atEnd = sb->value() == sb->maximum();
165 _qt_text->moveCursor( QTextCursor::End );
166 _qt_text->ensureCursorVisible();
167 sb->setValue( sb->maximum() );
174 resize( newWidth, newHeight );
181 _qt_text->setFocus();
188 #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.