File indexing completed on 2024-05-19 04:58:54

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2010-2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "licenseviewer.h"
0019 #include "qztools.h"
0020 
0021 #include <QFont>
0022 #include <QTextBrowser>
0023 #include <QVBoxLayout>
0024 #include <QDialogButtonBox>
0025 
0026 LicenseViewer::LicenseViewer(QWidget* parent)
0027     : QWidget()
0028 {
0029     setAttribute(Qt::WA_DeleteOnClose);
0030     setWindowTitle(tr("License Viewer"));
0031 
0032     m_textBrowser = new QTextBrowser(this);
0033 
0034     QFont serifFont = m_textBrowser->font();
0035     serifFont.setFamily(QSL("Courier"));
0036     m_textBrowser->setFont(serifFont);
0037 
0038     auto* buttonBox = new QDialogButtonBox(this);
0039     buttonBox->setStandardButtons(QDialogButtonBox::Close);
0040     connect(buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
0041 
0042     auto* l = new QVBoxLayout(this);
0043     l->addWidget(m_textBrowser);
0044     l->addWidget(buttonBox);
0045 
0046     setLayout(l);
0047 
0048     resize(600, 500);
0049 
0050     QzTools::centerWidgetToParent(this, parent);
0051 }
0052 
0053 void LicenseViewer::setLicenseFile(const QString &fileName)
0054 {
0055     m_textBrowser->setText(QzTools::readAllFileContents(fileName));
0056 }
0057 
0058 void LicenseViewer::setText(const QString &text)
0059 {
0060     m_textBrowser->setText(text);
0061 }