connection_indicator.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "connection_indicator.h"
  2. #include <QDebug>
  3. static const int SIZE = 20;
  4. static const QString greenSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.145, y1:0.16, x2:1, y2:1, stop:0 rgba(20, 252, 7, 255), stop:1 rgba(25, 134, 5, 255));").arg(SIZE/2);
  5. static const QString redSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.145, y1:0.16, x2:0.92, y2:0.988636, stop:0 rgba(255, 12, 12, 255), stop:0.869347 rgba(103, 0, 0, 255));").arg(SIZE/2);
  6. static const QString orangeSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.232, y1:0.272, x2:0.98, y2:0.959773, stop:0 rgba(255, 113, 4, 255), stop:1 rgba(91, 41, 7, 255))").arg(SIZE/2);
  7. static const QString blueSS = QString("color: white;border-radius: %1;background-color: qlineargradient(spread:pad, x1:0.04, y1:0.0565909, x2:0.799, y2:0.795, stop:0 rgba(203, 220, 255, 255), stop:0.41206 rgba(0, 115, 255, 255), stop:1 rgba(0, 49, 109, 255));").arg(SIZE/2);
  8. ConnectionIndicator::ConnectionIndicator(QWidget *parent) : QLabel(parent)
  9. {
  10. //Set to ok by default
  11. setState(StateDisconnected);
  12. setFixedSize(SIZE, SIZE);
  13. }
  14. void ConnectionIndicator::setState(State state)
  15. {
  16. qDebug() << "setState" << state;
  17. switch(state){
  18. case StateConnected:
  19. setStyleSheet(greenSS);
  20. break;
  21. case StateWarning:
  22. setStyleSheet(orangeSS);
  23. break;
  24. case StateDisconnected:
  25. setStyleSheet(redSS);
  26. break;
  27. case StateOkBlue:
  28. default:
  29. setStyleSheet(blueSS);
  30. break;
  31. }
  32. }
  33. void ConnectionIndicator::setState(bool state)
  34. {
  35. setState(state ? StateConnected : StateDisconnected);
  36. }