uniticon.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. Unit* getUnit();
  21. void setUnit(Unit* unit);
  22. void deactivate();
  23. void activate();
  24. void setState(int state);
  25. protected:
  26. void mousePressEvent(QMouseEvent* event);
  27. void enterEvent(QEvent* event);
  28. void leaveEvent(QEvent* event);
  29. signals:
  30. void clicked(UnitIcon*);
  31. void doubleclicked(UnitIcon*);
  32. void hovered(UnitIcon*);
  33. void unhovered(UnitIcon*);
  34. private:
  35. void drawIcon();
  36. int width_;
  37. int height_;
  38. int state_; // 0 = not initialized;
  39. // 1 = default;
  40. // 2 = hover;
  41. // 3 = active;
  42. QPixmap pixmap_;
  43. QImage active_border_;
  44. QImage hover_border_;
  45. QImage default_border_;
  46. QImage icon_;
  47. QTime previous_click_time_;
  48. QImage result_;
  49. Unit* unit_;
  50. };
  51. #endif // UNITICON_H