SVN commit 629273 by cgilles:
digiKam from trunk : first way to introduce a pop-up menu in Preview mode. This one provide minimum options : back, Forward, Edit, Open With, Assign Tags, Remove Tags, and Assign Rating. More than this can be added later : Delete item and Rotate... CCMAIL: [hidden email] M +22 -10 albumwidgetstack.cpp M +7 -4 albumwidgetstack.h M +7 -4 digikamview.cpp M +266 -4 imagepreviewview.cpp M +12 -5 imagepreviewview.h M +1 -1 imagepreviewwidget.cpp --- trunk/extragear/graphics/digikam/digikam/albumwidgetstack.cpp #629272:629273 @@ -81,6 +81,18 @@ // ----------------------------------------------------------------- + connect(d->imagePreviewView, SIGNAL(signalNextItem()), + this, SIGNAL(signalNextItem())); + + connect(d->imagePreviewView, SIGNAL(signalPrevItem()), + this, SIGNAL(signalPrevItem())); + + connect(d->imagePreviewView, SIGNAL( editImageSignal() ), + this, SIGNAL( editImageSignal() ) ); + + connect(d->imagePreviewView, SIGNAL( signalDeleteItem() ), + this, SIGNAL( signalDeleteItem() ) ); + connect(d->imagePreviewView, SIGNAL( previewLoadedSignal() ), this, SLOT( slotPreviewLoaded() ) ); } @@ -101,24 +113,24 @@ return d->albumIconView; } -ImagePreviewWidget* AlbumWidgetStack::imagePreviewWidget() +void AlbumWidgetStack::setPreviewItem(ImageInfo* info) { - return d->imagePreviewView->imagePreviewWidget(); -} - -void AlbumWidgetStack::setPreviewItem(const KURL& url) -{ - if (url.isEmpty()) + if (!info) { if (previewMode() == MediaPlayerMode) d->mediaPlayerView->setMediaPlayerFromUrl(KURL()); else if (previewMode() == PreviewImageMode) + { + //FIXME + //d->imagePreviewView->setImageInfo(); slotPreviewLoaded(); + //setPreviewMode(AlbumWidgetStack::PreviewAlbumMode); + } } else { AlbumSettings *settings = AlbumSettings::instance(); - QString currentFileExtension = QFileInfo(url.path()).extension(false); + QString currentFileExtension = QFileInfo(info->kurl().path()).extension(false); QString mediaplayerfilter = settings->getMovieFileFilter().lower() + settings->getMovieFileFilter().upper() + settings->getAudioFileFilter().lower() + @@ -126,7 +138,7 @@ if (mediaplayerfilter.contains(currentFileExtension) ) { setPreviewMode(AlbumWidgetStack::MediaPlayerMode); - d->mediaPlayerView->setMediaPlayerFromUrl(url); + d->mediaPlayerView->setMediaPlayerFromUrl(info->kurl()); } else { @@ -134,7 +146,7 @@ if (previewMode() == MediaPlayerMode) setPreviewItem(); - imagePreviewWidget()->setImagePath(url.path()); + d->imagePreviewView->setImageInfo(info); // NOTE: No need to toggle imediatly in PreviewImageMode here, // because we will recieve a signal for that when the image preview will be loaded. --- trunk/extragear/graphics/digikam/digikam/albumwidgetstack.h #629272:629273 @@ -35,6 +35,7 @@ namespace Digikam { +class ImageInfo; class AlbumIconView; class ImagePreviewWidget; class AlbumWidgetStackPriv; @@ -55,20 +56,22 @@ public: - AlbumWidgetStack( QWidget *parent=0 ); + AlbumWidgetStack(QWidget *parent=0); ~AlbumWidgetStack(); - AlbumIconView *albumIconView(); - ImagePreviewWidget *imagePreviewWidget(); + AlbumIconView *albumIconView(); - void setPreviewItem(const KURL& url=QString::null); + void setPreviewItem(ImageInfo* info=0); int previewMode(void); void setPreviewMode(int mode); signals: + void signalNextItem(); + void signalPrevItem(); void backToAlbumSignal(); void editImageSignal(); + void signalDeleteItem(); public slots: --- trunk/extragear/graphics/digikam/digikam/digikamview.cpp #629272:629273 @@ -293,10 +293,10 @@ // -- Preview image widget Connections ------------------------ - connect(d->albumWidgetStack->imagePreviewWidget(), SIGNAL(signalNextItem()), + connect(d->albumWidgetStack, SIGNAL(signalNextItem()), this, SLOT(slotNextItem())); - connect(d->albumWidgetStack->imagePreviewWidget(), SIGNAL(signalPrevItem()), + connect(d->albumWidgetStack, SIGNAL(signalPrevItem()), this, SLOT(slotPrevItem())); connect(d->albumWidgetStack, SIGNAL(backToAlbumSignal()), @@ -305,6 +305,9 @@ connect(d->albumWidgetStack, SIGNAL(editImageSignal()), this, SLOT(slotEditImage())); + connect(d->albumWidgetStack, SIGNAL(signalDeleteItem()), + this, SLOT(slot_imageDelete())); + // -- Selection timer --------------- connect(d->selectionTimer, SIGNAL(timeout()), @@ -644,7 +647,7 @@ d->rightSideBar->takeImageInfoOwnership(true); if (!d->albumWidgetStack->previewMode() == AlbumWidgetStack::PreviewAlbumMode) - d->albumWidgetStack->setPreviewItem(selectedItem->imageInfo()->kurl()); + d->albumWidgetStack->setPreviewItem(selectedItem->imageInfo()); } emit signalImageSelected(list, hasPrev, hasNext); @@ -896,7 +899,7 @@ item = iconItem; } - d->albumWidgetStack->setPreviewItem( item->imageInfo()->kurl() ); + d->albumWidgetStack->setPreviewItem(item->imageInfo()); } else { --- trunk/extragear/graphics/digikam/digikam/imagepreviewview.cpp #629272:629273 @@ -21,15 +21,31 @@ // Qt includes. #include <qstring.h> +#include <qvaluevector.h> +#include <qpainter.h> +#include <qpixmap.h> // KDE includes. #include <kdialogbase.h> #include <klocale.h> +#include <kservice.h> +#include <krun.h> +#include <ktrader.h> +#include <kstandarddirs.h> +#include <kiconloader.h> +#include <kmimetype.h> // Local includes. #include "ddebug.h" +#include "albumdb.h" +#include "albummanager.h" +#include "albumsettings.h" +#include "imageinfo.h" +#include "dpopupmenu.h" +#include "dmetadata.h" +#include "tagspopupmenu.h" #include "themeengine.h" #include "imagepreviewview.h" #include "imagepreviewview.moc" @@ -44,8 +60,13 @@ ImagePreviewViewPriv() { imagePreviewWidget = 0; + imageInfo = 0; } + QPixmap ratingPixmap; + + ImageInfo *imageInfo; + ImagePreviewWidget *imagePreviewWidget; }; @@ -59,6 +80,21 @@ setMargin(0); setLineWidth(1); + // -- Load rating Pixmap ------------------------------------------ + + KGlobal::dirs()->addResourceType("digikam_rating", + KGlobal::dirs()->kde_default("data") + + "digikam/data"); + QString ratingPixPath = KGlobal::dirs()->findResourceDir("digikam_rating", + "rating.png"); + ratingPixPath += "/rating.png"; + d->ratingPixmap = QPixmap(ratingPixPath); + + QPainter painter(&d->ratingPixmap); + painter.fillRect(0, 0, d->ratingPixmap.width(), d->ratingPixmap.height(), + ThemeEngine::instance()->textSpecialRegColor()); + painter.end(); + // ---------------------------------------------------------------- connect(ThemeEngine::instance(), SIGNAL(signalThemeChanged()), @@ -69,6 +105,12 @@ connect(d->imagePreviewWidget, SIGNAL( previewFailed() ), this, SIGNAL( previewLoadedSignal() ) ); + + connect(d->imagePreviewWidget, SIGNAL(signalNextItem()), + this, SIGNAL(signalNextItem())); + + connect(d->imagePreviewWidget, SIGNAL(signalPrevItem()), + this, SIGNAL(signalPrevItem())); } ImagePreviewView::~ImagePreviewView() @@ -76,15 +118,235 @@ delete d; } -ImagePreviewWidget* ImagePreviewView::imagePreviewWidget() +void ImagePreviewView::slotThemeChanged() { - return d->imagePreviewWidget; + setPaletteBackgroundColor(ThemeEngine::instance()->baseColor()); } -void ImagePreviewView::slotThemeChanged() +void ImagePreviewView::setImageInfo(ImageInfo* info) { - setPaletteBackgroundColor(ThemeEngine::instance()->baseColor()); + d->imageInfo = info; + if (d->imageInfo) + d->imagePreviewWidget->setImagePath(info->kurl().path()); + else + d->imagePreviewWidget->setImagePath(); } +void ImagePreviewView::mousePressEvent(QMouseEvent* e) +{ + if (e->button() == Qt::RightButton) + { + QPopupMenu *ratingMenu = 0; + TagsPopupMenu *assignTagsMenu = 0; + TagsPopupMenu *removeTagsMenu = 0; + + if (!d->imageInfo) + return; + + // -------------------------------------------------------- + + KURL url(d->imageInfo->kurl().path()); + KMimeType::Ptr mimePtr = KMimeType::findByURL(url, 0, true, true); + + QValueVector<KService::Ptr> serviceVector; + KTrader::OfferList offers = KTrader::self()->query(mimePtr->name(), "Type == 'Application'"); + + QPopupMenu openWithMenu; + + KTrader::OfferList::Iterator iter; + KService::Ptr ptr; + int index = 100; + + for( iter = offers.begin(); iter != offers.end(); ++iter ) + { + ptr = *iter; + openWithMenu.insertItem( ptr->pixmap(KIcon::Small), ptr->name(), index++); + serviceVector.push_back(ptr); + } + + // -------------------------------------------------------- + + DPopupMenu popmenu(this); + popmenu.insertItem(SmallIcon("back"), i18n("Back"), 10); + popmenu.insertItem(SmallIcon("forward"), i18n("Forward"), 11); + popmenu.insertItem(SmallIcon("editimage"), i18n("Edit..."), 12); + popmenu.insertItem(i18n("Open With"), &openWithMenu, 13); + + /* FIXME + popmenu.insertSeparator(); + popmenu.insertItem(SmallIcon("edittrash"), i18n("Move to Trash"), 14); + */ + + // Bulk assignment/removal of tags -------------------------- + + Q_LLONG id = d->imageInfo->id(); + QValueList<Q_LLONG> idList; + idList.append(id); + + assignTagsMenu = new TagsPopupMenu(idList, 1000, TagsPopupMenu::ASSIGN); + removeTagsMenu = new TagsPopupMenu(idList, 2000, TagsPopupMenu::REMOVE); + + popmenu.insertSeparator(); + + popmenu.insertItem(i18n("Assign Tag"), assignTagsMenu); + int i = popmenu.insertItem(i18n("Remove Tag"), removeTagsMenu); + + connect(assignTagsMenu, SIGNAL(signalTagActivated(int)), + this, SLOT(slotAssignTag(int))); + + connect(removeTagsMenu, SIGNAL(signalTagActivated(int)), + this, SLOT(slotRemoveTag(int))); + + AlbumDB* db = AlbumManager::instance()->albumDB(); + if (!db->hasTags( idList )) + popmenu.setItemEnabled(i, false); + + popmenu.insertSeparator(); + + // Assign Star Rating ------------------------------------------- + + ratingMenu = new QPopupMenu(); + + connect(ratingMenu, SIGNAL(activated(int)), + this, SLOT(slotAssignRating(int))); + + ratingMenu->insertItem(i18n("None"), 0); + + for (int i = 1 ; i <= 5 ; i++) + { + QPixmap pix(d->ratingPixmap.width() * 5, d->ratingPixmap.height()); + pix.fill(ratingMenu->colorGroup().background()); + + QPainter painter(&pix); + painter.drawTiledPixmap(0, 0, + i*d->ratingPixmap.width(), + pix.height(), + d->ratingPixmap); + painter.end(); + ratingMenu->insertItem(pix, i); + } + + popmenu.insertItem(i18n("Assign Rating"), ratingMenu); + + // -------------------------------------------------------- + + int idm = popmenu.exec(e->globalPos()); + + switch(idm) + { + case 10: // Back + { + emit signalPrevItem(); + break; + } + + case 11: // Forward + { + emit signalNextItem(); + break; + } + + case 12: // Edit... + { + emit editImageSignal(); + break; + } + + case 14: // Move to trash + { + emit signalDeleteItem(); + break; + } + + default: + break; + } + + // Open With... + if (idm >= 100 && idm < 1000) + { + KService::Ptr imageServicePtr = serviceVector[idm-100]; + KRun::run(*imageServicePtr, url); + } + + serviceVector.clear(); + delete assignTagsMenu; + delete removeTagsMenu; + delete ratingMenu; + } +} + +void ImagePreviewView::slotAssignTag(int tagID) +{ + if (d->imageInfo) + { + QStringList oldKeywords = d->imageInfo->tagNames(); + + d->imageInfo->setTag(tagID); + + // TODO MetadataHub: fix this part to use it instead. + + // Update Image Tags like Iptc keywords tags. + + if (AlbumSettings::instance()) + { + if (AlbumSettings::instance()->getSaveIptcRating()) + { + DMetadata metadata(d->imageInfo->filePath()); + metadata.setImageKeywords(oldKeywords, d->imageInfo->tagNames()); + metadata.applyChanges(); + } + } + } +} + +void ImagePreviewView::slotRemoveTag(int tagID) +{ + if (d->imageInfo) + { + QStringList oldKeywords = d->imageInfo->tagNames(); + + d->imageInfo->removeTag(tagID); + + // TODO MetadataHub: fix this part to use it instead. + + // Update Image Tags like Iptc keywords tags. + + if (AlbumSettings::instance()) + { + if (AlbumSettings::instance()->getSaveIptcRating()) + { + DMetadata metadata(d->imageInfo->filePath()); + metadata.setImageKeywords(oldKeywords, d->imageInfo->tagNames()); + metadata.applyChanges(); + } + } + } +} + +void ImagePreviewView::slotAssignRating(int rating) +{ + rating = QMIN(5, QMAX(0, rating)); + + if (d->imageInfo) + { + d->imageInfo->setRating(rating); + + // TODO MetadataHub: fix this part to use it instead. + + // Store Image rating as Iptc tag. + + if (AlbumSettings::instance()) + { + if (AlbumSettings::instance()->getSaveIptcRating()) + { + DMetadata metadata(d->imageInfo->filePath()); + metadata.setImageRating(rating); + metadata.applyChanges(); + } + } + } +} + } // NameSpace Digikam --- trunk/extragear/graphics/digikam/digikam/imagepreviewview.h #629272:629273 @@ -44,22 +44,29 @@ ImagePreviewView(QWidget *parent=0); ~ImagePreviewView(); - ImagePreviewWidget* imagePreviewWidget(); + void setImageInfo(ImageInfo* info=0); signals: + void signalNextItem(); + void signalPrevItem(); + void signalDeleteItem(); + void editImageSignal(); void previewLoadedSignal(); -public slots: - -// void slotPreviewFailed(); - private slots: void slotThemeChanged(); + void slotAssignTag(int tagID); + void slotRemoveTag(int tagID); + void slotAssignRating(int rating); private: + void mousePressEvent(QMouseEvent* e); + +private: + ImagePreviewViewPriv* d; }; --- trunk/extragear/graphics/digikam/digikam/imagepreviewwidget.cpp #629272:629273 @@ -76,7 +76,7 @@ setLineWidth(0); // --------------------------------------------------------------- - + connect(ThemeEngine::instance(), SIGNAL(signalThemeChanged()), this, SLOT(slotThemeChanged())); } _______________________________________________ Digikam-devel mailing list [hidden email] https://mail.kde.org/mailman/listinfo/digikam-devel |
Free forum by Nabble | Edit this page |