FlowGraphNodeWidget.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "FlowGraphNodeWidget.h"
  2. #include <QBoxLayout>
  3. #include <QLabel>
  4. #include <QCheckBox>
  5. #include <QComboBox>
  6. #include <QSpinBox>
  7. FlowGraphNodeWidget::FlowGraphNodeWidget(NodeWidgetType type, QWidget *parent) : QWidget(parent), m_type(type)
  8. {
  9. setFixedSize(QSize(130, 30));
  10. m_layout = new QVBoxLayout(this);
  11. m_layout->setMargin(0);
  12. }
  13. FlowGraphNodeWidget::NodeWidgetType FlowGraphNodeWidget::type() const
  14. {
  15. return m_type;
  16. }
  17. FlowGraphPlainNodeWidget::FlowGraphPlainNodeWidget(QWidget *parent) : FlowGraphNodeWidget(Plain, parent)
  18. {
  19. m_label = new QLabel(this);
  20. m_label->setText("test");
  21. m_label->setAlignment(Qt::AlignCenter);
  22. m_layout->setMargin(0);
  23. m_layout->addWidget(m_label);
  24. }
  25. void FlowGraphPlainNodeWidget::setText(const QString text)
  26. {
  27. m_label->setText(text);
  28. }
  29. FlowGraphCheckNodeWidget::FlowGraphCheckNodeWidget(QWidget *parent) : FlowGraphNodeWidget(CheckBox, parent)
  30. {
  31. m_checkBox = new QCheckBox("执行", this);
  32. m_layout->setMargin(0);
  33. m_layout->setAlignment(Qt::AlignCenter);
  34. m_layout->addWidget(m_checkBox);
  35. }
  36. FlowGraphComboNodeWidget::FlowGraphComboNodeWidget(QWidget *parent) : FlowGraphNodeWidget(ComboBox, parent)
  37. {
  38. m_combo = new QComboBox(this);
  39. setStyleSheet("QComboBox {"
  40. "border: 1px solid gray;"
  41. "border-radius: 3px;"
  42. "padding: 1px 18px 1px 3px;"
  43. "min-width: 6em;"
  44. "}"
  45. "QComboBox:editable {"
  46. "background: white;"
  47. "}"
  48. "QComboBox:!editable, QComboBox::drop-down:editable {"
  49. "background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
  50. "stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,"
  51. "stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);"
  52. "}");
  53. m_layout->addWidget(m_combo);
  54. }
  55. QList<QString> FlowGraphComboNodeWidget::items() const
  56. {
  57. return m_items;
  58. }
  59. void FlowGraphComboNodeWidget::setItems(QList<QString> items)
  60. {
  61. m_items = items;
  62. m_combo->clear();
  63. m_combo->addItems(items);
  64. }
  65. FlowGraphSpinNodeWidget::FlowGraphSpinNodeWidget(QWidget *parent) : FlowGraphNodeWidget(SpinBox, parent)
  66. {
  67. m_spinBox = new QSpinBox(this);
  68. m_spinBox->setMinimum(1);
  69. m_spinBox->setMaximum(10);
  70. m_spinBox->setValue(3);
  71. m_layout->addWidget(m_spinBox);
  72. }