Commit f42c4bb8 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Run clang-format

parent e8e7ea70
......@@ -6,19 +6,18 @@
#include "kontrast.h"
#include <QtMath>
#include <QRandomGenerator>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusMetaType>
#include <QDBusObjectPath>
#include <QDBusPendingCall>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <QDBusObjectPath>
#include <QDBusConnection>
#include <QDebug>
#include <QRandomGenerator>
#include <QtMath>
QDBusArgument &operator <<(QDBusArgument &arg, const Kontrast::ColorRGB &color)
QDBusArgument &operator<<(QDBusArgument &arg, const Kontrast::ColorRGB &color)
{
arg.beginStructure();
arg << color.red << color.green << color.blue;
......@@ -26,7 +25,7 @@ QDBusArgument &operator <<(QDBusArgument &arg, const Kontrast::ColorRGB &color)
return arg;
}
const QDBusArgument &operator >>(const QDBusArgument &arg, Kontrast::ColorRGB &color)
const QDBusArgument &operator>>(const QDBusArgument &arg, Kontrast::ColorRGB &color)
{
double red, green, blue;
arg.beginStructure();
......@@ -39,7 +38,6 @@ const QDBusArgument &operator >>(const QDBusArgument &arg, Kontrast::ColorRGB &c
return arg;
}
Kontrast::Kontrast(KAboutData about, QObject *parent)
: QObject(parent)
, m_about(about)
......@@ -178,9 +176,9 @@ qreal luminosity(const QColor color)
const qreal green = color.greenF();
const qreal blue = color.blueF();
const qreal redLum = (red <= 0.03928) ? red / 12.92 : qPow(((red + 0.055) / 1.055), 2.4);
const qreal greenLum = (green <= 0.03928) ? green / 12.92 : qPow(((green + 0.055) / 1.055), 2.4);
const qreal blueLum = (blue <= 0.03928) ? blue / 12.92 : qPow(((blue + 0.055) / 1.055), 2.4);
const qreal redLum = (red <= 0.03928) ? red / 12.92 : qPow(((red + 0.055) / 1.055), 2.4);
const qreal greenLum = (green <= 0.03928) ? green / 12.92 : qPow(((green + 0.055) / 1.055), 2.4);
const qreal blueLum = (blue <= 0.03928) ? blue / 12.92 : qPow(((blue + 0.055) / 1.055), 2.4);
return 0.2126 * redLum + 0.7152 * greenLum + 0.0722 * blueLum;
}
......@@ -249,7 +247,7 @@ void Kontrast::grabColor()
message << QLatin1String("x11:") << QVariantMap{};
QDBusPendingCall pendingCall = QDBusConnection::sessionBus().asyncCall(message);
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall);
connect(watcher, &QDBusPendingCallWatcher::finished, [this] (QDBusPendingCallWatcher *watcher) {
connect(watcher, &QDBusPendingCallWatcher::finished, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<QDBusObjectPath> reply = *watcher;
if (reply.isError()) {
qWarning() << "Couldn't get reply";
......@@ -270,7 +268,7 @@ QColor Kontrast::grabbedColor() const
return m_grabbedColor;
}
void Kontrast::gotColorResponse(uint response, const QVariantMap& results)
void Kontrast::gotColorResponse(uint response, const QVariantMap &results)
{
if (!response) {
if (results.contains(QLatin1String("color"))) {
......
/*
* SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
*
*
* SPDX-LicenseRef: GPL-3.0-or-later
*/
#pragma once
#include <QObject>
#include <KAboutData>
#include <QColor>
#include <QImage>
#include <KAboutData>
#include <QObject>
/**
* @brief Main class that expose all the value to the QML.
......@@ -17,27 +17,27 @@
class Kontrast : public QObject
{
Q_OBJECT
Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
Q_PROPERTY(int textHue READ textHue WRITE setTextHue NOTIFY textColorChanged)
Q_PROPERTY(int textSaturation READ textSaturation WRITE setTextSaturation NOTIFY textColorChanged)
Q_PROPERTY(int textLightness READ textLightness WRITE setTextLightness NOTIFY textColorChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(int backgroundHue READ backgroundHue WRITE setBackgroundHue NOTIFY backgroundColorChanged)
Q_PROPERTY(int backgroundSaturation READ backgroundSaturation WRITE setBackgroundSaturation NOTIFY backgroundColorChanged)
Q_PROPERTY(int backgroundLightness READ backgroundLightness WRITE setBackgroundLightness NOTIFY backgroundColorChanged)
Q_PROPERTY(qreal contrast READ contrast NOTIFY contrastChanged);
Q_PROPERTY(QColor displayTextColor READ displayTextColor NOTIFY contrastChanged);
Q_PROPERTY(KAboutData about READ about);
Q_PROPERTY(QColor grabbedColor READ grabbedColor NOTIFY grabbedColorChanged);
......@@ -51,39 +51,39 @@ public:
double green;
double blue;
};
QColor textColor() const;
void setTextColor(const QColor textColor);
int textHue() const;
void setTextHue(int hue);
int textSaturation() const;
void setTextSaturation(int saturation);
int textLightness() const;
void setTextLightness(int lightness);
QColor backgroundColor() const;
void setBackgroundColor(const QColor backgroundColor);
int backgroundHue() const;
void setBackgroundHue(int hue);
int backgroundSaturation() const;
void setBackgroundSaturation(int saturation);
int backgroundLightness() const;
void setBackgroundLightness(int lightness);
qreal contrast() const;
QColor displayTextColor() const;
KAboutData about() const;
QColor grabbedColor() const;
Q_INVOKABLE void random();
Q_INVOKABLE void reverse();
Q_INVOKABLE void grabColor();
......@@ -91,7 +91,7 @@ public:
private Q_SLOTS:
void gotColorResponse(uint response, const QVariantMap &results);
Q_SIGNALS:
void textColorChanged();
void backgroundColorChanged();
......
/*
* SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
*
*
* SPDX-LicenseRef: GPL-3.0-or-later
*/
#include "config-kontrast.h"
#include "savedcolormodel.h"
#include <KAboutData>
#include <KLocalizedContext>
#include <KLocalizedString>
#include <QApplication>
#include <QCommandLineParser>
#include <QQmlApplicationEngine>
#include <QtQml>
#include <QUrl>
#include <QIcon>
#include <QQmlApplicationEngine>
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <KLocalizedContext>
#include <KAboutData>
#include <KLocalizedString>
#include <QUrl>
#include <QtQml>
#include <kontrast.h>
#include "savedcolormodel.h"
#include "config-kontrast.h"
const QString DRIVER(QStringLiteral("QSQLITE"));
......@@ -26,12 +26,17 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
KLocalizedString::setApplicationDomain("kontrast");
KAboutData aboutData(QStringLiteral("kontrast"), i18nc("@title", "Kontrast"), QStringLiteral(KONTRAST_VERSION_STRING),
KAboutData aboutData(QStringLiteral("kontrast"),
i18nc("@title", "Kontrast"),
QStringLiteral(KONTRAST_VERSION_STRING),
i18nc("@title", "A contrast checker application"),
KAboutLicense::GPL_V3);
aboutData.addAuthor(i18nc("@info:credit", "Carl Schwan"), i18nc("@info:credit", "Maintainer and creator"), QStringLiteral("carl@carlschwan.eu"), QStringLiteral("https://carlschwan.eu"));
aboutData.addAuthor(i18nc("@info:credit", "Carl Schwan"),
i18nc("@info:credit", "Maintainer and creator"),
QStringLiteral("carl@carlschwan.eu"),
QStringLiteral("https://carlschwan.eu"));
aboutData.addCredit(i18nc("@info:credit", "Wikipedia"), i18nc("@info:credit", "Text on the main page CC-BY-SA-4.0"));
aboutData.addAuthor(i18nc("@info:credit", "Carson Black"), i18nc("@info:credit", "SQLite backend for favorite colors"));
......@@ -56,7 +61,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[])
kontrast.random();
QQmlApplicationEngine engine;
qmlRegisterSingletonInstance("org.kde.kontrast.private", 1, 0, "Kontrast", &kontrast);
qmlRegisterSingletonInstance("org.kde.kontrast.private", 1, 0, "ColorStore", new SavedColorModel(qApp));
......
/*
* SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
*
*
* SPDX-LicenseRef: GPL-3.0-or-later
*/
#include "savedcolormodel.h"
#include <QCoreApplication>
#include <QColor>
#include <QCoreApplication>
#include <QDebug>
#include <QDir>
#include <QStandardPaths>
#include <QSqlRecord>
#include <QSqlError>
#include <QSqlRecord>
#include <QStandardPaths>
SavedColorModel::SavedColorModel(QObject *parent)
: QSqlTableModel(parent)
......@@ -59,13 +59,13 @@ QVariant SavedColorModel::data(const QModelIndex &index, int role) const
QHash<int, QByteArray> SavedColorModel::roleNames() const
{
QHash<int, QByteArray> roles;
for (int i = 0; i < this->record().count(); i ++) {
for (int i = 0; i < this->record().count(); i++) {
roles.insert(Qt::UserRole + i + 1, record().fieldName(i).toUtf8());
}
return roles;
}
bool SavedColorModel::addColor(const QString& name, const QColor& foreground, const QColor& background)
bool SavedColorModel::addColor(const QString &name, const QColor &foreground, const QColor &background)
{
QSqlRecord newRecord = this->record();
newRecord.setValue(QStringLiteral("Name"), name);
......
/*
* SPDX-FileCopyrightText: (C) 2020 Carl Schwan <carl@carlschwan.eu>
* SPDX-FileCopyrightText: (C) 2020 Carson Black <uhhadd@gmail.com>
*
*
* SPDX-LicenseRef: GPL-3.0-or-later
*/
......@@ -16,25 +16,25 @@
struct ColorCombination {
QColor textColor;
QColor backgroundColor;
ColorCombination(QColor textColor, QColor backgroundColor)
: textColor(textColor)
, backgroundColor(backgroundColor)
{}
{
}
};
/**
* @brief Store all the user's favorite color combinations.
*/
class SavedColorModel : public QSqlTableModel
class SavedColorModel : public QSqlTableModel
{
Q_OBJECT
public:
enum ColorRoles {
TextColor = Qt::UserRole + 1,
BackgroundColor
BackgroundColor,
};
public:
......@@ -45,7 +45,7 @@ public:
QHash<int, QByteArray> roleNames() const override;
QVariant data(const QModelIndex &index, int role) const override;
Q_INVOKABLE bool addColor(const QString& name, const QColor& foreground, const QColor& background);
Q_INVOKABLE bool addColor(const QString &name, const QColor &foreground, const QColor &background);
Q_INVOKABLE bool removeColor(int index);
private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment