File indexing completed on 2025-01-05 04:49:36
0001 /* 0002 This file is part of KOrganizer. 0003 0004 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org> 0005 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com> 0006 SPDX-FileCopyrightText: 2007 Loïc Corbasson <loic.corbasson@gmail.com> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "configdialog.h" 0012 0013 #include <KConfig> 0014 #include <KLocalizedString> 0015 0016 #include <KConfigGroup> 0017 #include <QButtonGroup> 0018 #include <QDialogButtonBox> 0019 #include <QGroupBox> 0020 #include <QPushButton> 0021 #include <QRadioButton> 0022 #include <QVBoxLayout> 0023 0024 ConfigDialog::ConfigDialog(QWidget *parent) 0025 : QDialog(parent) 0026 , mAspectRatioGroup(new QButtonGroup(this)) 0027 { 0028 setWindowTitle(i18nc("@title:window", "Configure Picture of the Day")); 0029 auto mainLayout = new QVBoxLayout(this); 0030 0031 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0032 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0033 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0034 connect(buttonBox, &QDialogButtonBox::rejected, this, &ConfigDialog::reject); 0035 okButton->setDefault(true); 0036 setModal(true); 0037 auto topFrame = new QFrame(this); 0038 mainLayout->addWidget(topFrame); 0039 auto topLayout = new QVBoxLayout(topFrame); 0040 topLayout->setContentsMargins({}); 0041 0042 auto aspectRatioBox = new QGroupBox(i18n("Thumbnail Aspect Ratio Mode"), topFrame); 0043 topLayout->addWidget(aspectRatioBox); 0044 auto groupLayout = new QVBoxLayout(aspectRatioBox); 0045 0046 auto btn = new QRadioButton(i18n("Ignore aspect ratio"), aspectRatioBox); 0047 btn->setWhatsThis( 0048 i18n("The thumbnail will be scaled freely. " 0049 "The aspect ratio will not be preserved.")); 0050 mAspectRatioGroup->addButton(btn, int(Qt::IgnoreAspectRatio)); 0051 groupLayout->addWidget(btn); 0052 btn = new QRadioButton(i18n("Keep aspect ratio"), aspectRatioBox); 0053 btn->setWhatsThis( 0054 i18n("The thumbnail will be scaled to a rectangle " 0055 "as large as possible inside a given rectangle, " 0056 "preserving the aspect ratio.")); 0057 mAspectRatioGroup->addButton(btn, int(Qt::KeepAspectRatio)); 0058 groupLayout->addWidget(btn); 0059 btn = new QRadioButton(i18n("Keep aspect ratio by expanding"), aspectRatioBox); 0060 btn->setWhatsThis( 0061 i18n("The thumbnail will be scaled to a rectangle " 0062 "as small as possible outside a given rectangle, " 0063 "preserving the aspect ratio.")); 0064 mAspectRatioGroup->addButton(btn, int(Qt::KeepAspectRatioByExpanding)); 0065 groupLayout->addWidget(btn); 0066 0067 connect(okButton, &QPushButton::clicked, this, &ConfigDialog::slotOk); 0068 mainLayout->addStretch(1); 0069 mainLayout->addWidget(buttonBox); 0070 load(); 0071 } 0072 0073 ConfigDialog::~ConfigDialog() = default; 0074 0075 void ConfigDialog::load() 0076 { 0077 KConfig _config(QStringLiteral("korganizerrc"), KConfig::NoGlobals); 0078 KConfigGroup config(&_config, QStringLiteral("Calendar/Picoftheday Plugin")); 0079 int datenum = config.readEntry("AspectRatioMode", 0); 0080 QAbstractButton *btn = mAspectRatioGroup->button(datenum); 0081 if (!btn) { 0082 btn = mAspectRatioGroup->button(0); 0083 } 0084 btn->setChecked(true); 0085 } 0086 0087 void ConfigDialog::save() 0088 { 0089 KConfig _config(QStringLiteral("korganizerrc"), KConfig::NoGlobals); 0090 KConfigGroup config(&_config, QStringLiteral("Calendar/Picoftheday Plugin")); 0091 config.writeEntry("AspectRatioMode", mAspectRatioGroup->checkedId()); 0092 config.sync(); 0093 } 0094 0095 void ConfigDialog::slotOk() 0096 { 0097 save(); 0098 accept(); 0099 } 0100 0101 #include "moc_configdialog.cpp"