Pimcommon

configureplugindialog.cpp
1/*
2 SPDX-FileCopyrightText: 2016-2024 Laurent Montel <montel@kde.org>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "configureplugindialog.h"
8using namespace Qt::Literals::StringLiterals;
9
10#include <KConfigGroup>
11#include <KSharedConfig>
12#include <KWindowConfig>
13#include <PimCommon/PimUtil>
14#include <QDialogButtonBox>
15#include <QPushButton>
16#include <QVBoxLayout>
17#include <QWindow>
18
19using namespace PimCommon;
20namespace
21{
22static const char myConfigurePluginDialogGroupName[] = "ConfigurePluginDialog";
23}
24
25ConfigurePluginDialog::ConfigurePluginDialog(QWidget *parent)
26 : QDialog(parent)
27{
28}
29
30ConfigurePluginDialog::~ConfigurePluginDialog()
31{
32 saveConfig();
33}
34
35void ConfigurePluginDialog::initLayout(bool addSpacer)
36{
37 auto layout = new QVBoxLayout(this);
38 layout->addWidget(createLayout());
39 if (addSpacer) {
40 layout->addStretch(1);
41 }
42
44 mButtonBox->setObjectName("buttonBox"_L1);
45 layout->addWidget(mButtonBox);
46 connect(mButtonBox, &QDialogButtonBox::accepted, this, &ConfigurePluginDialog::slotAccepted);
48 connect(mButtonBox, &QDialogButtonBox::helpRequested, this, &ConfigurePluginDialog::slotHelpClicked);
49 connect(mButtonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, &ConfigurePluginDialog::slotRestoreDefaultClicked);
50 readConfig();
51 load();
52}
53
54void ConfigurePluginDialog::reset()
55{
56 // Reimplement it.
57}
58
59void ConfigurePluginDialog::help()
60{
61}
62
63QDialogButtonBox *ConfigurePluginDialog::buttonBox() const
64{
65 return mButtonBox;
66}
67
68void ConfigurePluginDialog::showHelp(const QString &name, const QString &anchor)
69{
70 PimCommon::Util::invokeHelp(name, anchor);
71}
72
73void ConfigurePluginDialog::slotHelpClicked()
74{
75 help();
76}
77
78void ConfigurePluginDialog::slotRestoreDefaultClicked()
79{
80 reset();
81}
82
83void ConfigurePluginDialog::slotAccepted()
84{
85 save();
86 accept();
87}
88
89void ConfigurePluginDialog::readConfig()
90{
91 create(); // ensure a window is created
92 windowHandle()->resize(QSize(600, 400));
93 KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myConfigurePluginDialogGroupName));
95 resize(windowHandle()->size()); // workaround for QTBUG-40584
96}
97
98void ConfigurePluginDialog::saveConfig()
99{
100 KConfigGroup group(KSharedConfig::openStateConfig(), QStringLiteral("ConfigurePluginDialog"));
101 group.writeEntry("Size", size());
102 group.sync();
103}
104
105#include "moc_configureplugindialog.cpp"
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
folderdialogacltab.h
void clicked(bool checked)
virtual void accept()
virtual void reject()
QPushButton * button(StandardButton which) const const
void addWidget(QWidget *w)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void setObjectName(QAnyStringView name)
void create(WId window, bool initializeWindow, bool destroyOldWindow)
QLayout * layout() const const
void resize(const QSize &)
QWindow * windowHandle() const const
void resize(const QSize &newSize)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:02:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.