DieItem.cpp 916 B

123456789101112131415161718192021222324252627282930
  1. #include "DieItem.h"
  2. #include <QPen>
  3. DieItem::DieItem(int row, int col, PICK_DIE_STATUS status, qreal size, QGraphicsItem* parent)
  4. : QGraphicsRectItem(parent), row(row), col(col), status(status) {
  5. setRect(0, 0, size, size); // 设置单元格大小
  6. setBrush(getColorByStatus(status));
  7. // 设置边框(Pen)
  8. setPen(QPen(QColor(0, 0, 0), 0.5)); // 黑色边框,宽度为0.5
  9. }
  10. QColor DieItem::getColorByStatus(PICK_DIE_STATUS status) {
  11. switch (status) {
  12. case DIE_EXIST: return QColor(0, 102, 255); // 蓝色
  13. case NO_EXIST: return QColor(200, 200, 200); // 浅灰
  14. case PICK_ING: return QColor(255, 255, 0); // 黄色
  15. case SKIP_DIE: return QColor(128, 128, 128); // 深灰
  16. case EDGE_DIE: return QColor(255, 165, 0); // 橙色
  17. default: return QColor(0, 0, 0);
  18. }
  19. }
  20. int DieItem::getRow() const {
  21. return row;
  22. }
  23. int DieItem::getCol() const {
  24. return col;
  25. }