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 - Configure 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::slotSetup() 0021 { 0022 setup(false); 0023 } 0024 0025 void Showfoto::slotSetupICC() 0026 { 0027 setup(true); 0028 } 0029 0030 bool Showfoto::setup(bool iccSetupPage) 0031 { 0032 QPointer<ShowfotoSetup> setup = new ShowfotoSetup(this, iccSetupPage ? ShowfotoSetup::ICCPage : ShowfotoSetup::LastPageUsed); 0033 0034 if (setup->exec() != QDialog::Accepted) 0035 { 0036 delete setup; 0037 return false; 0038 } 0039 0040 KSharedConfig::openConfig()->sync(); 0041 0042 applySettings(); 0043 0044 if (d->itemsNb == 0) 0045 { 0046 slotUpdateItemInfo(); 0047 toggleActions(false); 0048 } 0049 0050 delete setup; 0051 0052 return true; 0053 } 0054 0055 void Showfoto::readSettings() 0056 { 0057 d->settings = ShowfotoSettings::instance(); 0058 0059 readStandardSettings(); 0060 0061 QString defaultDir = d->settings->getLastOpenedDir(); 0062 0063 if (defaultDir.isNull()) 0064 { 0065 defaultDir = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); 0066 } 0067 0068 d->lastOpenedDirectory = QUrl::fromLocalFile(defaultDir); 0069 0070 d->rightSideBar->loadState(); 0071 d->leftSideBar->loadState(); 0072 d->folderView->loadState(); 0073 d->stackView->loadState(); 0074 0075 Digikam::ThemeManager::instance()->setCurrentTheme(d->settings->getCurrentTheme()); 0076 0077 d->thumbBar->setToolTipEnabled(d->settings->getShowToolTip()); 0078 } 0079 0080 void Showfoto::saveSettings() 0081 { 0082 saveStandardSettings(); 0083 0084 d->settings->setLastOpenedDir(d->lastOpenedDirectory.toLocalFile()); 0085 d->settings->setCurrentTheme(Digikam::ThemeManager::instance()->currentThemeName()); 0086 d->settings->syncConfig(); 0087 0088 d->rightSideBar->saveState(); 0089 d->leftSideBar->saveState(); 0090 d->folderView->saveState(); 0091 d->stackView->saveState(); 0092 } 0093 0094 void Showfoto::applySettings() 0095 { 0096 applyStandardSettings(); 0097 0098 d->settings->readSettings(); 0099 0100 d->rightSideBar->setStyle(d->settings->getRightSideBarStyle() == 0 ? 0101 DMultiTabBar::ActiveIconText : DMultiTabBar::AllIconsText); 0102 d->leftSideBar->setStyle(d->settings->getRightSideBarStyle() == 0 ? 0103 DMultiTabBar::ActiveIconText : DMultiTabBar::AllIconsText); 0104 0105 QString currentStyle = qApp->style()->objectName(); 0106 QString newStyle = d->settings->getApplicationStyle(); 0107 0108 if (currentStyle.compare(newStyle, Qt::CaseInsensitive) != 0) 0109 { 0110 qApp->setStyle(newStyle); 0111 qApp->style()->polish(qApp); 0112 qCDebug(DIGIKAM_SHOWFOTO_LOG) << "Switch to widget style: " << newStyle; 0113 } 0114 0115 m_fileDeleteAction->setIcon(QIcon::fromTheme(QLatin1String("edit-delete"))); 0116 m_fileDeleteAction->setText(i18n("Delete File")); 0117 0118 d->thumbBar->setToolTipEnabled(d->settings->getShowToolTip()); 0119 0120 d->rightSideBar->slotLoadMetadataFilters(); 0121 0122 applySortSettings(); 0123 } 0124 0125 void Showfoto::applySortSettings() 0126 { 0127 if (d->settings->getReverseSort()) 0128 { 0129 d->filterModel->setSortOrder(ShowfotoItemSortSettings::DescendingOrder); 0130 d->folderView->setSortOrder(ShowfotoItemSortSettings::DescendingOrder); 0131 d->stackView->setSortOrder(ShowfotoItemSortSettings::DescendingOrder); 0132 } 0133 else 0134 { 0135 d->filterModel->setSortOrder(ShowfotoItemSortSettings::AscendingOrder); 0136 d->folderView->setSortOrder(ShowfotoItemSortSettings::AscendingOrder); 0137 d->stackView->setSortOrder(ShowfotoItemSortSettings::AscendingOrder); 0138 } 0139 0140 switch (d->settings->getSortRole()) 0141 { 0142 case ShowfotoSetupMisc::SortByName: 0143 { 0144 d->filterModel->setSortRole(ShowfotoItemSortSettings::SortByFileName); 0145 d->folderView->setSortRole(ShowfotoFolderViewList::FileName); 0146 d->stackView->setSortRole(ShowfotoStackViewList::FileName); 0147 break; 0148 } 0149 0150 case ShowfotoSetupMisc::SortByFileSize: 0151 { 0152 d->filterModel->setSortRole(ShowfotoItemSortSettings::SortByFileSize); 0153 d->folderView->setSortRole(ShowfotoFolderViewList::FileSize); 0154 d->stackView->setSortRole(ShowfotoStackViewList::FileSize); 0155 break; 0156 } 0157 0158 default: 0159 { 0160 d->filterModel->setSortRole(ShowfotoItemSortSettings::SortByCreationDate); 0161 d->folderView->setSortRole(ShowfotoFolderViewList::FileDate); 0162 d->stackView->setSortRole(ShowfotoStackViewList::FileDate); 0163 break; 0164 } 0165 } 0166 } 0167 0168 void Showfoto::slotThemeChanged() 0169 { 0170 QString theme = ThemeManager::instance()->currentThemeName(); 0171 0172 if (qApp->activeWindow() && 0173 (d->settings->getCurrentTheme() != theme)) 0174 { 0175 qApp->processEvents(); 0176 0177 QColor color = qApp->palette().color(qApp->activeWindow()->backgroundRole()); 0178 QString iconTheme; 0179 QString msgText; 0180 0181 if (color.lightness() > 127) 0182 { 0183 msgText = i18n("You have chosen a bright color scheme. We switch " 0184 "to a dark icon theme. The icon theme is " 0185 "available after a restart of digiKam."); 0186 0187 iconTheme = QLatin1String("breeze"); 0188 } 0189 else 0190 { 0191 msgText = i18n("You have chosen a dark color scheme. We switch " 0192 "to a bright icon theme. The icon theme is " 0193 "available after a restart of digiKam."); 0194 0195 iconTheme = QLatin1String("breeze-dark"); 0196 } 0197 0198 if (d->settings->getIconTheme() != iconTheme) 0199 { 0200 QMessageBox::information(qApp->activeWindow(), 0201 qApp->applicationName(), msgText); 0202 0203 d->settings->setIconTheme(iconTheme); 0204 } 0205 } 0206 } 0207 0208 void Showfoto::slotSetupMetadataFilters(int tab) 0209 { 0210 ShowfotoSetup::execMetadataFilters(this, tab+1); 0211 d->rightSideBar->slotLoadMetadataFilters(); 0212 } 0213 0214 void Showfoto::slotSetupExifTool() 0215 { 0216 ShowfotoSetup::execExifTool(this); 0217 } 0218 0219 } // namespace ShowFoto