コード例 #1
0
View::View(QWidget *parent):
    QGraphicsView(parent)
{
    setGeometry(300,300,GS_WIDTH,GS_HEIGHT);
    menu_scene = new GraphicMenu(-width()/2,-height()/2,width(),height(),this);
    board_scene = new GraphicBoard(-width()/2,-height()/2,width(),height(),this);

    QIcon icon(QPixmap(":/Graphic_source/icon.png"));
    setWindowIcon(icon);

    setWindowTitle("Pentago");
    setFixedSize(this->size());//TODO:equally resize
    setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
    setCacheMode(QGraphicsView::CacheBackground);
    setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);

    connect(menu_scene, SIGNAL(New_game_selected(int)), this, SIGNAL(New_game(int)));
    connect(menu_scene, SIGNAL(Join_game_selected(std::string)), this, SIGNAL(Join_game(std::string)));
    connect(menu_scene, SIGNAL(Host_game_selected(std::string)), this, SIGNAL(Host_game(std::string)));
    connect(menu_scene, SIGNAL(Exit_game_pressed()), this, SLOT(close()));
    connect(menu_scene, SIGNAL(Load_game_selected(std::string)),this,SIGNAL(Load_game(std::string)));

    connect(board_scene, SIGNAL(quadrant_rotated(IView::quadrant,IView::turn)), this, SIGNAL(Rotate(IView::quadrant,IView::turn)));
    connect(board_scene, SIGNAL(Stone_clicked(int, int)), this, SIGNAL(Put_stone(int,int)));
    connect(board_scene, SIGNAL(leave_game()),this,SLOT(on_leave_game()));
    connect(board_scene, SIGNAL(save_game(QString)),this,SLOT(on_save_game(QString)));

    connect(board_scene, SIGNAL(message_sended(QString)), this, SLOT(on_msg_sended(QString)));

    connect(menu_scene, SIGNAL(game_go_to_start()),board_scene, SLOT(clean_board()));
    connect(menu_scene, SIGNAL(game_go_to_start()),board_scene, SLOT(clean_log()));
    Set_control_settings(View::MENU);//it must be called in presenter after view constructing
}
コード例 #2
0
ChessFieldModel::ChessFieldModel(QObject *parent) :
    QAbstractListModel(parent), m_chess_piece_images(to_int(ChessPiece::BK_PAWN)+1)
{
    m_role_names[CELL_COLOR] = "cell_color";
    m_role_names[IMAGE_PATH] = "image_path";

    for(int i=0; i<4; i++) {
        for(int j=0; j<4; j++) {
            m_list.append(std::pair<QString,QString>("white",""));
            m_list.append(std::pair<QString,QString>("brown",""));
        }
        for(int j=0; j<4; j++) {
            m_list.append(std::pair<QString,QString>("brown",""));
            m_list.append(std::pair<QString,QString>("white",""));
        }
    }

    m_chess_piece_images[to_int(ChessPiece::NONE)]      = "";
    m_chess_piece_images[to_int(ChessPiece::WT_KING)]   = "img/assets/wt_king.png";
    m_chess_piece_images[to_int(ChessPiece::WT_QUEEN)]  = "img/assets/wt_queen.png";
    m_chess_piece_images[to_int(ChessPiece::WT_BISHOP)] = "img/assets/wt_bishop.png";
    m_chess_piece_images[to_int(ChessPiece::WT_KNIGHT)] = "img/assets/wt_knight.png";
    m_chess_piece_images[to_int(ChessPiece::WT_CASTLE)] = "img/assets/wt_castle.png";
    m_chess_piece_images[to_int(ChessPiece::WT_PAWN)]   = "img/assets/wt_pawn.png";

    m_chess_piece_images[to_int(ChessPiece::BK_KING)]   = "img/assets/bk_king.png";
    m_chess_piece_images[to_int(ChessPiece::BK_QUEEN)]  = "img/assets/bk_queen.png";
    m_chess_piece_images[to_int(ChessPiece::BK_BISHOP)] = "img/assets/bk_bishop.png";
    m_chess_piece_images[to_int(ChessPiece::BK_KNIGHT)] = "img/assets/bk_knight.png";
    m_chess_piece_images[to_int(ChessPiece::BK_CASTLE)] = "img/assets/bk_castle.png";
    m_chess_piece_images[to_int(ChessPiece::BK_PAWN)]   = "img/assets/bk_pawn.png";

    clean_board();
}