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 "htmlparameterspage.h" 0016 0017 // Qt includes 0018 0019 #include <QIcon> 0020 #include <QApplication> 0021 #include <QStyle> 0022 #include <QSpacerItem> 0023 #include <QGridLayout> 0024 #include <QScrollArea> 0025 #include <QMap> 0026 #include <QLabel> 0027 0028 // KDE includes 0029 0030 #include <klocalizedstring.h> 0031 0032 // Local includes 0033 0034 #include "htmlwizard.h" 0035 #include "galleryinfo.h" 0036 #include "abstractthemeparameter.h" 0037 #include "dlayoutbox.h" 0038 #include "gallerytheme.h" 0039 0040 namespace DigikamGenericHtmlGalleryPlugin 0041 { 0042 0043 class Q_DECL_HIDDEN HTMLParametersPage::Private 0044 { 0045 public: 0046 0047 explicit Private() 0048 : content(nullptr) 0049 { 0050 } 0051 0052 QMap<QByteArray, QWidget*> themePrmWdgtList; 0053 QWidget* content; 0054 }; 0055 0056 HTMLParametersPage::HTMLParametersPage(QWizard* const dialog, const QString& title) 0057 : DWizardPage(dialog, title), 0058 d (new Private) 0059 { 0060 setObjectName(QLatin1String("ThemeParametersPage")); 0061 0062 DVBox* const vbox = new DVBox(this); 0063 0064 QLabel* const textLabel1 = new QLabel(vbox); 0065 textLabel1->setObjectName(QLatin1String("textLabel1")); 0066 textLabel1->setText(i18n("In this page, you can change some theme parameters. " 0067 "Depending on the theme, different parameters are available.")); 0068 0069 QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed); 0070 sizePolicy.setHorizontalStretch(0); 0071 sizePolicy.setVerticalStretch(0); 0072 sizePolicy.setHeightForWidth(textLabel1->sizePolicy().hasHeightForWidth()); 0073 0074 textLabel1->setSizePolicy(sizePolicy); 0075 textLabel1->setAlignment(Qt::AlignVCenter); 0076 textLabel1->setWordWrap(true); 0077 0078 QScrollArea* const mScrollArea = new QScrollArea(vbox); 0079 mScrollArea->setObjectName(QLatin1String("mScrollArea")); 0080 mScrollArea->setFrameShape(QFrame::NoFrame); 0081 mScrollArea->setWidgetResizable(true); 0082 0083 d->content = new QWidget(); 0084 d->content->setObjectName(QLatin1String("d->content")); 0085 d->content->setGeometry(QRect(0, 0, 600, 430)); 0086 mScrollArea->setWidget(d->content); 0087 0088 vbox->setContentsMargins(QMargins()); 0089 vbox->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0090 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0091 0092 setPageWidget(vbox); 0093 setLeftBottomPix(QIcon::fromTheme(QLatin1String("text-css"))); 0094 } 0095 0096 HTMLParametersPage::~HTMLParametersPage() 0097 { 0098 delete d; 0099 } 0100 0101 QWidget* HTMLParametersPage::themeParameterWidgetFromName(const QByteArray& name) const 0102 { 0103 return d->themePrmWdgtList[name]; 0104 } 0105 0106 void HTMLParametersPage::initializePage() 0107 { 0108 HTMLWizard* const wizard = dynamic_cast<HTMLWizard*>(assistant()); 0109 0110 if (!wizard) 0111 { 0112 return; 0113 } 0114 0115 GalleryInfo* const info = wizard->galleryInfo(); 0116 GalleryTheme::Ptr theme = wizard->galleryTheme(); 0117 0118 qDeleteAll(d->content->children()); 0119 d->themePrmWdgtList.clear(); 0120 0121 // Create layout. We need to recreate it every time, to get rid of spacers 0122 0123 QGridLayout* const layout = new QGridLayout(d->content); 0124 layout->setContentsMargins(QMargins()); 0125 layout->setSpacing(qMin(QApplication::style()->pixelMetric(QStyle::PM_LayoutHorizontalSpacing), 0126 QApplication::style()->pixelMetric(QStyle::PM_LayoutVerticalSpacing))); 0127 0128 // Create widgets 0129 0130 GalleryTheme::ParameterList parameterList = theme->parameterList(); 0131 QString themeInternalName = theme->internalName(); 0132 GalleryTheme::ParameterList::ConstIterator it = parameterList.constBegin(); 0133 GalleryTheme::ParameterList::ConstIterator end = parameterList.constEnd(); 0134 0135 for ( ; it != end ; ++it) 0136 { 0137 AbstractThemeParameter* const themeParameter = *it; 0138 QByteArray internalName = themeParameter->internalName(); 0139 QString value = info->getThemeParameterValue(themeInternalName, 0140 QString::fromLatin1(internalName), 0141 themeParameter->defaultValue()); 0142 0143 QString name = themeParameter->name(); 0144 name = i18nc("'%1' is a label for a theme parameter", "%1:", name); 0145 0146 QLabel* const label = new QLabel(name, d->content); 0147 label->setAlignment(Qt::AlignRight | Qt::AlignVCenter); 0148 QWidget* const widget = themeParameter->createWidget(d->content, value); 0149 label->setBuddy(widget); 0150 0151 int row = layout->rowCount(); 0152 layout->addWidget(label, row, 0); 0153 0154 if (widget->sizePolicy().expandingDirections() & Qt::Horizontal) 0155 { 0156 // Widget wants full width 0157 0158 layout->addWidget(widget, row, 1, 1, 2); 0159 } 0160 else 0161 { 0162 // Widget doesn't like to be stretched, add a spacer next to it 0163 0164 layout->addWidget(widget, row, 1); 0165 QSpacerItem* const spacer = new QSpacerItem(1, 1, QSizePolicy::Expanding, 0166 QSizePolicy::Minimum); 0167 layout->addItem(spacer, row, 2); 0168 } 0169 0170 d->themePrmWdgtList[internalName] = widget; 0171 } 0172 0173 // Add spacer at the end, so that widgets aren't spread on the whole parent height 0174 0175 QSpacerItem* const spacer = new QSpacerItem(1, 1, QSizePolicy::Minimum, 0176 QSizePolicy::Expanding); 0177 0178 layout->addItem(spacer, layout->rowCount(), 0); 0179 } 0180 0181 } // namespace DigikamGenericHtmlGalleryPlugin 0182 0183 #include "moc_htmlparameterspage.cpp"