File indexing completed on 2024-04-28 17:06:10

0001 /*
0002     SPDX-FileCopyrightText: 2005 Dirk Eschler <deschler@users.sourceforge.net>
0003     SPDX-FileCopyrightText: 2005-2022 Krusader Krew <https://krusader.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "krresulttabledialog.h"
0009 
0010 // QtGui
0011 #include <QFontDatabase>
0012 // QtWidgets
0013 #include <QDialogButtonBox>
0014 #include <QFrame>
0015 #include <QLabel>
0016 #include <QPushButton>
0017 #include <QVBoxLayout>
0018 
0019 #include <KConfigWidgets/KHelpClient>
0020 
0021 #include "../compat.h"
0022 #include "../icon.h"
0023 #include "../krglobal.h"
0024 
0025 KrResultTableDialog::KrResultTableDialog(QWidget *parent,
0026                                          DialogType type,
0027                                          const QString &caption,
0028                                          const QString &heading,
0029                                          const QString &headerIcon,
0030                                          const QString &hint)
0031     : QDialog(parent, Qt::WindowFlags())
0032 
0033 {
0034     setWindowTitle(caption);
0035     setWindowModality(Qt::WindowModal);
0036 
0037     auto *mainLayout = new QVBoxLayout;
0038     setLayout(mainLayout);
0039 
0040     auto *_topLayout = new QVBoxLayout();
0041     _topLayout->setAlignment(Qt::AlignTop);
0042 
0043     // +++ Heading +++
0044     // prepare the icon
0045     QWidget *_iconWidget = new QWidget(this);
0046     auto *_iconBox = new QHBoxLayout(_iconWidget);
0047     QLabel *_iconLabel = new QLabel(_iconWidget);
0048     _iconLabel->setPixmap(Icon(headerIcon).pixmap(32));
0049     _iconLabel->setMinimumWidth(fontMetrics().maxWidth() * 20);
0050     _iconLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
0051     _iconLabel->setFixedSize(_iconLabel->sizeHint());
0052     _iconBox->addWidget(_iconLabel);
0053     QLabel *_headingLabel = new QLabel(heading, _iconWidget);
0054     QFont defFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
0055     defFont.setBold(true);
0056     _headingLabel->setFont(defFont);
0057     _headingLabel->setIndent(10);
0058     _iconBox->addWidget(_headingLabel);
0059     _topLayout->addWidget(_iconWidget);
0060 
0061     // +++ Add some space between heading and table +++
0062     auto *hSpacer1 = new QSpacerItem(0, 5);
0063     _topLayout->addItem(hSpacer1);
0064 
0065     // +++ Table +++
0066     switch (type) {
0067     case Archiver:
0068         _resultTable = new KrArchiverResultTable(this);
0069         helpAnchor = QStringLiteral("konfig-archives"); // launch handbook at sect1-id via help button
0070         break;
0071     case Tool:
0072         _resultTable = new KrToolResultTable(this);
0073         helpAnchor = QStringLiteral("konfig-dependencies"); // TODO find a good anchor
0074         break;
0075     default:
0076         break;
0077     }
0078     _topLayout->addWidget(_resultTable);
0079 
0080     // +++ Separator +++
0081     KSeparator *hSep = new KSeparator(Qt::Horizontal, this);
0082     hSep->setContentsMargins(5, 5, 5, 5);
0083     _topLayout->addWidget(hSep);
0084 
0085     // +++ Hint +++
0086     if (!hint.isEmpty()) {
0087         QLabel *_hintLabel = new QLabel(hint, this);
0088         _hintLabel->setIndent(5);
0089         _hintLabel->setAlignment(Qt::AlignRight);
0090         _topLayout->addWidget(_hintLabel);
0091     }
0092     mainLayout->addLayout(_topLayout);
0093 
0094     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Help);
0095     mainLayout->addWidget(buttonBox);
0096     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0097     okButton->setDefault(true);
0098     okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
0099     connect(buttonBox, &QDialogButtonBox::accepted, this, &KrResultTableDialog::accept);
0100     connect(buttonBox, &QDialogButtonBox::helpRequested, this, &KrResultTableDialog::showHelp);
0101     buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
0102 
0103     this->setFixedSize(this->sizeHint()); // make non-resizeable
0104 }
0105 
0106 KrResultTableDialog::~KrResultTableDialog() = default;
0107 
0108 void KrResultTableDialog::showHelp()
0109 {
0110     if (!helpAnchor.isEmpty()) {
0111         KHelpClient::invokeHelp(helpAnchor);
0112     }
0113 }