raceicon.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef RACEICON_H
  2. #define RACEICON_H
  3. #include "race.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(QImage icon);
  17. void resize(int w, int h);
  18. void unsetRaceIcon();
  19. Race* getRace();
  20. void setRace(Race* race);
  21. int getState();
  22. void setState(int state);
  23. void deactivate();
  24. void activate();
  25. protected:
  26. void mousePressEvent(QMouseEvent* event) override;
  27. void enterEvent(QEvent* event) override;
  28. void leaveEvent(QEvent* event) override;
  29. signals:
  30. void clicked(RaceIcon*);
  31. void doubleclicked(RaceIcon*);
  32. void hovered(RaceIcon*);
  33. void unhovered(RaceIcon*);
  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. Race* race_;
  49. };
  50. #endif // RACEICON_H