qsptextbox.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #ifndef QSPTEXTBOX_H
  2. #define QSPTEXTBOX_H
  3. #include <QWidget>
  4. #include <QTextBrowser>
  5. #include <QString>
  6. #include <QFont>
  7. #include <QColor>
  8. #include <QImage>
  9. #include <QVariant>
  10. #include <QUrl>
  11. #include <QMovie>
  12. #include <QLabel>
  13. #include <QMap>
  14. #include <QKeyEvent>
  15. #include <QMutex>
  16. #include "videolabel.h"
  17. struct animation_gif
  18. {
  19. QMovie *movie;
  20. QLabel *movieLabel;
  21. };
  22. struct animation_video
  23. {
  24. VideoLabel *videoLabel;
  25. };
  26. namespace Ui {
  27. class QspTextBox;
  28. }
  29. class QspTextBox : public QTextBrowser
  30. {
  31. Q_OBJECT
  32. public:
  33. explicit QspTextBox(QWidget *parent = 0);
  34. ~QspTextBox();
  35. // Methods
  36. void RefreshUI(bool isScroll = false);
  37. // Accessors
  38. void SetIsHtml(bool isHtml);
  39. void SetText(const QString& text, bool isScroll = false);
  40. void SetTextFont(const QFont& new_font);
  41. QFont GetTextFont() const { return m_font; }
  42. QString GetText() const { return m_text; }
  43. bool SetLinkColor(const QColor &color);
  44. QColor GetLinkColor() { return m_linkColor; }
  45. void SetGamePath(const QString& path);
  46. QColor GetBackgroundColor();
  47. QColor GetForegroundColor(); //text color
  48. bool SetBackgroundColor(const QColor& color);
  49. bool SetForegroundColor(const QColor& color);
  50. void SetShowPlainText(bool isPlain);
  51. void SetDisableVideo(bool isDisableVideo) { disableVideo = isDisableVideo; }
  52. void keyPressEvent(QKeyEvent *event);
  53. #ifndef _WEBBOX_COMMON
  54. void SetBackgroundImage(const QImage& bmpBg);
  55. void LoadBackImage(const QString& fileName);
  56. //TODO:
  57. void SetHead(const QString &head) {};
  58. void SetFontType(const int fontType) {};
  59. void SetSizeType(const int sizeType) {};
  60. void SetCustomCSS(bool customCSS) {};
  61. #endif
  62. private:
  63. // Internal methods
  64. void wheelEvent(QWheelEvent *e);
  65. #ifndef _WEBBOX_COMMON
  66. void CalcImageSize();
  67. void paintEvent(QPaintEvent *e);
  68. QVariant loadResource(int type, const QUrl &name);
  69. void resizeEvent(QResizeEvent *e);
  70. void clearManualResources();
  71. #endif
  72. // Fields
  73. bool m_isUseHtml;
  74. QString m_outFormat;
  75. QString m_path;
  76. QString m_imagePath;
  77. QFont m_font;
  78. QString m_text;
  79. int m_posX;
  80. int m_posY;
  81. QColor m_linkColor;
  82. QColor m_backColor;
  83. QColor m_fontColor;
  84. bool showPlainText;
  85. bool disableVideo;
  86. #ifndef _WEBBOX_COMMON
  87. QImage m_bmpBg;
  88. QImage m_bmpRealBg;
  89. QMap<QString, animation_gif> animations_gif;
  90. QMap<QString, animation_video> animations_video;
  91. QMutex mutex;
  92. #endif
  93. #ifndef _WEBBOX_COMMON
  94. private slots:
  95. void repaintAnimation();
  96. void resizeAnimations();
  97. #endif
  98. };
  99. #endif // QSPTEXTBOX_H