selectcard.h 810 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef SELECTCARD_H
  2. #define SELECTCARD_H
  3. #include <QWidget>
  4. #include <QPainter>
  5. #include <QDebug>
  6. namespace Ui
  7. {
  8. class SelectCard;
  9. }
  10. struct SelectCardItem
  11. {
  12. QString caption;
  13. int id;
  14. QRect rect;
  15. QRect closeRect;
  16. bool selected = false;
  17. };
  18. class SelectCard : public QWidget
  19. {
  20. Q_OBJECT
  21. public:
  22. explicit SelectCard(QWidget* parent = nullptr);
  23. ~SelectCard();
  24. void addItem(QString name, int id);
  25. void setSelected(int id);
  26. bool hasItemId(int id);
  27. void mousePressEvent(QMouseEvent* event);
  28. void updateItemText(int id, QString& s);
  29. void deleteItemById(int id);
  30. signals:
  31. void onSelected(SelectCardItem* item);
  32. protected:
  33. void paintEvent(QPaintEvent* event);
  34. private:
  35. Ui::SelectCard* ui;
  36. QList<SelectCardItem*> items;
  37. };
  38. #endif // SELECTCARD_H