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

0001 /*
0002    SPDX-FileCopyrightText: 2020-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "threadmessagedialog.h"
0008 #include <KConfigGroup>
0009 #include <KLocalizedString>
0010 #include <KSharedConfig>
0011 #include <KWindowConfig>
0012 #include <QDialogButtonBox>
0013 #include <QFrame>
0014 #include <QStyle>
0015 #include <QVBoxLayout>
0016 #include <QWindow>
0017 
0018 namespace
0019 {
0020 static const char myThreadMessageDialogGroupName[] = "ThreadMessageDialog";
0021 }
0022 
0023 ThreadMessageDialog::ThreadMessageDialog(RocketChatAccount *account, QWidget *parent)
0024     : QDialog(parent)
0025     , mThreadMessageWidget(new ThreadMessageWidget(account, this))
0026 {
0027     setWindowTitle(i18nc("@title:window", "Thread"));
0028     auto mainLayout = new QVBoxLayout(this);
0029     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0030     mainLayout->setSpacing(0);
0031     mainLayout->setContentsMargins({});
0032 
0033     mThreadMessageWidget->setObjectName(QStringLiteral("mThreadMessageWidget"));
0034     mainLayout->addWidget(mThreadMessageWidget);
0035 
0036     auto separator = new QFrame(this);
0037     separator->setFrameShape(QFrame::HLine);
0038     separator->setFixedHeight(1);
0039 
0040     mainLayout->addWidget(separator);
0041 
0042     auto button = new QDialogButtonBox(QDialogButtonBox::Close, this);
0043     button->setContentsMargins(style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
0044                                style()->pixelMetric(QStyle::PM_LayoutTopMargin),
0045                                style()->pixelMetric(QStyle::PM_LayoutRightMargin),
0046                                style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
0047     button->setObjectName(QStringLiteral("button"));
0048     mainLayout->addWidget(button);
0049     connect(button, &QDialogButtonBox::rejected, this, &ThreadMessageDialog::reject);
0050     readConfig();
0051     setAttribute(Qt::WA_DeleteOnClose);
0052 }
0053 
0054 ThreadMessageDialog::~ThreadMessageDialog()
0055 {
0056     writeConfig();
0057 }
0058 
0059 void ThreadMessageDialog::setThreadMessageInfo(const ThreadMessageWidget::ThreadMessageInfo &info)
0060 {
0061     mThreadMessageWidget->setThreadMessageInfo(info);
0062 }
0063 
0064 void ThreadMessageDialog::readConfig()
0065 {
0066     create(); // ensure a window is created
0067     windowHandle()->resize(QSize(800, 300));
0068     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myThreadMessageDialogGroupName));
0069     KWindowConfig::restoreWindowSize(windowHandle(), group);
0070     resize(windowHandle()->size()); // workaround for QTBUG-40584
0071 }
0072 
0073 void ThreadMessageDialog::writeConfig()
0074 {
0075     KConfigGroup group(KSharedConfig::openStateConfig(), QLatin1String(myThreadMessageDialogGroupName));
0076     KWindowConfig::saveWindowSize(windowHandle(), group);
0077 }
0078 
0079 #include "moc_threadmessagedialog.cpp"