2021-01-12 12:15:03 +08:00
|
|
|
#include "StateWidget.h"
|
|
|
|
|
|
2021-03-05 15:32:31 +08:00
|
|
|
StateWidget::StateWidget(int flag,int index,QWidget *parent) : QWidget(parent)
|
2021-01-12 12:15:03 +08:00
|
|
|
{
|
|
|
|
|
gridlayout = new QGridLayout(this);
|
|
|
|
|
gridlayout->setMargin(0);
|
|
|
|
|
gridlayout->setVerticalSpacing(6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
title = new QLabel("new status");
|
|
|
|
|
title->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
2021-04-25 09:28:46 +08:00
|
|
|
title->setFixedSize(w/2,h+m_offset);
|
2021-01-12 12:15:03 +08:00
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
gridlayout->addWidget(title,0,0,1,1);
|
2021-01-12 12:15:03 +08:00
|
|
|
|
|
|
|
|
if(flag == 0)
|
|
|
|
|
{
|
|
|
|
|
label = new QLabel("0");
|
|
|
|
|
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
2021-04-25 09:28:46 +08:00
|
|
|
label->setFixedSize(w/2,h+m_offset);
|
2021-04-14 18:23:36 +08:00
|
|
|
setColor(state::gray);
|
|
|
|
|
gridlayout->addWidget(label,0,1,1,1);
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bar = new QProgressBar();
|
|
|
|
|
bar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
bar->setRange(0,100);
|
|
|
|
|
bar->setValue(0);
|
2021-04-25 09:28:46 +08:00
|
|
|
bar->setFixedSize(w/2,h+m_offset);
|
2021-04-14 18:23:36 +08:00
|
|
|
gridlayout->addWidget(bar,0,1,1,1);
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
2021-04-14 18:23:36 +08:00
|
|
|
|
|
|
|
|
this->setLayout(gridlayout);
|
2021-04-25 09:28:46 +08:00
|
|
|
this->resize(w,h+ 2 * m_offset);
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-03-05 15:32:31 +08:00
|
|
|
StateWidget::StateWidget(int flag, QString t,QVariant v,state s,int index, QWidget *parent) : QWidget(parent)
|
2021-01-12 12:15:03 +08:00
|
|
|
{
|
2021-03-05 15:32:31 +08:00
|
|
|
|
|
|
|
|
id = index;
|
|
|
|
|
|
2021-01-12 12:15:03 +08:00
|
|
|
gridlayout = new QGridLayout(this);
|
|
|
|
|
gridlayout->setMargin(0);
|
|
|
|
|
gridlayout->setVerticalSpacing(6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
title = new QLabel(t);
|
|
|
|
|
title->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
2021-04-25 09:28:46 +08:00
|
|
|
title->setFixedSize(w/2,h+m_offset);
|
2021-01-12 12:15:03 +08:00
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
gridlayout->addWidget(title,0,0,1,1);
|
2021-01-12 12:15:03 +08:00
|
|
|
|
|
|
|
|
if(flag == 0)
|
|
|
|
|
{
|
|
|
|
|
label = new QLabel(v.toString());
|
|
|
|
|
label->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
2021-04-25 09:28:46 +08:00
|
|
|
label->setFixedSize(w/2,h+m_offset);
|
2021-04-14 18:23:36 +08:00
|
|
|
setColor(s);
|
|
|
|
|
gridlayout->addWidget(label,0,1,1,1);
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bar = new QProgressBar();
|
2021-04-14 18:23:36 +08:00
|
|
|
bar->setFormat("%v");
|
2021-01-12 12:15:03 +08:00
|
|
|
bar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
|
|
|
|
bar->setRange(0,100);
|
|
|
|
|
bar->setValue(v.toDouble());
|
2021-04-25 09:28:46 +08:00
|
|
|
bar->setFixedSize(w/2,h+m_offset);
|
2021-04-14 18:23:36 +08:00
|
|
|
gridlayout->addWidget(bar,0,1,1,1);
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
2021-04-14 18:23:36 +08:00
|
|
|
|
|
|
|
|
this->setLayout(gridlayout);
|
2021-04-25 09:28:46 +08:00
|
|
|
this->resize(w,h + 2 * m_offset);
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
StateWidget::~StateWidget()
|
|
|
|
|
{
|
|
|
|
|
if(title)
|
|
|
|
|
{
|
|
|
|
|
delete title;
|
|
|
|
|
}
|
2021-01-12 12:15:03 +08:00
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
if(label)
|
|
|
|
|
{
|
|
|
|
|
delete label;
|
|
|
|
|
}
|
2021-01-12 12:15:03 +08:00
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
if(bar)
|
|
|
|
|
{
|
|
|
|
|
delete bar;
|
|
|
|
|
}
|
2021-01-12 12:15:03 +08:00
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
if(gridlayout)
|
|
|
|
|
{
|
|
|
|
|
delete gridlayout;
|
|
|
|
|
}
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
void StateWidget::setColor(state s)
|
|
|
|
|
{
|
|
|
|
|
if(label)
|
|
|
|
|
{
|
|
|
|
|
label->setProperty("state",s);
|
|
|
|
|
label->style()->unpolish(label);
|
|
|
|
|
label->style()->polish(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(bar)
|
|
|
|
|
{
|
|
|
|
|
bar->setProperty("state",s);
|
|
|
|
|
bar->style()->unpolish(bar);
|
|
|
|
|
bar->style()->polish(bar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void StateWidget::setValue(QString s)
|
2021-01-12 12:15:03 +08:00
|
|
|
{
|
2021-04-14 18:23:36 +08:00
|
|
|
if(label)
|
|
|
|
|
{
|
|
|
|
|
label->setText(s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(bar)
|
|
|
|
|
{
|
|
|
|
|
bar->setValue(s.toDouble());
|
|
|
|
|
}
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
|
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
void StateWidget::setRange(double m_min,double m_max)
|
2021-01-12 12:15:03 +08:00
|
|
|
{
|
2021-04-14 18:23:36 +08:00
|
|
|
min = m_min;
|
|
|
|
|
max = m_max;
|
|
|
|
|
|
|
|
|
|
if(bar)
|
|
|
|
|
{
|
|
|
|
|
bar->setRange(m_min,m_max);
|
|
|
|
|
}
|
2021-01-12 12:15:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-14 18:23:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|