GraphViewSettingItem.cpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "pch.h"
  2. #include "GraphViewSettingItem.h"
  3. #include <QColorDialog>
  4. GraphViewSettingItem::GraphViewSettingItem(GraphView* view, GraphSeries* series, QWidget *parent) : QWidget(parent), series(series), view(view)
  5. {
  6. ui.setupUi(this);
  7. // Init
  8. switch (series->type) {
  9. case GraphSeries::SeriesType::Dot:
  10. ui.SytleComboBox->setCurrentIndex(1);
  11. break;
  12. case GraphSeries::SeriesType::LineDot:
  13. ui.SytleComboBox->setCurrentIndex(2);
  14. break;
  15. case GraphSeries::SeriesType::Line:
  16. default:
  17. ui.SytleComboBox->setCurrentIndex(0);
  18. break;
  19. }
  20. ui.LineSlider->setValue(series->lineWidth);
  21. ui.CircleSlider->setValue(series->circleRadius);
  22. dissableSlidersOnType();
  23. updateGroupBoxTitle();
  24. //Connect
  25. connect(ui.LineSlider, &QSlider::valueChanged, [=](const int& newValue) { series->lineWidth = newValue; view->update(); });
  26. connect(ui.CircleSlider, &QSlider::valueChanged, [=](const int& newValue) { series->circleRadius = newValue; view->update(); });
  27. connect(ui.SytleComboBox, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), [=](const int& newValue) { setType(newValue);dissableSlidersOnType();view->update(); });
  28. connect(ui.HideCheckbox, &QCheckBox::stateChanged, [=](const int& newValue) { series->hide = (newValue==2); view->update(); });
  29. //connect(ui.SetColorButton, &QPushButton::pressed, this, &GraphViewSettingItem::setColor);
  30. connect(ui.NameEdit, &QLineEdit::textChanged, [=](const QString& text) { series->name = text; updateGroupBoxTitle(); });
  31. }
  32. GraphViewSettingItem::~GraphViewSettingItem()
  33. {
  34. }
  35. void GraphViewSettingItem::dissableSlidersOnType()
  36. {
  37. switch (series->type) {
  38. case GraphSeries::SeriesType::Line:
  39. ui.LineSlider->setEnabled(true);
  40. ui.CircleSlider->setEnabled(false);
  41. break;
  42. case GraphSeries::SeriesType::Dot:
  43. ui.LineSlider->setEnabled(false);
  44. ui.CircleSlider->setEnabled(true);
  45. break;
  46. case GraphSeries::SeriesType::LineDot:
  47. ui.LineSlider->setEnabled(true);
  48. ui.CircleSlider->setEnabled(true);
  49. break;
  50. default:
  51. break;
  52. }
  53. }
  54. void GraphViewSettingItem::setType(int type)
  55. {
  56. switch (type) {
  57. case 0:
  58. series->type = GraphSeries::SeriesType::Line;
  59. break;
  60. case 1:
  61. series->type = GraphSeries::SeriesType::Dot;
  62. break;
  63. case 2:
  64. series->type = GraphSeries::SeriesType::LineDot;
  65. break;
  66. default:
  67. break;
  68. }
  69. }
  70. void GraphViewSettingItem::setColor()
  71. {
  72. QColor color = QColorDialog::getColor(series->color, this, "Set Series Color", QColorDialog::ShowAlphaChannel);
  73. if (!color.isValid()) return;
  74. series->color = color;
  75. updateGroupBoxTitle();
  76. view->update();
  77. }
  78. void GraphViewSettingItem::updateGroupBoxTitle()
  79. {
  80. ui.GroupBox->setTitle("Series: " + series->name);
  81. QString style = "QGroupBox { color: rgb(%1, %2, %3); };";
  82. ui.GroupBox->setStyleSheet(style.arg(series->color.red()).arg(series->color.green()).arg(series->color.blue()));
  83. }