void KHistoryComboBox::addToHistory( const QString& item ) { if ( item.isEmpty() || (count() > 0 && item == itemText(0) )) { return; } bool wasCurrent = false; // remove all existing items before adding if ( !duplicatesEnabled() ) { int i = 0; int itemCount = count(); while ( i < itemCount ) { if ( itemText( i ) == item ) { if ( !wasCurrent ) wasCurrent = ( i == currentIndex() ); removeItem( i ); --itemCount; } else { ++i; } } } // now add the item if ( d->myPixProvider ) insertItem( 0, d->myPixProvider->pixmapFor(item, iconSize().height()), item); else insertItem( 0, item ); if ( wasCurrent ) setCurrentIndex( 0 ); const bool useComp = useCompletion(); const int last = count() - 1; // last valid index const int mc = maxCount(); const int stopAt = qMax(mc, 0); for (int rmIndex = last; rmIndex >= stopAt; --rmIndex) { // 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. const QString rmItem = itemText( rmIndex ); removeItem( rmIndex ); if ( useComp && !contains( rmItem ) ) completionObject()->removeItem( rmItem ); } if ( useComp ) completionObject()->addItem( item ); }
void KHistoryComboBox::init( bool useCompletion ) { // Set a default history size to something reasonable, Qt sets it to INT_MAX by default setMaxCount( 50 ); if ( useCompletion ) completionObject()->setOrder( KCompletion::Weighted ); setInsertPolicy( NoInsert ); d->myIterateIndex = -1; d->myRotated = false; d->myPixProvider = 0L; // obey HISTCONTROL setting QByteArray histControl = qgetenv("HISTCONTROL"); if ( histControl == "ignoredups" || histControl == "ignoreboth" ) setDuplicatesEnabled( false ); connect(this, SIGNAL(aboutToShowContextMenu(QMenu*)), SLOT(addContextMenuItems(QMenu*))); connect(this, SIGNAL(activated(int)), SLOT(slotReset())); connect(this, SIGNAL(returnPressed(QString)), SLOT(slotReset())); // We want slotSimulateActivated to be called _after_ QComboBoxPrivate::_q_returnPressed // otherwise there's a risk of emitting activated twice (slotSimulateActivated will find // the item, after some app's slotActivated inserted the item into the combo). connect(this, SIGNAL(returnPressed(QString)), SLOT(slotSimulateActivated(QString)), Qt::QueuedConnection); }
bool KHistoryComboBox::removeFromHistory( const QString& item ) { if ( item.isEmpty() ) return false; bool removed = false; const QString temp = currentText(); int i = 0; int itemCount = count(); while ( i < itemCount ) { if ( item == itemText( i ) ) { removed = true; removeItem( i ); --itemCount; } else { ++i; } } if ( removed && useCompletion() ) completionObject()->removeItem( item ); setEditText( temp ); return removed; }
void KHistoryComboBox::setHistoryItems( const QStringList &items, bool setCompletionList ) { QStringList insertingItems = items; KComboBox::clear(); // limit to maxCount() const int itemCount = insertingItems.count(); const int toRemove = itemCount - maxCount(); if (toRemove >= itemCount) { insertingItems.clear(); } else { for (int i = 0; i < toRemove; ++i) insertingItems.pop_front(); } insertItems( insertingItems ); if ( setCompletionList && useCompletion() ) { // we don't have any weighting information here ;( KCompletion *comp = completionObject(); comp->setOrder( KCompletion::Insertion ); comp->setItems( insertingItems ); comp->setOrder( KCompletion::Weighted ); } clearEditText(); }
void IngredientComboBox::reload() { QString remember_text; if ( isEditable() ) remember_text = lineEdit()->text(); ElementList ingredientList; database->loadIngredients( &ingredientList ); clear(); ingredientComboRows.clear(); int row = 0; if ( !m_specialItem.isEmpty() ) { insertItem( count(), m_specialItem ); ingredientComboRows.insert( row, -1 ); row++; } for ( ElementList::const_iterator it = ingredientList.constBegin(); it != ingredientList.constEnd(); ++it, ++row ) { insertItem( count(), (*it).name ); completionObject()->addItem((*it).name); ingredientComboRows.insert( row, (*it).id ); } if ( isEditable() ) setEditText( remember_text ); database->disconnect( this ); connect( database, SIGNAL( ingredientCreated( const Element & ) ), SLOT( createIngredient( const Element & ) ) ); connect( database, SIGNAL( ingredientRemoved( int ) ), SLOT( removeIngredient( int ) ) ); }
void IngredientComboBox::removeIngredient( int id ) { int row = -1; for ( QMap<int, int>::iterator it = ingredientComboRows.begin(); it != ingredientComboRows.end(); ++it ) { if ( it.value() == id ) { row = it.key(); completionObject()->removeItem( itemText(row) ); removeItem( row ); ingredientComboRows.erase( it ); break; } } if ( row == -1 ) return ; //now update the map by pushing everything after this item up QMap<int, int> new_map; for ( QMap<int, int>::iterator it = ingredientComboRows.begin(); it != ingredientComboRows.end(); ++it ) { if ( it.key() > row ) { new_map.insert( it.key() - 1, it.value() ); } else new_map.insert( it.key(), it.value() ); } ingredientComboRows = new_map; }
void IngredientComboBox::createIngredient( const Element &element ) { int row = findInsertionPoint( element.name ); QString remember_text; if ( isEditable() ) remember_text = lineEdit()->text(); insertItem( row, element.name ); completionObject()->addItem(element.name); if ( isEditable() ) lineEdit()->setText( remember_text ); //now update the map by pushing everything after this item down QMap<int, int> new_map; for ( QMap<int, int>::iterator it = ingredientComboRows.begin(); it != ingredientComboRows.end(); ++it ) { if ( it.key() >= row ) { new_map.insert( it.key() + 1, it.value() ); } else new_map.insert( it.key(), it.value() ); } ingredientComboRows = new_map; ingredientComboRows.insert( row, element.id ); }
KreTextEdit::KreTextEdit( QWidget *parent ): KTextEdit( parent )//, KCompletionBase() { KCompletion * comp = completionObject(); //creates the completion object comp->setIgnoreCase( true ); completing = false; QString spellCheckingConfigFileName = KStandardDirs::locateLocal( "config", KCmdLineArgs::aboutData()->appName() + "rc" ); KConfig localConfig( spellCheckingConfigFileName, KConfig::SimpleConfig ); KConfigGroup localGroup( &localConfig, "Spelling" ); //If we don't have our local configuration for spell checking, fall back to //user's global configuration. if ( !localConfig.hasGroup( "Spelling" ) ) { KConfig globalSonnetConfig( KStandardDirs::locateLocal( "config", "sonnetrc" ) ); KConfigGroup globalGroup( &globalSonnetConfig, "Spelling" ); globalGroup.copyTo( &localGroup ); localConfig.sync(); KConfigGroup group( KGlobal::config(), "Spelling" ); globalGroup.copyTo( &group ); } setSpellCheckingConfigFileName( spellCheckingConfigFileName ); if ( localGroup.readEntry( "checkerEnabledByDefault", false ) ) setCheckSpellingEnabled( true ); else setCheckSpellingEnabled( false ); //connect( this, SIGNAL( clicked( int, int ) ), SLOT( haltCompletion() ) ); }
void KHistoryComboBox::clearHistory() { const QString temp = currentText(); KComboBox::clear(); if ( useCompletion() ) completionObject()->clear(); setEditText( temp ); }
void KLSHistoryCombo::loadItems() { clear(); QStringList items = KLSConfig::comboUrlHistory(); bool block = signalsBlocked(); blockSignals( true ); setHistoryItems(items); blockSignals(block); completionObject()->setItems(items); setCompletionMode(KGlobalSettings::completionMode()); }
void IngredientComboBox::loadMore() { if ( loading_at >= ing_count-1 ) { endLoad(); return; } ElementList ingredientList; database->loadIngredients( &ingredientList, load_limit, loading_at ); for ( ElementList::const_iterator it = ingredientList.constBegin(); it != ingredientList.constEnd(); ++it, ++loading_at ) { insertItem( count(), (*it).name ); completionObject()->addItem((*it).name); ingredientComboRows.insert( loading_at, (*it).id ); } }
IngredientComboBox::IngredientComboBox( bool b, QWidget *parent, RecipeDB *db, const QString &specialItem ) : KComboBox( b, parent ), database( db ), loading_at(0), load_timer(new QTimer(this)), m_specialItem(specialItem) { connect( load_timer, SIGNAL(timeout()), SLOT(loadMore()) ); completionObject()->setIgnoreCase(true); }