/** * @file PaiJobSummaryWidget.cpp */ #include "PaiJobSummaryWidget.h" #include "PaiWorkflowDataModel.h" #include "PaiJob.h" #include "Utils.h" #include "PAIConst.h" #include "Log.h" #include #include #include #include #include #include #include #include using namespace pai::gui; PaiJobSummaryWidget::PaiJobSummaryWidget(pai::objectmodel::PaiJob* pJob,QWidget *parent) : QWidget(parent) { QPalette pal = palette(); pal.setColor(QPalette::Background, QColor("#daf5fe")); setPalette(pal); setWindowOpacity(0.7); setWindowFlags(Qt::FramelessWindowHint); this->resize(450,30); m_pMoreButton = new QPushButton(QIcon(":/log_shrink.png"),tr(""),this); m_pMoreButton->resize(10,10); m_pMoreButton->setCheckable(true); m_pMoreButton->setChecked(true); m_pMoreButton->setAutoDefault(false); m_pMoreButton->move(this->width()- 11,0); m_pMoreButton->setStyleSheet("QPushButton{border: 0px solid red;border-radius:3px}"); m_pSummaryName = new QLabel(tr("Summary"),this); m_pSummaryName->move(0,0); QHBoxLayout *pHoxLayout = new QHBoxLayout(); pHoxLayout->addWidget(m_pSummaryName); pHoxLayout->addStretch(100); pHoxLayout->addWidget(m_pMoreButton); m_pExtension = new QWidget(); QLabel *pProject = new QLabel(tr("Project:")); pProject->setStyleSheet("color:green"); QString strProject = pJob->GetVisibleFile(); QStringList list1 = strProject.split("/"); QLabel *pProjectInfo = new QLabel(list1.at(1)); QLabel *pSummaryUser = new QLabel(tr("Submitted User:")); pSummaryUser->setStyleSheet("color:green"); QString strUser = QString::fromStdString(pJob->GetJob()->GetCreatedBy()); QLabel *pSummaryUserInfo = new QLabel(strUser); QLabel *pSurVey = new QLabel(tr("Survey:")); pSurVey->setStyleSheet("color:green"); QLabel *pSurVeyInfo = new QLabel(list1.at(2)); QLabel *pSubmissionTime = new QLabel(tr("Submitted Time:")); pSubmissionTime->setStyleSheet("color:green"); QString strSubmissionTime = QString("%1").arg(QDateTime::fromMSecsSinceEpoch(pJob->GetJob()->GetSubmissionTime() / 1000).toString(LONG_TIME_FORMAT)); QLabel *pSubmissionTimeInfo = new QLabel(strSubmissionTime); QLabel *pJobName = new QLabel(tr("Job Name:")); pJobName->setStyleSheet("color:green"); QString strJobName = pJob->pai::objectmodel::PaiObject::GetName(); QLabel *pJobNameInfo = new QLabel(strJobName); QLabel *pStatUpdateTime = new QLabel(tr("Status Updated Time:")); pStatUpdateTime->setStyleSheet("color:green"); QString strStatusTime = QString("%1").arg(QDateTime::fromMSecsSinceEpoch(pJob->GetJob()->GetLastModifiedTime() / 1000).toString(LONG_TIME_FORMAT)); QLabel *pStatUpdateTimeInfo = new QLabel(strStatusTime); QLabel *pWorkflowName = new QLabel(tr("Workflow Name:")); pWorkflowName->setStyleSheet("color:green"); QString strWorkflowNmae = QString::fromStdString(pJob->GetJob()->GetWorkflowName()); QLabel *pWorkflowNameInfo = new QLabel(strWorkflowNmae); QLabel *pRunningTime = new QLabel(tr("Running Time:")); pRunningTime->setStyleSheet("color:green"); QString strRunningTime = ""; try { strRunningTime = QString(pai::utils::CUtils::TimeToString(pJob->GetJob()->GetRunningTime() / 1000000).c_str()); } catch(pai::error::invalid_argument& e) { pai::log::Info(std::string("Get running time error!")); } QLabel *pRunningTimeInfo = new QLabel(strRunningTime); QHBoxLayout *phlayouA = new QHBoxLayout; phlayouA->addWidget(pProject); phlayouA->addWidget(pProjectInfo); phlayouA->addStretch(20); QHBoxLayout *phlayouB = new QHBoxLayout; phlayouB->addWidget(pSummaryUser); phlayouB->addWidget(pSummaryUserInfo); phlayouB->addStretch(20); QHBoxLayout *phlayou1A = new QHBoxLayout; phlayou1A->addWidget(pSurVey); phlayou1A->addWidget(pSurVeyInfo); phlayou1A->addStretch(20); QHBoxLayout *phlayou1B = new QHBoxLayout; phlayou1B->addWidget(pSubmissionTime); phlayou1B->addWidget(pSubmissionTimeInfo); phlayou1B->addStretch(20); QHBoxLayout *phlayou2A = new QHBoxLayout; phlayou2A->addWidget(pJobName); phlayou2A->addWidget(pJobNameInfo); phlayou2A->addStretch(20); QHBoxLayout *phlayou2B = new QHBoxLayout; phlayou2B->addWidget(pStatUpdateTime); phlayou2B->addWidget(pStatUpdateTimeInfo); phlayou2B->addStretch(20); QHBoxLayout *phlayou3A = new QHBoxLayout; phlayou3A->addWidget(pWorkflowName); phlayou3A->addWidget(pWorkflowNameInfo); phlayou3A->addStretch(20); QHBoxLayout *phlayou3B = new QHBoxLayout; phlayou3B->addWidget(pRunningTime); phlayou3B->addWidget(pRunningTimeInfo); phlayou3B->addStretch(20); QGridLayout *pUpLayou = new QGridLayout; pUpLayou->addLayout(phlayouA,0,0,Qt::AlignLeft); pUpLayou->addLayout(phlayouB,0,1,Qt::AlignLeft); pUpLayou->addLayout(phlayou1A,1,0,Qt::AlignLeft); pUpLayou->addLayout(phlayou1B,1,1,Qt::AlignLeft); pUpLayou->addLayout(phlayou2A,2,0,Qt::AlignLeft); pUpLayou->addLayout(phlayou2B,2,1,Qt::AlignLeft); pUpLayou->addLayout(phlayou3A,3,0,Qt::AlignLeft); pUpLayou->addLayout(phlayou3B,3,1,Qt::AlignLeft); connect(m_pMoreButton, SIGNAL(toggled(bool)), m_pExtension, SLOT(setVisible(bool))); connect(m_pMoreButton, SIGNAL(clicked(bool)), this, SLOT(ResetButtonIcon())); m_pExtension->setLayout(pUpLayou); QVBoxLayout *mainLayout = new QVBoxLayout; mainLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); mainLayout->addLayout(pHoxLayout); mainLayout->addWidget(m_pExtension); mainLayout->setContentsMargins(5,4,5,4); this->setLayout(mainLayout); } PaiJobSummaryWidget::~PaiJobSummaryWidget() { } void PaiJobSummaryWidget::paintEvent(QPaintEvent *pEvent) { QWidget::paintEvent(pEvent); QPainter painter(this); if(m_pExtension->isHidden()) { painter.drawPixmap(0,0,this->width(),30,QPixmap(":/log_summary_shink.png")); } else { painter.drawPixmap(0,0,this->width(),this->height(),QPixmap(":/log_summary_exten.png")); } } void PaiJobSummaryWidget::ResetButtonIcon() { if((m_pExtension != NULL) && ( m_pMoreButton != NULL)) { if(m_pExtension->isHidden()) { m_pMoreButton->setIcon(QIcon(":/log_exten.png")); } else { m_pMoreButton->setIcon(QIcon(":/log_shrink.png")); } } }