Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OHistoryCombo Class Reference

A combobox for offering a history and completion. More...

#include </home/clem/local/src/opie/libopie2/qt3/opieui/ocombobox.h>

Inheritance diagram for OHistoryCombo:

Inheritance graph
[legend]
Collaboration diagram for OHistoryCombo:

Collaboration graph
[legend]
List of all members.

Public Slots

void addToHistory (const QString &item)
void clearHistory ()

Signals

void cleared ()

Public Member Functions

 OHistoryCombo (QWidget *parent=0L, const char *name=0L)
 OHistoryCombo (bool useCompletion, QWidget *parent=0L, const char *name=0L)
 ~OHistoryCombo ()
void setHistoryItems (QStringList items)
void setHistoryItems (QStringList items, bool setCompletionList)
QStringList historyItems () const
bool removeFromHistory (const QString &item)
void setPixmapProvider (OPixmapProvider *prov)
OPixmapProvider * pixmapProvider () const
void reset ()

Protected Member Functions

virtual void keyPressEvent (QKeyEvent *)
void insertItems (const QStringList &items)
bool useCompletion () const

Properties

QStringList historyItems

Private Slots

void slotReset ()
void slotClear ()
void addContextMenuItems (QPopupMenu *)

Private Member Functions

void init (bool useCompletion)

Private Attributes

int myIterateIndex
QString myText
bool myRotated
OPixmapProvider * myPixProvider
OHistoryComboPrivate * d

Detailed Description

A combobox for offering a history and completion.

A combobox which implements a history like a unix shell. You can navigate through all the items by using the Up or Down arrows (configurable of course). Additionally, weighted completion is available. So you should load and save the completion list to preserve the weighting between sessions.

Author:
Carsten Pfeiffer <pfeiffer@kde.org>

Definition at line 552 of file ocombobox.h.


Constructor & Destructor Documentation

OHistoryCombo::OHistoryCombo QWidget *  parent = 0L,
const char *  name = 0L
 

Constructs a "read-write" combobox. A read-only history combobox doesn't make much sense, so it is only available as read-write. Completion will be used automatically for the items in the combo.

The insertion-policy is set to NoInsertion, you have to add the items yourself via the slot addToHistory. If you want every item added, use

 connect( combo, SIGNAL( activated( const QString& )),
          combo, SLOT( addToHistory( const QString& )));
 

Use QComboBox::setMaxCount() to limit the history.

parent the parent object of this widget. name the name of this widget.

Definition at line 409 of file ocombobox.cpp.

References OComboBox::init().

OHistoryCombo::OHistoryCombo bool  useCompletion,
QWidget *  parent = 0L,
const char *  name = 0L
 

Same as the previous constructor, but additionally has the option to specify whether you want to let OHistoryCombo handle completion or not. If set to true, OHistoryCombo will sync the completion to the contents of the combobox.

Definition at line 416 of file ocombobox.cpp.

References OComboBox::init().

OHistoryCombo::~OHistoryCombo  ) 
 

Destructs the combo, the completion-object and the pixmap-provider

Definition at line 439 of file ocombobox.cpp.

References myPixProvider.


Member Function Documentation

void OHistoryCombo::addContextMenuItems QPopupMenu *   )  [private, slot]
 

Appends our own context menu entry.

Definition at line 482 of file ocombobox.cpp.

References slotClear(), text, and tr.

Referenced by init().

void OHistoryCombo::addToHistory const QString item  )  [slot]
 

Adds an item to the end of the history list and to the completion list. If maxCount() is reached, the first item of the list will be removed.

If the last inserted item is the same as item, it will not be inserted again.

If duplicatesEnabled() is false, any equal existing item will be removed before item is added.

Note: By using this method and not the Q and OComboBox insertItem() methods, you make sure that the combobox stays in sync with the completion. It would be annoying if completion would give an item not in the combobox, and vice versa.

See also:
removeFromHistory

QComboBox::setDuplicatesEnabled

Definition at line 491 of file ocombobox.cpp.

References OCompletionBase::completionObject(), OComboBox::contains(), i, QString::isEmpty(), myPixProvider, text, and useCompletion().

void OHistoryCombo::cleared  )  [signal]
 

Emitted when the history was cleared by the entry in the popup menu.

Referenced by slotClear().

void OHistoryCombo::clearHistory  )  [slot]
 

Clears the history and the completion list.

Definition at line 475 of file ocombobox.cpp.

References OCompletionBase::completionObject(), and useCompletion().

Referenced by slotClear().

QStringList OHistoryCombo::historyItems  )  const
 

Returns the list of history items. Empty, when this is not a read-write combobox.

See also:
setHistoryItems

Referenced by setPixmapProvider().

void OHistoryCombo::init bool  useCompletion  )  [private]
 

Definition at line 423 of file ocombobox.cpp.

References OComboBox::aboutToShowContextMenu(), addContextMenuItems(), OCompletionBase::completionObject(), myIterateIndex, myPixProvider, myRotated, OComboBox::returnPressed(), slotReset(), and OCompletion::Weighted.

void OHistoryCombo::insertItems const QStringList items  )  [protected]
 

Inserts items into the combo, honouring pixmapProvider() Does not update the completionObject.

Note: duplicatesEnabled() is not honored here.

Called from setHistoryItems() and setPixmapProvider()

Definition at line 647 of file ocombobox.cpp.

References QValueList< T >::begin(), QValueList< T >::end(), QString::isEmpty(), and myPixProvider.

Referenced by setHistoryItems(), and setPixmapProvider().

void OHistoryCombo::keyPressEvent QKeyEvent *   )  [protected, virtual]
 

Handling key-events, the shortcuts to rotate the items.

Definition at line 551 of file ocombobox.cpp.

References Qt::Key_Down, Qt::Key_Up, myIterateIndex, myRotated, myText, qDebug(), and text.

OPixmapProvider* OHistoryCombo::pixmapProvider  )  const [inline]
 

Returns:
the current pixmap provider.
See also:
setPixmapProvider

OPixmapProvider

Definition at line 683 of file ocombobox.h.

References myPixProvider.

bool OHistoryCombo::removeFromHistory const QString item  ) 
 

Removes all items named item.

Returns:
true if at least one item was removed.
See also:
addToHistory

Definition at line 530 of file ocombobox.cpp.

References OCompletionBase::completionObject(), i, text, and useCompletion().

void OHistoryCombo::reset  )  [inline]
 

Resets the current position of the up/down history. Call this when you manually call setCurrentItem() or clearEdit().

Definition at line 689 of file ocombobox.h.

References slotReset().

void OHistoryCombo::setHistoryItems QStringList  items,
bool  setCompletionList
 

Inserts items into the combobox. items might get truncated if it is longer than maxCount()

Set setCompletionList to true, if you don't have a list of completions. This tells OHistoryCombo to use all the items for the completion object as well. You won't have the benefit of weighted completion though, so normally you should do something like

 OConfig *config = kapp->config();
 QStringList list;

 // load the history and completion list after creating the history combo
 list = config->readListEntry( "Completion list" );
 combo->completionObject()->setItems( list );
 list = config->readListEntry( "History list" );
 combo->setHistoryItems( list );

 [...]

 // save the history and completion list when the history combo is
 // destroyed
 list = combo->completionObject()->items()
 config->writeEntry( "Completion list", list );
 list = combo->historyItems();
 config->writeEntry( "History list", list );
 

Be sure to use different names for saving with OConfig if you have more than one OHistoryCombo.

Note: When setCompletionList is true, the items are inserted into the OCompletion object with mode OCompletion::Insertion and the mode is set to OCompletion::Weighted afterwards.

See also:
historyItems

OComboBox::completionObject

OCompletion::setItems

OCompletion::items

Definition at line 444 of file ocombobox.cpp.

References QValueList< T >::begin(), OCompletionBase::completionObject(), QValueList< T >::count(), OCompletion::Insertion, insertItems(), QValueList< T >::isEmpty(), QValueList< T >::remove(), OCompletion::setItems(), OCompletion::setOrder(), useCompletion(), and OCompletion::Weighted.

void OHistoryCombo::setHistoryItems QStringList  items  )  [inline]
 

Inserts items into the combobox. items might get truncated if it is longer than maxCount()

See also:
historyItems

Definition at line 600 of file ocombobox.h.

void OHistoryCombo::setPixmapProvider OPixmapProvider *  prov  ) 
 

Sets a pixmap provider, so that items in the combobox can have a pixmap. OPixmapProvider is just an abstract class with the one pure virtual method OPixmapProvider::pixmapFor(). This method is called whenever an item is added to the OHistoryComboBox. Implement it to return your own custom pixmaps, or use the OURLPixmapProvider from libkio, which uses OMimeType::pixmapForURL to resolve icons.

Set prov to 0L if you want to disable pixmaps. Default no pixmaps.

See also:
pixmapProvider

Definition at line 629 of file ocombobox.cpp.

References historyItems(), insertItems(), items, and myPixProvider.

void OHistoryCombo::slotClear  )  [private, slot]
 

Called from the popupmenu, calls clearHistory() and emits cleared()

Definition at line 664 of file ocombobox.cpp.

References cleared(), and clearHistory().

Referenced by addContextMenuItems().

void OHistoryCombo::slotReset  )  [private, slot]
 

Resets the iterate index to -1

Definition at line 622 of file ocombobox.cpp.

References myIterateIndex, and myRotated.

Referenced by init(), and reset().

bool OHistoryCombo::useCompletion  )  const [inline, protected]
 

Returns:
if we can modify the completion object or not.

Definition at line 744 of file ocombobox.h.

References OCompletionBase::compObj().

Referenced by addToHistory(), clearHistory(), removeFromHistory(), and setHistoryItems().


Member Data Documentation

OHistoryComboPrivate* OHistoryCombo::d [private]
 

Reimplemented from OComboBox.

Definition at line 784 of file ocombobox.h.

int OHistoryCombo::myIterateIndex [private]
 

The current position (index) in the combobox, used for Up and Down

Definition at line 769 of file ocombobox.h.

Referenced by init(), keyPressEvent(), and slotReset().

OPixmapProvider* OHistoryCombo::myPixProvider [private]
 

Definition at line 781 of file ocombobox.h.

Referenced by addToHistory(), init(), insertItems(), pixmapProvider(), setPixmapProvider(), and ~OHistoryCombo().

bool OHistoryCombo::myRotated [private]
 

Indicates that the user at least once rotated Up through the entire list Needed to allow going back after rotation.

Definition at line 780 of file ocombobox.h.

Referenced by init(), keyPressEvent(), and slotReset().

QString OHistoryCombo::myText [private]
 

The text typed before Up or Down was pressed.

Definition at line 774 of file ocombobox.h.

Referenced by keyPressEvent().


Property Documentation

QStringList OHistoryCombo::historyItems [read, write]
 

Definition at line 554 of file ocombobox.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 5 17:42:45 2005 for OPIE by  doxygen 1.4.2