[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Completion in edit widgets (was KCompletion )
From:       Dawit Alemayehu <adawit () earthlink ! net>
Date:       2000-01-01 22:02:49
[Download RAW message or body]

On Mon, 27 Dec 1999, Carsten Pfeiffer wrote:
> Hi,
>
> I wrote a generic class KCompletion, which makes this possible.
> You have to supply completable words to it and then ask it whether some
> string (the user just typed) matches something. KCompletion then returns a
> completion of that string, if available.
> 
> There are three completion-modes:
>  - Auto-completion as used in minicli just searches for the first matching
>    item in the list of completable strings and returns the complete match.
>    This happens automatically, while the user is typing
> 
>  - Manual-completion does the same, it's just not automatic, the user has
>    to press a shortcut to invoke the completion.
> 
>  - Shell-completion does only return a complete match, when it is not
>    ambiguous. If there is more than one matching completion, it just
>    returns the longest possible string all matches begin with.
>    I.e. when you have the strings kdecore and kdeui, and you would
>    complete "k", shell-completion would return you "kde".
> 
> When there are multiple matches, you can rotate forwards and backwards
> through them.
> 
> Now if nobody objects, I'll put KCompletion into kdecore, Dawit will put
> his widgets into kdeui. I think the new KURLCompletion would go into kio,
> as it depends on that.

Hello everyone,

Based on Carsten Pfeiffer's excellent work, KCompletion,  I have re-written the
KLineEdit widget to allow the completion types described above.  I am also in
the process of creating a KComboBox with similar features (minus the rotation
since a combo-box has its own list box).  These classes will allow you to offer
the auto-completion feature with very minimal, if any, changes and can be used
as a drop in replacement for their Qt counter parts.

Now to the topic at hand.  In order to make completion a globally configurable
feature these classes rely on KGlobal.  However,  I needed to modify a couple
of classes so that the user can really configure these new features.  I need to
modify are KStdAccel which would gain four more static methods, three of which
simply return the key-bindings for completion and rotation while the fourth one
is a generic method that compares keys from a key event with an integer value
and return if they are equal.    Since I cannot access CVS to generate a diff,
( traceroute dies the same place reported by someone else on this list ), I
have provided the code snippet below:

bool KStdAccel::isEqual( QKeyEvent* ev, int skey )
{
    int key;
    switch ( ev->state() )
    {
        case Qt::AltButton:
            key = ev->key() + Qt::ALT;
            break;
        case Qt::ControlButton:
            key = ev->key() + Qt::CTRL;
            break;
        case Qt::ShiftButton:
            key = ev->key() + Qt::SHIFT;
            break;
        case (Qt::AltButton | Qt::ControlButton):
            key = ev->key() + Qt::ALT + Qt::CTRL;
            break;
        case (Qt::AltButton | Qt::ShiftButton):
            key = ev->key() + Qt::ALT + Qt::SHIFT;
            break;
        case (Qt::ControlButton | Qt::ShiftButton):
            key = ev->key() + Qt::CTRL + Qt::SHIFT;
            break;
        default:
            key = ev->key();
    }
    return (key == skey);
}

uint KStdAccel::completion()
{
  return readKey(KAccel::TextCompletion, Qt::CTRL+Qt::Key_End);
}

uint KStdAccel::rotateUp()
{
  return readKey(KAccel::RotateUpInList, Qt::Key_Up);
}

uint KStdAccel::rotateDown()
{
  return readKey(KAccel::RotateDownInList, Qt::Key_Down);
}

Additionally, the three constants in the above code also need to be added to
KAccel's StdAccel enumerator and there will be entries added to the standard
key configurations dialog in the control panel to allow the user to configure
these values...

If no one objects, I would like to submit these modifications after which I can
commit the changes to KLineEdit.

Regards,
Dawit A.

P.S.    There is one extra completion mode that is available in the widgets that
was not mentioned by Carsten above since it does not apply there.  This feature
is CompletionNone to turn completion off.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic