swift
validationindicator.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QLabel>
7 #include <QtGlobal>
8 
9 #include "ui_validationindicator.h"
10 
11 #include "gui/stylesheetutility.h"
12 #include "misc/icon.h"
13 #include "misc/icons.h"
14 #include "misc/statusmessage.h"
15 
16 using namespace swift::misc;
17 
18 namespace swift::gui::editors
19 {
20  CValidationIndicator::CValidationIndicator(QWidget *parent) : QFrame(parent), ui(new Ui::CValidationIndicator)
21  {
22  ui->setupUi(this);
23  this->clear();
24  this->setFrameStyle(QFrame::StyledPanel);
25  this->setFrameShadow(QFrame::Raised);
26  this->setAutoFillBackground(true);
27  m_originalStyleSheet = this->styleSheet();
28  connect(&m_resetTimer, &QTimer::timeout, this, &CValidationIndicator::clear);
29  m_resetTimer.setObjectName(this->objectName().append(":").append("resetTimer"));
30  m_resetTimer.start(ResetInterval);
31  }
32 
34 
36  {
37  this->show();
38  this->setBackgroundColor("green");
39  ui->lbl_Icon->setPixmap(CIcons::tick16());
40  }
41 
43  {
44  this->show();
45  this->setBackgroundColor("red");
46  ui->lbl_Icon->setPixmap(CStatusMessage::convertToIcon(CStatusMessage::SeverityError));
47  }
48 
50  {
51  this->show();
52  this->setBackgroundColor("yellow");
53  ui->lbl_Icon->setPixmap(CStatusMessage::convertToIcon(CStatusMessage::SeverityWarning));
54  }
55 
57  {
58  this->setBackgroundColor("");
59  ui->lbl_Icon->clear();
60  this->hide();
61  }
62 
64  {
65  if (ok) { passed(); }
66  else { failed(); }
67  }
68 
70  {
71  if (msgs.hasErrorMessages()) { this->failed(); }
72  else if (msgs.hasWarningMessages()) { this->warnings(); }
73  else { this->passed(); }
74  }
75 
76  void CValidationIndicator::paintEvent(QPaintEvent *paintEvent)
77  {
79  Q_UNUSED(paintEvent);
80  }
81 
82  void CValidationIndicator::setBackgroundColor(const QString &colorName)
83  {
84  if (colorName.isEmpty()) { this->setStyleSheet(m_originalStyleSheet); }
85  else
86  {
87  // I have to clean up any potential background image derived from style sheet
88  const QString s("background-color: %1; background-image: url(:/own/icons/own/transparent1px.png);");
89  this->setStyleSheet(s.arg(colorName));
90  m_resetTimer.start(ResetInterval); // restart
91  }
92  }
93 
94 } // namespace swift::gui::editors
static bool useStyleSheetInDerivedWidget(QWidget *derivedWidget, QStyle::PrimitiveElement element=QStyle::PE_Widget)
Use style sheets in derived widgets.
void setState(bool ok)
Ok or failed validation?
virtual void paintEvent(QPaintEvent *paintEvent)
Status messages, e.g. from Core -> GUI.
bool hasWarningMessages() const
Warning messages.
bool hasErrorMessages() const
Error messages.
Free functions in swift::misc.