Pimcommon

configureimmutablewidgetutils.cpp
1/*
2 SPDX-FileCopyrightText: 2013-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "configureimmutablewidgetutils.h"
8#include "simplestringlisteditor.h"
9
10#include <KLocalizedString>
11#include <KUrlRequester>
12
13#include <QButtonGroup>
14#include <QCheckBox>
15#include <QComboBox>
16#include <QGroupBox>
17#include <QHBoxLayout>
18#include <QLineEdit>
19#include <QRadioButton>
20#include <QSpinBox>
21#include <QVBoxLayout>
22#include <QWidget>
23
24using namespace PimCommon;
25
26void ConfigureImmutableWidgetUtils::checkLockDown(QWidget *w, const KConfigSkeletonItem *item)
27{
28 if (item->isImmutable()) {
29 w->setEnabled(false);
30 w->setToolTip(
31 i18n("<qt><p>This setting has been fixed by your administrator.</p>"
32 "<p>If you think this is an error, please contact him.</p></qt>"));
33 }
34}
35
36void ConfigureImmutableWidgetUtils::populateButtonGroup(QGroupBox *box, QButtonGroup *group, int orientation, const KCoreConfigSkeleton::ItemEnum *e)
37{
38 box->setTitle(e->label());
39 if (orientation == Qt::Horizontal) {
40 box->setLayout(new QHBoxLayout());
41 } else {
42 box->setLayout(new QVBoxLayout());
43 }
44 const int numberChoices(e->choices().size());
45 for (int i = 0; i < numberChoices; ++i) {
46 auto button = new QRadioButton(e->choices().at(i).label, box);
47 group->addButton(button, i);
48 box->layout()->addWidget(button);
49 }
50}
51
52void ConfigureImmutableWidgetUtils::populateCheckBox(QCheckBox *b, const KCoreConfigSkeleton::ItemBool *e)
53{
54 b->setText(e->label());
55}
56
57void ConfigureImmutableWidgetUtils::loadWidget(QLineEdit *b, const KCoreConfigSkeleton::ItemString *e)
58{
59 checkLockDown(b, e);
60 b->setText(e->value());
61}
62
63void ConfigureImmutableWidgetUtils::loadWidget(QCheckBox *b, const KCoreConfigSkeleton::ItemBool *e)
64{
65 checkLockDown(b, e);
66 b->setChecked(e->value());
67}
68
69void ConfigureImmutableWidgetUtils::loadWidget(PimCommon::SimpleStringListEditor *b, const KCoreConfigSkeleton::ItemStringList *e)
70{
71 checkLockDown(b, e);
72 b->setStringList(e->value());
73}
74
75void ConfigureImmutableWidgetUtils::loadWidget(QGroupBox *box, QButtonGroup *group, const KCoreConfigSkeleton::ItemEnum *e)
76{
77 Q_ASSERT(group->buttons().size() == e->choices().size());
78 checkLockDown(box, e);
79 group->buttons().at(e->value())->setChecked(true);
80}
81
82void ConfigureImmutableWidgetUtils::loadWidget(QSpinBox *b, const KCoreConfigSkeleton::ItemInt *e)
83{
84 checkLockDown(b, e);
85 b->setValue(e->value());
86}
87
88void ConfigureImmutableWidgetUtils::saveSpinBox(QSpinBox *b, KCoreConfigSkeleton::ItemInt *e)
89{
90 e->setValue(b->value());
91}
92
93void ConfigureImmutableWidgetUtils::saveSpinBox(QSpinBox *b, KCoreConfigSkeleton::ItemUInt *e)
94{
95 e->setValue(b->value());
96}
97
98void ConfigureImmutableWidgetUtils::loadWidget(QSpinBox *b, const KCoreConfigSkeleton::ItemUInt *e)
99{
100 checkLockDown(b, e);
101 b->setValue(e->value());
102}
103
104void ConfigureImmutableWidgetUtils::saveCheckBox(QCheckBox *b, KCoreConfigSkeleton::ItemBool *e)
105{
106 e->setValue(b->isChecked());
107}
108
109void ConfigureImmutableWidgetUtils::saveLineEdit(QLineEdit *b, KCoreConfigSkeleton::ItemString *e)
110{
111 e->setValue(b->text());
112}
113
114void ConfigureImmutableWidgetUtils::saveUrlRequester(KUrlRequester *b, KCoreConfigSkeleton::ItemString *e)
115{
116 e->setValue(b->text());
117}
118
119void ConfigureImmutableWidgetUtils::saveGroupBox(QGroupBox *b, KCoreConfigSkeleton::ItemBool *e)
120{
121 if (b->isCheckable()) {
122 e->setValue(b->isChecked());
123 }
124}
125
126void ConfigureImmutableWidgetUtils::loadWidget(KUrlRequester *b, const KCoreConfigSkeleton::ItemString *e)
127{
128 checkLockDown(b, e);
129 b->setText(e->value());
130}
131
132void ConfigureImmutableWidgetUtils::saveButtonGroup(QButtonGroup *group, KCoreConfigSkeleton::ItemEnum *e)
133{
134 Q_ASSERT(group->buttons().size() == e->choices().size());
135 if (group->checkedId() != -1) {
136 e->setValue(group->checkedId());
137 }
138}
139
140void ConfigureImmutableWidgetUtils::saveSimpleStringListEditor(PimCommon::SimpleStringListEditor *b, KCoreConfigSkeleton::ItemStringList *e)
141{
142 e->setValue(b->stringList());
143}
144
145void ConfigureImmutableWidgetUtils::loadWidget(QGroupBox *b, const KCoreConfigSkeleton::ItemBool *e)
146{
147 checkLockDown(b, e);
148 if (b->isCheckable()) {
149 b->setChecked(e->value());
150 }
151}
152
153void ConfigureImmutableWidgetUtils::loadWidget(QComboBox *b, const KCoreConfigSkeleton::ItemEnum *e)
154{
155 checkLockDown(b, e);
156 b->setCurrentIndex(e->value());
157}
158
159void ConfigureImmutableWidgetUtils::saveComboBox(QComboBox *b, KCoreConfigSkeleton::ItemEnum *e)
160{
161 Q_ASSERT(b->count() == e->choices().size());
162 if (b->currentIndex() != -1) {
163 e->setValue(b->currentIndex());
164 }
165}
void setValue(const T &v)
bool isImmutable() const
QString label() const
void setText(const QString &text)
QString text() const
The SimpleStringListEditor class.
void setStringList(const QStringList &strings)
Sets the list of strings displayed to strings.
QString i18n(const char *text, const TYPE &arg...)
folderdialogacltab.h
void setChecked(bool)
void setText(const QString &text)
void addButton(QAbstractButton *button, int id)
QList< QAbstractButton * > buttons() const const
int checkedId() const const
void setCurrentIndex(int index)
bool isCheckable() const const
bool isChecked() const const
void setTitle(const QString &title)
void addWidget(QWidget *w)
void setText(const QString &)
void setValue(int val)
Horizontal
void setEnabled(bool)
QLayout * layout() const const
void setLayout(QLayout *layout)
void setToolTip(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:39:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.