uniticon.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 resize(int w, int h);
  18. void unsetUnitIcon();
  19. void deactivate();
  20. void activate();
  21. protected:
  22. void mousePressEvent(QMouseEvent* event);
  23. void enterEvent(QEvent* event);
  24. void leaveEvent(QEvent* event);
  25. signals:
  26. void clicked();
  27. void doubleclicked();
  28. void hovered();
  29. void unhovered();
  30. private:
  31. void drawIcon();
  32. int width_;
  33. int height_;
  34. int state_; // 0 = not initialized;
  35. // 1 = default;
  36. // 2 = hover;
  37. // 3 = active;
  38. QPixmap pixmap_;
  39. QImage active_border_;
  40. QImage hover_border_;
  41. QImage default_border_;
  42. QImage icon_;
  43. QTime previous_click_time_;
  44. Unit* unit_;
  45. };
  46. #endif // UNITICON_H