File indexing completed on 2025-01-05 03:52:07
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2006-04-04 0007 * Description : a tool to generate HTML image galleries 0008 * 0009 * SPDX-FileCopyrightText: 2012-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 "htmlthemepage.h" 0016 0017 // Qt includes 0018 0019 #include <QIcon> 0020 #include <QHBoxLayout> 0021 #include <QApplication> 0022 #include <QStyle> 0023 0024 // KDE includes 0025 0026 #include <klocalizedstring.h> 0027 0028 // Local includes 0029 0030 #include "galleryinfo.h" 0031 #include "htmlwizard.h" 0032 #include "dlayoutbox.h" 0033 0034 namespace DigikamGenericHtmlGalleryPlugin 0035 { 0036 0037 class Q_DECL_HIDDEN HTMLThemePage::Private 0038 { 0039 public: 0040 0041 explicit Private() 0042 : themeList(nullptr), 0043 themeInfo(nullptr) 0044 { 0045 } 0046 0047 QListWidget* themeList; 0048 QTextBrowser* themeInfo; 0049 }; 0050 0051 HTMLThemePage::HTMLThemePage(QWizard* const dialog, const QString& title) 0052 : DWizardPage(dialog, title), 0053 d (new Private) 0054 { 0055 setObjectName(QLatin1String("ThemePage")); 0056 0057 DHBox* const hbox = new DHBox(this); 0058 0059 d->themeList = new QListWidget(hbox); 0060 d->themeList->setObjectName(QLatin1String("ThemeList")); 0061 0062 d->themeInfo = new QTextBrowser(hbox); 0063 d->themeInfo->setObjectName(QLatin1String("ThemeInfo")); 0064 0065 hbox->setContentsMargins(QMargins()); 0066 hbox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0067 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0068 0069 connect(d->themeList, SIGNAL(itemSelectionChanged()), 0070 this, SLOT(slotThemeSelectionChanged())); 0071 0072 setPageWidget(hbox); 0073 setLeftBottomPix(QIcon::fromTheme(QLatin1String("application-x-theme"))); 0074 } 0075 0076 HTMLThemePage::~HTMLThemePage() 0077 { 0078 delete d; 0079 } 0080 0081 void HTMLThemePage::initializePage() 0082 { 0083 HTMLWizard* const wizard = dynamic_cast<HTMLWizard*>(assistant()); 0084 0085 if (!wizard) 0086 { 0087 return; 0088 } 0089 0090 GalleryInfo* const info = wizard->galleryInfo(); 0091 GalleryTheme::List list = GalleryTheme::getList(); 0092 GalleryTheme::List::ConstIterator it = list.constBegin(); 0093 GalleryTheme::List::ConstIterator end = list.constEnd(); 0094 0095 d->themeList->clear(); 0096 0097 for ( ; it != end ; ++it) 0098 { 0099 GalleryTheme::Ptr theme = *it; 0100 ThemeListBoxItem* const item = new ThemeListBoxItem(theme); 0101 d->themeList->addItem(item); 0102 0103 if (theme->internalName() == info->theme()) 0104 { 0105 d->themeList->setCurrentItem(item); 0106 } 0107 } 0108 0109 // Set page states, whoch can only be disabled after they have *all* been added. 0110 0111 slotThemeSelectionChanged(); 0112 } 0113 0114 bool HTMLThemePage::validatePage() 0115 { 0116 if (!d->themeList->currentItem()) 0117 { 0118 return false; 0119 } 0120 0121 return true; 0122 } 0123 0124 void HTMLThemePage::slotThemeSelectionChanged() 0125 { 0126 if (d->themeList->currentItem()) 0127 { 0128 GalleryTheme::Ptr curTheme = currentTheme(); 0129 QString url = curTheme->authorUrl(); 0130 QString author = curTheme->authorName(); 0131 0132 if (!url.isEmpty()) 0133 { 0134 author = QString::fromUtf8("<a href='%1'>%2</a>").arg(url).arg(author); 0135 } 0136 0137 QString preview = curTheme->previewUrl(); 0138 QString image = QLatin1String(""); 0139 0140 if (!preview.isEmpty()) 0141 { 0142 image = QString::fromUtf8("<img src='%1/%2' /><br/><br/>") 0143 .arg(curTheme->directory(), curTheme->previewUrl()); 0144 } 0145 0146 QString advSet = (curTheme->parameterList().size() > 0) ? i18n("can be customized") 0147 : i18n("no customization available"); 0148 QString txt = image + QString::fromUtf8("<b>%3</b><br/><br/>%4<br/><br/>") 0149 .arg(curTheme->name(), curTheme->comment()) 0150 + i18n("Author: %1<br/><br/>", author) 0151 + QString::fromUtf8("<i>%1</i>").arg(advSet); 0152 0153 d->themeInfo->setHtml(txt); 0154 } 0155 else 0156 { 0157 d->themeInfo->clear(); 0158 } 0159 } 0160 0161 GalleryTheme::Ptr HTMLThemePage::currentTheme() const 0162 { 0163 ThemeListBoxItem* const item = dynamic_cast<ThemeListBoxItem*>(d->themeList->currentItem()); 0164 0165 if (item) 0166 { 0167 return item->m_theme; 0168 } 0169 0170 return GalleryTheme::Ptr(nullptr); 0171 } 0172 0173 } // namespace DigikamGenericHtmlGalleryPlugin 0174 0175 #include "moc_htmlthemepage.cpp"