jce-manager/main/jceWidgets/jcestatusbar.cpp

151 lines
5 KiB
C++
Raw Normal View History

2014-10-12 19:19:43 +00:00
#include "jcestatusbar.h"
jceStatusBar::jceStatusBar(QWidget *parent) :
2014-10-13 03:29:46 +00:00
QStatusBar(parent)
2014-10-12 19:19:43 +00:00
{
2014-10-14 03:47:15 +00:00
this->setFixedHeight(STATUS_ICON_HEIGH+30);
2014-10-13 03:29:46 +00:00
this->showMessage(tr("Ready"));
2014-10-14 03:47:15 +00:00
this->setStyleSheet("QStatusBar {"
"border: 0px solid black;"
"background: rgba(255, 255, 255, 255);"
"padding: 3px;"
"padding-left: 1px;"
"padding-right: 1px;"
"min-height: 50px;"
"max-height: 50px;"
"}");
2014-10-13 03:29:46 +00:00
//Icon
iconButtomStatusLabel = new QLabel(this);
2014-10-14 03:47:15 +00:00
iconButtomStatusLabel->setStyleSheet("QLabel {"
"border: 0px solid black"
"border-radius: 16px;"
"padding: 1px;"
"padding-left: 1px;"
"padding-right: 1px;"
"min-width: 48px;"
"max-width: 48px;"
"min-height: 48px;"
"max-height: 48px;"
"}");
iconButtomStatusLabel->setMaximumHeight(STATUS_ICON_HEIGH+2);
iconButtomStatusLabel->setMinimumHeight(STATUS_ICON_HEIGH+2);
2014-10-13 03:29:46 +00:00
iconButtomStatusLabel->setAlignment(Qt::AlignHCenter);
2014-10-12 19:19:43 +00:00
2014-10-13 03:29:46 +00:00
//ProgressBar
progressBar = new QProgressBar(this);
connect(progressBar,SIGNAL(valueChanged(int)),this,SLOT(setProgressValue(int)));
connect(this,SIGNAL(progressHasPacket(int)),this,SLOT(addValueToProgressBar(int)));
2014-10-12 19:19:43 +00:00
2014-10-13 03:29:46 +00:00
progressBar->setFixedWidth(120);
progressBar->setFixedHeight(STATUS_ICON_HEIGH);
progressBar->setStyleSheet("QProgressBar {"
"border: 1px solid gray;"
"border-radius: 3px;"
"background: transparent;"
"padding: 1px;"
"}"
"QProgressBar::chunk {"
"background: qlineargradient(x1: 0, y1: 0.5, x2: 1, y2: 0.5, stop: 0 #b4e391 , stop: 1 #61c419);"
"}");
progressBar->setRange(0,100);
progressBar->setValue(0);
progressBar->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
progressBar->setTextVisible(true);
progressBar->setFormat("%p%");
progressBar->setOrientation(Qt::Horizontal);
2014-10-12 19:19:43 +00:00
2014-10-13 03:29:46 +00:00
addPermanentWidget(progressBar,0);
addPermanentWidget(iconButtomStatusLabel,0);
2014-10-12 19:19:43 +00:00
}
void jceStatusBar::setIconConnectionStatus(jceProgressStatus update)
{
2014-10-13 03:29:46 +00:00
QPixmap iconPix;
switch (update)
2014-10-12 19:19:43 +00:00
{
2014-10-13 13:00:58 +00:00
case jceProgressStatus::Error:
2014-10-13 03:29:46 +00:00
setProgressValue(0);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/disconnected.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Error"));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Disconnected:
2014-10-13 03:29:46 +00:00
setProgressValue(0);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/disconnected.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Disconnected"));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Ready:
2014-10-13 03:29:46 +00:00
setProgressValue(0);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/disconnected.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Ready"));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Connecting:
2014-10-13 03:29:46 +00:00
setProgressValue(5);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/busy.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Connecting..."));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Sending:
2014-10-13 03:29:46 +00:00
if (progressBar->value() < 10)
setProgressValue(10);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/busy.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Sending..."));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Recieving:
2014-10-13 03:29:46 +00:00
if (progressBar->value() < 15)
setProgressValue(15);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/busy.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Recieving..."));
break;
case jceProgressStatus::Connected:
setProgressValue(30);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/busy.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Connected"));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Inserting:
2014-10-13 03:29:46 +00:00
setProgressValue(80);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/busy.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Inserting"));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::LoggedIn:
2014-10-13 03:29:46 +00:00
setProgressValue(100);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/connected.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Logged In."));
break;
2014-10-12 19:19:43 +00:00
case jceProgressStatus::Done:
2014-10-13 03:29:46 +00:00
setProgressValue(100);
2014-10-14 03:47:15 +00:00
iconPix.load(":/icons/connected.png");
2014-10-13 03:29:46 +00:00
showMessage(tr("Done"));
break;
2014-10-12 19:19:43 +00:00
}
2014-10-13 03:29:46 +00:00
iconButtomStatusLabel->setPixmap(iconPix);
2014-10-12 19:19:43 +00:00
2014-10-13 03:29:46 +00:00
repaint();
2014-10-12 19:19:43 +00:00
}
/**
* @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 || value == 100)
2014-10-12 19:19:43 +00:00
{
2014-10-13 03:29:46 +00:00
progressBar->setVisible(false);
progressBar->setValue(0);
2014-10-12 19:19:43 +00:00
}
2014-10-13 03:29:46 +00:00
else
2014-10-12 19:19:43 +00:00
{
2014-10-13 03:29:46 +00:00
progressBar->setValue(value);
progressBar->setVisible(true);
2014-10-12 19:19:43 +00:00
}
}
void jceStatusBar::addValueToProgressBar(int value)
{
2014-10-13 03:29:46 +00:00
progressBar->setValue(progressBar->value() + value);
2014-10-12 19:19:43 +00:00
}