File indexing completed on 2025-01-05 03:35:17
0001 /* 0002 File : ColorMapsDialog.cpp 0003 Project : LabPlot 0004 Description : dialog showing the available color maps 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2021 Alexander Semke <alexander.semke@web.de> 0007 SPDX-License-Identifier: GPL-2.0-or-later 0008 */ 0009 0010 #include "ColorMapsDialog.h" 0011 #include "backend/core/Settings.h" 0012 #include "kdefrontend/colormaps/ColorMapsWidget.h" 0013 0014 #include <QDialogButtonBox> 0015 #include <QWindow> 0016 0017 #include <KConfigGroup> 0018 0019 #include <KWindowConfig> 0020 0021 /*! 0022 \class ColorMapsDialog 0023 \brief Dialog showing the available color maps. Embeds \c ColorMapsWidget and provides the standard buttons. 0024 0025 \ingroup kdefrontend 0026 */ 0027 ColorMapsDialog::ColorMapsDialog(QWidget* parent) 0028 : QDialog(parent) 0029 , m_colorMapsWidget(new ColorMapsWidget(this)) { 0030 connect(m_colorMapsWidget, &ColorMapsWidget::doubleClicked, this, &QDialog::accept); 0031 0032 auto* layout = new QVBoxLayout(this); 0033 layout->addWidget(m_colorMapsWidget); 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", "Color Maps Browser")); 0043 setWindowIcon(QIcon::fromTheme(QLatin1String("color-management"))); 0044 create(); 0045 0046 QApplication::processEvents(QEventLoop::AllEvents, 0); 0047 0048 KConfigGroup conf = Settings::group(QStringLiteral("ColorMapsDialog")); 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 ColorMapsDialog::~ColorMapsDialog() { 0057 KConfigGroup conf = Settings::group(QStringLiteral("ColorMapsDialog")); 0058 KWindowConfig::saveWindowSize(windowHandle(), conf); 0059 } 0060 0061 QPixmap ColorMapsDialog::previewPixmap() const { 0062 return m_colorMapsWidget->previewPixmap(); 0063 } 0064 0065 QString ColorMapsDialog::name() const { 0066 return m_colorMapsWidget->name(); 0067 } 0068 0069 QVector<QColor> ColorMapsDialog::colors() const { 0070 return m_colorMapsWidget->colors(); 0071 }