diff --git a/ground.cpp b/ground.cpp index f00f6ca..a0bbedd 100644 --- a/ground.cpp +++ b/ground.cpp @@ -80,29 +80,26 @@ Ground::Ground(QWidget *parent) : retranslate(); //-----Example----- -// QPolygonF debugBorder, debugBarracks; -// //Set a default border. +// //Border. // debugBorder << QPointF(30, 60) << QPointF(120, 20) // << QPointF(400, 45) << QPointF(415, 280) // << QPointF(180, 340) << QPointF(15, 210); -// setBorder(debugBorder); -// //Set a default barracks. +// //Barracks. // debugBarracks << QPointF(200, 200) << QPointF(200, 275) // << QPointF(275, 275) << QPointF(275, 200); -// setBarracks(debugBarracks); -// //Set some robots. -// addRobot(new Robot(203, 203)); -// addRobot(new Robot(210, 210)); -// addRobot(new Robot(210, 220)); -// addRobot(new Robot(203, 210)); -// addRobot(new Robot(210, 203)); -// addRobot(new Robot(203, 250)); -// addRobot(new Robot(209, 250)); -// addRobot(new Robot(250, 210)); -// addRobot(new Robot(203, 207)); -// addRobot(new Robot(204, 207)); +// //Robots. +// Robot(203, 203)); +// Robot(210, 210)); +// Robot(210, 220)); +// Robot(203, 210)); +// Robot(210, 203)); +// Robot(203, 250)); +// Robot(209, 250)); +// Robot(250, 210)); +// Robot(203, 207)); +// Robot(204, 207)); } Ground::~Ground() @@ -413,6 +410,11 @@ void Ground::clearGroundData() m_robotList.clear(); m_robotInitialAngle.clear(); m_robotInitialPosition.clear(); + + //Hack way to repaint all the things. WTF! + hide(); + show(); + //Resize ground. setFixedSize(0,0); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 4dec181..130e09c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -34,16 +34,13 @@ MainWindow::MainWindow(QWidget *parent) : m_robotManagement(new RobotManagement(this)), m_groundGenerator(new GenerateGround(this)) { - //A hack, using box layout to make the ground the center. - QWidget *container=new QWidget(this); - //Set the central widget. - setCentralWidget(container); - QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::LeftToRight, - container); - container->setLayout(mainLayout); - //Add ground and panel to layout. - mainLayout->addWidget(m_ground, 1, Qt::AlignCenter); - mainLayout->addWidget(m_panel); + //Set the minimum size. + setMinimumSize(500, 309); + //Initial the scroll area. + QScrollArea *groundArea=new QScrollArea(this); + setCentralWidget(groundArea); + groundArea->setAlignment(Qt::AlignCenter); + groundArea->setWidget(m_ground); //Set the ground generator. m_ground->setGenerator(m_groundGenerator); diff --git a/robotaddwidget.cpp b/robotaddwidget.cpp index 36c21da..4dc3425 100644 --- a/robotaddwidget.cpp +++ b/robotaddwidget.cpp @@ -83,8 +83,8 @@ RobotAddWidget::RobotAddWidget(QWidget *parent) : mainLayout->widget()); buttonLayout->setSpacing(2); buttonLayout->addWidget(m_okay); - buttonLayout->addWidget(m_cancel); m_cancel->setShortcut(QKeySequence(Qt::Key_Escape)); + buttonLayout->addWidget(m_cancel); buttonLayout->addStretch(); mainLayout->addLayout(buttonLayout); @@ -107,6 +107,18 @@ void RobotAddWidget::updateXAndYRange(const int &minX, const int &minY, m_yData->setRange(minY, maxY); } +void RobotAddWidget::enabledWidget() +{ + m_okay->setDefault(true); + setEnabled(true); +} + +void RobotAddWidget::disabledWidget() +{ + m_okay->setDefault(false); + setEnabled(false); +} + void RobotAddWidget::showEvent(QShowEvent *event) { QWidget::showEvent(event); @@ -116,6 +128,8 @@ void RobotAddWidget::showEvent(QShowEvent *event) m_angleData->setValue(0); //Update the preview. onActionParameterChange(); + //Set the focus to x data edit. + m_xData->setFocus(); } void RobotAddWidget::retranslate() diff --git a/robotaddwidget.h b/robotaddwidget.h index 8c84e13..312cab8 100644 --- a/robotaddwidget.h +++ b/robotaddwidget.h @@ -51,6 +51,18 @@ class RobotAddWidget : public QWidget void updateXAndYRange(const int &minX, const int &minY, const int &maxX, const int &maxY); + /*! + * \brief Call this function will bind the default button and enabled this + * widget. + */ + void enabledWidget(); + + /*! + * \brief Call this function will unbind the default button and disable this + * widget. + */ + void disabledWidget(); + signals: /*! * \brief When this signal is emitted, the robot management dialog will be diff --git a/robotmanagement.cpp b/robotmanagement.cpp index 5d32b82..3719a69 100644 --- a/robotmanagement.cpp +++ b/robotmanagement.cpp @@ -110,7 +110,15 @@ GroundBase *RobotManagement::ground() void RobotManagement::addRobot() { + //Check the ground first. If it don't have a border, or barracks, we don't + //need to popup this dialog. + if(m_ground->border().isEmpty()) + { + return; + } //Show the add robot widget. + m_robotManagement->disabledWidget(); + m_robotAdd->enabledWidget(); m_stackLayout->setCurrentWidget(m_robotAdd); //Make the preview show the preview robot. m_groundPreview->setShowPreviewPoint(true); @@ -128,9 +136,17 @@ void RobotManagement::addRobot() void RobotManagement::manageRobot() { + //Check the ground first. If it don't have a border, or barracks, we don't + //need to popup this dialog. + if(m_ground->border().isEmpty()) + { + return; + } //When you manage the robot, we must reset the ground. m_ground->reset(); - //Show the manage widget. + //Show and enabled the manage widget, disabled the add widget. + m_robotAdd->disabledWidget(); + m_robotManagement->enabledWidget(); m_stackLayout->setCurrentWidget(m_robotManagement); //Hide the preview robot. m_groundPreview->setShowPreviewPoint(false); @@ -177,5 +193,6 @@ void RobotManagement::onActionAddRobot(const QPointF &position, //Or else, display an error information. QMessageBox::warning(this, tr("Add Robot Failed"), - tr("The robot is not in the barracks, you cannot add this robot")); + tr("The robot is not in the barracks, or the position has already got a robot.\n" + "Please change the position of the robot.")); } diff --git a/robotmanagewidget.cpp b/robotmanagewidget.cpp index 6d209ef..b70797e 100644 --- a/robotmanagewidget.cpp +++ b/robotmanagewidget.cpp @@ -89,8 +89,8 @@ RobotManageWidget::RobotManageWidget(QWidget *parent) : mainLayout->widget()); buttonLayout->setSpacing(2); buttonLayout->addWidget(m_okay); - buttonLayout->addWidget(m_cancel); m_cancel->setShortcut(QKeySequence(Qt::Key_Escape)); + buttonLayout->addWidget(m_cancel); buttonLayout->addStretch(); mainLayout->addLayout(buttonLayout); @@ -254,6 +254,18 @@ QList RobotManageWidget::angleList() return angleList; } +void RobotManageWidget::enabledWidget() +{ + m_okay->setDefault(true); + setEnabled(true); +} + +void RobotManageWidget::disabledWidget() +{ + m_okay->setDefault(false); + setEnabled(false); +} + void RobotManageWidget::setGround(GroundBase *ground) { //Save the new ground. diff --git a/robotmanagewidget.h b/robotmanagewidget.h index 2eab043..b427a39 100644 --- a/robotmanagewidget.h +++ b/robotmanagewidget.h @@ -65,6 +65,18 @@ class RobotManageWidget : public QWidget */ QList angleList(); + /*! + * \brief Call this function will bind the default button and enabled this + * widget. + */ + void enabledWidget(); + + /*! + * \brief Call this function will unbind the default button and disable this + * widget. + */ + void disabledWidget(); + signals: /*! * \brief When this signal is emitted, the robot management dialog will be