|
@@ -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, // iCurrLayers
|
|
|
- 32, // iLayersTotal
|
|
|
- 100, // iTopLev
|
|
|
- 50, // iBottomLev
|
|
|
- {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;
|
|
|
+ //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); // 1=绿,0=红
|
|
|
+ for(int i = 0; i < totalLayers; ++i)
|
|
|
+ {
|
|
|
+ const QColor color = m_boxes.iStatas[i] ? QColor(40, 129, 5) : QColor(255, 0, 0); // 1=绿,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;
|
|
|
// 主容器尺寸(占窗口80%)
|
|
|
// qDebug()<<ratio;
|
|
@@ -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;
|
|
|
+ //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, // iCurrLayers
|
|
|
+ 32, // iLayersTotal
|
|
|
+ 100, // iTopLev
|
|
|
+ 50, // iBottomLev
|
|
|
+ {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;
|
|
|
// 在这里可以添加其他处理逻辑,例如发送信号到其他对象
|
|
|
}
|