ValueControl.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #include "ValueControl.h"
  2. ValueControl::ValueControl(
  3. QWidget* parent,
  4. const QPoint& pos,
  5. const QSize& size,
  6. CONTROL_PROPERTY* pProperty
  7. ) :
  8. QLineEdit(parent)
  9. , VControlObject(pProperty)
  10. {
  11. // 设置默认属性(初始化值或者外部传入值)
  12. if (m_Property.m_strText.isEmpty())
  13. {
  14. m_Property.m_strText = "Value";
  15. }
  16. QLineEdit::setText(m_Property.m_strText);
  17. QLineEdit::setToolTip(m_Property.m_strTip);
  18. this->setTextColor(m_Property.m_clrText);
  19. this->setBgColor(m_Property.m_clrBg);
  20. QLineEdit::setFont(m_Property.m_Font);
  21. QLineEdit::setEnabled(m_Property.m_bEnable);
  22. // 不可编辑
  23. QLineEdit::setReadOnly(true);
  24. // 设置尺寸
  25. if (size == DEFAULT_CONTROL_SIZE)
  26. {
  27. this->resize(DEFAULT_VALUE_SIZE);
  28. }
  29. else
  30. {
  31. this->resize(size);
  32. }
  33. // 设置中心点坐标
  34. QPoint tempPos;
  35. tempPos.setX(pos.x() - width() / 2);
  36. tempPos.setY(pos.y() - height() / 2);
  37. // 设置位置
  38. this->move(tempPos);
  39. m_pWidget = this;
  40. m_Type = VALUE_TYPE::Control_Value;
  41. //// 2022-9-11 Value控件需要绑定默认的DataLink
  42. //this->bindDefaultDataLink();
  43. }
  44. ValueControl::~ValueControl()
  45. {
  46. }
  47. // 属性的实现函数
  48. void ValueControl::setText(const QString& title)
  49. {
  50. // qDebug() << m_Property.m_strText;
  51. if (this->m_Property.m_strText != title)
  52. {
  53. this->m_Property.m_strText = title;
  54. QLineEdit::setText(title);
  55. }
  56. }
  57. void ValueControl::setTip(const QString& tip)
  58. {
  59. if (this->m_Property.m_strTip != tip)
  60. {
  61. this->m_Property.m_strTip = tip;
  62. QLineEdit::setToolTip(tip);
  63. }
  64. }
  65. void ValueControl::setTextColor(const QColor& color)
  66. {
  67. QString qss = VControlObject::textColorQss(color);
  68. this->setStyleSheet(qss);
  69. }
  70. void ValueControl::setBgColor(const QColor& color)
  71. {
  72. QString qss = VControlObject::bgColorQss(color);
  73. this->setStyleSheet(qss);
  74. }
  75. void ValueControl::setFont(const QFont& font)
  76. {
  77. if (this->m_Property.m_Font != font)
  78. {
  79. this->m_Property.m_Font = font;
  80. QLineEdit::setFont(font);
  81. }
  82. }
  83. void ValueControl::setEnable(const bool enable)
  84. {
  85. if (this->m_Property.m_bEnable != enable)
  86. {
  87. this->m_Property.m_bEnable = enable;
  88. QLineEdit::setEnabled(enable);
  89. }
  90. }