mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 02:35:33 +08:00
refs #452 editors
the editors allow to enter data for the different value objects
This commit is contained in:
committed by
Mathew Sutcliffe
parent
93e6e1d38e
commit
513eb07a13
118
src/blackgui/editors/validationindicator.cpp
Normal file
118
src/blackgui/editors/validationindicator.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/* Copyright (C) 2015
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "validationindicator.h"
|
||||
#include "ui_validationindicator.h"
|
||||
#include "blackgui/stylesheetutility.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include <QPainter>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Editors
|
||||
{
|
||||
CValidationIndicator::CValidationIndicator(QWidget *parent) :
|
||||
QFrame(parent),
|
||||
ui(new Ui::CValidationIndicator)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->clear();
|
||||
this->setFrameStyle(QFrame::StyledPanel);
|
||||
this->setFrameShadow(QFrame::Raised);
|
||||
this->setAutoFillBackground(true);
|
||||
this->m_originalStyleSheet = this->styleSheet();
|
||||
connect(&this->m_resetTimer, &QTimer::timeout, this, &CValidationIndicator::clear);
|
||||
this->m_resetTimer.setObjectName(this->objectName().append(":").append("resetTimer"));
|
||||
this->m_resetTimer.start(ResetInterval);
|
||||
}
|
||||
|
||||
CValidationIndicator::~CValidationIndicator()
|
||||
{ }
|
||||
|
||||
void CValidationIndicator::passed()
|
||||
{
|
||||
this->show();
|
||||
setBackgroundColor("green");
|
||||
ui->lbl_Icon->setPixmap(CIcons::tick16());
|
||||
}
|
||||
|
||||
void CValidationIndicator::failed()
|
||||
{
|
||||
this->show();
|
||||
setBackgroundColor("red");
|
||||
ui->lbl_Icon->setPixmap(CStatusMessage::convertToIcon(CStatusMessage::SeverityError));
|
||||
}
|
||||
|
||||
void CValidationIndicator::warnings()
|
||||
{
|
||||
this->show();
|
||||
setBackgroundColor("yellow");
|
||||
ui->lbl_Icon->setPixmap(CStatusMessage::convertToIcon(CStatusMessage::SeverityWarning));
|
||||
}
|
||||
|
||||
void CValidationIndicator::clear()
|
||||
{
|
||||
setBackgroundColor("");
|
||||
ui->lbl_Icon->clear();
|
||||
this->hide();
|
||||
}
|
||||
|
||||
void CValidationIndicator::setState(bool ok)
|
||||
{
|
||||
if (ok)
|
||||
{
|
||||
passed();
|
||||
}
|
||||
else
|
||||
{
|
||||
failed();
|
||||
}
|
||||
}
|
||||
|
||||
void CValidationIndicator::setState(const BlackMisc::CStatusMessageList &msgs)
|
||||
{
|
||||
if (msgs.hasErrorMessages())
|
||||
{
|
||||
this->failed();
|
||||
}
|
||||
else if (msgs.hasWarningMessages())
|
||||
{
|
||||
this->warnings();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->passed();
|
||||
}
|
||||
}
|
||||
|
||||
void CValidationIndicator::paintEvent(QPaintEvent *paintEvent)
|
||||
{
|
||||
CStyleSheetUtility::useStyleSheetInDerivedWidget(this);
|
||||
Q_UNUSED(paintEvent);
|
||||
}
|
||||
|
||||
void CValidationIndicator::setBackgroundColor(const QString colorName)
|
||||
{
|
||||
if (colorName.isEmpty())
|
||||
{
|
||||
this->setStyleSheet(this->m_originalStyleSheet);
|
||||
}
|
||||
else
|
||||
{
|
||||
// I have to clean up any potential background image derived from style sheet
|
||||
const QString s("background-color: %1; background-image: url(:/own/icons/own/transparent1px.png);");
|
||||
this->setStyleSheet(s.arg(colorName));
|
||||
m_resetTimer.start(ResetInterval); // restart
|
||||
}
|
||||
}
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
Reference in New Issue
Block a user