Skip to content

Commit

Permalink
UI Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
Harinlen committed Jun 3, 2015
1 parent beb5be9 commit 05a32d5
Show file tree
Hide file tree
Showing 24 changed files with 650 additions and 264 deletions.
8 changes: 6 additions & 2 deletions Robot.pro
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ SOURCES += \
groundglobal.cpp \
polygoneditor.cpp \
robotmanagewidget.cpp \
about.cpp
about.cpp \
gridwidget.cpp \
robotbase.cpp

HEADERS += \
mainwindow.h \
Expand All @@ -54,7 +56,9 @@ HEADERS += \
groundglobal.h \
polygoneditor.h \
robotmanagewidget.h \
about.h
about.h \
gridwidget.h \
robotbase.h

RESOURCES += \
res.qrc
3 changes: 2 additions & 1 deletion about.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void About::showAbout(QWidget *parent)
About::About(QWidget *parent) :
QDialog(parent)
{
setWindowTitle(tr("About Robot Emulator"));
//Set the main layout.
QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::TopToBottom,
this);
Expand All @@ -40,7 +41,7 @@ About::About(QWidget *parent) :
icon->setPixmap(QPixmap("://res/icon.png"));
icon->setFixedSize(256, 256);
icon->setScaledContents(true);
mainLayout->addWidget(icon, 1, Qt::AlignHCenter);
mainLayout->addWidget(icon, 1, Qt::AlignCenter);
mainLayout->addWidget(new QLabel(tr("Robot Emulator"), this),
0,
Qt::AlignHCenter);
Expand Down
11 changes: 10 additions & 1 deletion generateground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <QBoxLayout>
#include <QPushButton>
#include <QTabWidget>
#include <QGroupBox>
#include <QMessageBox>

#include "groundbase.h"
Expand All @@ -32,6 +33,7 @@ GenerateGround::GenerateGround(QWidget *parent) :
m_borderEditor(new PolygonEditor(this)),
m_barracksEditor(new PolygonEditor(this)),
m_previewer(new GroundPreviewer(this)),
m_previewerGroup(new QGroupBox(this)),
m_okay(new QPushButton(this)),
m_cancel(new QPushButton(this))
{
Expand Down Expand Up @@ -113,7 +115,12 @@ GenerateGround::GenerateGround(QWidget *parent) :
setLayout(mainLayout);

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

QBoxLayout *groupLayout=new QBoxLayout(QBoxLayout::LeftToRight,
m_previewerGroup);
groupLayout->addWidget(m_previewer);
m_previewerGroup->setLayout(groupLayout);

m_tabManager->addTab(m_borderEditor, "");
m_tabManager->addTab(m_barracksEditor, "");
Expand All @@ -133,6 +140,8 @@ void GenerateGround::retranslate()
m_okay->setText(tr("Ok"));
m_cancel->setText(tr("Cancel"));

m_previewerGroup->setTitle(tr("Previewer"));

m_tabManager->setTabText(0, tr("Ground"));
m_tabManager->setTabText(1, tr("Barracks"));
}
Expand Down
2 changes: 2 additions & 0 deletions generateground.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "generategroundbase.h"

class QGroupBox;
class QPushButton;
class QTabWidget;
class PolygonEditor;
Expand Down Expand Up @@ -75,6 +76,7 @@ private slots:
QTabWidget *m_tabManager;
PolygonEditor *m_borderEditor, *m_barracksEditor;
GroundPreviewer *m_previewer;
QGroupBox *m_previewerGroup;
QPushButton *m_okay, *m_cancel;

QPolygonF m_border, m_barracks;
Expand Down
68 changes: 68 additions & 0 deletions gridwidget.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* Copyright (C) Kreogist Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QPainter>

#include "groundglobal.h"

#include "gridwidget.h"

GridWidget::GridWidget(QWidget *parent) :
QWidget(parent),
m_widget(nullptr)
{
setAutoFillBackground(true);
}

void GridWidget::paintEvent(QPaintEvent *event)
{
//Paint the widget.
QWidget::paintEvent(event);
//Paint the reference line.
QPainter painter(this);
painter.setPen(GroundGlobal::instance()->referenceLineColor());
painter.setBrush(QColor(0,0,0,0));
for(int i=30; i<=height(); i+=30)
{
painter.drawLine(0, i, width(), i);
}
for(int i=30; i<=width(); i+=30)
{
painter.drawLine(i, 0, i, height());
}
}
QWidget *GridWidget::widget() const
{
return m_widget;
}

void GridWidget::setWidget(QWidget *widget)
{
m_widget = widget;
m_widget->setParent(this);
}

void GridWidget::resizeEvent(QResizeEvent *event)
{
QWidget::resizeEvent(event);
//If the widget is not null, resize it.
if(m_widget)
{
m_widget->resize(size());
}
}

45 changes: 45 additions & 0 deletions gridwidget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (C) Kreogist Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef GRIDWIDGET_H
#define GRIDWIDGET_H

#include <QWidget>

class GridWidget : public QWidget
{
Q_OBJECT
public:
explicit GridWidget(QWidget *parent = 0);

QWidget *widget() const;
void setWidget(QWidget *widget);

signals:

public slots:

protected:
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event);

private:
QWidget *m_widget;
};

#endif // GRIDWIDGET_H
54 changes: 38 additions & 16 deletions ground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ Ground::Ground(QWidget *parent) :
m_lastOpenFolder(QApplication::applicationDirPath()),
m_lastSaveFolder(QApplication::applicationDirPath())
{
//Set parameters.
setContentsMargins(0,0,0,0);
//Initial robots.
Robot::initialRobotPatameters();
//Configure the timer.
m_timeline->setInterval(16); //This will update the image for 60fps.
m_timeline->setInterval(6); //This will update the image for 60fps.
connect(m_timeline, &QTimer::timeout,
this, &Ground::onActionUpdateRobot);

Expand All @@ -68,6 +71,11 @@ Ground::Ground(QWidget *parent) :
m_actions[SaveAs]->setShortcut(QKeySequence(Qt::CTRL+Qt::SHIFT+Qt::Key_S));
m_actions[Close]->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_W));

//Disable the save, save as and close as default.
m_actions[Save]->setEnabled(false);
m_actions[SaveAs]->setEnabled(false);
m_actions[Close]->setEnabled(false);

connect(m_actions[New],
static_cast<void (QAction::*)(bool)>(&QAction::triggered),
[=]{onActionNew();});
Expand Down Expand Up @@ -181,30 +189,36 @@ void Ground::paintEvent(QPaintEvent *event)
painter.setRenderHints(QPainter::Antialiasing |
QPainter::TextAntialiasing |
QPainter::SmoothPixmapTransform, true);
//Set translation.
painter.translate(Robot::detectRadius(), Robot::detectRadius());
//Draw the reference line.
painter.setPen(m_groundGlobal->referenceLineColor());
painter.setBrush(QColor(0,0,0,0));
for(int i=0; i<=height(); i+=30)
{
painter.drawLine(0, i, width(), i);
}
for(int i=0; i<=width(); i+=30)
{
painter.drawLine(i, 0, i, height());
}
//Draw the border.
painter.setPen(m_groundGlobal->borderColor());
QBrush borderBrush(Qt::DiagCrossPattern);
borderBrush.setColor(m_groundGlobal->borderColor());
painter.setBrush(borderBrush);
painter.drawPolygon(m_border);

//Draw the barracks.
painter.setPen(m_groundGlobal->barracksColor());
painter.setBrush(QColor(0,0,0,0));
painter.drawPolygon(m_barracks);

//Draw all the robot.
//First, draw the detect area.
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)
{
robot->paintRobotParameter(&painter);
}
//Finally, draw the robot.
for(Robot *robot : m_robotList)
{
robot->paintRobot(&painter);
}
}
Expand Down Expand Up @@ -294,7 +308,7 @@ void Ground::onActionUpdateRobot()
void Ground::onActionNew()
{
//Stop the time line.
m_timeline->stop();
pause();
//Close the current file.
if(!onActionClose())
{
Expand All @@ -319,7 +333,7 @@ void Ground::onActionNew()
bool Ground::onActionOpen()
{
//Stop the time line.
m_timeline->stop();
pause();

//Close the current file.
if(!onActionClose())
Expand Down Expand Up @@ -378,8 +392,8 @@ bool Ground::onActionSaveAs()

bool Ground::onActionClose()
{
//Stop the time line.
m_timeline->stop();
//Stop the timeline.
pause();

//Check if the current state is already close.
if(m_filePath.isEmpty() && !m_changed)
Expand Down Expand Up @@ -427,6 +441,10 @@ bool Ground::onActionClose()
m_filePath=QString();
m_fileName=QString();
m_changed=false;
//Disable save and save as.
m_actions[Save]->setEnabled(false);
m_actions[SaveAs]->setEnabled(false);
m_actions[Close]->setEnabled(false);
//Update the panel.
update();
return true;
Expand Down Expand Up @@ -646,6 +664,10 @@ bool Ground::readGroundData(const QString &filePath)
m_changed=false;
//Update the image.
update();
//Enabled save and save as actions.
m_actions[Save]->setEnabled(true);
m_actions[SaveAs]->setEnabled(true);
m_actions[Close]->setEnabled(true);
return true;
}
return false;
Expand Down
18 changes: 16 additions & 2 deletions groundglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ GroundGlobal *GroundGlobal::instance()

GroundGlobal::GroundGlobal(QObject *parent) :
QObject(parent),
m_borderColor(QColor(0,0,255)),
m_borderColor(QColor(5, 73, 88)),
m_barracksColor(QColor(255,127,0)),
m_referenceLineColor(QColor(200,200,200))
m_referenceLineColor(QColor(27, 68, 76)),
m_baseColor(QColor(1,33,44))
{
}

QColor GroundGlobal::baseColor() const
{
return m_baseColor;
}

void GroundGlobal::setBaseColor(const QColor &baseColor)
{
//Save base color.
m_baseColor = baseColor;
//Ask to change base color.
emit baseColorChanged(m_baseColor);
}

QColor GroundGlobal::borderColor()
{
return m_borderColor;
Expand Down
19 changes: 18 additions & 1 deletion groundglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,18 @@ class GroundGlobal : public QObject
*/
QColor referenceLineColor();

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

signals:
/*!
* \brief When this signal is emitted, it will ask the container to change
* the base color.
*/
void baseColorChanged(const QColor &color);

public slots:
/*!
Expand All @@ -69,10 +80,16 @@ public slots:
*/
void setBarracksColor(const QColor &barracksColor);

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

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

#endif // GROUNDGLOBAL_H
Loading

0 comments on commit 05a32d5

Please sign in to comment.