ZKTextView.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * ZKTextView.h
  3. *
  4. * Created on: Jun 10, 2017
  5. * Author: guoxs
  6. */
  7. #ifndef _CONTROL_ZKTEXTVIEW_H_
  8. #define _CONTROL_ZKTEXTVIEW_H_
  9. #include "ZKBase.h"
  10. class ZKTextViewPrivate;
  11. /**
  12. * @brief 文本控件
  13. */
  14. class ZKTextView : public ZKBase {
  15. ZK_DECLARE_PRIVATE(ZKTextView)
  16. public:
  17. ZKTextView(ZKBase *pParent);
  18. virtual ~ZKTextView();
  19. /**
  20. * @brief 设置string文本
  21. */
  22. void setText(const std::string &text);
  23. /**
  24. * @brief 设置字符串文本
  25. */
  26. void setText(const char *text);
  27. /**
  28. * @brief 设置字符文本
  29. */
  30. void setText(char text);
  31. /**
  32. * @brief 设置数字文本
  33. */
  34. void setText(int text);
  35. /**
  36. * @brief 获取文本内容
  37. */
  38. const std::string& getText() const;
  39. /**
  40. * @brief 支持多国语言设置接口
  41. */
  42. void setTextTr(const char *name);
  43. void reloadTextTr();
  44. /**
  45. * @brief 设置文本颜色
  46. * @param color 颜色值为0x ARGB
  47. */
  48. void setTextColor(int color);
  49. /**
  50. * @brief 设置文本状态颜色
  51. * @param status 状态
  52. * 正常状态: ZK_CONTROL_STATUS_NORMAL
  53. * 按下状态: ZK_CONTROL_STATUS_PRESSED
  54. * 选中状态: ZK_CONTROL_STATUS_SELECTED
  55. * 选中按下状态: ZK_CONTROL_STATUS_PRESSED | ZK_CONTROL_STATUS_SELECTED
  56. * 无效状态: ZK_CONTROL_STATUS_INVALID
  57. * @param color 颜色值为0x ARGB
  58. */
  59. void setTextStatusColor(int status, uint32_t color);
  60. /**
  61. * @brief 获取文本内容宽高
  62. * @param text 文本内容
  63. * @param w 返回文本宽度
  64. * @param h 返回文本高度
  65. */
  66. void getTextExtent(const char *text, int &w, int &h);
  67. /**
  68. * @brief 设置文本大小
  69. * @param size 文本大小
  70. */
  71. void setTextSize(uint32_t size);
  72. /**
  73. * @brief 设置文本行间距
  74. * @param space 间距值
  75. */
  76. void setTextRowSpace(int space);
  77. /**
  78. * @brief 设置文本列间距
  79. * @param space 间距值
  80. */
  81. void setTextColSpace(int space);
  82. public:
  83. /**
  84. * @brief 文本内容改变监听接口
  85. */
  86. class ITextChangeListener {
  87. public:
  88. virtual ~ITextChangeListener() { }
  89. virtual void onTextChanged(ZKTextView *pTextView, const std::string &text) = 0;
  90. };
  91. void setTextChangeListener(ITextChangeListener *pListener);
  92. protected:
  93. ZKTextView(ZKBase *pParent, ZKBasePrivate *pBP);
  94. virtual void onBeforeCreateWindow(const Json::Value &json);
  95. virtual void onAfterCreateWindow(const Json::Value &json);
  96. virtual const char* getClassName() const { return ZK_TEXTVIEW; }
  97. virtual void onDraw(ZKCanvas *pCanvas);
  98. virtual void onTimer(int id);
  99. private:
  100. void parseTextViewAttributeFromJson(const Json::Value &json);
  101. };
  102. #endif /* _CONTROL_ZKTEXTVIEW_H_ */