File indexing completed on 2025-01-05 03:35:37
0001 /* 0002 File : ExamplesDialog.cpp 0003 Project : LabPlot 0004 Description : dialog showing the available example projects 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2021 Alexander Semke <alexander.semke@web.de> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "ExamplesDialog.h" 0011 #include "backend/core/Settings.h" 0012 #include "kdefrontend/examples/ExamplesWidget.h" 0013 0014 #include <QDialogButtonBox> 0015 #include <QWindow> 0016 0017 #include <KConfigGroup> 0018 0019 #include <KWindowConfig> 0020 0021 /*! 0022 \class ExamplesDialog 0023 \brief Dialog showing the available example projects. 0024 0025 \ingroup kdefrontend 0026 */ 0027 ExamplesDialog::ExamplesDialog(QWidget* parent) 0028 : QDialog(parent) 0029 , m_examplesWidget(new ExamplesWidget(this)) { 0030 connect(m_examplesWidget, &ExamplesWidget::doubleClicked, this, &QDialog::accept); 0031 0032 auto* layout = new QVBoxLayout(this); 0033 layout->addWidget(m_examplesWidget); 0034 0035 // dialog buttons 0036 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0037 layout->addWidget(buttonBox); 0038 0039 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0040 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0041 0042 setWindowTitle(i18nc("@title:window", "Example Projects")); 0043 setWindowIcon(QIcon::fromTheme(QLatin1String("folder-documents"))); 0044 create(); 0045 0046 QApplication::processEvents(QEventLoop::AllEvents, 0); 0047 0048 KConfigGroup conf = Settings::group(QStringLiteral("ExamplesDialog")); 0049 if (conf.exists()) { 0050 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0051 resize(windowHandle()->size()); 0052 } else 0053 resize(QSize(0, 0).expandedTo(minimumSize())); 0054 } 0055 0056 ExamplesDialog::~ExamplesDialog() { 0057 KConfigGroup conf = Settings::group(QStringLiteral("ExamplesDialog")); 0058 KWindowConfig::saveWindowSize(windowHandle(), conf); 0059 } 0060 0061 /*! 0062 * return the path for the current selected example project 0063 */ 0064 QString ExamplesDialog::path() const { 0065 return m_examplesWidget->path(); 0066 }