1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2007 Urs Wolfer <uwolfer at kde.org>
4 SPDX-FileCopyrightText: 2008 Friedrich W. H. Kossebau <kossebau@kde.org>
5 SPDX-FileCopyrightText: 2010 Teo Mrnjavac <teo@kde.org>
6
7 Parts of this class have been take from the KAboutApplication class, which was
8 SPDX-FileCopyrightText: 2000 Waldo Bastian <bastian@kde.org>
9 SPDX-FileCopyrightText: 2000 Espen Sand <espen@kde.org>
10
11 SPDX-License-Identifier: LGPL-2.0-only
12*/
13
14#include "klicensedialog_p.h"
15
16// KF
17#include <KAboutData>
18#include <KLocalizedString>
19// Qt
20#include <QDialogButtonBox>
21#include <QFontDatabase>
22#include <QScrollBar>
23#include <QStyle>
24#include <QTextBrowser>
25#include <QVBoxLayout>
26
27KLicenseDialog::KLicenseDialog(const KAboutLicense &license, QWidget *parent)
28 : QDialog(parent)
29{
30 setAttribute(Qt::WA_DeleteOnClose);
31 QVBoxLayout *layout = new QVBoxLayout(this);
32
33 setWindowTitle(i18nc("@title:window", "License Agreement"));
34
35 const QFont font = QFontDatabase::systemFont(type: QFontDatabase::FixedFont);
36
37 const QString licenseText = license.text();
38
39 QTextBrowser *licenseBrowser = new QTextBrowser(this);
40 licenseBrowser->setFont(font);
41 licenseBrowser->setLineWrapMode(QTextEdit::NoWrap);
42 licenseBrowser->setText(licenseText);
43 layout->addWidget(licenseBrowser);
44
45 QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
46 buttonBox->setStandardButtons(QDialogButtonBox::Close);
47 connect(sender: buttonBox, signal: &QDialogButtonBox::accepted, context: this, slot: &QDialog::accept);
48 connect(sender: buttonBox, signal: &QDialogButtonBox::rejected, context: this, slot: &QDialog::reject);
49 layout->addWidget(buttonBox);
50
51 // try to set up the dialog such that the full width of the
52 // document is visible without horizontal scroll-bars being required
53 auto *style = this->style();
54 const int leftMarginHint = style->pixelMetric(metric: QStyle::PM_LayoutLeftMargin);
55 const int rightMarginHint = style->pixelMetric(metric: QStyle::PM_LayoutRightMargin);
56 const qreal idealWidth = licenseBrowser->document()->idealWidth() + leftMarginHint + rightMarginHint + licenseBrowser->verticalScrollBar()->width() * 2;
57
58 // try to allow enough height for a reasonable number of lines to be shown
59 QFontMetrics metrics(font);
60 const int idealHeight = metrics.height() * 30;
61
62 resize(sizeHint().expandedTo(otherSize: QSize(qRound(d: idealWidth), idealHeight)));
63}
64
65KLicenseDialog::~KLicenseDialog() = default;
66
67#include "moc_klicensedialog_p.cpp"
68

source code of kxmlgui/src/klicensedialog_p.cpp