#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "gamewindow.h"
#include <QMainWindow>
#include <QLabel>
#include <QTextBlock>
#include <QTextEdit>
#include <QHBoxLayout>
#include <QPushButton>
#include "imagebutton.h"
#include <QPoint>
#include <QCheckbox>
class mainWindow:public QWidget
{
Q_OBJECT
public:
mainWindow(QWidget*parent=0);
void mousePressEvent(QMouseEvent*e);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
private:
GameWindow *board;
QHBoxLayout *mainLayout;
QPushButton *button;
QPushButton *giveUp,*takeABack;
ImageButton *equal,*defeated,*back,*start;
QPoint last;
QPixmap bkGround;
QCheckBox *showStep;
void paintEvent(QPaintEvent *event);
signals:
void mainMenu();
protected slots:
void onReturnManiMenu();
void onPlayAgain();
};
#endif
#include "mainwindow.h"
#include <QLabel>
#include "gamewindow.h"
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
mainWindow::mainWindow(QWidget*parent):QWidget(parent)
{
bkGround = QPixmap(":/bkground/bkground");
this->setWindowIcon(QIcon(":/icon/Icon"));
mainLayout = new QHBoxLayout;
board = new GameWindow(this);
mainLayout->addWidget(board);
QVBoxLayout *rLayout = new QVBoxLayout;
start = new ImageButton(QPixmap(":/button/start0"),QPixmap(":/button/start1"),this);
start->setFixedSize(100,36);
rLayout->addWidget(start);
connect(start,SIGNAL(clicked(bool)),board,SLOT(start()));
back = new ImageButton(QPixmap(":/button/back0"),QPixmap(":/button/back1"),this);
back->setFixedSize(100,36);
rLayout->addWidget(back);
connect(back,SIGNAL(clicked(bool)),board,SLOT(Back()));
defeated = new ImageButton(QPixmap(":/button/defeated0"),QPixmap(":/button/defeated1"),this);
defeated->setFixedSize(100,36);
rLayout->addWidget(defeated);
connect(defeated,SIGNAL(clicked(bool)),board,SLOT(defeated()));
showStep = new QCheckBox(QStringLiteral("显示标号"),this);
showStep->setCheckable(true);
showStep->setChecked(false);
board->setShowStep(false);
rLayout->addWidget(showStep);
connect(showStep,SIGNAL(toggled(bool)),board,SLOT(setShowStep(bool)));
this->setSizePolicy(QSizePolicy::Fixed,QSizePolicy::Fixed);
mainLayout->addLayout(rLayout);
setLayout(mainLayout);
this->setWindowTitle("goBang.exe");
//this->setWindowFlags(Qt::FramelessWindowHint);
//this->setWindowFlags(Qt::WindowCloseButtonHint);
connect(board,SIGNAL(returnMainMenu()),this,SLOT(onReturnManiMenu()));
}
void mainWindow::mousePressEvent(QMouseEvent *event)
{
if(event->button()==Qt::LeftButton)
{
last = event->globalPos();
return;
}
QWidget::mousePressEvent(event);
}
void mainWindow::mouseMoveEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton){
int dx = event->globalX()-last.x();
int dy = event->globalY()-last.y();
last = event->globalPos();
move(x()+dx,y()+dy);
return;
}
QWidget::mouseMoveEvent(event);
}
void mainWindow::mouseReleaseEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton){
int dx = event->globalX()-last.x();
int dy = event->globalY()-last.y();
move(x()+dx,y()+dy);
return;
}
}
void mainWindow::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.drawPixmap(rect(),bkGround);
return;
}
void mainWindow::onReturnManiMenu()
{
emit mainMenu();
close();
}
void mainWindow::onPlayAgain()
{
}