26 #include <QVBoxLayout>
29 #define YUILogComponent "qt-ui"
30 #include <yui/YUILog.h>
36 #include <yui/YEvent.h>
37 #include "YQMultiLineEdit.h"
38 #include "YQSignalBlocker.h"
39 #include "YQWidgetCaption.h"
43 : QFrame( (QWidget *) parent->widgetRep() )
44 , YMultiLineEdit( parent, label )
46 QVBoxLayout* layout =
new QVBoxLayout(
this );
50 layout->setSpacing( YQWidgetSpacing );
51 layout->setMargin ( YQWidgetMargin );
54 YUI_CHECK_NEW( _caption );
55 layout->addWidget( _caption );
57 _qt_textEdit =
new QTextEdit(
this );
58 YUI_CHECK_NEW( _qt_textEdit );
59 layout->addWidget( _qt_textEdit );
61 _qt_textEdit->setAcceptRichText(
false );
62 _qt_textEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
64 _caption->setBuddy( _qt_textEdit );
66 connect( _qt_textEdit, &pclass(_qt_textEdit)::textChanged,
79 return toUTF8( _qt_textEdit->document()->toPlainText() );
87 _qt_textEdit->setText( fromUTF8( text ) );
94 YMultiLineEdit::setLabel( label );
100 YMultiLineEdit::setInputMaxLength( newMaxLength );
102 QString text = _qt_textEdit->document()->toPlainText();
104 if ( (
int) text.length() > inputMaxLength() )
106 text.truncate( inputMaxLength() );
107 _qt_textEdit->setText(text);
114 if ( inputMaxLength() >= 0 && _qt_textEdit->toPlainText().length() > inputMaxLength() )
115 _qt_textEdit->undo();
130 _caption->setEnabled( enabled );
131 _qt_textEdit->setEnabled( enabled );
132 YWidget::setEnabled( enabled );
138 return max( 30, sizeHint().width() );
144 int hintHeight = defaultVisibleLines() * _qt_textEdit->fontMetrics().lineSpacing();
145 hintHeight += _qt_textEdit->frameWidth() * 2 + YQWidgetMargin * 2;
147 if ( !_caption->isHidden() )
148 hintHeight += _caption->sizeHint().height() + YQWidgetSpacing;
150 return max( 10, hintHeight );
156 resize( newWidth, newHeight );
162 _qt_textEdit->setFocus();
168 #include "YQMultiLineEdit.moc"
Helper class to block Qt signals for QWidgets or QObjects as long as this object exists.
void changed()
Triggered when the text changes.
virtual std::string value()
Get the current value (the text entered by the user or set from the outside) of this MultiLineEdit...
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void setValue(const std::string &text)
Set the current value (the text entered by the user or set from the outside) of this MultiLineEdit...
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
virtual int preferredWidth()
Preferred width of the widget.
virtual ~YQMultiLineEdit()
Destructor.
virtual void setInputMaxLength(int numberOfChars)
Set the maximum input length, i.e., the maximum number of characters the user can enter...
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
void enforceMaxInputLength()
Enforce the maximum input length: If the text becomes too long, remove the just-entered character at ...
virtual void setLabel(const std::string &label)
Set the label (the caption above the MultiLineEdit).
virtual int preferredHeight()
Preferred height of the widget.
static YQUI * ui()
Access the global Qt-UI.
YQMultiLineEdit(YWidget *parent, const std::string &label)
Constructor.