Skip to content

Commit 8a5ddf6

Browse files
committed
Assortment of low-priority fixes to appease the linter
1 parent 334ea18 commit 8a5ddf6

File tree

8 files changed

+48
-51
lines changed

8 files changed

+48
-51
lines changed

modules/Lith/Core/colortheme.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ QColor ColorTheme::dim(const QColor& color) {
1515
}
1616

1717
QPalette ColorTheme::palette() const {
18-
auto mix = [](const QColor& a, const QColor& b, float ratio = 0.5) {
19-
return QColor::fromRgbF(
20-
a.redF() * ratio + b.redF() * (1.0F - ratio), a.greenF() * ratio + b.greenF() * (1.0F - ratio),
21-
a.blueF() * ratio + b.blueF() * (1.0F - ratio), a.alphaF() * ratio + b.alphaF() * (1.0F - ratio)
22-
);
23-
};
18+
auto mix = &ColorUtils::mixColors;
2419

2520
// TODO very likely needs a bit of tweaking to differentiate button, window and base
2621
QColor windowText {m_weechatColors[0]};
@@ -31,7 +26,7 @@ QPalette ColorTheme::palette() const {
3126
QColor button = mix(windowText, window, 0.20);
3227
QColor light = mix(windowText, button, 0.4);
3328
QColor dark = mix(window, windowText, 0.4);
34-
QColor mid = mix(light, dark);
29+
QColor mid = mix(light, dark, 0.5);
3530
QColor text = windowText;
3631
QColor bright_text = text;
3732
QPalette palette {windowText, button, light, dark, mid, text, bright_text, base, window};

modules/Lith/Core/colorutils.h

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,50 @@ class ColorUtils : public QObject {
1111
QML_SINGLETON
1212
public:
1313
explicit ColorUtils(QObject* parent = nullptr);
14-
static ColorUtils* create(QQmlEngine* qmlEngine, QJSEngine* jsEngine) {
15-
Q_UNUSED(jsEngine)
16-
return new ColorUtils(qmlEngine);
17-
}
14+
15+
struct HSLA {
16+
HSLA() = default;
17+
HSLA(float h, float s, float l, float a = 1.0)
18+
: h(h)
19+
, s(s)
20+
, l(l)
21+
, a(a) {
22+
}
23+
explicit HSLA(QColor c) {
24+
c.getHslF(&h, &s, &l, &a);
25+
}
26+
QColor toColor() const {
27+
return QColor::fromHslF(h, s, l, a);
28+
}
29+
float h = 0.0F;
30+
float s = 0.0F;
31+
float l = 0.0F;
32+
float a = 0.0F;
33+
};
34+
1835

1936
Q_INVOKABLE static QColor mixColors(QColor a, QColor b, float ratio) {
2037
return QColor::fromRgbF(
21-
a.redF() * ratio + b.redF() * (1.0f - ratio), a.greenF() * ratio + b.greenF() * (1.0f - ratio),
22-
a.blueF() * ratio + b.blueF() * (1.0f - ratio), a.alphaF() * ratio + b.alphaF() * (1.0f - ratio)
38+
(a.redF() * ratio) + (b.redF() * (1.0F - ratio)), (a.greenF() * ratio) + (b.greenF() * (1.0F - ratio)),
39+
(a.blueF() * ratio) + (b.blueF() * (1.0F - ratio)), (a.alphaF() * ratio) + (b.alphaF() * (1.0F - ratio))
2340
);
2441
}
2542
Q_INVOKABLE static QColor setAlpha(QColor c, float alpha) {
26-
QColor modified = c;
27-
modified.setAlphaF(alpha);
28-
return modified;
43+
c.setAlphaF(alpha);
44+
return c;
2945
}
3046
Q_INVOKABLE static QColor darken(QColor c, float ratio) {
31-
qreal newLightness = qMax(0.0f, qMin(1.0f, c.lightnessF() / ratio));
32-
return QColor::fromHslF(c.hslHueF(), c.hslSaturationF(), newLightness);
47+
HSLA hsla(c);
48+
hsla.l = std::clamp(hsla.l / ratio, 0.0F, 1.0F);
49+
return hsla.toColor();
3350
}
3451
Q_INVOKABLE static QColor lighten(QColor c, float ratio) {
35-
return darken(c, 1.0f / ratio);
52+
return darken(c, 1.0F / ratio);
3653
}
3754
Q_INVOKABLE static QColor saturate(QColor c, float ratio) {
38-
float h = c.hslHueF();
39-
float s = c.hslSaturationF();
40-
float l = c.lightnessF();
41-
float a = c.alphaF();
42-
43-
s *= ratio;
44-
if (s > 1.0) {
45-
s = 1.0;
46-
}
47-
if (s < 0.0) {
48-
s = 0.0;
49-
}
50-
return QColor::fromHslF(h, s, l, a);
55+
HSLA hsla(c);
56+
hsla.s = std::clamp(hsla.s * ratio, 0.0F, 1.0F);
57+
return hsla.toColor();
5158
}
5259
// If used with light mode, this will make things lighter and vice versa.
5360
Q_INVOKABLE static QColor daytimeModeAdjust(QColor c, float ratio);

modules/Lith/Core/formattedstring.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ class LITHCORE_EXPORT FormattedString {
4242
: pos(pos)
4343
, n(n) {
4444
}
45-
Part() {
46-
}
45+
Part() = default;
4746
Part(Part&& o) = default;
4847
Part(const Part& o) = default;
4948
~Part() = default;

modules/Lith/Core/lith.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class LITHCORE_EXPORT ProxyBufferList : public QSortFilterProxyModel {
212212
PROPERTY(QString, filterWord)
213213
PROPERTY(bool, showOnlyBuffersWithNewMessages, false)
214214
public:
215-
ProxyBufferList(Lith* parent = nullptr, QAbstractListModel* parentModel = nullptr);
215+
explicit ProxyBufferList(Lith* parent = nullptr, QAbstractListModel* parentModel = nullptr);
216216

217217
bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override;
218218
bool lessThan(const QModelIndex& source_left, const QModelIndex& source_right) const override;

modules/Lith/Core/protocol.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ namespace WeeChatProtocol {
6868
if (len == static_cast<uint32_t>(-1)) {
6969
r = PlainString {};
7070
} else if (len == 0) {
71-
r = PlainString {QLatin1String("")};
71+
r = PlainString {QString("")};
7272
} else if (len > 0) {
7373
parserBuffer->resize(len);
7474
s.readRawData(parserBuffer->data(), static_cast<int>(len));
@@ -218,8 +218,8 @@ namespace WeeChatProtocol {
218218
}
219219
for (int j = 0; j < r.keys.count(); j++) {
220220
auto keys = r.keys.at(j).split(QStringLiteral(":"));
221-
auto name = keys.first();
222-
auto type = keys.last();
221+
const auto& name = keys.first();
222+
const auto& type = keys.last();
223223
if (type == QStringLiteral("int")) {
224224
Integer i = parse<Integer>(s, &innerOk);
225225
if (!innerOk) {

modules/Lith/Core/weechat.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ QCoro::Task<void> Weechat::onHandshakeAccepted(StringMap data) {
227227
hashString = QStringLiteral("password_hash=%1:%2:%3").arg(algo).arg(salt.toHex()).arg(hash.toHex());
228228
}
229229

230-
m_initializationStatus = (Initialization) (m_initializationStatus | HANDSHAKE);
230+
m_initializationStatus = static_cast<Initialization>(m_initializationStatus | HANDSHAKE);
231231
m_passwordAttempts++;
232232

233233
m_connection->write(QStringLiteral("init"), QString(), hashString);
@@ -256,7 +256,7 @@ void Weechat::requestHotlist() {
256256

257257
void Weechat::onConnected() {
258258
m_reconnectTimer->stop();
259-
m_initializationStatus = (Initialization) (m_initializationStatus | CONNECTION_OPENED);
259+
m_initializationStatus = static_cast<Initialization>(m_initializationStatus | CONNECTION_OPENED);
260260

261261
lith()->log(Logger::Protocol, QStringLiteral("Connected to WeeChat, starting handshake"));
262262

@@ -366,7 +366,7 @@ void Weechat::onMessageReceived(QByteArray& data) {
366366

367367
if (c_initializationMap->contains(id)) {
368368
// wtf, why can't I write this as |= ?
369-
m_initializationStatus = (Initialization) (m_initializationStatus | c_initializationMap->value(id, UNINITIALIZED));
369+
m_initializationStatus = static_cast<Initialization>(m_initializationStatus | c_initializationMap->value(id, UNINITIALIZED));
370370
if (!QMetaObject::invokeMethod(
371371
Lith::instance(), id.toStdString().c_str(), Qt::QueuedConnection, Q_ARG(WeeChatProtocol::HData, hda)
372372
)) {
@@ -378,7 +378,7 @@ void Weechat::onMessageReceived(QByteArray& data) {
378378
}
379379
} else {
380380
auto parts = id.split(QStringLiteral(";"));
381-
auto name = parts.first();
381+
const auto& name = parts.first();
382382
if (!QMetaObject::invokeMethod(
383383
Lith::instance(), name.toStdString().c_str(), Qt::QueuedConnection, Q_ARG(WeeChatProtocol::HData, hda)
384384
)) {

modules/Lith/Style/constants.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include "../Core/lith.h"
55

66
FontSizes::FontSizes(QObject* parent)
7-
: m_settings(Lith::settingsGet()) {
7+
: QObject(parent)
8+
, m_settings(Lith::settingsGet()) {
89
connect(m_settings, &Settings::baseFontPixelSizeChanged, this, &FontSizes::fontSizesChanged);
910
connect(m_settings, &Settings::useBaseFontPixelSizeForMessagesChanged, this, &FontSizes::messageChanged);
1011
connect(m_settings, &Settings::messageFontPixelSizeChanged, this, &FontSizes::messageChanged);
@@ -47,7 +48,6 @@ int FontSizes::message() const {
4748
}
4849
}
4950

50-
ControlProperties::ControlProperties(QObject *parent)
51-
{
52-
51+
ControlProperties::ControlProperties(QObject* parent)
52+
: QObject(parent) {
5353
}

modules/Lith/Style/constants.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ class FontSizes : public QObject {
1818
Q_PROPERTY(int message READ message NOTIFY messageChanged)
1919
public:
2020
explicit FontSizes(QObject* parent = nullptr);
21-
static FontSizes* create(QQmlEngine* qmlEngine, QJSEngine* jsEngine) {
22-
Q_UNUSED(jsEngine)
23-
return new FontSizes(qmlEngine);
24-
}
2521

2622
int tiny() const;
2723
int small() const;
@@ -51,7 +47,7 @@ class ControlProperties : public QObject {
5147
return new ControlProperties(qmlEngine);
5248
}
5349

54-
qreal buttonRadius() const {
50+
static qreal buttonRadius() {
5551
return 4.0;
5652
}
5753

0 commit comments

Comments
 (0)