jce-manager/main/jceWidgets/jcestatusbar.cpp

131 lines
3.8 KiB
C++
Raw Normal View History

2014-10-12 19:19:43 +00:00
#include "jcestatusbar.h"
jceStatusBar::jceStatusBar(QWidget *parent) :
QStatusBar(parent)
{
2014-10-12 22:14:26 +00:00
this->setStyleSheet("QStatusBar { border: 0px solid black };");
2014-10-12 19:19:43 +00:00
this->setFixedHeight(STATUS_ICON_HEIGH+5);
this->showMessage(tr("Ready"));
//Icon
iconButtomStatusLabel = new QLabel(this);
iconButtomStatusLabel->setAlignment(Qt::AlignHCenter);
//ProgressBar
progressBar = new QProgressBar(this);
connect(progressBar,SIGNAL(valueChanged(int)),this,SLOT(setProgressValue(int)));
connect(this,SIGNAL(progressHasPacket(int)),this,SLOT(addValueToProgressBar(int)));
progressBar->setFixedWidth(120);
progressBar->setFixedHeight(STATUS_ICON_HEIGH);
2014-10-12 22:14:26 +00:00
progressBar->setStyleSheet("QProgressBar {"
2014-10-12 19:19:43 +00:00
"border: 1px solid gray;"
"border-radius: 3px;"
"background: transparent;"
"padding: 1px;"
"}"
2014-10-12 22:14:26 +00:00
"QProgressBar::chunk {"
"background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 #b4e391 , stop: 1 #61c419);"
2014-10-12 19:19:43 +00:00
"}");
progressBar->setRange(0,100);
progressBar->setValue(0);
2014-10-12 22:14:26 +00:00
progressBar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
2014-10-12 19:19:43 +00:00
progressBar->setTextVisible(true);
progressBar->setFormat("%p%");
2014-10-12 22:14:26 +00:00
progressBar->setOrientation(Qt::Horizontal);
2014-10-12 19:19:43 +00:00
addPermanentWidget(progressBar,0);
addPermanentWidget(iconButtomStatusLabel,0);
}
void jceStatusBar::setIconConnectionStatus(jceProgressStatus update)
{
QPixmap iconPix;
switch (update)
{
2014-10-12 22:14:26 +00:00
case jceProgressStatus::ERROR:
setProgressValue(0);
iconPix.load(":/icons/redStatusIcon.png");
showMessage(tr("Error"));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Disconnected:
2014-10-12 22:14:26 +00:00
setProgressValue(0);
2014-10-12 19:19:43 +00:00
iconPix.load(":/icons/redStatusIcon.png");
showMessage(tr("Disconnected"));
break;
case jceProgressStatus::Ready:
setProgressValue(0);
2014-10-12 19:19:43 +00:00
iconPix.load(":/icons/redStatusIcon.png");
2014-10-12 22:14:26 +00:00
showMessage(tr("Ready"));
2014-10-12 19:19:43 +00:00
break;
case jceProgressStatus::Connecting:
2014-10-12 22:14:26 +00:00
setProgressValue(5);
2014-10-12 19:19:43 +00:00
iconPix.load(":/icons/blueStatusIcon.png");
showMessage(tr("Connecting..."));
break;
case jceProgressStatus::Sending:
if (progressBar->value() < 10)
setProgressValue(10);
2014-10-12 19:19:43 +00:00
iconPix.load(":/icons/blueStatusIcon.png");
2014-10-12 22:14:26 +00:00
showMessage(tr("Sending..."));
2014-10-12 19:19:43 +00:00
break;
case jceProgressStatus::Recieving:
if (progressBar->value() < 15)
setProgressValue(15);
2014-10-12 19:19:43 +00:00
iconPix.load(":/icons/blueStatusIcon.png");
2014-10-12 22:14:26 +00:00
showMessage(tr("Recieving..."));
2014-10-12 19:19:43 +00:00
break;
case jceProgressStatus::Inserting:
2014-10-12 22:14:26 +00:00
setProgressValue(80);
2014-10-12 19:19:43 +00:00
iconPix.load(":/icons/blueStatusIcon.png");
2014-10-12 22:14:26 +00:00
showMessage(tr("Inserting"));
2014-10-12 19:19:43 +00:00
break;
case jceProgressStatus::LoggedIn:
setProgressValue(100);
iconPix.load(":/icons/greenStatusIcon.png");
2014-10-12 22:14:26 +00:00
showMessage(tr("Logged In."));
2014-10-12 19:19:43 +00:00
break;
case jceProgressStatus::Done:
setProgressValue(100);
iconPix.load(":/icons/greenStatusIcon.png");
2014-10-12 22:14:26 +00:00
showMessage(tr("Done"));
2014-10-12 19:19:43 +00:00
break;
case jceProgressStatus::Connected:
setProgressValue(100);
iconPix.load(":/icons/greenStatusIcon.png");
showMessage(tr("Connected"));
break;
}
iconButtomStatusLabel->setPixmap(iconPix);
repaint();
}
/**
* @brief Every time the value changes this method will be called
* @param value = the value of the progress Bar
*/
void jceStatusBar::setProgressValue(int value)
{
if (value == 0)
{
progressBar->setVisible(false);
progressBar->setValue(0);
}
else
{
progressBar->setValue(value);
progressBar->setVisible(true);
}
}
void jceStatusBar::addValueToProgressBar(int value)
{
progressBar->setValue(progressBar->value() + value);
}