diff --git a/qml/main.qml b/qml/main.qml index e6f59e0..4029171 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -67,7 +67,7 @@ Item { onNewColor: { background.color = color - rootItem.darkMode = lightness < 128 ? true : false + rootItem.darkMode = darkMode } } diff --git a/src/backgroundhelper.cpp b/src/backgroundhelper.cpp index 2a2b5b9..6416e67 100644 --- a/src/backgroundhelper.cpp +++ b/src/backgroundhelper.cpp @@ -39,7 +39,12 @@ void BackgroundHelper::setColor(QColor c) { m_color = c; m_type = 1; - emit newColor(c, c.lightness()); + + bool isDark = (c.red() * 0.299 + + c.green() * 0.587 + + c.blue() * 0.114) < 186; + + emit newColor(c, isDark); } void BackgroundHelper::setBackgound(const QString &fileName) @@ -75,8 +80,13 @@ void BackgroundHelper::setBackgound(const QString &fileName) sumB /= measureArea; QColor c = QColor(sumR, sumG, sumB); + QColor textColor = (sumR * 0.299 + + sumG * 0.587 + + sumB * 0.114) > 186 ? "#000000" : "#FFFFFF"; + + qDebug() << c << textColor; - emit newColor(c, c.lightness()); + emit newColor(c, textColor == "#FFFFFF"); // clear cache. QPixmapCache::clear(); diff --git a/src/backgroundhelper.h b/src/backgroundhelper.h index 52e2967..04d65b2 100644 --- a/src/backgroundhelper.h +++ b/src/backgroundhelper.h @@ -38,7 +38,7 @@ private slots: void onChanged(); signals: - void newColor(QColor color, int lightness); + void newColor(QColor color, bool darkMode); private: int m_statusBarHeight;