|
@@ -1,17 +1,10 @@
|
|
|
#include "MaterialBox.h"
|
|
|
|
|
|
|
|
|
-MaterialBox::MaterialBox(int flag, QWidget *parent) : QWidget(parent)
|
|
|
+MaterialBox::MaterialBox(int flag, QWidget *parent) :
|
|
|
+ QWidget(parent)
|
|
|
{
|
|
|
- boxes = {
|
|
|
- 2,
|
|
|
- 32,
|
|
|
- 100,
|
|
|
- 50,
|
|
|
- {15.5, 20.3},
|
|
|
- {1,0,1,1,0},
|
|
|
-
|
|
|
- };
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -52,22 +45,28 @@ void MaterialBox::paintInitFrom(QWidget *parent)
|
|
|
int innerY = containerHeightdp + 5;
|
|
|
|
|
|
|
|
|
- const int totalLayers = boxes.iLayersTotal;
|
|
|
+ const int totalLayers = m_boxes.iLayersTotal;
|
|
|
const float spacing = static_cast<float>((static_cast<float>(innerHeight -totalLayers)) /static_cast<float>(totalLayers));
|
|
|
- qDebug()<<spacing;
|
|
|
+
|
|
|
float rectHeight = 2.5;
|
|
|
const float rectWeight = static_cast<float>(innerWidth);
|
|
|
- if((0<=totalLayers)&&(totalLayers<=8)){
|
|
|
+ if ((0 <= totalLayers) && (totalLayers <= 8))
|
|
|
+ {
|
|
|
rectHeight = 2.5;
|
|
|
- }else if((9<=totalLayers)&&(totalLayers<=16)){
|
|
|
+ }
|
|
|
+ else if((9<=totalLayers)&&(totalLayers<=16))
|
|
|
+ {
|
|
|
rectHeight = 1.5;
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
rectHeight = 1;
|
|
|
}
|
|
|
|
|
|
|
|
|
- for(int i = 0; i < totalLayers; ++i) {
|
|
|
- const QColor color = boxes.iStatas[i] ? QColor(40, 129, 5) : QColor(255, 0, 0);
|
|
|
+ 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);
|
|
@@ -76,12 +75,13 @@ void MaterialBox::paintInitFrom(QWidget *parent)
|
|
|
|
|
|
}
|
|
|
|
|
|
-QPixmap MaterialBox::getGlobalPixmap() const {
|
|
|
+QPixmap MaterialBox::getGlobalPixmap() const
|
|
|
+{
|
|
|
return globalPixmap;
|
|
|
}
|
|
|
|
|
|
-void MaterialBox::initFrom(QWidget *parent){
|
|
|
-
|
|
|
+void MaterialBox::initFrom(QWidget *parent)
|
|
|
+{
|
|
|
int ratio = parent->height()/100;
|
|
|
|
|
|
|
|
@@ -97,37 +97,64 @@ void MaterialBox::initFrom(QWidget *parent){
|
|
|
int innerY = containerHeightdp + 5*ratio;
|
|
|
|
|
|
|
|
|
- const int totalLayers = boxes.iLayersTotal;
|
|
|
+ const int totalLayers = m_boxes.iLayersTotal;
|
|
|
const float spacing = static_cast<float>((static_cast<float>(innerHeight -totalLayers*ratio)) /static_cast<float>(totalLayers));
|
|
|
- qDebug()<<spacing;
|
|
|
+
|
|
|
float rectHeight = 2.5*ratio;
|
|
|
const float rectWeight = static_cast<float>(innerWidth);
|
|
|
- if((0<=totalLayers)&&(totalLayers<=8)){
|
|
|
+ if((0<=totalLayers)&&(totalLayers<=8))
|
|
|
+ {
|
|
|
rectHeight = 2.5*ratio;
|
|
|
- }else if((9<=totalLayers)&&(totalLayers<=16)){
|
|
|
+ }
|
|
|
+ else if((9<=totalLayers)&&(totalLayers<=16))
|
|
|
+ {
|
|
|
rectHeight = 1.5*ratio;
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
rectHeight = 1*ratio;
|
|
|
}
|
|
|
|
|
|
BackgroundRect* backgroundRect = new BackgroundRect(containerWidthdp, containerHeightdp, containerWidth, containerHeight);
|
|
|
- scene = new QGraphicsScene(parent);
|
|
|
- view = new MaterialBoxGraphicsView(scene);
|
|
|
- scene->addItem(backgroundRect);
|
|
|
- for (int i = 0; i < totalLayers; ++i) {
|
|
|
- MaterialBoxDie* materialBoxDie = new MaterialBoxDie(i, 0, boxes.iStatas[i],rectWeight, rectHeight);
|
|
|
+ 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, 0, m_boxes.iStatas[i],rectWeight, rectHeight);
|
|
|
materialBoxDie->setPos(innerX,(innerY+ i * (rectHeight + spacing) ));
|
|
|
- scene->addItem(materialBoxDie);
|
|
|
+ m_pScene->addItem(materialBoxDie);
|
|
|
|
|
|
}
|
|
|
- connect(view, &MaterialBoxGraphicsView::layerRightClicked, this, &MaterialBox::handleLayerRightClicked);
|
|
|
- view->resize(parent->width(), parent->height());
|
|
|
- view->resetTransform();
|
|
|
- view->setSceneRect(0, 0, parent->width(), parent->height());
|
|
|
+ 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::UpdataGenerateTestData()
|
|
|
+{
|
|
|
+ m_boxes = {
|
|
|
+ 2,
|
|
|
+ 32,
|
|
|
+ 100,
|
|
|
+ 50,
|
|
|
+ {15.5, 20.3},
|
|
|
+ {1,0,1,1,0},
|
|
|
+
|
|
|
+ };
|
|
|
}
|
|
|
-void MaterialBox::handleLayerRightClicked(int layer) {
|
|
|
+
|
|
|
+void MaterialBox::handleLayerRightClicked(int layer)
|
|
|
+{
|
|
|
qDebug() << "Right-clicked on layer:" << layer;
|
|
|
|
|
|
}
|