Skip to content

Commit

Permalink
1.0 Release Candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 4, 2015
1 parent 05a32d5 commit 1133cb7
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 39 deletions.
5 changes: 4 additions & 1 deletion Robot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ win32
macx
{
ICON = icon.icns
QMAKE_CXXFLAGS -= -O2
QMAKE_CXXFLAGS += -O3
}

SOURCES += \
Expand Down Expand Up @@ -58,7 +60,8 @@ HEADERS += \
robotmanagewidget.h \
about.h \
gridwidget.h \
robotbase.h
robotbase.h \
mainpage.h

RESOURCES += \
res.qrc
26 changes: 25 additions & 1 deletion gridwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,45 @@

#include <QWidget>

/*!
* \brief The GridWidget class is a class provide the grid background for UI
* enhancement.
*/
class GridWidget : public QWidget
{
Q_OBJECT
public:
/*!
* \brief Construct the GridWidget.
* \param parent
*/
explicit GridWidget(QWidget *parent = 0);

/*!
* \brief Get the central widget.
* \return The central widget. It will be nullptr if you don't set.
*/
QWidget *widget() const;
void setWidget(QWidget *widget);

signals:

public slots:
/*!
* \brief Set the central widget. It will change the parentship of the
* widget.
* \param widget The prefer central widget.
*/
void setWidget(QWidget *widget);

protected:
/*!
* \brief Reimplemented from QWidget::resizeEvent().
*/
void resizeEvent(QResizeEvent *event);

/*!
* \brief Reimplemented from QWidget::paintEvent().
*/
void paintEvent(QPaintEvent *event);

private:
Expand Down
63 changes: 54 additions & 9 deletions ground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Ground::Ground(QWidget *parent) :
GroundBase(parent),
m_border(QPolygonF()),
m_barracks(QPolygonF()),
m_showDirection(true),
m_showDetectRadius(true),
m_filePath(QString()),
m_fileName(QString()),
m_changed(false),
Expand All @@ -55,7 +57,7 @@ Ground::Ground(QWidget *parent) :
//Initial robots.
Robot::initialRobotPatameters();
//Configure the timer.
m_timeline->setInterval(6); //This will update the image for 60fps.
setSpeed(16); //This will update the image for 60fps.
connect(m_timeline, &QTimer::timeout,
this, &Ground::onActionUpdateRobot);

Expand All @@ -64,6 +66,11 @@ Ground::Ground(QWidget *parent) :
{
m_actions[i]=new QAction(this);
}
m_actions[ShowDetectRange]->setCheckable(true);
m_actions[ShowDetectRange]->setChecked(true);

m_actions[ShowDirection]->setCheckable(true);
m_actions[ShowDirection]->setChecked(true);
//Set the key sequence.
m_actions[New]->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_N));
m_actions[Open]->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_O));
Expand Down Expand Up @@ -108,6 +115,13 @@ Ground::Ground(QWidget *parent) :
static_cast<void (QAction::*)(bool)>(&QAction::triggered),
[=]{onActionChangeDetectRangeLineColor();});

connect(m_actions[ShowDetectRange],
static_cast<void (QAction::*)(bool)>(&QAction::triggered),
[=]{update();});
connect(m_actions[ShowDirection],
static_cast<void (QAction::*)(bool)>(&QAction::triggered),
[=]{update();});

retranslate();

//-----Example-----
Expand Down Expand Up @@ -191,9 +205,16 @@ void Ground::paintEvent(QPaintEvent *event)
QPainter::SmoothPixmapTransform, true);
//Set translation.
painter.translate(Robot::detectRadius(), Robot::detectRadius());
//Draw the border.
//Draw the ground.
//Paint the ground base.
painter.setPen(Qt::NoPen);
QBrush borderBrush(Qt::SolidPattern);
borderBrush.setColor(m_groundGlobal->groundColor());
painter.setBrush(borderBrush);
painter.drawPolygon(m_border);
//Paint the ground border.
painter.setPen(m_groundGlobal->borderColor());
QBrush borderBrush(Qt::DiagCrossPattern);
borderBrush.setStyle(Qt::FDiagPattern);
borderBrush.setColor(m_groundGlobal->borderColor());
painter.setBrush(borderBrush);
painter.drawPolygon(m_border);
Expand All @@ -204,19 +225,34 @@ void Ground::paintEvent(QPaintEvent *event)
painter.drawPolygon(m_barracks);

//Draw all the robot.
if(m_robotList.isEmpty())
{
return;
}
//First, draw the detect area.
painter.setPen(Qt::NoPen);
for(Robot *robot : m_robotList)
if(m_actions[ShowDetectRange]->isChecked())
{
robot->paintRobotDetectArea(&painter);
painter.setPen(Qt::NoPen);
for(Robot *robot : m_robotList)
{
robot->paintRobotDetectArea(&painter);
}
}
//Then, draw the parameter.
painter.setPen(Robot::directionLineColor());
for(Robot *robot : m_robotList)
if(m_actions[ShowDirection]->isChecked())
{
robot->paintRobotParameter(&painter);
painter.setPen(Robot::directionLineColor());
painter.setBrush(Qt::NoBrush);
for(Robot *robot : m_robotList)
{
robot->paintRobotParameter(&painter);
}
}
//Finally, draw the robot.
QPen robotPen(Robot::robotBorder());
robotPen.setWidth(2);
painter.setPen(robotPen);
painter.setBrush(Robot::robotColor());
for(Robot *robot : m_robotList)
{
robot->paintRobot(&painter);
Expand All @@ -236,6 +272,8 @@ void Ground::retranslate()
m_actions[RobotColor]->setText(tr("Set robot color"));
m_actions[RobotDirectionLineColor]->setText(tr("Set robot direction line color"));
m_actions[RobotDetectRangeColor]->setText(tr("Set robot detect range color"));
m_actions[ShowDirection]->setText(tr("Show Robot Direction"));
m_actions[ShowDetectRange]->setText(tr("Show Detect Range"));
}

void Ground::onActionUpdateRobot()
Expand Down Expand Up @@ -830,6 +868,8 @@ void Ground::setMenuBar(MenuBar *menuBar)
menuBar->addCategoryAction(MenuBar::Ground, m_actions[RobotColor]);
menuBar->addCategoryAction(MenuBar::Ground, m_actions[RobotDirectionLineColor]);
menuBar->addCategoryAction(MenuBar::Ground, m_actions[RobotDetectRangeColor]);
menuBar->addCategoryAction(MenuBar::Ground, m_actions[ShowDirection]);
menuBar->addCategoryAction(MenuBar::Ground, m_actions[ShowDetectRange]);
}

void Ground::setGenerator(GenerateGroundBase *generator)
Expand Down Expand Up @@ -863,6 +903,11 @@ void Ground::syncRobotData(const QList<Robot *> &robots,
reset();
}

void Ground::setSpeed(const int &speed)
{
m_timeline->setInterval(speed);
}

void Ground::setBarracks(const QPolygonF &barracks)
{
//Check if the barracks is all in the border.
Expand Down
12 changes: 11 additions & 1 deletion ground.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Ground : public GroundBase
void setGenerator(GenerateGroundBase *generator);

/*!
* \brief syncRobotData.
* \brief Reimplemented from GroundBase::syncRobotData().
*/
void syncRobotData(const QList<Robot *> &robots,
const QList<QPointF> &initialPosition,
Expand All @@ -77,6 +77,11 @@ class Ground : public GroundBase
signals:

public slots:
/*!
* \brief Reimplemented from GroundBase::setSpeed().
*/
void setSpeed(const int &speed);

/*!
* \brief Reimplemented from GroundBase::setBorder(const QPolygonF &).
*/
Expand Down Expand Up @@ -170,13 +175,18 @@ private slots:
RobotColor,
RobotDirectionLineColor,
RobotDetectRangeColor,
ShowDirection,
ShowDetectRange,
GroundActionsCount
};
QAction *m_actions[GroundActionsCount];

QPolygonF m_border, m_barracks;
QList<Robot *> m_robotList;

//Display options.
bool m_showDirection, m_showDetectRadius;

//Project file status.
QString m_filePath, m_fileName;
bool m_changed;
Expand Down
22 changes: 19 additions & 3 deletions groundbase.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ class GroundBase : public QWidget

/*!
* \brief Set the robots information to the given parameters, remove the
* \param robots
* \param initialPosition
* \param initialAngle
* \param robots The robot list.
* \param initialPosition The initial position of the robots.
* \param initialAngle The initial angle of the robots.
*/
virtual void syncRobotData(const QList<Robot *> &robots,
const QList<QPointF> &initialPosition,
Expand All @@ -125,6 +125,22 @@ class GroundBase : public QWidget
void barracksChanged();

public slots:
/*!
* \brief Change the time line speed of the ground. The parameter speed
* should be one of the following data:\n
* Format: Value - Description (Update Interval, Maximum Frame Per Second)\n
* * 64 - A quarter speed (64ms, 15fps) \n
* * 32 - A half speed (32ms, 30 fps) \n
* * 16 - Original speed (16ms, 60 fps) \n
* * 8 - Double speed (8ms, 120 fps) \n
* * 5 - Triple speed (5ms, 180 fps) \n
* * 4 - Quadra speed. (4ms, 240fps) \n
* * 3 - Panta speed. (3ms, 300fps) \n
* * 2 - Hexa speed. (2ms, 480fps)
* \param speedMeter The speed interval.
*/
virtual void setSpeed(const int &speed)=0;

/*!
* \brief Sets the border for the ground to border. \n
* The border must be at least a triangle, if it's not a more complex
Expand Down
17 changes: 14 additions & 3 deletions groundglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ GroundGlobal *GroundGlobal::instance()

GroundGlobal::GroundGlobal(QObject *parent) :
QObject(parent),
m_borderColor(QColor(5, 73, 88)),
m_barracksColor(QColor(255,127,0)),
m_borderColor(QColor(73, 229, 249, 100)),
m_barracksColor(QColor(79,219,251)),
m_referenceLineColor(QColor(27, 68, 76)),
m_baseColor(QColor(1,33,44))
m_baseColor(QColor(1,7,20)),
m_groundColor(QColor(0x00, 0x40, 0x51))
{
}

QColor GroundGlobal::groundColor() const
{
return m_groundColor;
}

void GroundGlobal::setGroundColor(const QColor &groundColor)
{
m_groundColor = groundColor;
}

QColor GroundGlobal::baseColor() const
{
return m_baseColor;
Expand Down
15 changes: 14 additions & 1 deletion groundglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ class GroundGlobal : public QObject
*/
QColor baseColor() const;

/*!
* \brief Get the color of the ground.
* \return The QColor of the ground.
*/
QColor groundColor() const;

signals:
/*!
* \brief When this signal is emitted, it will ask the container to change
Expand All @@ -86,10 +92,17 @@ public slots:
*/
void setBaseColor(const QColor &baseColor);

/*!
* \brief Sets the color of the ground.
* \param groundColor The prefer color of the ground.
*/
void setGroundColor(const QColor &groundColor);

private:
static GroundGlobal *m_instance;
explicit GroundGlobal(QObject *parent = 0);
QColor m_borderColor, m_barracksColor, m_referenceLineColor, m_baseColor;
QColor m_borderColor, m_barracksColor, m_referenceLineColor, m_baseColor,
m_groundColor;
};

#endif // GROUNDGLOBAL_H
Loading

0 comments on commit 1133cb7

Please sign in to comment.