26 #include <QVBoxLayout> 29 #define YUILogComponent "qt-ui" 30 #include <yui/YUILog.h> 34 #include <yui/YEvent.h> 35 #include "YQMultiLineEdit.h" 36 #include "YQSignalBlocker.h" 37 #include "YQWidgetCaption.h" 44 : QFrame( (QWidget *) parent->widgetRep() )
45 , YMultiLineEdit( parent, label )
47 QVBoxLayout* layout =
new QVBoxLayout(
this );
51 layout->setSpacing( YQWidgetSpacing );
52 layout->setMargin ( YQWidgetMargin );
55 YUI_CHECK_NEW( _caption );
56 layout->addWidget( _caption );
58 _qt_textEdit =
new QTextEdit(
this );
59 YUI_CHECK_NEW( _qt_textEdit );
60 layout->addWidget( _qt_textEdit );
62 _qt_textEdit->setAcceptRichText(
false );
63 _qt_textEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
65 _caption->setBuddy( _qt_textEdit );
67 connect( _qt_textEdit, &pclass(_qt_textEdit)::textChanged,
80 return toUTF8( _qt_textEdit->document()->toPlainText() );
88 _qt_textEdit->setText( fromUTF8( text ) );
95 YMultiLineEdit::setLabel( label );
101 YMultiLineEdit::setInputMaxLength( newMaxLength );
103 QString text = _qt_textEdit->document()->toPlainText();
105 if ( (
int) text.length() > inputMaxLength() )
107 text.truncate( inputMaxLength() );
108 _qt_textEdit->setText(text);
115 if ( inputMaxLength() >= 0 && _qt_textEdit->toPlainText().length() > inputMaxLength() )
116 _qt_textEdit->undo();
131 _caption->setEnabled( enabled );
132 _qt_textEdit->setEnabled( enabled );
133 YWidget::setEnabled( enabled );
139 return std::max( 30, sizeHint().width() );
145 int hintHeight = defaultVisibleLines() * _qt_textEdit->fontMetrics().lineSpacing();
146 hintHeight += _qt_textEdit->frameWidth() * 2 + YQWidgetMargin * 2;
148 if ( !_caption->isHidden() )
149 hintHeight += _caption->sizeHint().height() + YQWidgetSpacing;
151 return std::max( 10, hintHeight );
157 resize( newWidth, newHeight );
163 _qt_textEdit->setFocus();
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.