mainwindow.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3. #include <QMainWindow>
  4. #include<QPainter>
  5. #include<QPaintEvent>
  6. #include<QMouseEvent>
  7. #include<QVector>
  8. #include<QMessageBox>
  9. #include"chessitem.h"
  10. /*
  11. QT的2D绘画
  12. */
  13. const int CHESS_R = 15;
  14. const int CHESS_C = 15;
  15. const int MAX_X = 50;
  16. const int MAX_Y = 50;
  17. QT_BEGIN_NAMESPACE
  18. namespace Ui { class MainWindow; }
  19. QT_END_NAMESPACE
  20. class MainWindow : public QMainWindow
  21. {
  22. Q_OBJECT
  23. public:
  24. MainWindow(QWidget *parent = nullptr);
  25. ~MainWindow();
  26. protected:
  27. //实时绘制界面
  28. void paintEvent(QPaintEvent *event);
  29. //点击事件
  30. void mousePressEvent(QMouseEvent *event);
  31. private:
  32. Ui::MainWindow *ui;
  33. bool b_black;
  34. //定义棋子个数
  35. QVector<ChessItem> p_ChessItem;
  36. //初始化界面
  37. void InitUI();
  38. //画棋盘
  39. void DraChessBoard();
  40. //画鼠标上的棋子
  41. void DrawHandChess();
  42. //绘制棋盘上的棋子
  43. void DrawChessItem();
  44. void DrawChessAtPoint(QPainter &painter,QPoint &point);
  45. //判断五子是否连接
  46. int CountNearItem(ChessItem item,QPoint pt);
  47. };
  48. #endif // MAINWINDOW_H