113 lines
4.1 KiB
C++
113 lines
4.1 KiB
C++
|
|
#include "settingsdialog.h"
|
||
|
|
|
||
|
|
SettingsDialog::SettingsDialog(QWidget *parent) :
|
||
|
|
QDialog(parent)
|
||
|
|
{
|
||
|
|
// 创建UI元素
|
||
|
|
QLabel *xMinLabel = new QLabel("X Axis Min:", this);
|
||
|
|
xMinLineEdit = new QLineEdit(this);
|
||
|
|
QLabel *xMaxLabel = new QLabel("X Axis Max:", this);
|
||
|
|
xMaxLineEdit = new QLineEdit(this);
|
||
|
|
QLabel *yMinLabel = new QLabel("Y Axis Min:", this);
|
||
|
|
yMinLineEdit = new QLineEdit(this);
|
||
|
|
QLabel *yMaxLabel = new QLabel("Y Axis Max:", this);
|
||
|
|
yMaxLineEdit = new QLineEdit(this);
|
||
|
|
|
||
|
|
QLabel *curveColor1Label = new QLabel("Curve 1 Color:", this);
|
||
|
|
curveColor1Button = new QPushButton(this);
|
||
|
|
curveColor1Button->setStyleSheet("background-color: blue");
|
||
|
|
|
||
|
|
QLabel *curveColor2Label = new QLabel("Curve 2 Color:", this);
|
||
|
|
curveColor2Button = new QPushButton(this);
|
||
|
|
curveColor2Button->setStyleSheet("background-color: green");
|
||
|
|
|
||
|
|
QLabel *backgroundColorLabel = new QLabel("Background Color:", this);
|
||
|
|
backgroundColorButton = new QPushButton(this);
|
||
|
|
backgroundColorButton->setStyleSheet("background-color: white");
|
||
|
|
|
||
|
|
gridCheckBox = new QCheckBox("Show Grid", this);
|
||
|
|
gridCheckBox->setChecked(true);
|
||
|
|
|
||
|
|
// 设置布局
|
||
|
|
QGridLayout *layout = new QGridLayout(this);
|
||
|
|
layout->addWidget(xMinLabel, 0, 0);
|
||
|
|
layout->addWidget(xMinLineEdit, 0, 1);
|
||
|
|
layout->addWidget(xMaxLabel, 1, 0);
|
||
|
|
layout->addWidget(xMaxLineEdit, 1, 1);
|
||
|
|
layout->addWidget(yMinLabel, 2, 0);
|
||
|
|
layout->addWidget(yMinLineEdit, 2, 1);
|
||
|
|
layout->addWidget(yMaxLabel, 3, 0);
|
||
|
|
layout->addWidget(yMaxLineEdit, 3, 1);
|
||
|
|
|
||
|
|
layout->addWidget(curveColor1Label, 4, 0);
|
||
|
|
layout->addWidget(curveColor1Button, 4, 1);
|
||
|
|
layout->addWidget(curveColor2Label, 5, 0);
|
||
|
|
layout->addWidget(curveColor2Button, 5, 1);
|
||
|
|
layout->addWidget(backgroundColorLabel, 6, 0);
|
||
|
|
layout->addWidget(backgroundColorButton, 6, 1);
|
||
|
|
|
||
|
|
layout->addWidget(gridCheckBox, 7, 0, 1, 2);
|
||
|
|
|
||
|
|
// 确认和取消按钮
|
||
|
|
QPushButton *okButton = new QPushButton("OK", this);
|
||
|
|
QPushButton *cancelButton = new QPushButton("Cancel", this);
|
||
|
|
|
||
|
|
QHBoxLayout *buttonLayout = new QHBoxLayout;
|
||
|
|
buttonLayout->addWidget(okButton);
|
||
|
|
buttonLayout->addWidget(cancelButton);
|
||
|
|
|
||
|
|
// 将按钮布局添加到主布局
|
||
|
|
layout->addLayout(buttonLayout, 8, 0, 1, 2);
|
||
|
|
|
||
|
|
// 设置对话框的主要布局
|
||
|
|
setLayout(layout);
|
||
|
|
|
||
|
|
// 连接按钮信号到槽
|
||
|
|
connect(curveColor1Button, &QPushButton::clicked, this, [=](){
|
||
|
|
QColor color = QColorDialog::getColor(Qt::blue, this);
|
||
|
|
if (color.isValid()) {
|
||
|
|
curveColor1Button->setStyleSheet(QString("background-color: %1").arg(color.name()));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
connect(curveColor2Button, &QPushButton::clicked, this, [=](){
|
||
|
|
QColor color = QColorDialog::getColor(Qt::green, this);
|
||
|
|
if (color.isValid()) {
|
||
|
|
curveColor2Button->setStyleSheet(QString("background-color: %1").arg(color.name()));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
connect(backgroundColorButton, &QPushButton::clicked, this, [=](){
|
||
|
|
QColor color = QColorDialog::getColor(Qt::white, this);
|
||
|
|
if (color.isValid()) {
|
||
|
|
backgroundColorButton->setStyleSheet(QString("background-color: %1").arg(color.name()));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
connect(okButton, &QPushButton::clicked, this, &QDialog::accept);
|
||
|
|
connect(cancelButton, &QPushButton::clicked, this, &QDialog::reject);
|
||
|
|
}
|
||
|
|
|
||
|
|
SettingsDialog::~SettingsDialog() = default;
|
||
|
|
|
||
|
|
double SettingsDialog::getXMin() const { return xMinLineEdit->text().toDouble(); }
|
||
|
|
double SettingsDialog::getXMax() const { return xMaxLineEdit->text().toDouble(); }
|
||
|
|
double SettingsDialog::getYMin() const { return yMinLineEdit->text().toDouble(); }
|
||
|
|
double SettingsDialog::getYMax() const { return yMaxLineEdit->text().toDouble(); }
|
||
|
|
|
||
|
|
QColor SettingsDialog::getCurveColor(int index) const {
|
||
|
|
switch (index) {
|
||
|
|
case 0: return QColor(curveColor1Button->styleSheet().mid(17, 7));
|
||
|
|
case 1: return QColor(curveColor2Button->styleSheet().mid(17, 7));
|
||
|
|
default: return QColor(Qt::black);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
QColor SettingsDialog::getBackgroundColor() const {
|
||
|
|
return QColor(backgroundColorButton->styleSheet().mid(17, 7));
|
||
|
|
}
|
||
|
|
|
||
|
|
bool SettingsDialog::isGridVisible() const {
|
||
|
|
return gridCheckBox->isChecked();
|
||
|
|
}
|