Skip to content

Commit

Permalink
New session action
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 1, 2015
1 parent be65931 commit c828fb2
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 183 deletions.
13 changes: 4 additions & 9 deletions Robot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ SOURCES += \
paneldock.cpp \
robotaddwidget.cpp \
generateground.cpp \
groundeditor.cpp \
generategroundbase.cpp \
barrackseditor.cpp \
barrackseditorbase.cpp \
pointeditor.cpp \
groundpreviewer.cpp \
groundrealtimepreviewer.cpp \
groundglobal.cpp
groundglobal.cpp \
polygoneditor.cpp

HEADERS += \
mainwindow.h \
Expand All @@ -35,11 +32,9 @@ HEADERS += \
paneldock.h \
robotaddwidget.h \
generateground.h \
groundeditor.h \
generategroundbase.h \
barrackseditor.h \
barrackseditorbase.h \
pointeditor.h \
groundpreviewer.h \
groundrealtimepreviewer.h \
groundglobal.h
groundglobal.h \
polygoneditor.h
24 changes: 0 additions & 24 deletions barrackseditor.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions barrackseditor.h

This file was deleted.

24 changes: 0 additions & 24 deletions barrackseditorbase.cpp

This file was deleted.

36 changes: 0 additions & 36 deletions barrackseditorbase.h

This file was deleted.

109 changes: 103 additions & 6 deletions generateground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@
#include <QBoxLayout>
#include <QPushButton>
#include <QTabWidget>
#include <QMessageBox>

#include "groundeditor.h"
#include "barrackseditor.h"
#include "groundbase.h"
#include "polygoneditor.h"
#include "groundpreviewer.h"

#include "generateground.h"

GenerateGround::GenerateGround(QWidget *parent) :
GenerateGroundBase(parent),
m_tabManager(new QTabWidget(this)),
m_groundEditor(new GroundEditor(this)),
m_barracksEditor(new BarracksEditor(this)),
m_borderEditor(new PolygonEditor(this)),
m_barracksEditor(new PolygonEditor(this)),
m_previewer(new GroundPreviewer(this)),
m_okay(new QPushButton(this)),
m_cancel(new QPushButton(this))
{
Expand All @@ -37,13 +40,71 @@ GenerateGround::GenerateGround(QWidget *parent) :
setWindowFlags(Qt::Sheet);
#endif

//Link the previewer.
connect(m_borderEditor, &PolygonEditor::polygonChange,
m_previewer, &GroundPreviewer::setPreviewBorder);
connect(m_barracksEditor, &PolygonEditor::polygonChange,
m_previewer, &GroundPreviewer::setPreviewBarracks);

//Configure buttons.
m_cancel->setShortcut(QKeySequence(Qt::Key_Escape));
connect(m_okay,
static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
[=]
{
//Check is the ground and barracks polygon available.
QPolygonF ground=m_borderEditor->polygon();
if(ground.size()<3) //Simplified than a triangle.
{
//Set the tab to ground editor.
m_tabManager->setCurrentWidget(m_borderEditor);
//Raise the information.
QMessageBox::information(this,
tr("Ground border invalid"),
tr("The ground border must be at least a triangle."));
return;
}
QPolygonF barracks=m_barracksEditor->polygon();
if(barracks.size()<3) //Simplified than a triangle.
{
//Set the tab to barracks editor.
m_tabManager->setCurrentWidget(m_barracksEditor);
//Raise the information.
QMessageBox::information(this,
tr("Barracks border invalid"),
tr("The barracks border must be at least a triangle."));
return;
}
//Check the barracks is valid or not.
for(QPointF point : barracks)
{
//If there's one point which is not in the ground,
//Ask user to change the barracks.
if(!ground.containsPoint(point, Qt::OddEvenFill))
{
//Set the tab to barracks editor.
m_tabManager->setCurrentWidget(m_barracksEditor);
//Raise the information.
QMessageBox::information(this,
tr("Barracks border invalid"),
tr("The barracks border must be inside the border.\n"
"You may:\n"
" 1. Enlarge the border."
" 2. Reduce the barracks."));
return;
}
}
//Now all the polygon should be okay, save the data.
m_border=ground;
m_barracks=barracks;
//Finished.
done(QDialog::Accepted);
});
connect(m_cancel,
static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
[=]
{
close();
done(QDialog::Rejected);
});

//Initial the layout.
Expand All @@ -52,8 +113,9 @@ GenerateGround::GenerateGround(QWidget *parent) :
setLayout(mainLayout);

mainLayout->addWidget(m_tabManager, 1);
mainLayout->addWidget(m_previewer, 0, Qt::AlignCenter);

m_tabManager->addTab(m_groundEditor, "");
m_tabManager->addTab(m_borderEditor, "");
m_tabManager->addTab(m_barracksEditor, "");

QBoxLayout *buttonLayout=new QBoxLayout(QBoxLayout::TopToBottom,
Expand All @@ -74,3 +136,38 @@ void GenerateGround::retranslate()
m_tabManager->setTabText(0, tr("Ground"));
m_tabManager->setTabText(1, tr("Barracks"));
}

QPolygonF GenerateGround::barracks() const
{
return m_barracks;
}

void GenerateGround::setBarracks(const QPolygonF &barracks)
{
//Save the barracks first.
m_barracks = barracks;
//Set the polygon to the editor.
m_barracksEditor->setPolygon(m_barracks);
}

void GenerateGround::showEvent(QShowEvent *event)
{
//Show the widget.
GenerateGroundBase::showEvent(event);
//Set default widget to border editor.
m_tabManager->setCurrentWidget(m_borderEditor);
}

QPolygonF GenerateGround::border() const
{
return m_border;
}

void GenerateGround::setBorder(const QPolygonF &border)
{
//Save the border first.
m_border = border;
//Set the polygon to the editor.
m_borderEditor->setPolygon(m_border);
}

35 changes: 31 additions & 4 deletions generateground.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

class QPushButton;
class QTabWidget;
class GroundEditor;
class BarracksEditor;
class PolygonEditor;
class GroundPreviewer;
/*!
* \brief The GenerateGround class is a default realization of
* GenerateGroundBase.
Expand All @@ -39,18 +39,45 @@ class GenerateGround : public GenerateGroundBase
*/
explicit GenerateGround(QWidget *parent = 0);

/*!
* \brief Reimplemented from GenerateGroundBase::border().
*/
QPolygonF border() const;

/*!
* \brief Reimplemented from GenerateGroundBase::barracks().
*/
QPolygonF barracks() const;

signals:

public slots:
/*!
* \brief Reimplemented from GenerateGroundBase::setBorder().
*/
void setBorder(const QPolygonF &border);

/*!
* \brief Reimplemented from GenerateGroundBase::setBarracks().
*/
void setBarracks(const QPolygonF &barracks);

protected:
/*!
* \brief Reimplemented from GenerateGroundBase::showEvent().
*/
void showEvent(QShowEvent *event);

private slots:
void retranslate();

private:
QTabWidget *m_tabManager;
GroundEditor *m_groundEditor;
BarracksEditor *m_barracksEditor;
PolygonEditor *m_borderEditor, *m_barracksEditor;
GroundPreviewer *m_previewer;
QPushButton *m_okay, *m_cancel;

QPolygonF m_border, m_barracks;
};

#endif // GENERATEGROUND_H
24 changes: 0 additions & 24 deletions generategroundbase.cpp

This file was deleted.

Loading

0 comments on commit c828fb2

Please sign in to comment.