diff -r 12f9ea615cbc -r 314e12e23c3a src/colors.cpp --- a/src/colors.cpp Thu Jan 04 19:40:52 2018 +0200 +++ b/src/colors.cpp Thu Jan 04 19:44:26 2018 +0200 @@ -30,7 +30,7 @@ void initColors() { - print ("Initializing color information.\n"); + print("Initializing color information.\n"); static ColorData colors; colorData = &colors; } @@ -45,18 +45,18 @@ bool LDColor::isLDConfigColor() const { - return colorData->contains (index()); + return colorData->contains(index()); } const ColorData::Entry& LDColor::data() const { - return colorData->get (index()); + return colorData->get(index()); } QString LDColor::name() const { if (isDirect()) - return "0x" + QString::number (index(), 16).toUpper(); + return "0x" + QString::number(index(), 16).toUpper(); else if (isLDConfigColor()) return data().name; else if (index() == -1) @@ -75,12 +75,12 @@ if (isDirect()) { QColor color; - color.setRed ((index() & 0x0FF0000) >> 16); - color.setGreen ((index() & 0x000FF00) >> 8); - color.setBlue (index() & 0x00000FF); + color.setRed((index() & 0x0FF0000) >> 16); + color.setGreen((index() & 0x000FF00) >> 8); + color.setBlue(index() & 0x00000FF); if (index() >= 0x3000000) - color.setAlpha (128); + color.setAlpha(128); return color; } @@ -97,7 +97,7 @@ QColor LDColor::edgeColor() const { if (isDirect()) - return ::luma (faceColor()) < 48 ? Qt::white : Qt::black; + return ::luma(faceColor()) < 48 ? Qt::white : Qt::black; else if (isLDConfigColor()) return data().edgeColor; else @@ -106,12 +106,12 @@ int LDColor::luma() const { - return ::luma (faceColor()); + return ::luma(faceColor()); } int LDColor::edgeLuma() const { - return ::luma (edgeColor()); + return ::luma(edgeColor()); } qint32 LDColor::index() const @@ -122,9 +122,9 @@ QString LDColor::indexString() const { if (isDirect()) - return "0x" + QString::number (index(), 16).toUpper(); + return "0x" + QString::number(index(), 16).toUpper(); - return QString::number (index()); + return QString::number(index()); } bool LDColor::isDirect() const @@ -132,9 +132,9 @@ return index() >= 0x02000000; } -int luma (const QColor& col) +int luma(const QColor& col) { - return (0.2126f * col.red()) + (0.7152f * col.green()) + (0.0722f * col.blue()); + return (0.2126f * col.red()) +(0.7152f * col.green()) +(0.0722f * col.blue()); } ColorData::ColorData() @@ -160,15 +160,15 @@ colorData = nullptr; } -bool ColorData::contains (int code) const +bool ColorData::contains(int code) const { return code >= 0 and code < EntryCount; } -const ColorData::Entry& ColorData::get (int code) const +const ColorData::Entry& ColorData::get(int code) const { - if (not contains (code)) - throw std::runtime_error ("Attempted to get non-existant color information"); + if (not contains(code)) + throw std::runtime_error("Attempted to get non-existant color information"); return m_data[code]; } @@ -176,54 +176,54 @@ void ColorData::loadFromLdconfig() { QString path = LDPaths::ldConfigPath(); - QFile fp (path); + QFile fp(path); - if (not fp.open (QIODevice::ReadOnly)) + if (not fp.open(QIODevice::ReadOnly)) { - QMessageBox::critical (nullptr, "Error", "Unable to open LDConfig.ldr for parsing: " + fp.errorString()); + QMessageBox::critical(nullptr, "Error", "Unable to open LDConfig.ldr for parsing: " + fp.errorString()); return; } // TODO: maybe LDConfig can be loaded as a Document? Or would that be overkill? while (not fp.atEnd()) { - QString line = QString::fromUtf8 (fp.readLine()); + QString line = QString::fromUtf8(fp.readLine()); if (line.isEmpty() or line[0] != '0') continue; // empty or illogical - line.remove ('\r'); - line.remove ('\n'); + line.remove('\r'); + line.remove('\n'); // Parse the line - LDConfigParser parser (line, ' '); + LDConfigParser parser(line, ' '); QString name; QString facename; QString edgename; QString codestring; // Check 0 !COLOUR, parse the name - if (not parser.compareToken (0, "0") or not parser.compareToken (1, "!COLOUR") or not parser.getToken (name, 2)) + if (not parser.compareToken(0, "0") or not parser.compareToken(1, "!COLOUR") or not parser.getToken(name, 2)) continue; // Replace underscores in the name with spaces for readability - name.replace ("_", " "); + name.replace("_", " "); - if (not parser.parseTag ("CODE", codestring)) + if (not parser.parseTag("CODE", codestring)) continue; bool ok; - int code = codestring.toShort (&ok); + int code = codestring.toShort(&ok); - if (not ok or not contains (code)) + if (not ok or not contains(code)) continue; - if (not parser.parseTag ("VALUE", facename) or not parser.parseTag ("EDGE", edgename)) + if (not parser.parseTag("VALUE", facename) or not parser.parseTag("EDGE", edgename)) continue; // Ensure that our colors are correct - QColor faceColor (facename); - QColor edgeColor (edgename); + QColor faceColor(facename); + QColor edgeColor(edgename); if (not faceColor.isValid() or not edgeColor.isValid()) continue; @@ -234,22 +234,22 @@ entry.edgeColor = edgeColor; entry.hexcode = facename; - if (parser.parseTag ("ALPHA", codestring)) - entry.faceColor.setAlpha (qBound (0, codestring.toInt(), 255)); + if (parser.parseTag("ALPHA", codestring)) + entry.faceColor.setAlpha(qBound(0, codestring.toInt(), 255)); } } // ============================================================================= // -LDConfigParser::LDConfigParser (QString inText, char sep) +LDConfigParser::LDConfigParser(QString inText, char sep) { - m_tokens = inText.split (sep, QString::SkipEmptyParts); + m_tokens = inText.split(sep, QString::SkipEmptyParts); m_pos = -1; } // ============================================================================= // -bool LDConfigParser::getToken (QString& val, const int pos) +bool LDConfigParser::getToken(QString& val, const int pos) { if (pos >= m_tokens.size()) return false; @@ -260,9 +260,9 @@ // ============================================================================= // -bool LDConfigParser::findToken (int& result, char const* needle, int args) +bool LDConfigParser::findToken(int& result, char const* needle, int args) { - for (int i = 0; i < (m_tokens.size() - args); ++i) + for (int i = 0; i <(m_tokens.size() - args); ++i) { if (m_tokens[i] == needle) { @@ -276,11 +276,11 @@ // ============================================================================= // -bool LDConfigParser::compareToken (int inPos, QString text) +bool LDConfigParser::compareToken(int inPos, QString text) { QString tok; - if (not getToken (tok, inPos)) + if (not getToken(tok, inPos)) return false; return (tok == text); @@ -290,14 +290,14 @@ // // Helper function for parseLDConfig // -bool LDConfigParser::parseTag (char const* tag, QString& val) +bool LDConfigParser::parseTag(char const* tag, QString& val) { int pos; // Try find the token and get its position - if (not findToken (pos, tag, 1)) + if (not findToken(pos, tag, 1)) return false; // Get the token after it and store it into val - return getToken (val, pos + 1); + return getToken(val, pos + 1); } \ No newline at end of file