void KOEditorAttachments::slotRemove() { QList<Q3IconViewItem *> toDelete; for ( Q3IconViewItem *it = mAttachments->firstItem(); it; it = it->nextItem() ) { if ( it->isSelected() ) { AttachmentIconItem *item = static_cast<AttachmentIconItem *>( it ); if ( !item ) { continue; } if ( KMessageBox::questionYesNo( this, i18nc( "@info", "Do you really want to remove the attachment labeled \"%1\"?", item->label() ), i18nc( "@title:window", "Remove Attachment?" ) ) == KMessageBox::Yes ) { toDelete.append( it ); } } } for ( QList<Q3IconViewItem *>::ConstIterator it = toDelete.constBegin(); it != toDelete.constEnd(); ++it ) { delete *it; } }
virtual Q3DragObject *dragObject () { int count = 0; for ( Q3IconViewItem *it = firstItem(); it; it = it->nextItem() ) { if ( it->isSelected() ) { ++count; } } QPixmap pixmap; if ( count > 1 ) { pixmap = KIconLoader::global()->loadIcon( "mail-attachment", KIconLoader::Desktop ); } if ( pixmap.isNull() ) { pixmap = static_cast<AttachmentIconItem *>( currentItem() )->icon(); } QPoint hotspot( pixmap.width() / 2, pixmap.height() / 2 ); QDrag *drag = new QDrag( this ); drag->setMimeData( mimeData() ); drag->setPixmap( pixmap ); drag->setHotSpot( hotspot ); drag->exec( Qt::CopyAction ); return 0; }
QMimeData *mimeData() { // create a list of the URL:s that we want to drag KUrl::List urls; QStringList labels; for ( Q3IconViewItem *it = firstItem(); it; it = it->nextItem() ) { if ( it->isSelected() ) { AttachmentIconItem *item = static_cast<AttachmentIconItem *>( it ); if ( item->isBinary() ) { urls.append( tempFileForAttachment( item->attachment() ) ); } else { urls.append( item->uri() ); } labels.append( KUrl::toPercentEncoding( item->label() ) ); } } if ( selectionMode() == Q3IconView::NoSelection ) { AttachmentIconItem *item = static_cast<AttachmentIconItem *>( currentItem() ); if ( item ) { urls.append( item->uri() ); labels.append( KUrl::toPercentEncoding( item->label() ) ); } } QMap<QString, QString> metadata; metadata["labels"] = labels.join( ":" ); QMimeData *mimeData = new QMimeData; urls.populateMimeData( mimeData, metadata ); return mimeData; }
void KOEditorAttachments::slotShow() { for ( Q3IconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) { if ( item->isSelected() ) { showAttachment( item ); } } }
static Q3IconViewItem *findIVItem(Q3IconView *iconView, int child) { int id = 1; Q3IconViewItem *item = iconView->firstItem(); while (item && id < child) { item = item->nextItem(); ++id; } return item; }
void KOEditorAttachments::selectionChanged() { bool selected = false; for ( Q3IconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) { if ( item->isSelected() ) { selected = true; break; } } mRemoveBtn->setEnabled( selected ); }
/*! \internal */ bool QAccessibleIconView::setSelected(int child, bool on, bool extend) { if (!child || (extend && iconView()->selectionMode() != Q3IconView::Extended && iconView()->selectionMode() != Q3IconView::Multi)) return false; Q3IconViewItem *item = findIVItem(iconView(), child); if (!item) return false; if (!extend) { iconView()->setSelected(item, on, true); } else { Q3IconViewItem *current = iconView()->currentItem(); if (!current) return false; bool down = false; Q3IconViewItem *temp = current; while ((temp = temp->nextItem())) { if (temp == item) { down = true; break; } } temp = current; if (down) { while ((temp = temp->nextItem())) { iconView()->setSelected(temp, on, true); if (temp == item) break; } } else { while ((temp = temp->prevItem())) { iconView()->setSelected(temp, on, true); if (temp == item) break; } } } return true; }
void KOEditorAttachments::fillIncidence( KCal::Incidence *i ) { i->clearAttachments(); Q3IconViewItem *item; AttachmentIconItem *attitem; for ( item = mAttachments->firstItem(); item; item = item->nextItem() ) { attitem = static_cast<AttachmentIconItem*>(item); if ( attitem ) { i->addAttachment( new KCal::Attachment( *( attitem->attachment() ) ) ); } } }
void KOEditorAttachments::slotEdit() { for ( Q3IconViewItem *item = mAttachments->firstItem(); item; item = item->nextItem() ) { if ( item->isSelected() ) { AttachmentIconItem *attitem = static_cast<AttachmentIconItem*>( item ); if ( !attitem || !attitem->attachment() ) { return; } AttachmentEditDialog *dialog = new AttachmentEditDialog( attitem, mAttachments, false ); dialog->setModal( false ); connect( dialog, SIGNAL(hidden()), dialog, SLOT(delayedDestruct()) ); dialog->show(); } } }
/*! \internal */ QVector<int> QAccessibleIconView::selection() const { QVector<int> array; uint size = 0; int id = 1; array.resize(iconView()->count()); Q3IconViewItem *item = iconView()->firstItem(); while (item) { if (item->isSelected()) { ++size; array[(int)size-1] = id; } item = item->nextItem(); ++id; } array.resize(size); return array; }
/****************************************************************************** * Public Slots * *****************************************************************************/ void K3IconViewSearchLine::updateSearch( const QString &s ) { Q3IconView *iv = d->iconView; if( ! iv ) return; // disabled QString search = d->search = s.isNull() ? text() : s; QIconViewItemList *hi = &(d->hiddenItems); Q3IconViewItem *currentItem = iv->currentItem(); Q3IconViewItem *item = NULL; // Remove Non-Matching items, add them them to hidden list Q3IconViewItem *i = iv->firstItem(); while ( i != NULL ) { item = i; i = i->nextItem(); // Point to next, otherwise will loose it. if ( ! itemMatches( item, search ) ) { hideItem( item ); if ( item == currentItem ) currentItem = NULL; // It's not in iconView anymore. } } // Add Matching items, remove from hidden list QIconViewItemList::iterator it = hi->begin(); while ( it != hi->end() ) { item = *it; ++it; if ( itemMatches( item, search ) ) showItem( item ); } iv->sort(); if ( currentItem != NULL ) iv->ensureItemVisible( currentItem ); }