raceicon.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #ifndef RACEICON_H
  2. #define RACEICON_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 RaceIcon : public QLabel {
  12. Q_OBJECT
  13. public:
  14. explicit RaceIcon(QWidget* parent = 0, int width = 64, int height = 64);
  15. ~RaceIcon();
  16. void setRaceIcon(QString racename);
  17. void setRaceIcon(QImage icon);
  18. void resize(int w, int h);
  19. void unsetRaceIcon();
  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 // RACEICON_H