Messagelib

developertooldialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "developertooldialog.h"
7 #include "developertoolwidget.h"
8 #include <KConfigGroup>
9 #include <KLocalizedString>
10 #include <KSharedConfig>
11 #include <KWindowConfig>
12 #include <QDialogButtonBox>
13 #include <QVBoxLayout>
14 #include <QWindow>
15 
16 namespace
17 {
18 static const char myDeveloperToolDialogConfigGroupName[] = "DeveloperToolDialog";
19 }
20 
21 using namespace WebEngineViewer;
22 DeveloperToolDialog::DeveloperToolDialog(QWidget *parent)
23  : QDialog(parent)
24  , mDeveloperToolWidget(new DeveloperToolWidget(this))
25 {
26  setWindowTitle(i18nc("@title:window", "Developer Tool"));
27  auto mainLayout = new QVBoxLayout(this);
28  mainLayout->setObjectName(QLatin1StringView("mainLayout"));
29 
30  mDeveloperToolWidget->setObjectName(QLatin1StringView("mDeveloperToolWidget"));
31  mainLayout->addWidget(mDeveloperToolWidget);
32 
33  auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
34  buttonBox->setObjectName(QLatin1StringView("buttonBox"));
35  connect(buttonBox, &QDialogButtonBox::rejected, this, &DeveloperToolDialog::reject);
36  connect(mDeveloperToolWidget, &DeveloperToolWidget::closeRequested, this, &DeveloperToolDialog::reject);
37  mainLayout->addWidget(buttonBox);
38  readConfig();
39 }
40 
41 DeveloperToolDialog::~DeveloperToolDialog()
42 {
43  writeConfig();
44 }
45 
46 QWebEnginePage *DeveloperToolDialog::enginePage() const
47 {
48  return mDeveloperToolWidget->enginePage();
49 }
50 
51 void DeveloperToolDialog::readConfig()
52 {
53  create(); // ensure a window is created
54  windowHandle()->resize(QSize(800, 600));
55  KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myDeveloperToolDialogConfigGroupName));
56  KWindowConfig::restoreWindowSize(windowHandle(), group);
57  resize(windowHandle()->size()); // workaround for QTBUG-40584
58 }
59 
60 void DeveloperToolDialog::writeConfig()
61 {
62  KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myDeveloperToolDialogConfigGroupName));
63  KWindowConfig::saveWindowSize(windowHandle(), group);
64 }
65 
66 #include "moc_developertooldialog.cpp"
QAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
static KSharedConfig::Ptr openStateConfig(const QString &fileName=QString())
KCONFIGGUI_EXPORT void restoreWindowSize(QWindow *window, const KConfigGroup &config)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KCONFIGGUI_EXPORT void saveWindowSize(const QWindow *window, KConfigGroup &config, KConfigGroup::WriteConfigFlags options=KConfigGroup::Normal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:55:20 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.