|
|
An enhanced QLineEdit widget for inputting text.
This widget has the same behaviour as QLineEdit with the following added functionalities : a popup menu that provides basic features such as copy/cut/paste to manipulate content through the mouse, a built-in hook into KCompletion which provides automatic & manual completion as well as iteration through a given list, and the ability to change which keyboard keys to use for these features. Additionally, since this widget inherits form QLineEdit, it can be used as a drop-in replacement where the above extra functionalities are needed and/or useful.
KLineEdit emits a few more additional signals than QLineEdit: completion, rotateUp and rotateDown and @returnPressed. The completion signal can be connected to a slot that will assist the user in filling out the remaining text. The two rotation signals are intended to be used to iterate through a list of predefined text entries.
By default, when you create a completion object through either completionObject() or setCompletionObject this widget will be automatically enabled to handle the signals. If you do not need this feature, simply use the appropriate accessor methods to turn it off.
The default key-bindings for completion and rotation are determined from the global settings in KStdAccel. However, these values can be set locally overriding the global settings. Simply invoking useGlobalSettings allows you to immediately default the bindings back to the global settings again. Also if you are interested in only defaulting the key-bindings individually for each action, simply call the setXXXKey methods without any argumet. For example, after locally customizing the key-binding that invokes manual completion, simply invoking setCompletionKey(), without any argument, will result in the completion key being set to 0. This will then force the key-event filter to use the global value.
NOTE: if the EchoMode for this widget is set to something other than QLineEdit::Normal, the completion mode will always be defaulted to KGlobal::CompletionNone. This is done purposefully to protect against protected entries such as passwords being cached in KCompletion's list. Hence, if the EchoMode is not QLineEdit::Normal, the completion mode is automatically disabled.
To enable the basic completion feature :
KLineEdit *edit = new KLineEdit( true, this, "mywidget" ); KCompletion *comp = edit->completionObject(); // Connect to the return pressed signal - optional connect(edit,SIGNAL(returnPressed(const QString&)),comp,SLOT(addItem(const QString&));
To use a customized completion objects or your own completion object :
KLineEdit *edit = new KLineEdit( this,"mywidget" ); KURLCompletion *comp = new KURLCompletion(); edit->setCompletionObject( comp ); // Connect to the return pressed signal - optional connect(edit,SIGNAL(returnPressed(const QString&)),comp,SLOT(addItem(const QString&));
Other miscelanous function call examples :
// Tell the widget not to handle completion and // rotation internally. edit->setHandleSignals( false ); // Set your own completion key for manual completions. edit->setCompletionKey( Qt::End ); // Shows the context (popup) menu edit->setEnableContextMenu(); // Temporarly disable signal emition edit->disableSignals(); // Default the key-bindings to system settings. edit->useGlobalSettings();
|
Constructs a KLineEdit object with a default text, a parent, and a name.
Parameters:
string | text to be shown in the edit widget |
parent | the parent object of this widget |
name | the name of this widget |
hsig | determines if this widget automatically handles both signals internally. |
|
Constructs a KLineEdit object with a parent and a name.
Parameters:
string | text to be shown in the edit widget |
parent | the parent object of this widget |
name | the name of this widget |
hsig | determines if this widget automatically handles both signals internally. |
~ |
[virtual]
Destructor.
void |
Puts cursor at the end of the string.
This method is deprecated. Use QLineEdit::end instead.
void |
[virtual]
Re-implemented from KCompletionBase for internal reasons.
This function is re-implemented in order to make sure that the EchoMode is acceptable before we set the completion mode.
See KCompletionBase::setCompletionMode
Reimplemented from KCompletionBase
void |
[virtual]
Enables/disables the popup (context) menu.
This method also allows you to enable/disable the context menu. If this method is invoked without an argument, the context menu will be enabled. By default the mode changer is visible when context menu is enabled. Use either the second boolean parameter or hideModechanger() if you do not want this item to be visible. Also by default, the context menu is created if this widget is editable. Call this function with the argument set to false to disable the popup menu.
Parameters:
showMenu | if true, show the context menu. |
showMode | if true, show the mode changer item. |
bool |
[const]
Returns true when the context menu is enabled.
Returns: true
if context menu is enabled.
void |
[signal]
This signal is emitted when the user presses the return key. The argument is the current text. Note that this signal is NOT emitted if the widget's EchoMode is set to QLineEdit::Password.
Reimplemented from QLineEdit
void |
[signal]
Signal emitted when the completion key is pressed.
Please note that this signal is NOT emitted if the completion mode is set to CompletionNone or EchoMode is NOT normal.
void |
[signal]
Signal emitted when the rotate up key is pressed. See KCompletionBase::setRotateUpKey.
Note that this signal is NOT emitted if the completion mode is set to CompletionNone or EchoMode is NOT normal.
void |
[signal]
Signal emitted when the rotate down key is pressed. See KCompletionBase::setRotateDownKey.
Note that this signal is NOT emitted if the completion mode is set to CompletionNone or EchoMode is NOT normal.
void |
[protected virtual slot]
Accepts the "aboutToShow" signal from the completion sub-menu inserted by showCompletionMenu.
This method sets the completion mode to the one requested by the end user.
void |
[protected virtual slot]
Populates the sub menu before it is displayed.
All the items are inserted by the completion base class. See @KCompletionBase::insertCompletionItems. The items then invoke the slot giiven by the
void |
[protected virtual slot]
Inserts the completion menu item as needed.
Since this widget comes with its own pop-up menu this slot is needed to invoke the method need to insert the completion menu. This method, KCompletionBase::insetCompeltionMenu, is defined by the KCompletionBase.
void |
[protected virtual slot]
Completes the remaining text with a matching one from a given list.
void |
[protected virtual]
Initializes variables. Called from the constructors.
void |
[protected]
Rotates the text on rotation events.
Parameters:
string | the text to replace the current one with. |
void |
[protected const virtual]
Implementation of KCompletionBase::connectSignals().
This function simply connects the signals to appropriate slots when they are handled internally.
Parameters:
handle | if true, handle completion & roation internally. |
Reimplemented from KCompletionBase
void |
[protected virtual]
Re-implemented for internal reasons. API not affected.
Reimplemented from QLineEdit
void |
[protected virtual]
Re-implemented for internal reasons. API not affected.
See QLineEdit::mousePressEvent.
Reimplemented from QLineEdit