File indexing completed on 2024-12-08 04:34:38

0001 /*
0002    SPDX-FileCopyrightText: 2023-2024 Laurent Montel <montel.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "whatsnewdialog.h"
0008 #include "whatsnewwidget.h"
0009 
0010 #include <KConfigGroup>
0011 #include <KLocalizedString>
0012 #include <KSharedConfig>
0013 #include <KWindowConfig>
0014 #include <QDialogButtonBox>
0015 #include <QVBoxLayout>
0016 #include <QWindow>
0017 namespace
0018 {
0019 const char myWhatsNewDialogGroupName[] = "WhatsNewDialog";
0020 }
0021 WhatsNewDialog::WhatsNewDialog(QWidget *parent)
0022     : QDialog(parent)
0023     , mWhatsNewWidget(new WhatsNewWidget(this))
0024 {
0025     setWindowTitle(i18nc("@title:window", "What's new in Ruqola"));
0026     auto mainLayout = new QVBoxLayout(this);
0027     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0028 
0029     mWhatsNewWidget->setObjectName(QStringLiteral("mWhatsNewWidget"));
0030     mainLayout->addWidget(mWhatsNewWidget);
0031 
0032     auto button = new QDialogButtonBox(QDialogButtonBox::Close, this);
0033     button->setObjectName(QStringLiteral("button"));
0034     mainLayout->addWidget(button);
0035     connect(button, &QDialogButtonBox::rejected, this, &WhatsNewDialog::reject);
0036     connect(button, &QDialogButtonBox::accepted, this, &WhatsNewDialog::accept);
0037     readConfig();
0038 }
0039 
0040 WhatsNewDialog::~WhatsNewDialog()
0041 {
0042     writeConfig();
0043 }
0044 
0045 void WhatsNewDialog::readConfig()
0046 {
0047     create(); // ensure a window is created
0048     windowHandle()->resize(QSize(400, 300));
0049     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myWhatsNewDialogGroupName));
0050     KWindowConfig::restoreWindowSize(windowHandle(), group);
0051     resize(windowHandle()->size()); // workaround for QTBUG-40584
0052 }
0053 
0054 void WhatsNewDialog::writeConfig()
0055 {
0056     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myWhatsNewDialogGroupName));
0057     KWindowConfig::saveWindowSize(windowHandle(), group);
0058 }
0059 
0060 void WhatsNewDialog::updateInformations()
0061 {
0062     mWhatsNewWidget->updateInformations();
0063 }
0064 
0065 #include "moc_whatsnewdialog.cpp"