File indexing completed on 2024-05-12 15:28:21
0001 /*************************************************************************** 0002 File : GridDialog.cpp 0003 Project : LabPlot 0004 -------------------------------------------------------------------- 0005 Copyright : (C) 2011-2020 by Alexander Semke 0006 Email (use @ for *) : alexander.semke@web.de 0007 Description : dialog for editing the grid properties for the worksheet view 0008 0009 ***************************************************************************/ 0010 0011 /*************************************************************************** 0012 * * 0013 * This program is free software; you can redistribute it and/or modify * 0014 * it under the terms of the GNU General Public License as published by * 0015 * the Free Software Foundation; either version 2 of the License, or * 0016 * (at your option) any later version. * 0017 * * 0018 * This program is distributed in the hope that it will be useful, * 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0021 * GNU General Public License for more details. * 0022 * * 0023 * You should have received a copy of the GNU General Public License * 0024 * along with this program; if not, write to the Free Software * 0025 * Foundation, Inc., 51 Franklin Street, Fifth Floor, * 0026 * Boston, MA 02110-1301 USA * 0027 * * 0028 ***************************************************************************/ 0029 0030 #include "GridDialog.h" 0031 0032 #include <QComboBox> 0033 #include <QDialogButtonBox> 0034 #include <QLabel> 0035 #include <QSpinBox> 0036 #include <QGridLayout> 0037 #include <QWindow> 0038 0039 #include <KLocalizedString> 0040 #include <KColorButton> 0041 #include <KConfigGroup> 0042 #include <KSharedConfig> 0043 #include <KWindowConfig> 0044 0045 //TODO: 0046 //1. improve the layout and move the UI-part to a ui-file 0047 //2. restore the currently active grid settings 0048 0049 /** 0050 * @brief Provides a dialog for editing the grid properties for the worksheet view 0051 * \ingroup kdefrontend 0052 */ 0053 GridDialog::GridDialog(QWidget* parent) : QDialog(parent) { 0054 setWindowTitle(i18nc("@title:window", "Custom Grid")); 0055 0056 QWidget* widget = new QWidget; 0057 auto* layout = new QGridLayout(widget); 0058 0059 QLabel* label = new QLabel(i18n("Style:"), widget); 0060 layout->addWidget(label, 0, 0); 0061 0062 cbStyle = new QComboBox(this); 0063 cbStyle->addItem(i18n("Lines")); 0064 cbStyle->addItem(i18n("Dots")); 0065 cbStyle->setCurrentIndex(0); 0066 layout->addWidget(cbStyle, 0, 1); 0067 0068 label = new QLabel(i18n("Horizontal spacing:"), widget); 0069 layout->addWidget(label, 1, 0); 0070 0071 sbHorizontalSpacing = new QSpinBox(widget); 0072 sbHorizontalSpacing->setRange(1,100); 0073 sbHorizontalSpacing->setValue(10); 0074 layout->addWidget(sbHorizontalSpacing, 1, 1); 0075 0076 label = new QLabel(i18n("Vertical spacing:"), widget); 0077 layout->addWidget(label, 2, 0); 0078 0079 sbVerticalSpacing = new QSpinBox(widget); 0080 sbVerticalSpacing->setRange(1,100); 0081 sbVerticalSpacing->setValue(10); 0082 layout->addWidget(sbVerticalSpacing, 2, 1); 0083 0084 label = new QLabel(i18n("Color:"), widget); 0085 layout->addWidget(label, 3, 0); 0086 0087 kcbColor = new KColorButton(widget); 0088 kcbColor->setColor(Qt::gray); 0089 layout->addWidget(kcbColor , 3, 1); 0090 0091 label = new QLabel(i18n("Opacity:"), widget); 0092 layout->addWidget(label, 4, 0); 0093 0094 sbOpacity = new QSpinBox(widget); 0095 sbOpacity->setRange(1,100); 0096 sbOpacity->setValue(100); 0097 layout->addWidget(sbOpacity, 4, 1); 0098 0099 label = new QLabel(i18n(" %"), widget); 0100 layout->addWidget(label, 4, 2); 0101 0102 auto* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0103 auto* vlayout = new QVBoxLayout(this); 0104 vlayout->addWidget(widget); 0105 vlayout->addWidget(buttonBox); 0106 0107 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0108 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0109 0110 //restore saved settings if available 0111 create(); // ensure there's a window created 0112 KConfigGroup conf(KSharedConfig::openConfig(), QLatin1String("GridDialog")); 0113 if (conf.exists()) { 0114 KWindowConfig::restoreWindowSize(windowHandle(), conf); 0115 resize(windowHandle()->size()); // workaround for QTBUG-40584 0116 } else 0117 resize(QSize(300, 0).expandedTo(minimumSize())); 0118 } 0119 0120 GridDialog::~GridDialog() { 0121 //save the current settings 0122 KConfigGroup conf(KSharedConfig::openConfig(), QLatin1String("GridDialog")); 0123 KWindowConfig::saveWindowSize(windowHandle(), conf); 0124 } 0125 0126 void GridDialog::save(WorksheetView::GridSettings& settings) { 0127 if (cbStyle->currentIndex() == 0) 0128 settings.style = WorksheetView::GridStyle::Line; 0129 else 0130 settings.style = WorksheetView::GridStyle::Dot; 0131 0132 settings.horizontalSpacing = sbHorizontalSpacing->value(); 0133 settings.verticalSpacing = sbVerticalSpacing->value(); 0134 settings.color = kcbColor->color(); 0135 settings.opacity = (float)sbOpacity->value()/100; 0136 }