fix/refactor backlight stuff (#394)

* fix/refactor backlight stuff:
- fix colors dont turn of when backlight 0 and black is set
- add option to use not colored backlight
- fix colored backlight not colored on very low color values
- various code style tunings

* apply needed change to wizard

* backlight disabled on static color and efects

* fix warnings

* try fix udp compiler warnings
This commit is contained in:
redPanther
2017-02-11 22:52:47 +01:00
committed by GitHub
parent 199d266bc0
commit e1165e112f
33 changed files with 364 additions and 240 deletions

View File

@@ -6,25 +6,27 @@ using namespace commandline;
bool ColorOption::validate(Parser & parser, QString & value)
{
// Check if we can create the color by name
_color = QColor(value);
if (_color.isValid()) {
return true;
}
// Check if we can create the color by name
_color = QColor(value);
if (_color.isValid())
{
return true;
}
// check if we can create the color by hex RRGGBB getColors
_color = QColor(QString("#%1").arg(value));
if (_color.isValid()) {
return true;
}
// check if we can create the color by hex RRGGBB getColors
_color = QColor(QString("#%1").arg(value));
if (_color.isValid())
{
return true;
}
if(!parser.isSet(*this)){
// Return true if no value is available
return true;
}
if(!parser.isSet(*this))
{
// Return true if no value is available
return true;
}
QStringList error;
_error = QString("Invalid color. A color is specified by a six lettered RRGGBB hex getColors or one of the following names:\n\t- %1").arg(QColor::colorNames().join("\n\t- "));
_error = QString("Invalid color. A color is specified by a six lettered RRGGBB hex getColors or one of the following names:\n\t- %1").arg(QColor::colorNames().join("\n\t- "));
return false;
return false;
}

View File

@@ -6,32 +6,36 @@ using namespace commandline;
bool ColorsOption::validate(Parser & parser, QString & value)
{
// Clear any old results
_colors.clear();
// Clear any old results
_colors.clear();
// Check if we can create the color by name
QColor color(value);
if (color.isValid()) {
_colors.push_back(color);
return true;
}
// Check if we can create the color by name
QColor color(value);
if (color.isValid())
{
_colors.push_back(color);
return true;
}
// check if we can create the color by hex RRGGBB getColors
QRegularExpression hexRe("^([0-9A-F]{6})+$", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = hexRe.match(value);
if(match.hasMatch()) {
Q_FOREACH(const QString m, match.capturedTexts()){
_colors.push_back(QColor(QString("#%1").arg(m)));
}
return true;
}
// check if we can create the color by hex RRGGBB getColors
QRegularExpression hexRe("^([0-9A-F]{6})+$", QRegularExpression::CaseInsensitiveOption);
QRegularExpressionMatch match = hexRe.match(value);
if(match.hasMatch())
{
Q_FOREACH(const QString m, match.capturedTexts())
{
_colors.push_back(QColor(QString("#%1").arg(m)));
}
return true;
}
if(!parser.isSet(*this)){
if(!parser.isSet(*this))
{
// Return true if no value is available
return true;
}
_error = QString("Invalid color. A color is specified by a six lettered RRGGBB hex getColors or one of the following names:\n\t- %1").arg(QColor::colorNames().join("\n\t- "));
_error = QString("Invalid color. A color is specified by a six lettered RRGGBB hex getColors or one of the following names:\n\t- %1").arg(QColor::colorNames().join("\n\t- "));
return false;
return false;
}

View File

@@ -5,16 +5,17 @@ using namespace commandline;
double DoubleOption::getDouble(Parser &parser, bool *ok)
{
_double = value(parser).toDouble(ok);
return _double;
_double = value(parser).toDouble(ok);
return _double;
}
double *DoubleOption::getDoublePtr(Parser &parser, bool *ok)
{
if (parser.isSet(this)) {
getDouble(parser, ok);
return &_double;
} else {
return nullptr;
}
if (parser.isSet(this))
{
getDouble(parser, ok);
return &_double;
}
return nullptr;
}

View File

@@ -4,7 +4,8 @@ using namespace commandline;
bool ImageOption::validate(Parser & parser, QString & value)
{
if(value.size()){
if(value.size())
{
_image = QImage(value);
if (_image.isNull())
@@ -12,7 +13,7 @@ bool ImageOption::validate(Parser & parser, QString & value)
_error = QString("File %1 could not be opened as image").arg(value);
return false;
}
}
}
return true;
return true;
}

View File

@@ -5,16 +5,16 @@ using namespace commandline;
int IntOption::getInt(Parser &parser, bool *ok, int base)
{
_int = value(parser).toInt(ok, base);
return _int;
_int = value(parser).toInt(ok, base);
return _int;
}
int *IntOption::getIntPtr(Parser &parser, bool *ok, int base)
{
if (parser.isSet(this)) {
getInt(parser, ok, base);
return &_int;
} else {
return nullptr;
}
if (parser.isSet(this))
{
getInt(parser, ok, base);
return &_int;
}
return nullptr;
}

View File

@@ -6,26 +6,26 @@ using namespace commandline;
bool Option::validate(Parser & parser, QString &value)
{
/* By default everything is accepted */
return true;
return true;
}
QString Option::value(Parser &parser)
{
return parser.value(*this);
return parser.value(*this);
}
std::string Option::getStdString(Parser &parser)
{
return value(parser).toStdString();
return value(parser).toStdString();
}
std::wstring Option::getStdWString(Parser &parser)
{
return value(parser).toStdWString();
return value(parser).toStdWString();
}
const char* Option::getCString(Parser &parser)
{
return value(parser).toLocal8Bit().constData();
return value(parser).toLocal8Bit().constData();
}

View File

@@ -6,85 +6,88 @@ using namespace commandline;
bool Parser::parse(const QStringList &arguments)
{
if (!_parser.parse(arguments)) {
return false;
}
if (!_parser.parse(arguments))
{
return false;
}
Q_FOREACH(Option * option, _options) {
QString value = this->value(*option);
if (!option->validate(*this, value)) {
const QString error = option->getError();
if (error.size()) {
_errorText = tr("%1 is not a valid option for %2\n%3").arg(value, option->name(), error);
}
else {
_errorText = tr("%1 is not a valid option for %2").arg(value, option->name());
}
return false;
Q_FOREACH(Option * option, _options)
{
QString value = this->value(*option);
if (!option->validate(*this, value)) {
const QString error = option->getError();
if (error.size()) {
_errorText = tr("%1 is not a valid option for %2\n%3").arg(value, option->name(), error);
}
}
return true;
else
{
_errorText = tr("%1 is not a valid option for %2").arg(value, option->name());
}
return false;
}
}
return true;
}
void Parser::process(const QStringList &arguments)
{
_parser.process(arguments);
if (!parse(arguments)) {
_parser.process(arguments);
if (!parse(arguments))
{
fprintf(stdout, "%s", qPrintable(tr("Error: %1").arg(_errorText)));
showHelp(EXIT_FAILURE);
}
showHelp(EXIT_FAILURE);
}
}
void Parser::process(const QCoreApplication &app)
{
Q_UNUSED(app);
process(QCoreApplication::arguments());
Q_UNUSED(app);
process(QCoreApplication::arguments());
}
QString Parser::errorText() const
{
if (_errorText.size()) {
return _errorText;
}
else {
return _parser.errorText();
}
return (_errorText.size()) ? _errorText : _parser.errorText();
}
bool Parser::addOption(Option &option)
{
return addOption(&option);
return addOption(&option);
}
bool Parser::addOption(Option * const option)
{
_options[option->name()] = option;
return _parser.addOption(*option);
_options[option->name()] = option;
return _parser.addOption(*option);
}
QStringList Parser::_getNames(const char shortOption, const QString longOption)
{
QStringList names;
if (shortOption != 0x0) {
if (shortOption != 0x0)
{
names << QString(shortOption);
}
if (longOption.size()) {
if (longOption.size())
{
names << longOption;
}
return names;
}
QString Parser::_getDescription(const QString description, const QString default_)
{
/* Add the translations if available */
QString formattedDescription(tr(qPrintable(description)));
/* Fill in the default if needed */
if (default_.size()) {
if(!formattedDescription.contains("%1")){
if (default_.size())
{
if(!formattedDescription.contains("%1"))
{
formattedDescription += " [default: %1]";
}
formattedDescription = formattedDescription.arg(default_);
}
return formattedDescription;
}

View File

@@ -5,21 +5,22 @@ using namespace commandline;
bool ValidatorOption::validate(Parser & parser, QString & value)
{
if (parser.isSet(*this) || !defaultValues().empty()) {
if (parser.isSet(*this) || !defaultValues().empty())
{
int pos = 0;
validator->fixup(value);
return validator->validate(value, pos) == QValidator::Acceptable;
} else {
return true;
}
return true;
}
const QValidator *ValidatorOption::getValidator() const
{
return validator;
}
void ValidatorOption::setValidator(const QValidator *validator)
{
ValidatorOption::validator = validator;
return validator;
}
void ValidatorOption::setValidator(const QValidator *validator)
{
ValidatorOption::validator = validator;
}