File indexing completed on 2025-01-05 03:57:55

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2004-11-22
0007  * Description : stand alone digiKam image editor - Internal setup
0008  *
0009  * SPDX-FileCopyrightText: 2004-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  *
0011  * SPDX-License-Identifier: GPL-2.0-or-later
0012  *
0013  * ============================================================ */
0014 
0015 #include "showfoto_p.h"
0016 
0017 namespace ShowFoto
0018 {
0019 
0020 void Showfoto::setupActions()
0021 {
0022     Digikam::ThemeManager::instance()->setThemeMenuAction(new QMenu(i18n("&Themes"), this));
0023     setupStandardActions();
0024 
0025     // Extra 'File' menu actions ---------------------------------------------
0026 
0027     d->fileOpenAction = buildStdAction(StdOpenAction, this, SLOT(slotOpenFile()), this);
0028     actionCollection()->addAction(QLatin1String("showfoto_open_file"), d->fileOpenAction);
0029 
0030     // ---------
0031 
0032     d->openFilesInFolderAction = new QAction(QIcon::fromTheme(QLatin1String("folder-pictures")), i18n("Open folder"), this);
0033     actionCollection()->setDefaultShortcut(d->openFilesInFolderAction, Qt::CTRL | Qt::SHIFT | Qt::Key_O);
0034 
0035     connect(d->openFilesInFolderAction, &QAction::triggered,
0036             this, &Showfoto::slotOpenFolder);
0037 
0038     actionCollection()->addAction(QLatin1String("showfoto_open_folder"), d->openFilesInFolderAction);
0039 
0040     // ---------
0041 
0042     QAction* const quit = buildStdAction(StdQuitAction, this, SLOT(close()), this);
0043     actionCollection()->addAction(QLatin1String("showfoto_quit"), quit);
0044 
0045     // -- Standard 'Help' menu actions ---------------------------------------------
0046 
0047     createHelpActions(QLatin1String("showfoto_editor"), false);
0048 }
0049 
0050 void Showfoto::setupConnections()
0051 {
0052     setupStandardConnections();
0053 
0054     connect(d->thumbBarDock, SIGNAL(dockLocationChanged(Qt::DockWidgetArea)),
0055             d->thumbBar, SLOT(slotDockLocationChanged(Qt::DockWidgetArea)));
0056 
0057     connect(d->thumbBar, SIGNAL(showfotoItemInfoActivated(ShowfotoItemInfo)),
0058             this, SLOT(slotShowfotoItemInfoActivated(ShowfotoItemInfo)));
0059 
0060     connect(d->stackView, SIGNAL(signalShowfotoItemInfoActivated(ShowfotoItemInfo)),
0061             this, SLOT(slotShowfotoItemInfoActivated(ShowfotoItemInfo)));
0062 
0063     connect(d->folderView, SIGNAL(signalLoadContentsFromPath(QString)),
0064             this, SLOT(slotOpenFolderFromPath(QString)));
0065 
0066     connect(d->folderView, SIGNAL(signalLoadContentsFromFiles(QStringList,QString)),
0067             this, SLOT(slotOpenFilesfromPath(QStringList,QString)));
0068 
0069     connect(d->folderView, SIGNAL(signalAppendContentsFromFiles(QStringList,QString)),
0070             this, SLOT(slotAppendFilesfromPath(QStringList,QString)));
0071 
0072     connect(d->stackView, SIGNAL(signalLoadContentsFromFiles(QStringList,QString)),
0073             this, SLOT(slotOpenFilesfromPath(QStringList,QString)));
0074 
0075     connect(d->stackView, SIGNAL(signalClearItemsList()),
0076             this, SLOT(slotClearThumbBar()));
0077 
0078     connect(d->stackView, SIGNAL(signalRemoveItemInfos(QList<ShowfotoItemInfo>)),
0079             this, SLOT(slotRemoveItemInfos(QList<ShowfotoItemInfo>)));
0080 
0081     connect(this, SIGNAL(signalSelectionChanged(QRect)),
0082             d->rightSideBar, SLOT(slotImageSelectionChanged(QRect)));
0083 
0084     connect(this, &Showfoto::signalOpenFolder,
0085             this, &Showfoto::slotOpenFolder);
0086 
0087     connect(this, &Showfoto::signalOpenFile,
0088             this, &Showfoto::slotOpenFile);
0089 
0090     connect(this, SIGNAL(signalInfoList(ShowfotoItemInfoList)),
0091             d->model, SLOT(reAddShowfotoItemInfos(ShowfotoItemInfoList)));
0092 
0093     connect(d->thumbLoadThread, SIGNAL(signalThumbnailLoaded(LoadingDescription,QPixmap)),
0094             d->model, SLOT(slotThumbnailLoaded(LoadingDescription,QPixmap)));
0095 
0096     connect(this, SIGNAL(signalNoCurrentItem()),
0097             d->rightSideBar, SLOT(slotNoCurrentItem()));
0098 
0099     connect(d->rightSideBar, SIGNAL(signalSetupMetadataFilters(int)),
0100             this, SLOT(slotSetupMetadataFilters(int)));
0101 
0102     connect(d->rightSideBar, SIGNAL(signalSetupExifTool()),
0103             this, SLOT(slotSetupExifTool()));
0104 
0105     connect(d->folderView, SIGNAL(signalSetup()),
0106             this, SLOT(slotSetup()));
0107 
0108     connect(d->dDHandler, SIGNAL(signalDroppedUrls(QList<QUrl>,bool,QUrl)),
0109             this, SLOT(slotDroppedUrls(QList<QUrl>,bool,QUrl)));
0110 
0111     connect(ThemeManager::instance(), SIGNAL(signalThemeChanged()),
0112             this, SLOT(slotThemeChanged()));
0113 }
0114 
0115 void Showfoto::setupUserArea()
0116 {
0117     QWidget* const widget            = new QWidget(this);
0118     QHBoxLayout* const hlay          = new QHBoxLayout(widget);
0119     m_splitter                       = new Digikam::SidebarSplitter(widget);
0120 
0121     const int spacing                = qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing),
0122                              QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing));
0123     d->leftSideBar                   = new Digikam::Sidebar(widget, m_splitter, Qt::LeftEdge);
0124     d->leftSideBar->setObjectName(QLatin1String("ShowFoto Sidebar Left"));
0125     d->leftSideBar->setContentsMargins(0, 0, spacing, 0);
0126 
0127     d->folderView                    = new ShowfotoFolderViewSideBar(this);
0128     d->leftSideBar->appendTab(d->folderView, d->folderView->getIcon(), d->folderView->getCaption());
0129 
0130     d->stackView                     = new ShowfotoStackViewSideBar(this);
0131     d->leftSideBar->appendTab(d->stackView, d->stackView->getIcon(), d->stackView->getCaption());
0132 
0133     KMainWindow* const viewContainer = new KMainWindow(widget, Qt::Widget);
0134     m_splitter->addWidget(viewContainer);
0135     m_stackView                      = new Digikam::EditorStackView(viewContainer);
0136     m_canvas                         = new Digikam::Canvas(m_stackView);
0137     viewContainer->setCentralWidget(m_stackView);
0138 
0139     m_splitter->setFrameStyle(QFrame::NoFrame);
0140     m_splitter->setFrameShape(QFrame::NoFrame);
0141     m_splitter->setFrameShadow(QFrame::Plain);
0142     m_splitter->setStretchFactor(m_splitter->indexOf(viewContainer), 10);      // set Canvas default size to max.
0143     m_splitter->setOpaqueResize(false);
0144 
0145     m_canvas->makeDefaultEditingCanvas();
0146     m_stackView->setCanvas(m_canvas);
0147     m_stackView->setViewMode(Digikam::EditorStackView::CanvasMode);
0148 
0149     d->rightSideBar                  = new Digikam::ItemPropertiesSideBar(widget, m_splitter, Qt::RightEdge);
0150     d->rightSideBar->setObjectName(QLatin1String("ShowFoto Sidebar Right"));
0151 
0152     hlay->addWidget(d->leftSideBar);
0153     hlay->addWidget(m_splitter);
0154     hlay->addWidget(d->rightSideBar);
0155     hlay->setContentsMargins(QMargins());
0156     hlay->setSpacing(0);
0157 
0158     // Code to check for the now depreciated HorizontalThumbar directive. It
0159     // is found, it is honored and deleted. The state will from than on be saved
0160     // by viewContainers built-in mechanism.
0161 
0162     d->thumbBarDock                  = new Digikam::ThumbBarDock(viewContainer, Qt::Tool);
0163     d->thumbBarDock->setObjectName(QLatin1String("editor_thumbbar"));
0164     d->thumbBarDock->setAllowedAreas(Qt::TopDockWidgetArea | Qt::BottomDockWidgetArea);
0165     d->thumbBar                      = new ShowfotoThumbnailBar(d->thumbBarDock);
0166 
0167     d->thumbBarDock->setWidget(d->thumbBar);
0168 
0169     viewContainer->addDockWidget(Qt::TopDockWidgetArea, d->thumbBarDock);
0170     d->thumbBarDock->setFloating(false);
0171 
0172     d->model                         = new ShowfotoThumbnailModel(d->thumbBar);
0173     d->model->setThumbnailLoadThread(d->thumbLoadThread);
0174     d->model->setSendRemovalSignals(true);
0175 
0176     d->dDHandler                     = new ShowfotoDragDropHandler(d->model);
0177     d->model->setDragDropHandler(d->dDHandler);
0178 
0179     d->filterModel                   = new ShowfotoFilterModel(d->thumbBar);
0180     d->filterModel->setSourceShowfotoModel(d->model);
0181     d->filterModel->setCategorizationMode(ShowfotoItemSortSettings::NoCategories);
0182     d->filterModel->sort(0);
0183 
0184     d->thumbBar->setModels(d->model, d->filterModel);
0185     d->thumbBar->setSelectionMode(QAbstractItemView::SingleSelection);
0186 
0187     viewContainer->setAutoSaveSettings(QLatin1String("ImageViewer Thumbbar"), true);
0188 
0189     d->thumbBar->installOverlays();
0190     d->stackView->setThumbbar(d->thumbBar);
0191 
0192     setCentralWidget(widget);
0193 }
0194 
0195 void Showfoto::slotContextMenu()
0196 {
0197     if (m_contextMenu)
0198     {
0199         m_contextMenu->addSeparator();
0200         addServicesMenu();
0201         m_contextMenu->exec(QCursor::pos());
0202     }
0203 }
0204 
0205 void Showfoto::addServicesMenu()
0206 {
0207     addServicesMenuForUrl(d->thumbBar->currentUrl());
0208 }
0209 
0210 void Showfoto::toggleNavigation(int index)
0211 {
0212     if (!m_actionEnabledState)
0213     {
0214         return;
0215     }
0216 
0217     if ((d->itemsNb == 0) || (d->itemsNb == 1))
0218     {
0219         m_backwardAction->setEnabled(false);
0220         m_forwardAction->setEnabled(false);
0221         m_firstAction->setEnabled(false);
0222         m_lastAction->setEnabled(false);
0223     }
0224     else
0225     {
0226         m_backwardAction->setEnabled(true);
0227         m_forwardAction->setEnabled(true);
0228         m_firstAction->setEnabled(true);
0229         m_lastAction->setEnabled(true);
0230     }
0231 
0232     if (index == 1)
0233     {
0234         m_backwardAction->setEnabled(false);
0235         m_firstAction->setEnabled(false);
0236     }
0237 
0238     if (index == d->itemsNb)
0239     {
0240         m_forwardAction->setEnabled(false);
0241         m_lastAction->setEnabled(false);
0242     }
0243 }
0244 
0245 void Showfoto::toggleActions(bool val)
0246 {
0247     toggleStandardActions(val);
0248 }
0249 
0250 } // namespace ShowFoto