summaryrefslogtreecommitdiff
path: root/libopie2/qt3/opieui/ocombobox.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/qt3/opieui/ocombobox.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/qt3/opieui/ocombobox.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/libopie2/qt3/opieui/ocombobox.cpp b/libopie2/qt3/opieui/ocombobox.cpp
index a1dd5f5..8dbda8f 100644
--- a/libopie2/qt3/opieui/ocombobox.cpp
+++ b/libopie2/qt3/opieui/ocombobox.cpp
@@ -131,385 +131,388 @@ void OComboBox::setAutoCompletion( bool autocomplete )
{
if ( autocomplete )
{
d->olineEdit->setCompletionMode( OGlobalSettings::CompletionAuto );
setCompletionMode( OGlobalSettings::CompletionAuto );
}
else
{
d->olineEdit->setCompletionMode( OGlobalSettings::completionMode() );
setCompletionMode( OGlobalSettings::completionMode() );
}
}
}
void OComboBox::setContextMenuEnabled( bool showMenu )
{
if( d->olineEdit )
{
d->olineEdit->setContextMenuEnabled( showMenu );
m_bEnableMenu = showMenu;
}
}
/*
void OComboBox::setURLDropsEnabled( bool enable )
{
if ( d->olineEdit )
d->olineEdit->setURLDropsEnabled( enable );
}
bool OComboBox::isURLDropsEnabled() const
{
return d->olineEdit && d->olineEdit->isURLDropsEnabled();
}
*/
void OComboBox::setCompletedText( const QString& text, bool marked )
{
if ( d->olineEdit )
d->olineEdit->setCompletedText( text, marked );
}
void OComboBox::setCompletedText( const QString& text )
{
if ( d->olineEdit )
d->olineEdit->setCompletedText( text );
}
void OComboBox::makeCompletion( const QString& text )
{
if( d->olineEdit )
d->olineEdit->makeCompletion( text );
else // read-only combo completion
{
if( text.isNull() || !listBox() )
return;
int index = listBox()->index( listBox()->findItem( text ) );
if( index >= 0 ) {
setCurrentItem( index );
}
}
}
void OComboBox::rotateText( OCompletionBase::KeyBindingType type )
{
if ( d->olineEdit )
d->olineEdit->rotateText( type );
}
bool OComboBox::eventFilter( QObject* o, QEvent* ev )
{
QLineEdit *edit = lineEdit();
int type = ev->type();
if ( o == edit )
{
//OCursor::autoHideEventFilter( edit, ev );
if ( type == QEvent::KeyPress )
{
QKeyEvent *e = static_cast<QKeyEvent *>( ev );
if ( e->key() == Key_Return || e->key() == Key_Enter)
{
// On Return pressed event, emit both
// returnPressed(const QString&) and returnPressed() signals
emit returnPressed();
emit returnPressed( currentText() );
if ( d->olineEdit && d->olineEdit->completionBox(false) &&
d->olineEdit->completionBox()->isVisible() )
d->olineEdit->completionBox()->hide();
return m_trapReturnKey;
}
}
}
// wheel-scrolling changes the current item
if ( type == QEvent::Wheel ) {
if ( !listBox() || listBox()->isHidden() ) {
QWheelEvent *e = static_cast<QWheelEvent*>( ev );
static const int WHEEL_DELTA = 120;
int skipItems = e->delta() / WHEEL_DELTA;
if ( e->state() & ControlButton ) // fast skipping
skipItems *= 10;
int newItem = currentItem() - skipItems;
if ( newItem < 0 )
newItem = 0;
else if ( newItem >= count() )
newItem = count() -1;
setCurrentItem( newItem );
if ( !text( newItem ).isNull() )
emit activated( text( newItem ) );
emit activated( newItem );
e->accept();
return true;
}
}
return QComboBox::eventFilter( o, ev );
}
void OComboBox::setTrapReturnKey( bool grab )
{
m_trapReturnKey = grab;
}
bool OComboBox::trapReturnKey() const
{
return m_trapReturnKey;
}
/*
void OComboBox::setEditURL( const OURL& url )
{
QComboBox::setEditText( url.prettyURL() );
}
void OComboBox::insertURL( const OURL& url, int index )
{
QComboBox::insertItem( url.prettyURL(), index );
}
void OComboBox::insertURL( const QPixmap& pixmap, const OURL& url, int index )
{
QComboBox::insertItem( pixmap, url.prettyURL(), index );
}
void OComboBox::changeURL( const OURL& url, int index )
{
QComboBox::changeItem( url.prettyURL(), index );
}
void OComboBox::changeURL( const QPixmap& pixmap, const OURL& url, int index )
{
QComboBox::changeItem( pixmap, url.prettyURL(), index );
}
*/
void OComboBox::setCompletedItems( const QStringList& items )
{
if ( d->olineEdit )
d->olineEdit->setCompletedItems( items );
}
OCompletionBox * OComboBox::completionBox( bool create )
{
if ( d->olineEdit )
return d->olineEdit->completionBox( create );
return 0;
}
// QWidget::create() turns off mouse-Tracking which would break auto-hiding
void OComboBox::create( WId id, bool initializeWindow, bool destroyOldWindow )
{
QComboBox::create( id, initializeWindow, destroyOldWindow );
//OCursor::setAutoHideCursor( lineEdit(), true, true );
}
void OComboBox::setLineEdit( OLineEdit *edit )
{
#if QT_VERSION > 290
QComboBox::setLineEdit( edit );
- d->olineEdit = dynamic_cast<OLineEdit*>( edit );
+ if ( !edit->inherits( "OLineEdit" ) )
+ d->olineEdit = 0;
+ else
+ d->olineEdit = static_cast<OLineEdit*>( edit );
setDelegate( d->olineEdit );
// forward some signals. We only emit returnPressed() ourselves.
if ( d->olineEdit ) {
connect( d->olineEdit, SIGNAL( completion( const QString& )),
SIGNAL( completion( const QString& )) );
connect( d->olineEdit, SIGNAL( substringCompletion( const QString& )),
SIGNAL( substringCompletion( const QString& )) );
connect( d->olineEdit,
SIGNAL( textRotation( OCompletionBase::KeyBindingType )),
SIGNAL( textRotation( OCompletionBase::KeyBindingType )) );
connect( d->olineEdit,
SIGNAL( completionModeChanged( OGlobalSettings::Completion )),
SIGNAL( completionModeChanged( OGlobalSettings::Completion)));
connect( d->olineEdit,
SIGNAL( aboutToShowContextMenu( QPopupMenu * )),
SIGNAL( aboutToShowContextMenu( QPopupMenu * )) );
}
#else
#warning OComboBox is not fully functional with Qt2
#endif
}
// Temporary functions until QT3 appears. - Seth Chaiklin 20 may 2001
void OComboBox::deleteWordForward()
{
lineEdit()->cursorWordForward(TRUE);
#if QT_VERSION > 290
if ( lineEdit()->hasSelectedText() )
#else
if ( lineEdit()->hasMarkedText() )
#endif
{
lineEdit()->del();
}
}
void OComboBox::deleteWordBack()
{
lineEdit()->cursorWordBackward(TRUE);
#if QT_VERSION > 290
if ( lineEdit()->hasSelectedText() )
#else
if ( lineEdit()->hasMarkedText() )
#endif
{
lineEdit()->del();
}
}
void OComboBox::setCurrentItem( const QString& item, bool insert, int index )
{
int sel = -1;
for (int i = 0; i < count(); ++i)
if (text(i) == item)
{
sel = i;
break;
}
if (sel == -1 && insert)
{
insertItem(item, index);
if (index >= 0)
sel = index;
else
sel = count() - 1;
}
setCurrentItem(sel);
}
void OComboBox::setCurrentItem(int index)
{
QComboBox::setCurrentItem(index);
}
/*======================================================================================
* OHistoryCombo
*======================================================================================*/
// we are always read-write
OHistoryCombo::OHistoryCombo( QWidget *parent, const char *name )
: OComboBox( true, parent, name )
{
init( true ); // using completion
}
// we are always read-write
OHistoryCombo::OHistoryCombo( bool useCompletion,
QWidget *parent, const char *name )
: OComboBox( true, parent, name )
{
init( useCompletion );
}
void OHistoryCombo::init( bool useCompletion )
{
if ( useCompletion )
completionObject()->setOrder( OCompletion::Weighted );
setInsertionPolicy( NoInsertion );
myIterateIndex = -1;
myRotated = false;
myPixProvider = 0L;
connect( this, SIGNAL(aboutToShowContextMenu(QPopupMenu*)),
SLOT(addContextMenuItems(QPopupMenu*)) );
connect( this, SIGNAL( activated(int) ), SLOT( slotReset() ));
connect( this, SIGNAL( returnPressed(const QString&) ), SLOT(slotReset()));
}
OHistoryCombo::~OHistoryCombo()
{
delete myPixProvider;
}
void OHistoryCombo::setHistoryItems( QStringList items,
bool setCompletionList )
{
OComboBox::clear();
// limit to maxCount()
while ( (int) items.count() > maxCount() && !items.isEmpty() )
items.remove( items.begin() );
insertItems( items );
if ( setCompletionList && useCompletion() ) {
// we don't have any weighting information here ;(
OCompletion *comp = completionObject();
comp->setOrder( OCompletion::Insertion );
comp->setItems( items );
comp->setOrder( OCompletion::Weighted );
}
clearEdit();
}
QStringList OHistoryCombo::historyItems() const
{
QStringList list;
for ( int i = 0; i < count(); i++ )
list.append( text( i ) );
return list;
}
void OHistoryCombo::clearHistory()
{
OComboBox::clear();
if ( useCompletion() )
completionObject()->clear();
}
void OHistoryCombo::addContextMenuItems( QPopupMenu* menu )
{
if ( menu &&!lineEdit()->text().isEmpty())
{
menu->insertSeparator();
menu->insertItem( tr("Empty Contents"), this, SLOT( slotClear()));
}
}
void OHistoryCombo::addToHistory( const QString& item )
{
if ( item.isEmpty() || (count() > 0 && item == text(0) ))
return;
// remove all existing items before adding
if ( !duplicatesEnabled() ) {
for ( int i = 0; i < count(); i++ ) {
if ( text( i ) == item )
removeItem( i );
}
}
// now add the item
if ( myPixProvider )
//insertItem( myPixProvider->pixmapFor(item, KIcon::SizeSmall), item, 0);
insertItem( myPixProvider->pixmapFor(item, 16), item, 0);
else
insertItem( item, 0 );
int last;
QString rmItem;
bool useComp = useCompletion();
while ( count() > maxCount() && count() > 0 ) {
// remove the last item, as long as we are longer than maxCount()
// remove the removed item from the completionObject if it isn't
// anymore available at all in the combobox.