多层停车场'

This commit is contained in:
wmj committed 2017-12-17 12:14:53 +08:00
1 parent 44681472d0
commit 91c77a42b5
14 files changed
+226 -260

No files matched your search

+50 -11
View File
@@ -1,17 +1,56 @@
#include "monitor.h"
#include <QPainter>
#include "ui_monitor.h"
#include <QObject>
#include <QDebug>
Monitor::Monitor(QWidget *parent) : QWidget(parent)
Monitor::Monitor(QWidget *parent) :
QWidget(parent),
ui(new Ui::Monitor)
{
resize(800, 600);
ui->setupUi(this);
QObject::connect(ui->downStairButton, QPushButton::clicked, [&]() {
qDebug() << "下一层按钮";
if (m_currentFloor > 0) {
m_currentFloor -= 1;
showParkinglot();
}
if (m_currentFloor == 0)
ui->downStairButton->setEnabled(false);
if (m_currentFloor == m_parkinglots.size() - 2)
ui->upStairButton->setEnabled(true);
});
QObject::connect(ui->upStairButton, QPushButton::clicked, [&]() {
qDebug() << "上一层按钮";
if (m_currentFloor < m_parkinglots.size() - 1) {
m_currentFloor += 1;
showParkinglot();
}
if (m_currentFloor == m_parkinglots.size() - 1)
ui->upStairButton->setEnabled(false);
if (m_currentFloor == 1)
ui->downStairButton->setEnabled(true);
});
if (m_currentFloor == 0) // 如果默认楼层就是顶层或者最下一层,把相应的按钮disable
ui->downStairButton->setEnabled(false);
else if (m_currentFloor == m_parkinglots.size() - 1)
ui->upStairButton->setEnabled(false);
showParkinglot();
}
void Monitor::paintEvent(QPaintEvent *) {
QPainter painter(this);
painter.drawLine(80, 100, 650, 500);
painter.setPen(Qt::red);
painter.drawRect(10, 10, 100, 400);
painter.setPen(QPen(Qt::green, 5));
painter.setBrush(Qt::blue);
painter.drawEllipse(50, 150, 400, 200);
Monitor::~Monitor()
{
delete ui;
}
void Monitor::showParkinglot()
{
if (m_parkinglots.at(m_currentFloor) == nullptr)
m_parkinglots[m_currentFloor] = new ParkingLotWidget(this, m_xmlPath.at(m_currentFloor));
ui->currentFloor->setText("<center>" + m_parkinglots.at(m_currentFloor)->getName() + "</center>");
for (auto p = m_parkinglots.begin(); p != m_parkinglots.end(); p++)
if (*p != nullptr)
(*p)->hide();
m_parkinglots.at(m_currentFloor)->show();
//ui->rootLayout->replaceWidget(ui->parkingLotView, m_parkinglots.at(m_currentFloor));
//ui->parkingLotView = m_parkinglots.at(m_currentFloor);
}