123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 |
- #include "MaterialBox.h"
- MaterialBox::MaterialBox(int flag, QWidget *parent) :
- QWidget(parent)
- {
-
- }
- void MaterialBox::paintEvent(QPaintEvent *event)
- {
- QPainter painter(this);
- painter.setRenderHint(QPainter::Antialiasing);
-
- painter.fillRect(this->rect(), Qt::white);
- }
- void MaterialBox::paintInitFrom(QWidget *parent)
- {
-
- const int containerWidthdp = parent->width() * 0.25;
- const int containerHeightdp = parent->height() * 0.05;
- const int containerWidth = parent->width() * 0.5;
- const int containerHeight = parent->height() *0.9;
- globalPixmap = QPixmap(parent->width(), parent->height());
- globalPixmap.fill(Qt::white);
-
- QPainter painter(&globalPixmap);
- painter.setRenderHint(QPainter::Antialiasing);
-
- painter.setPen(Qt::black);
- painter.setBrush(Qt::lightGray);
- painter.drawRect(containerWidthdp, containerHeightdp, containerWidth, containerHeight);
-
- int innerWidth = containerWidth - 10;
- int innerHeight = containerHeight - 10;
- int innerX = containerWidthdp + containerWidth*0.1;
- int innerY = containerHeightdp + 5;
-
- const int totalLayers = m_boxes.iLayersTotal;
- const float spacing = static_cast<float>((static_cast<float>(innerHeight -totalLayers)) /static_cast<float>(totalLayers));
-
- float rectHeight = 2.5;
- const float rectWeight = static_cast<float>(innerWidth);
- if ((0 <= totalLayers) && (totalLayers <= 8))
- {
- rectHeight = 2.5;
- }
- else if((9<=totalLayers)&&(totalLayers<=16))
- {
- rectHeight = 1.5;
- }
- else
- {
- rectHeight = 1;
- }
-
- for(int i = 0; i < totalLayers; ++i)
- {
- const QColor color = m_boxes.iStatas[i] ? QColor(40, 129, 5) : QColor(255, 0, 0);
- const int yPos = innerY + i * (rectHeight + spacing);
- painter.setPen(Qt::NoPen);
- painter.setBrush(color);
- painter.drawRect(static_cast<float>(innerX), static_cast<float>(yPos), static_cast<float>(rectWeight), static_cast<float>(rectHeight));
- }
- }
- QPixmap MaterialBox::getGlobalPixmap() const
- {
- return globalPixmap;
- }
- void MaterialBox::initFrom(QWidget *parent)
- {
- int ratio = parent->height()/100;
-
-
-
- const int containerWidthdp = parent->width() * 0.25;
- const int containerHeightdp = parent->height() * 0.05;
- const int containerWidth = parent->width() * 0.5;
- const int containerHeight = parent->height() *0.9;
-
- int innerWidth = containerWidth - 10*ratio;
- int innerHeight = containerHeight - 10*ratio;
- int innerX = containerWidthdp + containerWidth*0.1;
- int innerY = containerHeightdp + 5*ratio;
-
- const int totalLayers = m_boxes.iLayersTotal;
- const float spacing = static_cast<float>((static_cast<float>(innerHeight -totalLayers*ratio)) /static_cast<float>(totalLayers));
-
- float rectHeight = 2.5*ratio;
- const float rectWeight = static_cast<float>(innerWidth);
- if((0<=totalLayers)&&(totalLayers<=8))
- {
- rectHeight = 2.5*ratio;
- }
- else if((9<=totalLayers)&&(totalLayers<=16))
- {
- rectHeight = 1.5*ratio;
- }
- else
- {
- rectHeight = 1*ratio;
- }
- BackgroundRect* backgroundRect = new BackgroundRect(containerWidthdp, containerHeightdp, containerWidth, containerHeight);
- m_pScene = new QGraphicsScene(parent);
- m_pView = new MaterialBoxGraphicsView(m_pScene);
- m_pScene->addItem(backgroundRect);
- for (int i = 0; i < totalLayers; ++i)
- {
- MaterialBoxDie* materialBoxDie = new MaterialBoxDie(i+1, m_boxes.iStatas[i],rectWeight, rectHeight);
- materialBoxDie->setPos(innerX,(innerY+ i * (rectHeight + spacing) ));
- m_pScene->addItem(materialBoxDie);
- }
- connect(m_pView, &MaterialBoxGraphicsView::layerRightClicked, this, &MaterialBox::handleLayerRightClicked);
- m_pView->resize(parent->width(), parent->height());
- m_pView->resetTransform();
- m_pView->setSceneRect(0, 0, parent->width(), parent->height());
- }
- void MaterialBox::UpdataVal(std::vector<ns_module::MATERIAL_BOX_STRUCT>& veMaterial)
- {
- for (auto& a : veMaterial)
- {
- m_boxes = a;
- }
- }
- void MaterialBox::setMaterialBoxInfo(ns_module::CViewInterface* CViewInterface) {
- m_pCViewInterface = CViewInterface;
- }
- void MaterialBox::UpdataGenerateTestData()
- {
- m_boxes = {
- 2,
- 32,
- 100,
- 50,
- {15.5, 20.3}
-
-
- };
- }
- void MaterialBox::handleLayerRightClicked(int layer)
- {
- qDebug() << "Right-clicked on layer:" << layer;
-
- }
|