![](http://static.javashuo.com/static/loading.gif)
#include
"mainwindow.h"
![](http://static.javashuo.com/static/loading.gif)
MainWindow::MainWindow(QWidget *parent)
![](http://static.javashuo.com/static/loading.gif)
: QMainWindow(parent)
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
QToolBar *bar =
this->addToolBar(
"Tools");
![](http://static.javashuo.com/static/loading.gif)
QActionGroup *group =
new QActionGroup(bar);
![](http://static.javashuo.com/static/loading.gif)
QAction *drawLineAction =
new QAction(
"Line", bar);
![](http://static.javashuo.com/static/loading.gif)
drawLineAction->setIcon(QIcon(
":/line.png"));
![](http://static.javashuo.com/static/loading.gif)
drawLineAction->setToolTip(tr(
"Draw a line."));
![](http://static.javashuo.com/static/loading.gif)
drawLineAction->setStatusTip(tr(
"Draw a line."));
![](http://static.javashuo.com/static/loading.gif)
drawLineAction->setCheckable(
true);
![](http://static.javashuo.com/static/loading.gif)
drawLineAction->setChecked(
true);
![](http://static.javashuo.com/static/loading.gif)
group->addAction(drawLineAction);
![](http://static.javashuo.com/static/loading.gif)
bar->addAction(drawLineAction);
![](http://static.javashuo.com/static/loading.gif)
QAction *drawRectAction =
new QAction(
"Rectangle", bar);
![](http://static.javashuo.com/static/loading.gif)
drawRectAction->setIcon(QIcon(
":/rect.png"));
![](http://static.javashuo.com/static/loading.gif)
drawRectAction->setToolTip(tr(
"Draw a rectangle."));
![](http://static.javashuo.com/static/loading.gif)
drawRectAction->setStatusTip(tr(
"Draw a rectangle."));
![](http://static.javashuo.com/static/loading.gif)
drawRectAction->setCheckable(
true);
![](http://static.javashuo.com/static/loading.gif)
group->addAction(drawRectAction);
![](http://static.javashuo.com/static/loading.gif)
bar->addAction(drawRectAction);
![](http://static.javashuo.com/static/loading.gif)
QLabel *statusMsg =
new QLabel;
![](http://static.javashuo.com/static/loading.gif)
statusBar()->addWidget(statusMsg);
![](http://static.javashuo.com/static/loading.gif)
PaintWidget *paintWidget =
new PaintWidget(
this);
![](http://static.javashuo.com/static/loading.gif)
QGraphicsView *view =
new QGraphicsView(paintWidget,
this);
![](http://static.javashuo.com/static/loading.gif)
setCentralWidget(view);
![](http://static.javashuo.com/static/loading.gif)
connect(drawLineAction, SIGNAL(triggered()),
this, SLOT(drawLineActionTriggered()));
![](http://static.javashuo.com/static/loading.gif)
connect(drawRectAction, SIGNAL(triggered()),
this, SLOT(drawRectActionTriggered()));
![](http://static.javashuo.com/static/loading.gif)
connect(
this, SIGNAL(changeCurrentShape(Shape::Code)),
![](http://static.javashuo.com/static/loading.gif)
paintWidget, SLOT(setCurrentShape(Shape::Code)));
![](http://static.javashuo.com/static/loading.gif)
}
void MainWindow::drawLineActionTriggered()
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
emit changeCurrentShape(Shape::Line);
![](http://static.javashuo.com/static/loading.gif)
}
void MainWindow::drawRectActionTriggered()
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
emit changeCurrentShape(Shape::Rect);
![](http://static.javashuo.com/static/loading.gif)
}