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

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "trackingdetailsdialog.h"
0008 #include <KConfigGroup>
0009 #include <KLocalizedString>
0010 #include <KSharedConfig>
0011 #include <KWindowConfig>
0012 #include <QDialogButtonBox>
0013 #include <QPushButton>
0014 #include <QVBoxLayout>
0015 #include <QWindow>
0016 #include <TextCustomEditor/RichTextEditorWidget>
0017 
0018 using namespace WebEngineViewer;
0019 namespace
0020 {
0021 static const char myMailTrackingDetailsDialogConfigGroupName[] = "MailTrackingDetailsDialog";
0022 }
0023 TrackingDetailsDialog::TrackingDetailsDialog(QWidget *parent)
0024     : QDialog(parent)
0025     , mDetails(new TextCustomEditor::RichTextEditorWidget(this))
0026 {
0027     setWindowTitle(i18nc("@title:window", "Details"));
0028     setAttribute(Qt::WA_DeleteOnClose);
0029     setModal(false);
0030 
0031     auto mainLayout = new QVBoxLayout(this);
0032     mainLayout->setObjectName(QLatin1StringView("mainLayout"));
0033 
0034     auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
0035     buttonBox->setObjectName(QLatin1StringView("buttonbox"));
0036     connect(buttonBox, &QDialogButtonBox::rejected, this, &TrackingDetailsDialog::reject);
0037     connect(buttonBox->button(QDialogButtonBox::Close), &QPushButton::clicked, this, &TrackingDetailsDialog::close);
0038 
0039     mDetails->setObjectName(QLatin1StringView("detail"));
0040     mainLayout->addWidget(mDetails);
0041     mainLayout->addWidget(buttonBox);
0042     mDetails->setReadOnly(true);
0043     readConfig();
0044 }
0045 
0046 TrackingDetailsDialog::~TrackingDetailsDialog()
0047 {
0048     writeConfig();
0049 }
0050 
0051 void TrackingDetailsDialog::readConfig()
0052 {
0053     create(); // ensure a window is created
0054     windowHandle()->resize(QSize(600, 400));
0055     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myMailTrackingDetailsDialogConfigGroupName));
0056     KWindowConfig::restoreWindowSize(windowHandle(), group);
0057     resize(windowHandle()->size()); // workaround for QTBUG-40584
0058 }
0059 
0060 void TrackingDetailsDialog::writeConfig()
0061 {
0062     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1StringView(myMailTrackingDetailsDialogConfigGroupName));
0063     KWindowConfig::saveWindowSize(windowHandle(), group);
0064 }
0065 
0066 void TrackingDetailsDialog::setDetails(const QString &details)
0067 {
0068     mDetails->setHtml(details);
0069 }
0070 
0071 #include "moc_trackingdetailsdialog.cpp"