Warning, file /education/kmplot/kmplot/plotstylewidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 KmPlot - a math. function plotter for the KDE-Desktop 0003 0004 SPDX-FileCopyrightText: 2006 David Saxton <david@bluehaze.org> 0005 0006 This file is part of the KDE Project. 0007 KmPlot is part of the KDE-EDU Project. 0008 0009 SPDX-License-Identifier: GPL-2.0-or-later 0010 */ 0011 0012 #include "plotstylewidget.h" 0013 #include "kgradientdialog.h" 0014 #include "ui_plotstylewidget.h" 0015 0016 #include <KColorButton> 0017 0018 #include <QDialog> 0019 #include <QDialogButtonBox> 0020 #include <QHBoxLayout> 0021 #include <QLabel> 0022 0023 class PlotStyleDialogWidget : public QWidget, public Ui::PlotStyleWidget 0024 { 0025 public: 0026 PlotStyleDialogWidget(QWidget *parent = 0) 0027 : QWidget(parent) 0028 { 0029 setupUi(this); 0030 lineStyle->addItem(i18n("Solid"), int(Qt::SolidLine)); 0031 lineStyle->addItem(i18n("Dash"), int(Qt::DashLine)); 0032 lineStyle->addItem(i18n("Dot"), int(Qt::DotLine)); 0033 lineStyle->addItem(i18n("Dash Dot"), int(Qt::DashDotLine)); 0034 lineStyle->addItem(i18n("Dash Dot Dot"), int(Qt::DashDotDotLine)); 0035 } 0036 }; 0037 0038 // BEGIN class PlotStyleWidget 0039 PlotStyleWidget::PlotStyleWidget(QWidget *parent) 0040 : QGroupBox(parent) 0041 { 0042 m_color = new KColorButton(this); 0043 QPushButton *advancedButton = new QPushButton(this); 0044 advancedButton->setText(i18n("Advanced...")); 0045 connect(advancedButton, &QPushButton::clicked, this, &PlotStyleWidget::advancedOptions); 0046 0047 QHBoxLayout *layout = new QHBoxLayout; 0048 layout->addWidget(new QLabel(i18n("Color:"), this)); 0049 layout->addWidget(m_color); 0050 layout->addStretch(1); 0051 layout->addWidget(advancedButton); 0052 setLayout(layout); 0053 0054 m_dialog = new QDialog(this); 0055 QVBoxLayout *mainLayout = new QVBoxLayout; 0056 m_dialog->setLayout(mainLayout); 0057 m_dialog->setWindowTitle(i18nc("@title:window", "Plot Appearance")); 0058 0059 m_dialogWidget = new PlotStyleDialogWidget(m_dialog); 0060 m_dialogWidget->layout()->setContentsMargins(0, 0, 0, 0); 0061 mainLayout->addWidget(m_dialogWidget); 0062 0063 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok); 0064 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0065 okButton->setDefault(true); 0066 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0067 connect(buttonBox, &QDialogButtonBox::accepted, m_dialog, &QDialog::accept); 0068 connect(buttonBox, &QDialogButtonBox::rejected, m_dialog, &QDialog::reject); 0069 mainLayout->addWidget(buttonBox); 0070 } 0071 0072 void PlotStyleWidget::init(const PlotAppearance &plot, Function::Type type) 0073 { 0074 m_dialogWidget->gradientButton->setGradient(plot.gradient); 0075 m_dialogWidget->lineWidth->setValue(plot.lineWidth); 0076 m_color->setColor(plot.color); 0077 m_dialogWidget->useGradient->setChecked(plot.useGradient); 0078 setStyle(plot.style); 0079 m_dialogWidget->showExtrema->setChecked(plot.showExtrema); 0080 m_dialogWidget->showPlotName->setChecked(plot.showPlotName); 0081 0082 // Show/hide stuff as appropriate 0083 m_dialogWidget->showExtrema->setVisible(type == Function::Cartesian); 0084 m_dialogWidget->showTangentField->setVisible(type == Function::Differential); 0085 0086 layout()->invalidate(); 0087 resize(layout()->minimumSize()); 0088 } 0089 0090 PlotAppearance PlotStyleWidget::plot(bool visible) 0091 { 0092 PlotAppearance p; 0093 p.lineWidth = m_dialogWidget->lineWidth->value(); 0094 p.color = m_color->color(); 0095 p.useGradient = m_dialogWidget->useGradient->isChecked(); 0096 p.showTangentField = m_dialogWidget->showTangentField->isChecked(); 0097 p.gradient = m_dialogWidget->gradientButton->gradient(); 0098 p.visible = visible; 0099 p.style = style(); 0100 p.showExtrema = m_dialogWidget->showExtrema->isChecked(); 0101 p.showPlotName = m_dialogWidget->showPlotName->isChecked(); 0102 return p; 0103 } 0104 0105 Qt::PenStyle PlotStyleWidget::style() const 0106 { 0107 return (Qt::PenStyle)m_dialogWidget->lineStyle->itemData(m_dialogWidget->lineStyle->currentIndex()).toInt(); 0108 } 0109 0110 void PlotStyleWidget::setStyle(Qt::PenStyle style) 0111 { 0112 m_dialogWidget->lineStyle->setCurrentIndex(m_dialogWidget->lineStyle->findData(int(style))); 0113 } 0114 0115 void PlotStyleWidget::advancedOptions() 0116 { 0117 m_dialog->show(); 0118 } 0119 // END class PlotStyleWidget