uniticon.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #ifndef UNITICON_H
  2. #define UNITICON_H
  3. #include "units/unit.h"
  4. #include <QObject>
  5. #include <QWidget>
  6. #include <QLabel>
  7. #include <QImage>
  8. #include <QPixmap>
  9. #include <QPainter>
  10. #include <QTime>
  11. class UnitIcon : public QLabel {
  12. Q_OBJECT
  13. public:
  14. explicit UnitIcon(QWidget* parent = 0, int width = 64, int height = 64);
  15. ~UnitIcon();
  16. void setUnitIcon(QString racename, QString unitname);
  17. void setUnitIcon(QImage icon);
  18. void resize(int w, int h);
  19. void unsetUnitIcon();
  20. void deactivate();
  21. void activate();
  22. protected:
  23. void mousePressEvent(QMouseEvent* event);
  24. void enterEvent(QEvent* event);
  25. void leaveEvent(QEvent* event);
  26. signals:
  27. void clicked();
  28. void doubleclicked();
  29. void hovered();
  30. void unhovered();
  31. private:
  32. void drawIcon();
  33. int width_;
  34. int height_;
  35. int state_; // 0 = not initialized;
  36. // 1 = default;
  37. // 2 = hover;
  38. // 3 = active;
  39. QPixmap pixmap_;
  40. QImage active_border_;
  41. QImage hover_border_;
  42. QImage default_border_;
  43. QImage icon_;
  44. QTime previous_click_time_;
  45. Unit* unit_;
  46. };
  47. #endif // UNITICON_H