File indexing completed on 2025-01-05 04:54:20

0001 /*
0002    SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "knotedisplayconfigwidget.h"
0008 #include <config-knotes.h>
0009 
0010 #include "attributes/notedisplayattribute.h"
0011 
0012 #include <KColorButton>
0013 #include <KLocalizedString>
0014 
0015 #include <QCheckBox>
0016 #include <QGridLayout>
0017 #include <QLabel>
0018 #include <QSpinBox>
0019 
0020 KNoteDisplayConfigWidget::KNoteDisplayConfigWidget(bool defaults, QWidget *parent)
0021     : QWidget(parent)
0022 {
0023     auto layout = new QGridLayout(this);
0024     layout->setContentsMargins({});
0025 
0026     auto label_FgColor = new QLabel(i18n("&Text color:"), this);
0027     label_FgColor->setObjectName(QLatin1StringView("label_FgColor"));
0028     layout->addWidget(label_FgColor, 0, 0);
0029 
0030     kcfg_FgColor = new KColorButton(this);
0031     kcfg_FgColor->setObjectName(QLatin1StringView("kcfg_FgColor"));
0032     label_FgColor->setBuddy(kcfg_FgColor);
0033     layout->addWidget(kcfg_FgColor, 0, 1);
0034 
0035     auto label_BgColor = new QLabel(i18n("&Background color:"), this);
0036     label_BgColor->setObjectName(QLatin1StringView("label_BgColor"));
0037     layout->addWidget(label_BgColor, 1, 0);
0038 
0039     kcfg_BgColor = new KColorButton(this);
0040     kcfg_BgColor->setObjectName(QLatin1StringView("kcfg_BgColor"));
0041     label_BgColor->setBuddy(kcfg_BgColor);
0042     layout->addWidget(kcfg_BgColor, 1, 1);
0043 
0044 #if KDEPIM_HAVE_X11
0045     kcfg_ShowInTaskbar = new QCheckBox(i18n("&Show note in taskbar"), this);
0046     kcfg_ShowInTaskbar->setObjectName(QLatin1StringView("kcfg_ShowInTaskbar"));
0047     kcfg_RememberDesktop = new QCheckBox(i18n("&Remember desktop"), this);
0048     kcfg_RememberDesktop->setObjectName(QLatin1StringView("kcfg_RememberDesktop"));
0049 #endif
0050     if (defaults) {
0051         auto label_Width = new QLabel(i18n("Default &width:"), this);
0052 
0053         layout->addWidget(label_Width, 2, 0);
0054 
0055         kcfg_Width = new QSpinBox(this);
0056         kcfg_Width->setObjectName(QLatin1StringView("kcfg_Width"));
0057         label_Width->setBuddy(kcfg_Width);
0058         kcfg_Width->setRange(50, 2000);
0059         kcfg_Width->setSingleStep(10);
0060         layout->addWidget(kcfg_Width, 2, 1);
0061 
0062         auto label_Height = new QLabel(i18n("Default &height:"), this);
0063         layout->addWidget(label_Height, 3, 0);
0064 
0065         kcfg_Height = new QSpinBox(this);
0066         kcfg_Height->setObjectName(QLatin1StringView("kcfg_Height"));
0067         kcfg_Height->setRange(50, 2000);
0068         kcfg_Height->setSingleStep(10);
0069         label_Height->setBuddy(kcfg_Height);
0070         layout->addWidget(kcfg_Height, 3, 1);
0071 
0072 #if KDEPIM_HAVE_X11
0073         layout->addWidget(kcfg_ShowInTaskbar, 4, 0);
0074         layout->addWidget(kcfg_RememberDesktop, 5, 0);
0075 #endif
0076     } else {
0077 #if KDEPIM_HAVE_X11
0078         layout->addWidget(kcfg_ShowInTaskbar, 2, 0);
0079         layout->addWidget(kcfg_RememberDesktop, 3, 0);
0080 #endif
0081     }
0082     layout->setRowStretch(6, 1);
0083 }
0084 
0085 KNoteDisplayConfigWidget::~KNoteDisplayConfigWidget() = default;
0086 
0087 void KNoteDisplayConfigWidget::load(NoteShared::NoteDisplayAttribute *attr)
0088 {
0089     if (attr) {
0090         kcfg_FgColor->setColor(attr->foregroundColor());
0091         kcfg_BgColor->setColor(attr->backgroundColor());
0092 #if KDEPIM_HAVE_X11
0093         kcfg_ShowInTaskbar->setChecked(attr->showInTaskbar());
0094         kcfg_RememberDesktop->setChecked(attr->rememberDesktop());
0095 #endif
0096         if (kcfg_Height) {
0097             kcfg_Height->setValue(attr->size().height());
0098         }
0099         if (kcfg_Width) {
0100             kcfg_Width->setValue(attr->size().width());
0101         }
0102     }
0103 }
0104 
0105 void KNoteDisplayConfigWidget::save(NoteShared::NoteDisplayAttribute *attr)
0106 {
0107     if (attr) {
0108         attr->setForegroundColor(kcfg_FgColor->color());
0109         attr->setBackgroundColor(kcfg_BgColor->color());
0110 #if KDEPIM_HAVE_X11
0111         attr->setShowInTaskbar(kcfg_ShowInTaskbar->isChecked());
0112         attr->setRememberDesktop(kcfg_RememberDesktop->isChecked());
0113 #endif
0114         if (kcfg_Height && kcfg_Width) {
0115             attr->setSize(QSize(kcfg_Width->value(), kcfg_Height->value()));
0116         }
0117     }
0118 }
0119 
0120 #include "moc_knotedisplayconfigwidget.cpp"