diff --git a/core/showfoto/main/main.cpp b/core/showfoto/main/main.cpp index b4f755214a..76c0178d91 100644 --- a/core/showfoto/main/main.cpp +++ b/core/showfoto/main/main.cpp @@ -1,137 +1,137 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2004-11-22 * Description : showFoto is a stand alone version of image * editor with no support of digiKam database. * * Copyright (C) 2004-2005 by Renchi Raju * Copyright (C) 2004-2018 by Gilles Caulier * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ // Qt includes #include #include #include #include #include #include // KDE includes #include #include #include #include // Local includes #include "digikam_config.h" #include "digikam_debug.h" #include "digikam_globals.h" #include "digikam_version.h" #include "metaengine.h" #include "daboutdata.h" #include "showfoto.h" using namespace Digikam; int main(int argc, char* argv[]) { QApplication app(argc, argv); tryInitDrMingw(); #ifdef Q_OS_LINUX app.setAttribute(Qt::AA_UseHighDpiPixmaps, true); #endif // if we have some local breeze icon resource, prefer it DXmlGuiWindow::setupIconTheme(); KLocalizedString::setApplicationDomain("digikam"); KAboutData aboutData(QLatin1String("showfoto"), // component name i18n("Showfoto"), // display name digiKamVersion()); // NOTE: showFoto version = digiKam version aboutData.setShortDescription(DAboutData::digiKamSlogan());; aboutData.setLicense(KAboutLicense::GPL); aboutData.setCopyrightStatement(DAboutData::copyright()); aboutData.setOtherText(additionalInformation()); aboutData.setHomepage(DAboutData::webProjectUrl().url()); aboutData.setProductName(QByteArray("digikam/showfoto")); // For bugzilla DAboutData::authorsRegistration(aboutData); QCommandLineParser parser; KAboutData::setApplicationData(aboutData); parser.addVersionOption(); parser.addHelpOption(); aboutData.setupCommandLine(&parser); parser.addPositionalArgument(QLatin1String("files"), i18n("File(s) or folder(s) to open"), QLatin1String("[file(s) or folder(s)]")); parser.process(app); aboutData.processCommandLine(&parser); KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(QLatin1String("ImageViewer Settings")); QString iconTheme = group.readEntry(QLatin1String("Icon Theme"), QString()); MetaEngine::initializeExiv2(); // Force to use application icon for non plasma desktop as Unity for ex. QApplication::setWindowIcon(QIcon::fromTheme(QLatin1String("showfoto"), app.windowIcon())); QList urlList; QStringList urls = parser.positionalArguments(); - foreach(const QString& url, urls) + foreach (const QString& url, urls) { urlList.append(QUrl::fromLocalFile(url)); } parser.clearPositionalArguments(); if (!iconTheme.isEmpty()) { QIcon::setThemeName(iconTheme); } ShowFoto::ShowFoto* const w = new ShowFoto::ShowFoto(urlList); // If application storage place in home directory to save customized XML settings files do not exist, create it, // else QFile will not able to create new files as well. if (!QFile::exists(QStandardPaths::writableLocation(QStandardPaths::DataLocation))) { QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::DataLocation)); } // If application cache place in home directory to save cached files do not exist, create it. if (!QFile::exists(QStandardPaths::writableLocation(QStandardPaths::CacheLocation))) { QDir().mkpath(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)); } w->show(); int ret = app.exec(); MetaEngine::cleanupExiv2(); return ret; } diff --git a/core/showfoto/main/showfoto.cpp b/core/showfoto/main/showfoto.cpp index a2bce93300..d6c857edf5 100644 --- a/core/showfoto/main/showfoto.cpp +++ b/core/showfoto/main/showfoto.cpp @@ -1,858 +1,857 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 2004-11-22 * Description : stand alone digiKam image editor * * Copyright (C) 2004-2018 by Gilles Caulier * Copyright (C) 2006-2012 by Marcel Wiesweg * Copyright (C) 2009-2011 by Andi Clemens * Copyright (C) 2004-2005 by Renchi Raju * Copyright (C) 2005-2006 by Tom Albers * Copyright (C) 2008 by Arnd Baecker * Copyright (C) 2013-2015 by Mohamed_Anwer * * This program is free software; you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation; * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "showfoto.h" #include "showfoto_p.h" namespace ShowFoto { ShowFoto::ShowFoto(const QList& urlList) : Digikam::EditorWindow(QLatin1String("Showfoto")), d(new Private) { setXMLFile(QLatin1String("showfotoui5.rc")); m_nonDestructive = false; // Show splash-screen at start up. KSharedConfig::Ptr config = KSharedConfig::openConfig(); KConfigGroup group = config->group(configGroupName()); if (group.readEntry(QLatin1String("ShowSplash"), true) && !qApp->isSessionRestored()) { d->splash = new Digikam::DSplashScreen(); d->splash->show(); } // Setup loading cache and thumbnails interface. Digikam::LoadingCacheInterface::initialize(); Digikam::MetadataSettings::instance(); d->thumbLoadThread = new Digikam::ThumbnailLoadThread(); d->thumbLoadThread->setThumbnailSize(Digikam::ThumbnailSize::Huge); d->thumbLoadThread->setSendSurrogatePixmap(true); // Check ICC profiles repository availability if (d->splash) { d->splash->setMessage(i18n("Checking ICC repository...")); } d->validIccPath = Digikam::SetupICC::iccRepositoryIsValid(); // Populate Themes if (d->splash) { d->splash->setMessage(i18n("Loading themes...")); } Digikam::ThemeManager::instance(); // -- Build the GUI ----------------------------------- setupUserArea(); setupActions(); setupStatusBar(); createGUI(xmlFile()); cleanupActions(); // Create tool selection view setupSelectToolsAction(); // Create context menu. setupContextMenu(); // Make signals/slots connections setupConnections(); // -- Read settings -------------------------------- readSettings(); applySettings(); setAutoSaveSettings(configGroupName(), true); d->rightSideBar->loadState(); //-------------------------------------------------- d->thumbBarDock->reInitialize(); // -- Load current items --------------------------- slotDroppedUrls(urlList); if (!d->infoList.isEmpty()) { slotOpenUrl(d->thumbBar->currentInfo()); } } ShowFoto::~ShowFoto() { delete m_canvas; m_canvas = 0; Digikam::WSStarter::cleanUp(); Digikam::ThumbnailLoadThread::cleanUp(); Digikam::LoadingCacheInterface::cleanUp(); Digikam::DMediaServerMngr::instance()->saveAtShutdown(); delete d->model; delete d->filterModel; delete d->thumbBar; delete d->rightSideBar; delete d->thumbLoadThread; delete d; } bool ShowFoto::queryClose() { // wait if a save operation is currently running if (!waitForSavingToComplete()) { return false; } if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return false; } saveSettings(); return true; } void ShowFoto::show() { // Remove Splashscreen. if (d->splash) { d->splash->finish(this); delete d->splash; d->splash = 0; } // Display application window. QMainWindow::show(); // Report errors from ICC repository path. KSharedConfig::Ptr config = KSharedConfig::openConfig(); if (!d->validIccPath) { QString message = i18n("

The ICC profile path seems to be invalid.

" "

If you want to set it now, select \"Yes\", otherwise " "select \"No\". In this case, \"Color Management\" feature " "will be disabled until you solve this issue

"); if (QMessageBox::warning(this, qApp->applicationName(), message, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { if (!setup(true)) { KConfigGroup group = config->group(QLatin1String("Color Management")); group.writeEntry(QLatin1String("EnableCM"), false); config->sync(); } } else { KConfigGroup group = config->group(QLatin1String("Color Management")); group.writeEntry(QLatin1String("EnableCM"), false); config->sync(); } } // Start the Media Server if necessary Digikam::DMediaServerMngr::instance()->loadAtStartup(); } void ShowFoto::slotOpenFile() { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return; } QList urls = Digikam::ImageDialog::getImageURLs(this, d->lastOpenedDirectory); openUrls(urls); } void ShowFoto::openUrls(const QList &urls) { if (!urls.isEmpty()) { ShowfotoItemInfoList infos; ShowfotoItemInfo iteminfo; DMetadata meta; for (QList::const_iterator it = urls.constBegin(); it != urls.constEnd(); ++it) { QFileInfo fi((*it).toLocalFile()); iteminfo.name = fi.fileName(); iteminfo.mime = fi.suffix(); iteminfo.size = fi.size(); iteminfo.url = QUrl::fromLocalFile(fi.filePath()); iteminfo.folder = fi.path(); iteminfo.dtime = fi.created(); meta.load(fi.filePath()); iteminfo.ctime = meta.getImageDateTime(); iteminfo.width = meta.getImageDimensions().width(); iteminfo.height = meta.getImageDimensions().height(); iteminfo.photoInfo = meta.getPhotographInformation(); infos.append(iteminfo); } if (d->droppedUrls) { //replace the equal sign with "<<" to keep the previous pics in the list d->infoList << infos; } else { d->infoList = infos; d->model->clearShowfotoItemInfos(); emit signalInfoList(d->infoList); slotOpenUrl(d->thumbBar->currentInfo()); } } } void ShowFoto::slotOpenUrl(const ShowfotoItemInfo& info) { if (d->thumbBar->currentInfo().isNull()) { return; } QString localFile; if (info.url.isLocalFile()) { // file protocol. We do not need the network localFile = info.url.toLocalFile(); } else { QMessageBox::critical(this, i18n("Error Loading File"), i18n("Failed to load file: %1\n" "Remote file handling is not supported", info.url.fileName())); return; } d->currentLoadedUrl = info.url; m_canvas->load(localFile, m_IOFileSettings); //TODO : add preload here like in ImageWindow::slotLoadCurrent() ??? } void ShowFoto::slotShowfotoItemInfoActivated(const ShowfotoItemInfo& info) { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->currentLoadedUrl)) { d->thumbBar->setCurrentUrl(d->currentLoadedUrl); return; } slotOpenUrl(info); } Digikam::ThumbBarDock* ShowFoto::thumbBar() const { return d->thumbBarDock; } Digikam::Sidebar* ShowFoto::rightSideBar() const { return (dynamic_cast(d->rightSideBar)); } void ShowFoto::slotChanged() { QString mpixels; QSize dims(m_canvas->imageWidth(), m_canvas->imageHeight()); mpixels.setNum(dims.width()*dims.height()/1000000.0, 'f', 2); QString str = (!dims.isValid()) ? i18nc("unknown image dimensions", "Unknown") : i18nc("%1 width, %2 height, %3 mpixels", "%1x%2 (%3Mpx)", dims.width(),dims.height(),mpixels); m_resLabel->setAdjustedText(str); if (!d->thumbBar->currentInfo().isNull()) { if (d->thumbBar->currentUrl().isValid()) { QRect sel = m_canvas->getSelectedArea(); Digikam::DImg* const img = m_canvas->interface()->getImg(); d->rightSideBar->itemChanged(d->thumbBar->currentUrl(), sel, img); } } } void ShowFoto::slotUpdateItemInfo() { d->itemsNb = d->thumbBar->showfotoItemInfos().size(); int index = 0; QString text; if (d->itemsNb > 0) { index = 1; for (int i = 0; i < d->itemsNb; i++) { QUrl url = d->thumbBar->showfotoItemInfos().at(i).url; if (url.matches(d->thumbBar->currentUrl(), QUrl::None)) { break; } ++index; } text = i18nc(" ( of )", "%1 (%2 of %3)", d->thumbBar->currentInfo().name, index, d->itemsNb); setCaption(QDir::toNativeSeparators(d->thumbBar->currentUrl().adjusted(QUrl::RemoveFilename).toLocalFile())); } else { text = QLatin1String(""); setCaption(QLatin1String("")); } m_nameLabel->setText(text); toggleNavigation(index); } void ShowFoto::slotOpenFolder(const QUrl& url) { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return; } m_canvas->load(QString(), m_IOFileSettings); d->thumbBar->showfotoItemInfos().clear(); emit signalNoCurrentItem(); openFolder(url); toggleNavigation(1); } void ShowFoto::slotOpenFilesInFolder() { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return; } - QUrl url = QUrl::fromLocalFile(DFileDialog::getExistingDirectory(this, i18n("Open Images From Folder"), - d->lastOpenedDirectory.toLocalFile())); + QUrl url = DFileDialog::getExistingDirectoryUrl(this, i18n("Open Images From Folder"), + d->lastOpenedDirectory); if (!url.isEmpty()) { m_canvas->load(QString(), m_IOFileSettings); d->thumbBar->showfotoItemInfos().clear(); - d->lastOpenedDirectory = url; emit signalNoCurrentItem(); openFolder(url); toggleNavigation(1); } } void ShowFoto::slotFirst() { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return; } d->thumbBar->toFirstIndex(); d->thumbBar->setCurrentInfo(d->thumbBar->showfotoItemInfos().first()); slotOpenUrl(d->thumbBar->showfotoItemInfos().first()); } void ShowFoto::slotLast() { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return; } d->thumbBar->toLastIndex(); d->thumbBar->setCurrentInfo(d->thumbBar->showfotoItemInfos().last()); slotOpenUrl(d->thumbBar->showfotoItemInfos().last()); } void ShowFoto::slotForward() { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return; } bool currentIsNull = d->thumbBar->currentInfo().isNull(); if (!currentIsNull) { d->thumbBar->toNextIndex(); slotOpenUrl(d->thumbBar->currentInfo()); } } void ShowFoto::slotBackward() { if (!d->thumbBar->currentInfo().isNull() && !promptUserSave(d->thumbBar->currentUrl())) { return; } bool currentIsNull = d->thumbBar->currentInfo().isNull(); if (!currentIsNull) { d->thumbBar->toPreviousIndex(); slotOpenUrl(d->thumbBar->currentInfo()); } } void ShowFoto::slotPrepareToLoad() { Digikam::EditorWindow::slotPrepareToLoad(); // Here we enable specific actions on showfoto. d->openFilesInFolderAction->setEnabled(true); d->fileOpenAction->setEnabled(true); } void ShowFoto::slotLoadingStarted(const QString& filename) { Digikam::EditorWindow::slotLoadingStarted(filename); // Here we disable specific actions on showfoto. d->openFilesInFolderAction->setEnabled(false); d->fileOpenAction->setEnabled(false); } void ShowFoto::slotLoadingFinished(const QString& filename, bool success) { Digikam::EditorWindow::slotLoadingFinished(filename, success); // Here we re-enable specific actions on showfoto. d->openFilesInFolderAction->setEnabled(true); d->fileOpenAction->setEnabled(true); } void ShowFoto::slotSavingStarted(const QString& filename) { Digikam::EditorWindow::slotSavingStarted(filename); // Here we disable specific actions on showfoto. d->openFilesInFolderAction->setEnabled(false); d->fileOpenAction->setEnabled(false); } void ShowFoto::moveFile() { /* * moveFile() -> moveLocalFile() -> movingSaveFileFinished() * | | * finishSaving(true) save...IsComplete() */ qCDebug(DIGIKAM_SHOWFOTO_LOG) << m_savingContext.destinationURL << m_savingContext.destinationURL.isLocalFile(); if (m_savingContext.destinationURL.isLocalFile()) { qCDebug(DIGIKAM_SHOWFOTO_LOG) << "moving a local file"; EditorWindow::moveFile(); } else { QMessageBox::critical(this, i18n("Error Saving File"), i18n("Failed to save file: %1", i18n("Remote file handling is not supported"))); } } void ShowFoto::finishSaving(bool success) { Digikam::EditorWindow::finishSaving(success); // Here we re-enable specific actions on showfoto. d->openFilesInFolderAction->setEnabled(true); d->fileOpenAction->setEnabled(true); } void ShowFoto::saveIsComplete() { Digikam::LoadingCacheInterface::putImage(m_savingContext.destinationURL.toLocalFile(), m_canvas->currentImage()); //d->thumbBar->invalidateThumb(d->currentItem); // Pop-up a message to bring user when save is done. Digikam::DNotificationWrapper(QLatin1String("editorsavefilecompleted"), i18n("Image saved successfully"), this, windowTitle()); resetOrigin(); } void ShowFoto::saveAsIsComplete() { resetOriginSwitchFile(); /* Digikam::LoadingCacheInterface::putImage(m_savingContext.destinationURL.toLocalFile(), m_canvas->currentImage()); // Add the file to the list of thumbbar images if it's not there already Digikam::ThumbBarItem* foundItem = d->thumbBar->findItemByUrl(m_savingContext.destinationURL); d->thumbBar->invalidateThumb(foundItem); qCDebug(DIGIKAM_SHOWFOTO_LOG) << wantedUrls; if (!foundItem) { foundItem = new Digikam::ThumbBarItem(d->thumbBar, m_savingContext.destinationURL); } // shortcut slotOpenUrl d->thumbBar->blockSignals(true); d->thumbBar->setSelected(foundItem); d->thumbBar->blockSignals(false); d->currentItem = foundItem; slotUpdateItemInfo(); // Pop-up a message to bring user when save is done. Digikam::DNotificationWrapper("editorsavefilecompleted", i18n("Image saved successfully"), this, windowTitle()); */ } void ShowFoto::saveVersionIsComplete() { } QUrl ShowFoto::saveDestinationUrl() { if (d->thumbBar->currentInfo().isNull()) { qCWarning(DIGIKAM_GENERAL_LOG) << "Cannot return the url of the image to save " << "because no image is selected."; return QUrl(); } return d->thumbBar->currentUrl(); } bool ShowFoto::save() { if (d->thumbBar->currentInfo().isNull()) { qCWarning(DIGIKAM_GENERAL_LOG) << "This should not happen"; return true; } startingSave(d->currentLoadedUrl); return true; } bool ShowFoto::saveAs() { if (d->thumbBar->currentInfo().isNull()) { qCWarning(DIGIKAM_GENERAL_LOG) << "This should not happen"; return false; } return (startingSaveAs(d->currentLoadedUrl)); } void ShowFoto::slotDeleteCurrentItem() { QUrl urlCurrent(d->thumbBar->currentUrl()); QString warnMsg(i18n("About to delete file \"%1\"\nAre you sure?", urlCurrent.fileName())); if (QMessageBox::warning(this, qApp->applicationName(), warnMsg, QMessageBox::Apply | QMessageBox::Abort) != QMessageBox::Apply) { return; } else { bool ret = QFile::remove(urlCurrent.toLocalFile()); if (!ret) { QMessageBox::critical(this, qApp->applicationName(), i18n("Cannot delete \"%1\"", urlCurrent.fileName())); return; } // No error, remove item in thumbbar. d->model->removeIndex(d->thumbBar->currentIndex()); // Disable menu actions and SideBar if no current image. d->itemsNb = d->thumbBar->showfotoItemInfos().size(); if (d->itemsNb == 0) { slotUpdateItemInfo(); toggleActions(false); m_canvas->load(QString(), m_IOFileSettings); } else { // If there is an image after the deleted one, make that selected. slotOpenUrl(d->thumbBar->currentInfo()); } } } void ShowFoto::slotRevert() { if (!promptUserSave(d->thumbBar->currentUrl())) { return; } m_canvas->slotRestore(); } bool ShowFoto::saveNewVersion() { return false; } bool ShowFoto::saveCurrentVersion() { return false; } bool ShowFoto::saveNewVersionAs() { return false; } bool ShowFoto::saveNewVersionInFormat(const QString&) { return false; } void ShowFoto::openFolder(const QUrl& url) { if (!url.isValid() || !url.isLocalFile()) { return; } + d->lastOpenedDirectory = url; + // Parse image IO mime types registration to get files filter pattern. QString filter; QStringList mimeTypes = supportedImageMimeTypes(QIODevice::ReadOnly, filter); QString patterns = filter.toLower(); patterns.append (QLatin1Char(' ')); patterns.append (filter.toUpper()); qCDebug(DIGIKAM_SHOWFOTO_LOG) << "patterns=" << patterns; // Get all image files from directory. QDir dir(url.toLocalFile(), patterns); dir.setFilter(QDir::Files); if (!dir.exists()) { return; } QFileInfoList fileinfolist = dir.entryInfoList(); if (fileinfolist.isEmpty()) { //emit signalSorry(); return; } QFileInfoList::const_iterator fi; ShowfotoItemInfoList infos; ShowfotoItemInfo iteminfo; DMetadata meta; // And open all items in image editor. for (fi = fileinfolist.constBegin(); fi != fileinfolist.constEnd(); ++fi) { iteminfo.name = (*fi).fileName(); iteminfo.mime = (*fi).suffix(); iteminfo.size = (*fi).size(); iteminfo.folder = (*fi).path(); iteminfo.url = QUrl::fromLocalFile((*fi).filePath()); iteminfo.dtime = (*fi).created(); meta.load((*fi).filePath()); iteminfo.ctime = meta.getImageDateTime(); iteminfo.width = meta.getImageDimensions().width(); iteminfo.height = meta.getImageDimensions().height(); iteminfo.photoInfo = meta.getPhotographInformation(); infos.append(iteminfo); } if (d->droppedUrls) { d->infoList << infos; } else { d->infoList = infos; d->model->clearShowfotoItemInfos(); emit signalInfoList(d->infoList); slotOpenUrl(d->thumbBar->currentInfo()); } - - d->lastOpenedDirectory = QUrl::fromLocalFile(dir.absolutePath()); } void ShowFoto::slotDroppedUrls(const QList& droppedUrls) { if (!droppedUrls.isEmpty()) { QList validUrls; foreach (const QUrl& url, droppedUrls) { if (url.isValid()) { validUrls << url; } } d->droppedUrls = true; QList imagesUrls; QList foldersUrls; foreach (const QUrl& url, validUrls) { if (QMimeDatabase().mimeTypeForUrl(url).name().startsWith(QLatin1String("image"), Qt::CaseInsensitive)) { imagesUrls << url; } if (QMimeDatabase().mimeTypeForUrl(url).name() == QLatin1String("inode/directory")) { foldersUrls << url; } } if (!imagesUrls.isEmpty()) { openUrls(imagesUrls); } if (!foldersUrls.isEmpty()) { foreach (const QUrl& fUrl, foldersUrls) { openFolder(fUrl); } } d->model->clearShowfotoItemInfos(); emit signalInfoList(d->infoList); if (!d->infoList.isEmpty()) { slotOpenUrl(d->thumbBar->currentInfo()); } else { QMessageBox::information(this, qApp->applicationName(), i18n("There is no dropped item to process.")); qWarning(DIGIKAM_SHOWFOTO_LOG) << "infolist is empty.."; } d->droppedUrls = false; } } void ShowFoto::slotSetupMetadataFilters(int tab) { Setup::execMetadataFilters(this, tab+1); } void ShowFoto::slotAddedDropedItems(QDropEvent* e) { QList list = e->mimeData()->urls(); QList urls; - foreach(const QUrl& url, list) + foreach (const QUrl& url, list) { QFileInfo fi(url.toLocalFile()); if (fi.exists()) { urls.append(url); } } e->accept(); if (!urls.isEmpty()) { slotDroppedUrls(urls); } } void ShowFoto::slotFileWithDefaultApplication() { Digikam::DFileOperations::openFilesWithDefaultApplication(QList() << d->thumbBar->currentUrl()); } void ShowFoto::slotOpenWith(QAction* action) { openWith(d->thumbBar->currentUrl(), action); } } // namespace ShowFoto #include "moc_showfoto.cpp" diff --git a/core/showfoto/thumbbar/showfotothumbnailbar.cpp b/core/showfoto/thumbbar/showfotothumbnailbar.cpp index ffeef2ee99..7bc2e8be72 100644 --- a/core/showfoto/thumbbar/showfotothumbnailbar.cpp +++ b/core/showfoto/thumbbar/showfotothumbnailbar.cpp @@ -1,213 +1,213 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 02-08-2013 * Description : Thumbnail bar for Showfoto * * Copyright (C) 2013 by Mohamed_Anwer * Copyright (C) 2013-2018 by Gilles Caulier * * This program is free software you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #include "showfotothumbnailbar.h" // Qt includes #include // Local includes #include "digikam_debug.h" #include "showfotosettings.h" #include "showfotodelegate.h" #include "showfotofiltermodel.h" #include "itemviewtooltip.h" #include "showfototooltipfiller.h" #include "showfotocategorizedview.h" #include "imageselectionoverlay.h" #include "showfotokineticscroller.h" #include "showfotocoordinatesoverlay.h" namespace ShowFoto { class Q_DECL_HIDDEN ShowfotoThumbnailBar::Private { public: explicit Private() { scrollPolicy = Qt::ScrollBarAlwaysOn; duplicatesFilter = 0; kScroller = 0; } Qt::ScrollBarPolicy scrollPolicy; NoDuplicatesShowfotoFilterModel* duplicatesFilter; ShowfotoKineticScroller* kScroller; }; ShowfotoThumbnailBar::ShowfotoThumbnailBar(QWidget* const parent) : ShowfotoCategorizedView(parent), d(new Private()) { setItemDelegate(new ShowfotoThumbnailDelegate(this)); setSpacing(3); setUsePointingHandCursor(false); setScrollStepGranularity(3); setScrollCurrentToCenter(ShowfotoSettings::instance()->getItemCenter()); setScrollBarPolicy(Qt::ScrollBarAlwaysOn); setDragEnabled(true); setAcceptDrops(true); setDropIndicatorShown(true); slotSetupChanged(); d->kScroller = new ShowfotoKineticScroller(); d->kScroller->enableKineticScrollFor(this); } ShowfotoThumbnailBar::~ShowfotoThumbnailBar() { delete d; } void ShowfotoThumbnailBar::installOverlays() { addOverlay(new ShowfotoCoordinatesOverlay(this)); } void ShowfotoThumbnailBar::slotDockLocationChanged(Qt::DockWidgetArea area) { if (area == Qt::LeftDockWidgetArea || area == Qt::RightDockWidgetArea) { setFlow(TopToBottom); d->kScroller->setScrollFlow(TopToBottom); } else { setFlow(LeftToRight); d->kScroller->setScrollFlow(LeftToRight); } scrollTo(currentIndex()); } void ShowfotoThumbnailBar::setScrollBarPolicy(Qt::ScrollBarPolicy policy) { if (policy == Qt::ScrollBarAsNeeded) { // Delegate resizing will cause endless relayouting, see bug #228807 qCDebug(DIGIKAM_GENERAL_LOG) << "The Qt::ScrollBarAsNeeded policy is not supported by ShowfotoThumbnailBar"; } d->scrollPolicy = policy; if (flow() == TopToBottom) { setVerticalScrollBarPolicy(d->scrollPolicy); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } else { setHorizontalScrollBarPolicy(d->scrollPolicy); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); } } void ShowfotoThumbnailBar::setFlow(QListView::Flow flow) { setWrapping(false); ShowfotoCategorizedView::setFlow(flow); ShowfotoThumbnailDelegate* const del = static_cast(delegate()); del->setFlow(flow); // Reset the minimum and maximum sizes. setMinimumSize(QSize(0, 0)); setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); // Adjust minimum and maximum width to thumbnail sizes. if (flow == TopToBottom) { int viewportFullWidgetOffset = size().width() - viewport()->size().width(); setMinimumWidth(del->minimumSize() + viewportFullWidgetOffset); setMaximumWidth(del->maximumSize() + viewportFullWidgetOffset); } else { int viewportFullWidgetOffset = size().height() - viewport()->size().height(); setMinimumHeight(del->minimumSize() + viewportFullWidgetOffset); setMaximumHeight(del->maximumSize() + viewportFullWidgetOffset); } setScrollBarPolicy(d->scrollPolicy); } void ShowfotoThumbnailBar::slotSetupChanged() { ShowfotoCategorizedView::slotSetupChanged(); } bool ShowfotoThumbnailBar::event(QEvent* e) { // reset widget max/min sizes if (e->type() == QEvent::StyleChange || e->type() == QEvent::Show) { setFlow(flow()); } return ShowfotoCategorizedView::event(e); } QModelIndex ShowfotoThumbnailBar::nextIndex(const QModelIndex& index) const { return showfotoFilterModel()->index(index.row() + 1, 0); } QModelIndex ShowfotoThumbnailBar::previousIndex(const QModelIndex& index) const { return showfotoFilterModel()->index(index.row() - 1, 0); } QModelIndex ShowfotoThumbnailBar::firstIndex() const { return showfotoFilterModel()->index(0, 0); } QModelIndex ShowfotoThumbnailBar::lastIndex() const { return showfotoFilterModel()->index(showfotoFilterModel()->rowCount() - 1, 0); } -ShowfotoItemInfo ShowfotoThumbnailBar::findItemByUrl(const QUrl url) +ShowfotoItemInfo ShowfotoThumbnailBar::findItemByUrl(const QUrl& url) { ShowfotoItemInfoList lst = showfotoItemInfos(); - for(int i = 0 ; i< lst.size() ; i++) + for (int i = 0 ; i < lst.size() ; ++i) { - if(lst.at(i).url == url) + if (lst.at(i).url == url) { return lst.at(i); } } return ShowfotoItemInfo(); } } // namespace ShowFoto diff --git a/core/showfoto/thumbbar/showfotothumbnailbar.h b/core/showfoto/thumbbar/showfotothumbnailbar.h index a83aa89a95..e4466bb5d1 100644 --- a/core/showfoto/thumbbar/showfotothumbnailbar.h +++ b/core/showfoto/thumbbar/showfotothumbnailbar.h @@ -1,82 +1,82 @@ /* ============================================================ * * This file is a part of digiKam project * http://www.digikam.org * * Date : 02-08-2013 * Description : Thumbnail bar for Showfoto * * Copyright (C) 2013 by Mohamed_Anwer * Copyright (C) 2013-2018 by Gilles Caulier * * This program is free software you can redistribute it * and/or modify it under the terms of the GNU General * Public License as published by the Free Software Foundation * either version 2, or (at your option) * any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * ============================================================ */ #ifndef SHOW_FOTO_THUMB_NAIL_BAR_H #define SHOW_FOTO_THUMB_NAIL_BAR_H // Local Includes #include "showfotocategorizedview.h" namespace ShowFoto { class ShowfotoItemViewToolTip; class ShowfotoThumbnailBar : public ShowfotoCategorizedView { Q_OBJECT public: explicit ShowfotoThumbnailBar(QWidget* const parent = 0); ~ShowfotoThumbnailBar(); /** * This installs a duplicate filter model, if the ShwofotoImageModel may contain duplicates. * Otherwise, just use setModels(). */ void setModelsFiltered(ShowfotoImageModel* model, ShowfotoSortFilterModel* filterModel); QModelIndex nextIndex(const QModelIndex& index) const; QModelIndex previousIndex(const QModelIndex& index) const; QModelIndex firstIndex() const; QModelIndex lastIndex() const; /// Sets the policy always for the one scroll bar which is relevant, depending on orientation void setScrollBarPolicy(Qt::ScrollBarPolicy policy); void setFlow(QListView::Flow newFlow); - ShowfotoItemInfo findItemByUrl(const QUrl url); + ShowfotoItemInfo findItemByUrl(const QUrl& url); void installOverlays(); public Q_SLOTS: void slotDockLocationChanged(Qt::DockWidgetArea area); protected: virtual void slotSetupChanged(); virtual bool event(QEvent*); private: class Private; Private* const d; }; } // namespace ShowFoto #endif // SHOW_FOTO_THUMB_NAIL_BAR_H