Author: sh-sh-sh
Date: Tue Jul 3 16:49:18 2007
New Revision: 39147
URL: http://svn.opensuse.org/viewcvs/yast?rev=39147&view=rev
Log:
ported MultiLineEdit
Modified:
branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc
branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc
branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.h
branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc
branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.h
branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc
branches/tmp/sh/mod-ui/qt/src/YQUI.h
branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc
branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc
Modified: branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/ChangeLog Tue Jul 3 16:49:18 2007
@@ -318,3 +318,10 @@
functions each - see the respective header files. See the YQ sample
implementations for more details.
+
+2007-07-03 16:30 sh@suse.de
+
+* Ported YMultiLineEdit
+ - renamed text() -> value()
+ - renamed setText() -> setValue()
+ - new: YMultiLineEdit::defaultVisibleLines() (use this in preferredHeight() )
\ No newline at end of file
Modified: branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/Makefile.am Tue Jul 3 16:49:18 2007
@@ -102,9 +102,11 @@
YUIPlugin.h \
YUISymbols.h \
YUI_util.h \
+ YWidget.h \
YWidgetFactory.h \
YWidgetID.h \
YWidgetOpt.h \
+ YWidget_OptimizeChanges.h \
\
YAlignment.h \
YBarGraph.h \
@@ -152,7 +154,6 @@
YTime.h \
YTransText.h \
YTree.h \
- YWidget.h \
YWizard.h \
TreeItem.h
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YCPDialogParser.cc Tue Jul 3 16:49:18 2007
@@ -54,6 +54,7 @@
#include "YLayoutBox.h"
#include "YMenuButton.h"
#include "YMultiSelectionBox.h"
+#include "YMultiLineEdit.h"
#include "YPackageSelector.h"
#include "YPushButton.h"
#include "YRadioButton.h"
@@ -1710,9 +1711,9 @@
* This widget is a multiple line text entry field with a label above it.
* An initial text can be provided.
*
- * @note You can and should set a keyboard shortcut within the
- * label. When the user presses the hotkey, the corresponding MultiLineEdit
- * widget will get the keyboard focus.
+ * Note: You can and should set a keyboard shortcut within the label. When the
+ * user presses the hotkey, the corresponding MultiLineEdit widget will get the
+ * keyboard focus.
**/
YWidget *
@@ -1728,12 +1729,21 @@
term->toString().c_str() );
return 0;
}
+
+ rejectAllOptions( term, optList );
+
+ string label = term->value( argnr )->asString()->value();
+ string initialValue;
+
+ if ( term->size() >= argnr + 2 )
+ initialValue = term->value( argnr+1 )->asString()->value();
- YCPString initial_text( "" );
- if ( term->size() >= argnr + 2 ) initial_text = term->value( argnr+1 )->asString();
+ YMultiLineEdit * multiLineEdit = YUI::widgetFactory()->createMultiLineEdit( parent, label );
- rejectAllOptions( term,optList );
- return YUI::ui()->createMultiLineEdit( parent, opt, term->value( argnr )->asString(), initial_text );
+ if ( ! initialValue.empty() )
+ multiLineEdit->setValue( initialValue );
+
+ return multiLineEdit;
}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.cc Tue Jul 3 16:49:18 2007
@@ -17,9 +17,6 @@
/-*/
-#include
-#include
-#include
#define y2log_component "ui"
#include
@@ -27,93 +24,128 @@
#include "YMacroRecorder.h"
#include "YMultiLineEdit.h"
+#define DEFAULT_VISIBLE_LINES 3
-YMultiLineEdit::YMultiLineEdit( const YWidgetOpt & opt, const YCPString & label )
- : YWidget( opt )
- , _label( label )
+struct YMultiLineEditPrivate
{
+ YMultiLineEditPrivate( const string & label )
+ : label( label )
+ , inputMaxLength( -1 )
+ , defaultVisibleLines( DEFAULT_VISIBLE_LINES )
+ {}
+
+ string label;
+ int inputMaxLength;
+ int defaultVisibleLines;
+};
+
+
+
+
+YMultiLineEdit::YMultiLineEdit( YWidget * parent, const string & label )
+ : YWidget( parent )
+ , priv( new YMultiLineEditPrivate( label ) )
+{
+ YUI_CHECK_NEW( priv );
+
setDefaultStretchable( YD_HORIZ, true );
setDefaultStretchable( YD_VERT, true );
}
-void YMultiLineEdit::setLabel( const YCPString & newLabel )
+YMultiLineEdit::~YMultiLineEdit()
{
- _label = newLabel;
+ // NOP
}
+string YMultiLineEdit::label()
+{
+ return priv->label;
+}
+
-YCPValue YMultiLineEdit::changeWidget( const YCPSymbol & property, const YCPValue & newValue )
+void YMultiLineEdit::setLabel( const string & label )
{
- string s = property->symbol();
+ priv->label = label;
+}
- /**
- * @property string Value
- * The text contents as one large string containing newlines.
- */
- if ( s == YUIProperty_Value )
- {
- if ( newValue->isString() )
- {
- setText( newValue->asString() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "MultiLineEdit: Invalid Value property - string expected, not %s",
- newValue->toString().c_str() );
- return YCPBoolean( false );
- }
- }
- /**
- * @property string Label The label above the log text.
- */
- else if ( s == YUIProperty_Label )
- {
- if ( newValue->isString() )
- {
- setLabel( newValue->asString() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "MultiLineEdit: Invalid Label property - string expected, not %s",
- newValue->toString().c_str() );
+int YMultiLineEdit::inputMaxLength() const
+{
+ return priv->inputMaxLength;
+}
- return YCPBoolean( false );
- }
- }
- /**
- * @property integer InputMaxLength limit the number of characters which
- * can be inserted. A value of -1 means unlimited input.
- */
- else if ( s == YUIProperty_InputMaxLength )
+
+void YMultiLineEdit::setInputMaxLength( int len )
+{
+ priv->inputMaxLength = len;
+}
+
+
+int YMultiLineEdit::defaultVisibleLines() const
+{
+ return priv->defaultVisibleLines;
+}
+
+
+void YMultiLineEdit::setDefaultVisibleLines( int newVisibleLines )
+{
+ priv->defaultVisibleLines = newVisibleLines;
+}
+
+
+const YPropertySet &
+YMultiLineEdit::propertySet()
+{
+ static YPropertySet propSet;
+
+ if ( propSet.isEmpty() )
{
- if ( newValue->isInteger() )
- {
- setInputMaxLength( newValue->asInteger()->value() );
- return YCPBoolean( true );
- }
- else
- {
- y2error( "MultiLineEdit: Invalid parameter %s for InputMaxLength property. Must be integer.",
- newValue->toString().c_str() );
- return YCPBoolean( false );
- }
+ /*
+ * @property string Value the MultiLineEdit text contents (with newlines)
+ * @property string Label caption above the MultiLineEdit
+ * @property integer InputMaxLength maximum number of input characters
+ */
+ propSet.add( YProperty( YUIProperty_Value, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_Label, YStringProperty ) );
+ propSet.add( YProperty( YUIProperty_InputMaxLength, YIntegerProperty ) );
+ propSet.add( YWidget::propertySet() );
}
- else return YWidget::changeWidget( property, newValue );
+
+ return propSet;
}
+bool
+YMultiLineEdit::setProperty( const string & propertyName, const YPropertyValue & val )
+{
+ propertySet().check( propertyName, val.type() ); // throws exceptions if not found or type mismatch
-YCPValue YMultiLineEdit::queryWidget( const YCPSymbol & property )
+ if ( propertyName == YUIProperty_Value ) setValue( val.stringVal() );
+ else if ( propertyName == YUIProperty_Label ) setLabel( val.stringVal() );
+ else if ( propertyName == YUIProperty_InputMaxLength ) setInputMaxLength( val.integerVal() );
+ else
+ {
+ YWidget::setProperty( propertyName, val );
+ }
+
+ return true; // success -- no special processing necessary
+}
+
+
+YPropertyValue
+YMultiLineEdit::getProperty( const string & propertyName )
{
- string s = property->symbol();
- if ( s == YUIProperty_Label ) return label();
- else if ( s == YUIProperty_Value ) return text();
- else return YWidget::queryWidget( property );
+ propertySet().check( propertyName ); // throws exceptions if not found
+
+ if ( propertyName == YUIProperty_Value ) return YPropertyValue( value() );
+ else if ( propertyName == YUIProperty_Label ) return YPropertyValue( label() );
+ else if ( propertyName == YUIProperty_InputMaxLength ) return YPropertyValue( inputMaxLength() );
+ else
+ {
+ return YWidget::getProperty( propertyName );
+ }
}
@@ -122,6 +154,3 @@
macroRecorder->recordWidgetProperty( this, YUIProperty_Value );
}
-void YMultiLineEdit::setInputMaxLength( const YCPInteger & numberOfChars )
-{
-}
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.h?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YMultiLineEdit.h Tue Jul 3 16:49:18 2007
@@ -20,10 +20,9 @@
#define YMultiLineEdit_h
#include "YWidget.h"
-#include
-#include <deque>
class YMacroRecorder;
+class YMultiLineEditPrivate;
class YMultiLineEdit : public YWidget
@@ -32,56 +31,127 @@
/**
* Constructor.
**/
- YMultiLineEdit( const YWidgetOpt & opt,
- const YCPString & label );
+ YMultiLineEdit( YWidget * parent, const string & label );
public:
/**
+ * Destructor.
+ **/
+ virtual ~YMultiLineEdit();
+
+ /**
* Returns a descriptive name of this widget class for logging,
* debugging etc.
**/
virtual const char * widgetClass() { return "YMultiLineEdit"; }
+ /**
+ * Get the current value (the text entered by the user or set from the
+ * outside) of this MultiLineEdit.
+ *
+ * Derived classes are required to implement this.
+ **/
+ virtual string value() = 0;
/**
- * Implements the ui command changeWidget for the widget specific
- * properties.
+ * Set the current value (the text entered by the user or set from the
+ * outside) of this MultiLineEdit.
+ *
+ * Derived classes are required to implement this.
**/
- YCPValue changeWidget( const YCPSymbol & property, const YCPValue & newvalue );
+ virtual void setValue( const string & text ) = 0;
/**
- * Implements the ui command changeWidget for the widget specific properties.
+ * Get the label (the caption above the MultiLineEdit).
**/
- YCPValue queryWidget( const YCPSymbol & property );
+ string label();
+ /**
+ * Set the label (the caption above the MultiLineEdit).
+ *
+ * Derived classes are free to reimplement this, but they should call this
+ * base class method at the end of the overloaded function.
+ **/
+ virtual void setLabel( const string & label );
/**
- * Set the label above the log lines. Overload this, but call
- * YMultiLineEdit::setLabel at the end of your own function.
+ * The maximum input length, i.e., the maximum number of characters the
+ * user can enter. -1 means no limit.
**/
- virtual void setLabel( const YCPString & newLabel );
+ int inputMaxLength() const;
/**
- * Set the edited text.
+ * Set the maximum input length, i.e., the maximum number of characters the
+ * user can enter. -1 means no limit.
+ *
+ * Derived classes are free to reimplement this, but they should call this
+ * base class method at the end of the overloaded function.
**/
- virtual void setText( const YCPString & text ) = 0;
+ virtual void setInputMaxLength( int numberOfChars );
/**
- * Get the edited text.
+ * Return the number of input lines that are visible by default.
+ *
+ * This is what the widget would like to get (which will be reflected by
+ * preferredHeight() ), not what it currently actually has due to layout
+ * constraints.
**/
- virtual YCPString text() = 0;
+ int defaultVisibleLines() const;
/**
- * Get the label above the log lines.
+ * Set the number of input lines that are visible by default.
+ *
+ * This is what the widget would like to get (which will be reflected by
+ * preferredHeight() ), not what it currently actually has due to layout
+ * constraints.
+ *
+ * Notice that since a MultiLineEdit is stretchable in both dimensions, it
+ * might get more or less screen space, depending on the layout. This value
+ * is only meaningful if there are no other layout constraints.
+ *
+ * Changing this value will not trigger a re-layout.
+ *
+ * Derived classes can overwrite this function (but should call this base
+ * class function in the new function implementation), but it will normally
+ * be sufficient to query defaultVisibleLines() in preferredHeight().
**/
- YCPString label() const { return _label; }
+ virtual void setDefaultVisibleLines( int newVisibleLines );
+
+ /**
+ * Set a property.
+ * Reimplemented from YWidget.
+ *
+ * This function may throw YUIPropertyExceptions.
+ *
+ * This function returns 'true' if the value was successfully set and
+ * 'false' if that value requires special handling (not in error cases:
+ * those are covered by exceptions).
+ **/
+ virtual bool setProperty( const string & propertyName,
+ const YPropertyValue & val );
+
+ /**
+ * Get a property.
+ * Reimplemented from YWidget.
+ *
+ * This method may throw YUIPropertyExceptions.
+ **/
+ virtual YPropertyValue getProperty( const string & propertyName );
+
+ /**
+ * Return this class's property set.
+ * This also initializes the property upon the first call.
+ *
+ * Reimplemented from YWidget.
+ **/
+ virtual const YPropertySet & propertySet();
/**
* Get the string of this widget that holds the keyboard shortcut.
*
* Reimplemented from YWidget.
**/
- virtual string shortcutString() { return label()->value(); }
+ virtual string shortcutString() { return label(); }
/**
* Set the string of this widget that holds the keyboard shortcut.
@@ -89,23 +159,16 @@
* Reimplemented from YWidget.
**/
virtual void setShortcutString( const string & str )
- { setLabel( YCPString( str ) ); }
-
+ { setLabel( str ); }
+
/**
* The name of the widget property that will return user input.
* Inherited from YWidget.
**/
const char *userInputProperty() { return YUIProperty_Value; }
-
- /**
- * Specify the amount of characters which can be inserted.
- *
- * Overload this to limit the input.
- **/
- virtual void setInputMaxLength( const YCPInteger & numberOfChars );
-private:
+private:
/**
* Save the widget's user input to a macro recorder.
* Intentionally declared as "private" so all macro recording internals are
@@ -114,9 +177,7 @@
virtual void saveUserInput( YMacroRecorder *macroRecorder );
- // Data members
-
- YCPString _label;
+ ImplPtr<YMultiLineEditPrivate> priv;
};
Modified: branches/tmp/sh/mod-ui/core/libyui/src/YUI.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/core/libyui/src/YUI.h?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/core/libyui/src/YUI.h (original)
+++ branches/tmp/sh/mod-ui/core/libyui/src/YUI.h Tue Jul 3 16:49:18 2007
@@ -448,7 +448,6 @@
virtual YDialog *createDialog( YWidgetOpt & opt ) = 0;
virtual YWidget *createLogView( YWidget *parent, YWidgetOpt & opt, const YCPString & label, int visibleLines, int maxLines ) = 0;
virtual YWidget *createMenuButton( YWidget *parent, YWidgetOpt & opt, const YCPString & label ) = 0;
- virtual YWidget *createMultiLineEdit( YWidget *parent, YWidgetOpt & opt, const YCPString & label, const YCPString & text ) = 0;
virtual YWidget *createTree( YWidget *parent, YWidgetOpt & opt, const YCPString & label ) = 0;
virtual YWidget *createTable( YWidget *parent, YWidgetOpt & opt, vector<string> header ) = 0;
virtual YWidget *createProgressBar( YWidget *parent, YWidgetOpt & opt, const YCPString & label, const YCPInteger & maxprogress, const YCPInteger & progress ) = 0;
Modified: branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.cc Tue Jul 3 16:49:18 2007
@@ -29,167 +29,181 @@
#include "YEvent.h"
#include "YQMultiLineEdit.h"
-#define VISIBLE_LINES 3
-
-YQMultiLineEdit::YQMultiLineEdit( QWidget * parent,
- const YWidgetOpt & opt,
- const YCPString & label,
- const YCPString & initialText )
- : QVBox( parent )
- , YMultiLineEdit( opt, label )
- , InputMaxLength( -1 )
+YQMultiLineEdit::YQMultiLineEdit( YWidget * parent, const string & label )
+ : QVBox( (QWidget *) parent->widgetRep() )
+ , YMultiLineEdit( parent, label )
{
setWidgetRep( this );
setSpacing( YQWidgetSpacing );
- setMargin( YQWidgetMargin );
-
- if ( label->value().length() > 0 )
- {
- _qt_label = new QLabel( fromUTF8( label->value() ), this );
- _qt_label->setTextFormat( QLabel::PlainText );
- }
- else
- _qt_label = 0;
-
- _qt_textedit = new QTextEdit( this );
- _qt_textedit->setTextFormat( Qt::PlainText );
- _qt_textedit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
- _qt_textedit->setText( fromUTF8( initialText->value() ) );
+ setMargin ( YQWidgetMargin );
- if ( _qt_label )
- _qt_label->setBuddy( _qt_textedit );
+ _qt_label = new QLabel( fromUTF8( label ), this );
+ _qt_label->setTextFormat( QLabel::PlainText );
+
+ if ( label.empty() )
+ _qt_label->hide();
- connect( _qt_textedit, SIGNAL( textChanged( void ) ), this, SLOT( changed ( void ) ) );
-}
+ _qt_textEdit = new QTextEdit( this );
+ _qt_textEdit->setTextFormat( Qt::PlainText );
+ _qt_textEdit->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
+ _qt_label->setBuddy( _qt_textEdit );
-void YQMultiLineEdit::setEnabled( bool enabled )
-{
- _qt_textedit->setEnabled( enabled );
- YWidget::setEnabled( enabled );
+ connect( _qt_textEdit, SIGNAL( textChanged( void ) ),
+ this, SLOT ( changed ( void ) ) );
}
-int YQMultiLineEdit::preferredWidth()
+YQMultiLineEdit::~YQMultiLineEdit()
{
- return max( 30, sizeHint().width() );
+ // NOP
}
-int YQMultiLineEdit::preferredHeight()
+string YQMultiLineEdit::value()
{
- int hintHeight = VISIBLE_LINES * _qt_textedit->fontMetrics().lineSpacing();
- hintHeight += _qt_textedit->frameWidth() * 2 + YQWidgetMargin * 2;
-
- if ( _qt_label && _qt_label->isShown() )
- hintHeight += _qt_label->sizeHint().height() + YQWidgetSpacing;
-
- return max( 10, hintHeight );
+ return toUTF8( _qt_textEdit->text() );
}
-void YQMultiLineEdit::setSize( int newWidth, int newHeight )
+void YQMultiLineEdit::setValue( const string & text )
{
- resize( newWidth, newHeight );
+ _qt_textEdit->blockSignals( true );
+ _qt_textEdit->setText( fromUTF8( text ) );
+ _qt_textEdit->blockSignals( false );
}
-void YQMultiLineEdit::setText( const YCPString & text )
+void YQMultiLineEdit::setLabel( const string & label )
{
- _qt_textedit->blockSignals( true );
- _qt_textedit->setText( fromUTF8( text->value() ) );
- _qt_textedit->blockSignals( false );
-}
-
-
-YCPString YQMultiLineEdit::text()
-{
- return YCPString( toUTF8( _qt_textedit->text() ) );
-}
-
-
-void YQMultiLineEdit::setLabel( const YCPString & label )
-{
- if ( _qt_label )
- _qt_label->setText( fromUTF8( label->value() ) );
+ _qt_label->setText( fromUTF8( label ) );
+
+ if ( label.empty() )
+ {
+ if ( _qt_label->isVisible() )
+ _qt_label->hide();
+ }
+ else
+ {
+ if ( _qt_label->isHidden() )
+ _qt_label->show();
+ }
+
YMultiLineEdit::setLabel( label );
}
-bool YQMultiLineEdit::setKeyboardFocus()
+void YQMultiLineEdit::setInputMaxLength( int newMaxLength )
{
- _qt_textedit->setFocus();
+ YMultiLineEdit::setInputMaxLength( newMaxLength );
- return true;
+ QString text = _qt_textEdit->text();
+
+ if ( (int) text.length() > inputMaxLength() )
+ {
+ text.truncate( inputMaxLength() );
+ _qt_textEdit->setText(text);
+ }
}
-int YQMultiLineEdit::visibleLines() const
+void YQMultiLineEdit::enforceMaxInputLength()
{
- return VISIBLE_LINES;
-}
+ if ( inputMaxLength() >= 0 && _qt_textEdit->length() > inputMaxLength() )
+ {
+ int index;
+ int para;
+ _qt_textEdit->getCursorPosition( ¶, &index);
-void YQMultiLineEdit::changed()
-{
+ QString text = _qt_textEdit->text();
- // if we reached the maximum number of characters which can be inserted
- if ( InputMaxLength >= 0 && InputMaxLength < _qt_textedit->length() ) {
- int index, para;
- _qt_textedit->getCursorPosition( ¶, &index);
-
- QString text = _qt_textedit->text();
-
int pos = 0; // current positon in text
int section =0; // section in text;
// iterate over the string
- while ( pos != (int)text.length()+1 ) {
+
+ while ( pos != (int) text.length()+1 )
+ {
// we reached the paragraph where the user entered
// a character
- if ( section == para ) {
+ if ( section == para )
+ {
// remove that character
text.remove( pos+index-1, 1 );
break;
}
-
+
// new paragraph begins
- if ( text[pos] == '\n' ) {
+ if ( text[pos] == '\n' )
section++;
- }
+
pos++;
}
-
- _qt_textedit->setText( text );
-
+
+ _qt_textEdit->setText( text );
+
// user removed a paragraph
- if ( index == 0 ) {
+ if ( index == 0 )
+ {
--para;
// the new index is the end of the previous paragraph
- index = _qt_textedit->paragraphLength(para) + 1;
+ index = _qt_textEdit->paragraphLength(para) + 1;
}
// adjust to new cursor position before the removed character
- _qt_textedit->setCursorPosition( para, index-1 );
+ _qt_textEdit->setCursorPosition( para, index-1 );
}
+}
+
+
+void YQMultiLineEdit::changed()
+{
+ enforceMaxInputLength();
if ( notify() )
YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
}
-void YQMultiLineEdit::setInputMaxLength( const YCPInteger & numberOfChars)
+
+void YQMultiLineEdit::setEnabled( bool enabled )
{
- InputMaxLength = numberOfChars->asInteger()->value();
-
- QString text = _qt_textedit->text();
+ _qt_textEdit->setEnabled( enabled );
+ YWidget::setEnabled( enabled );
+}
- // truncate the text if appropriate
- if ( InputMaxLength < (int)text.length() ) {
- text.truncate( InputMaxLength );
- _qt_textedit->setText(text);
- }
+int YQMultiLineEdit::preferredWidth()
+{
+ return max( 30, sizeHint().width() );
+}
+
+
+int YQMultiLineEdit::preferredHeight()
+{
+ int hintHeight = defaultVisibleLines() * _qt_textEdit->fontMetrics().lineSpacing();
+ hintHeight += _qt_textEdit->frameWidth() * 2 + YQWidgetMargin * 2;
+
+ if ( _qt_label && _qt_label->isShown() )
+ hintHeight += _qt_label->sizeHint().height() + YQWidgetSpacing;
+
+ return max( 10, hintHeight );
}
+
+void YQMultiLineEdit::setSize( int newWidth, int newHeight )
+{
+ resize( newWidth, newHeight );
+}
+
+
+bool YQMultiLineEdit::setKeyboardFocus()
+{
+ _qt_textEdit->setFocus();
+
+ return true;
+}
+
+
#include "YQMultiLineEdit.moc"
Modified: branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.h?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQMultiLineEdit.h Tue Jul 3 16:49:18 2007
@@ -22,104 +22,118 @@
#include
#include
-#include
#include "YMultiLineEdit.h"
class QTextEdit;
+/**
+ * MultiLineEdit - an input area for multi-line text.
+ **/
class YQMultiLineEdit : public QVBox, public YMultiLineEdit
{
Q_OBJECT
public:
/**
- * Constructor
+ * Constructor.
**/
- YQMultiLineEdit( QWidget * parent,
- const YWidgetOpt & opt,
- const YCPString & label,
- const YCPString & initialText );
+ YQMultiLineEdit( YWidget * parent, const string & label );
/**
- * Inherited from YWidget: Sets the enabled state of the
- * widget. All new widgets are enabled per definition. Only
- * enabled widgets can take user input.
+ * Destructor.
**/
- void setEnabled( bool enabled );
+ virtual ~YQMultiLineEdit();
/**
- * Preferred width of the widget.
+ * Get the current value (the text entered by the user or set from the
+ * outside) of this MultiLineEdit.
*
- * Reimplemented from YWidget.
+ * Implemented from YMultiLineEdit.
**/
- virtual int preferredWidth();
+ virtual string value();
/**
- * Preferred height of the widget.
+ * Set the current value (the text entered by the user or set from the
+ * outside) of this MultiLineEdit.
*
- * Reimplemented from YWidget.
+ * Implemented from YMultiLineEdit.
**/
- virtual int preferredHeight();
+ virtual void setValue( const string & text );
/**
- * Set the new size of the widget.
+ * Set the label (the caption above the MultiLineEdit).
*
- * Reimplemented from YWidget.
+ * Reimplemented from YMultiLineEdit.
**/
- virtual void setSize( int newWidth, int newHeight );
-
+ virtual void setLabel( const string & label );
+
/**
- * Accept the keyboard focus.
+ * Set the maximum input length, i.e., the maximum number of characters the
+ * user can enter. -1 means no limit.
+ *
+ * Reimplemented from YMultiLineEdit.
**/
- bool setKeyboardFocus();
-
+ virtual void setInputMaxLength( int numberOfChars );
+
/**
- * Set the widget's label header.
+ * Set enabled/disabled state.
+ *
+ * Reimplemented from YWidget.
**/
- void setLabel( const YCPString & newLabel );
+ virtual void setEnabled( bool enabled );
/**
- * Set the edited text.
- * Inherited from YMultiLineEdit.
+ * Preferred width of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- void setText( const YCPString & text );
+ virtual int preferredWidth();
/**
- * Get the edited text.
- * Inherited from YMultiLineEdit.
+ * Preferred height of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- YCPString text();
+ virtual int preferredHeight();
/**
- * Get the number of lines visible by default
+ * Set the new size of the widget.
+ *
+ * Reimplemented from YWidget.
**/
- int visibleLines() const;
+ virtual void setSize( int newWidth, int newHeight );
/**
- * Specify the amount of characters which can be inserted.
- *
- * Reimplemented from YMulitLineEdit.
+ * Accept the keyboard focus.
**/
- void setInputMaxLength( const YCPInteger & numberOfChars );
+ virtual bool setKeyboardFocus();
protected slots:
+
/**
* Triggered when the text changes.
**/
void changed();
+ /**
+ * Enforce the maximum input length: If the text becomes too long, remove
+ * the just-entered character at the current cursor position.
+ *
+ * Note that this is a lot more user friendly than silently truncating at
+ * the end of the text: In the latter case, chances are that the user never
+ * gets to know that text was truncated. Removing the just-typed character
+ * OTOH is something he will notice very quickly.
+ **/
+ void enforceMaxInputLength();
+
protected:
QLabel * _qt_label;
- QTextEdit * _qt_textedit;
-
- // specifies how much characters can be inserted. -1 for unlimited input
- int InputMaxLength;
-
+ QTextEdit * _qt_textEdit;
};
Modified: branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQMultiSelectionBox.cc Tue Jul 3 16:49:18 2007
@@ -48,6 +48,9 @@
_qt_label = new QLabel( fromUTF8( label ), this );
_qt_label->setTextFormat( QLabel::PlainText );
+ if ( label.empty() )
+ _qt_label->hide();
+
_qt_listView = new QListView( this );
_qt_listView->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ) );
_qt_listView->addColumn( "" ); // QListView doesn't have one single column by default!
@@ -75,6 +78,18 @@
YQMultiSelectionBox::setLabel( const string & label )
{
_qt_label->setText( fromUTF8( label ) );
+
+ if ( label.empty() )
+ {
+ if ( _qt_label->isVisible() )
+ _qt_label->hide();
+ }
+ else
+ {
+ if ( _qt_label->isHidden() )
+ _qt_label->show();
+ }
+
YMultiSelectionBox::setLabel( label );
}
Modified: branches/tmp/sh/mod-ui/qt/src/YQUI.h
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI.h?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQUI.h (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQUI.h Tue Jul 3 16:49:18 2007
@@ -452,7 +452,6 @@
YWidget * createIntField ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int minValue, int maxValue, int initialValue);
YWidget * createLogView ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, int visibleLines, int maxLines );
- YWidget * createMultiLineEdit ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, const YCPString & text);
YWidget * createProgressBar ( YWidget * parent, YWidgetOpt & opt, const YCPString & label, const YCPInteger & maxProgress, const YCPInteger & currentProgress );
YWidget * createMenuButton ( YWidget * parent, YWidgetOpt & opt, const YCPString & label);
YWidget * createTable ( YWidget * parent, YWidgetOpt & opt, vector<string> header);
Modified: branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQUI_widgets.cc Tue Jul 3 16:49:18 2007
@@ -30,7 +30,6 @@
#include "YQIntField.h"
#include "YQLogView.h"
#include "YQMenuButton.h"
-#include "YQMultiLineEdit.h"
#include "YQMultiProgressMeter.h"
#include "YQPackageSelectorPlugin.h"
#include "YQPartitionSplitter.h"
@@ -110,15 +109,6 @@
}
-YWidget * YQUI::createMultiLineEdit( YWidget * parent,
- YWidgetOpt & opt,
- const YCPString & label,
- const YCPString & initialText )
-{
- return new YQMultiLineEdit( (QWidget *) ( parent->widgetRep() ), opt, label, initialText);
-}
-
-
YWidget * YQUI::createTree ( YWidget * parent,
YWidgetOpt & opt,
const YCPString & label )
Modified: branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc
URL: http://svn.opensuse.org/viewcvs/yast/branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc?rev=39147&r1=39146&r2=39147&view=diff
==============================================================================
--- branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc (original)
+++ branches/tmp/sh/mod-ui/qt/src/YQWidgetFactory.cc Tue Jul 3 16:49:18 2007
@@ -228,7 +228,10 @@
YQMultiLineEdit *
YQWidgetFactory::createMultiLineEdit( YWidget * parent, const string & label )
{
- return 0; // FIXME: TO DO
+ YQMultiLineEdit * multiLineEdit = new YQMultiLineEdit( parent, label );
+ YUI_CHECK_NEW( multiLineEdit );
+
+ return multiLineEdit;
}
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org