File indexing completed on 2025-01-05 05:23:46

0001 /*
0002     This file is part of the Okteta Kasten Framework, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2022 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "licensedialog.hpp"
0010 
0011 // KF
0012 #include <KAboutData>
0013 #include <KLocalizedString>
0014 // Qt
0015 #include <QTextBrowser>
0016 #include <QDialogButtonBox>
0017 #include <QScrollBar>
0018 #include <QVBoxLayout>
0019 #include <QFontDatabase>
0020 #include <QFontMetrics>
0021 // Std
0022 #include <cmath>
0023 
0024 
0025 LicenseDialog::LicenseDialog(const KAboutLicense& license, QWidget* parent)
0026     : QDialog(parent)
0027 {
0028     setAttribute(Qt::WA_DeleteOnClose);
0029     setWindowTitle(i18nc("@title:window", "License Agreement"));
0030 
0031     auto* mainLayout = new QVBoxLayout(this);
0032 
0033     const QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
0034 
0035     const QString licenseText = license.text();
0036 
0037     auto* licenseBrowser = new QTextBrowser(this);
0038     licenseBrowser->setFont(font);
0039     licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
0040     licenseBrowser->setText(licenseText);
0041     mainLayout->addWidget(licenseBrowser);
0042 
0043     auto* buttonBox = new QDialogButtonBox(this);
0044     buttonBox->setStandardButtons(QDialogButtonBox::Close);
0045     connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
0046     connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
0047     mainLayout->addWidget(buttonBox);
0048 
0049     // Resize initially to a width without a horizontal scrollbar
0050     const QMargins mainLayoutMargine = mainLayout->contentsMargins();
0051     const int idealDialogWidth = std::ceil(licenseBrowser->document()->idealWidth()) + mainLayoutMargine.left() + mainLayoutMargine.right() + licenseBrowser->verticalScrollBar()->width() + 2 * licenseBrowser->frameWidth();
0052 
0053     // Some rough initial number of lines (matching 5.95 KXmlGui's license dialog), ignoring dialogbutton box details
0054     QFontMetrics metrics(font);
0055     const int someDialogHeight = metrics.height() * 30;
0056 
0057     resize(sizeHint().expandedTo(QSize(idealDialogWidth, someDialogHeight)));
0058 }
0059 
0060 #include "moc_licensedialog.cpp"