kdeui Library API Documentation

KCompletionBox Class Reference

A little utility class for "completion-widgets", like KLineEdit or KComboBox. A helper widget for "completion-widgets" (KLineEdit, KComboBox)). More...

#include <kcompletionbox.h>

Inheritance diagram for KCompletionBox:

KListBox QListBox List of all members.

Public Slots

QStringList items () const
void insertItems (const QStringList &items, int index=-1)
void setItems (const QStringList &items)
virtual void popup ()
void setTabHandling (bool enable)
bool isTabHandling () const
void setCancelledText (const QString &txt)
QString cancelledText () const
void down ()
void up ()
void pageDown ()
void pageUp ()
void home ()
void end ()
virtual void show ()
virtual void hide ()

Signals

void activated (const QString &)
void userCancelled (const QString &)

Public Member Functions

 KCompletionBox (QWidget *parent, const char *name=0)
 ~KCompletionBox ()
virtual QSize sizeHint () const

Protected Slots

virtual void slotActivated (QListBoxItem *)

Protected Member Functions

QRect calculateGeometry () const
void sizeAndPosition ()
virtual bool eventFilter (QObject *, QEvent *)
virtual void virtual_hook (int id, void *data)

Detailed Description

A little utility class for "completion-widgets", like KLineEdit or KComboBox. A helper widget for "completion-widgets" (KLineEdit, KComboBox)).

KCompletionBox is a listbox, displayed as a rectangle without any window decoration, usually directly under the lineedit or combobox. It is filled with all possible matches for a completion, so the user can select the one he wants.

It is used when KGlobalSettings::Completion == CompletionPopup or CompletionPopupAuto.

Author:
Carsten Pfeiffer <pfeiffer@kde.org>

Definition at line 41 of file kcompletionbox.h.


Constructor & Destructor Documentation

KCompletionBox::KCompletionBox QWidget parent,
const char *  name = 0
 

Constructs a KCompletionBox.

The parent widget is used to give the focus back when pressing the up-button on the very first item.

Definition at line 46 of file kcompletionbox.cpp.

References QListBox::clicked(), QListBox::currentChanged(), KListBox::doubleClicked(), QListBox::setColumnMode(), and slotActivated().

KCompletionBox::~KCompletionBox  ) 
 

Destroys the box.

Definition at line 77 of file kcompletionbox.cpp.


Member Function Documentation

QStringList KCompletionBox::items  )  const [slot]
 

Returns a list of all items currently in the box.

Definition at line 83 of file kcompletionbox.cpp.

References QListBox::count(), and QListBox::text().

void KCompletionBox::insertItems const QStringList items,
int  index = -1
[slot]
 

Inserts items into the box.

Does not clear the items before. index determines at which position items will be inserted. (defaults to appending them at the end)

Definition at line 456 of file kcompletionbox.cpp.

References QListBox::insertStringList().

void KCompletionBox::setItems const QStringList items  )  [slot]
 

Clears the box and inserts items.

Definition at line 465 of file kcompletionbox.cpp.

References QListBox::firstItem(), QListBox::insertItem(), QListBox::insertStringList(), QListBoxItem::next(), and QListBox::triggerUpdate().

void KCompletionBox::popup  )  [virtual, slot]
 

Adjusts the size of the box to fit the width of the parent given in the constructor and pops it up at the most appropriate place, relative to the parent.

Depending on the screensize and the position of the parent, this may be a different place, however the default is to pop it up and the lower left corner of the parent.

Make sure to hide() the box when appropriate.

Definition at line 238 of file kcompletionbox.cpp.

References QListBox::clearSelection(), QListBox::count(), QListBox::ensureCurrentVisible(), QSize::height(), hide(), QListBox::setCurrentItem(), show(), and sizeAndPosition().

void KCompletionBox::setTabHandling bool  enable  )  [slot]
 

Makes this widget (when visible) capture Tab-key events to traverse the items in the dropdown list.

Default off, as it conflicts with the usual behavior of Tab to traverse widgets. It is useful for cases like Konqueror's Location Bar, though.

See also:
isTabHandling

Definition at line 414 of file kcompletionbox.cpp.

bool KCompletionBox::isTabHandling  )  const [slot]
 

Returns:
true if this widget is handling Tab-key events to traverse the items in the dropdown list, otherwise false.
Default is false.

See also:
setTabHandling

Definition at line 419 of file kcompletionbox.cpp.

void KCompletionBox::setCancelledText const QString txt  )  [slot]
 

Sets the text to be emitted if the user chooses not to pick from the available matches.

If the canceled text is not set through this function, the userCancelled signal will not be emitted.

See also:
userCancelled( const QString& )
Parameters:
txt the text to be emitted if the user cancels this box

Definition at line 424 of file kcompletionbox.cpp.

QString KCompletionBox::cancelledText  )  const [slot]
 

Returns:
the text set via setCancelledText() or QString::null.

Definition at line 429 of file kcompletionbox.cpp.

void KCompletionBox::down  )  [slot]
 

Moves the selection one line down or select the first item if nothing is selected yet.

Definition at line 369 of file kcompletionbox.cpp.

References QListBox::count(), QListBox::currentItem(), QListBox::currentText(), QListBox::highlighted(), QListBox::setCurrentItem(), and QListBox::setSelected().

Referenced by eventFilter().

void KCompletionBox::up  )  [slot]
 

Moves the selection one line up or select the first item if nothing is selected yet.

Definition at line 384 of file kcompletionbox.cpp.

References QListBox::currentItem(), and QListBox::setCurrentItem().

Referenced by eventFilter().

void KCompletionBox::pageDown  )  [slot]
 

Moves the selection one page down.

Definition at line 390 of file kcompletionbox.cpp.

References QListBox::count(), QListBox::currentItem(), QListBox::numItemsVisible(), and QListBox::setCurrentItem().

Referenced by eventFilter().

void KCompletionBox::pageUp  )  [slot]
 

Moves the selection one page up.

Definition at line 397 of file kcompletionbox.cpp.

References QListBox::currentItem(), QListBox::numItemsVisible(), and QListBox::setCurrentItem().

Referenced by eventFilter().

void KCompletionBox::home  )  [slot]
 

Moves the selection up to the first item.

Definition at line 404 of file kcompletionbox.cpp.

References QListBox::setCurrentItem().

Referenced by eventFilter().

void KCompletionBox::end  )  [slot]
 

Moves the selection down to the last item.

Definition at line 409 of file kcompletionbox.cpp.

References QListBox::count(), and QListBox::setCurrentItem().

Referenced by eventFilter().

void KCompletionBox::show  )  [virtual, slot]
 

Re-implemented for internal reasons.

API is unaffected.

Definition at line 288 of file kcompletionbox.cpp.

References sizeAndPosition().

Referenced by popup().

void KCompletionBox::hide  )  [virtual, slot]
 

Re-implemented for internal reasons.

API is unaffected.

Definition at line 312 of file kcompletionbox.cpp.

Referenced by eventFilter(), popup(), and slotActivated().

void KCompletionBox::activated const QString  )  [signal]
 

Emitted when an item was selected, contains the text of the selected item.

Referenced by slotActivated().

void KCompletionBox::userCancelled const QString  )  [signal]
 

Emitted whenever the user chooses to ignore the available selections and close the this box.

QRect KCompletionBox::calculateGeometry  )  const [protected]
 

This calculates the size of the dropdown and the relative position of the top left corner with respect to the parent widget.

This matches the geometry and position normally used by K/QComboBox when used with one.

Definition at line 320 of file kcompletionbox.cpp.

References QListBox::count(), QObject::inherits(), QRect::isNull(), QListBox::itemHeight(), QPoint::x(), and QPoint::y().

Referenced by sizeAndPosition().

void KCompletionBox::sizeAndPosition  )  [protected]
 

This properly sizes and positions the listbox.

Definition at line 256 of file kcompletionbox.cpp.

References QRect::bottom(), calculateGeometry(), KGlobalSettings::desktopGeometry(), QRect::right(), QRect::size(), QRect::x(), QPoint::x(), QRect::y(), and QPoint::y().

Referenced by popup(), and show().

bool KCompletionBox::eventFilter QObject ,
QEvent
[protected, virtual]
 

Reimplemented from KListBox to get events from the viewport (to hide this widget on mouse-click, Escape-presses, etc.

Definition at line 101 of file kcompletionbox.cpp.

References QKeyEvent::accept(), down(), end(), hide(), home(), QKeyEvent::key(), pageDown(), pageUp(), QMouseEvent::pos(), QListBox::selectedItem(), QKeyEvent::state(), QEvent::type(), and up().

void KCompletionBox::slotActivated QListBoxItem  )  [protected, virtual, slot]
 

Called when an item was activated.

Emits activated() with the item.

Definition at line 92 of file kcompletionbox.cpp.

References activated(), hide(), and QListBoxItem::text().

Referenced by KCompletionBox().


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for kdeui Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed May 5 07:16:14 2004 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003