BmpButton.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef BMPBUTTON_H
  2. #define BMPBUTTON_H
  3. #include <QAbstractButton>
  4. #include <QScopedPointer>
  5. class BmpButtonPrivate;
  6. class BmpButton : public QAbstractButton
  7. {
  8. Q_OBJECT
  9. Q_DISABLE_COPY(BmpButton)
  10. public:
  11. enum ButtonStatus {
  12. B_Normal = 0,
  13. B_Press,
  14. B_Check,
  15. };
  16. enum Type {
  17. T_Translate = 0,
  18. T_NoTranslate = 1
  19. };
  20. class CustomString {
  21. public:
  22. explicit CustomString(const QString& string, const bool translate) {
  23. this->string = string;
  24. this->translate = translate;
  25. }
  26. ~CustomString() {}
  27. QString string;
  28. bool translate;
  29. };
  30. explicit BmpButton(QWidget *parent = NULL);
  31. ~BmpButton();
  32. void setNormalBmpPath(const QString &path);
  33. void setPressBmpPath(const QString &path);
  34. void setCheckBmpPath(const QString &path);
  35. void setStatus(const BmpButton::ButtonStatus &status);
  36. BmpButton::ButtonStatus getStatus();
  37. void enableLongPress(const bool flag);
  38. void enableLongPressRestore(const bool flag);
  39. void setLanguageType(const BmpButton::Type type);
  40. void setCustomText(const QList<BmpButton::CustomString>& text);
  41. protected:
  42. bool event(QEvent* event);
  43. void styleChange();
  44. void mousePressEvent(QMouseEvent* event);
  45. void mouseReleaseEvent(QMouseEvent* event);
  46. void paintEvent(QPaintEvent* event);
  47. virtual void normalPaint(QPainter& painter);
  48. virtual void pressPaint(QPainter& painter);
  49. virtual void checkPaint(QPainter& painter);
  50. signals:
  51. void longPressed();
  52. private slots:
  53. void onTimeout();
  54. //signals:
  55. // void bmpButtomPress();
  56. // void bmpButtonRelease();
  57. private:
  58. friend class BmpButtonPrivate;
  59. QScopedPointer<BmpButtonPrivate> m_Private;
  60. };
  61. #endif // BMPBUTTON_H