File indexing completed on 2025-01-26 04:57:23

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include "developertooldialog.h"
0007 #include "developertoolwidget.h"
0008 #include <KConfigGroup>
0009 #include <KLocalizedString>
0010 #include <KSharedConfig>
0011 #include <KWindowConfig>
0012 #include <QDialogButtonBox>
0013 #include <QVBoxLayout>
0014 #include <QWindow>
0015 
0016 namespace
0017 {
0018 static const char myDeveloperToolDialogConfigGroupName[] = "DeveloperToolDialog";
0019 }
0020 
0021 using namespace WebEngineViewer;
0022 DeveloperToolDialog::DeveloperToolDialog(QWidget *parent)
0023     : QDialog(parent)
0024     , mDeveloperToolWidget(new DeveloperToolWidget(this))
0025 {
0026     setWindowTitle(i18nc("@title:window", "Developer Tool"));
0027     auto mainLayout = new QVBoxLayout(this);
0028     mainLayout->setObjectName(QLatin1StringView("mainLayout"));
0029 
0030     mDeveloperToolWidget->setObjectName(QLatin1StringView("mDeveloperToolWidget"));
0031     mainLayout->addWidget(mDeveloperToolWidget);
0032 
0033     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
0034     buttonBox->setObjectName(QLatin1StringView("buttonBox"));
0035     connect(buttonBox, &QDialogButtonBox::rejected, this, &DeveloperToolDialog::reject);
0036     connect(mDeveloperToolWidget, &DeveloperToolWidget::closeRequested, this, &DeveloperToolDialog::reject);
0037     mainLayout->addWidget(buttonBox);
0038     readConfig();
0039 }
0040 
0041 DeveloperToolDialog::~DeveloperToolDialog()
0042 {
0043     writeConfig();
0044 }
0045 
0046 QWebEnginePage *DeveloperToolDialog::enginePage() const
0047 {
0048     return mDeveloperToolWidget->enginePage();
0049 }
0050 
0051 void DeveloperToolDialog::readConfig()
0052 {
0053     create(); // ensure a window is created
0054     windowHandle()->resize(QSize(800, 600));
0055     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myDeveloperToolDialogConfigGroupName));
0056     KWindowConfig::restoreWindowSize(windowHandle(), group);
0057     resize(windowHandle()->size()); // workaround for QTBUG-40584
0058 }
0059 
0060 void DeveloperToolDialog::writeConfig()
0061 {
0062     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myDeveloperToolDialogConfigGroupName));
0063     KWindowConfig::saveWindowSize(windowHandle(), group);
0064 }
0065 
0066 #include "moc_developertooldialog.cpp"