Commit e6e11758 authored by Nate Graham's avatar Nate Graham 🔩

[kcms/keyboard] Use correct color for layout label in KCM

The label was always using the text color from the Plasma theme, which
just happened to work fine as long you were using the same colors for
both your Plasma and Apps colors (e.g. both dark or both light). But
when using one dark and the other light, the text would become
invisible.

This is resolved by adding a paremeter to the function that allows it to
specify whether it should get its text color from the Plasma theme or
apps color scheme. Then the function invocation for the tray item asks
for the Plasma theme color and the invocation in the KCM asks for the
apps color scheme color.

BUG: 431361
FIXED-IN: 5.21
parent 238ad49b
......@@ -26,6 +26,7 @@
#include <QStandardPaths>
#include <QStringList>
#include <QPalette>
#include <QPixmap>
#include <QPainter>
#include <QIcon>
......@@ -213,7 +214,7 @@ QString getPixmapKey(const KeyboardConfig& keyboardConfig)
return QStringLiteral("_"); // should not happen
}
void Flags::drawLabel(QPainter& painter, const QString& layoutText, bool flagShown)
void Flags::drawLabel(QPainter& painter, const QString& layoutText, bool flagShown, ColorType colorType)
{
QFont font = painter.font();
QRect rect = painter.window();
......@@ -223,14 +224,21 @@ void Flags::drawLabel(QPainter& painter, const QString& layoutText, bool flagSho
// we init svg so that we get notification about theme change
getSvg();
const QColor textColor = flagShown ? Qt::black : Plasma::Theme().color(Plasma::Theme::TextColor);
QColor textColor;
if (flagShown) {
textColor = Qt::black;
} else if (colorType == ColorType::Plasma) {
textColor = Plasma::Theme().color(Plasma::Theme::TextColor);
} else {
textColor = QPalette().color(QPalette::Text);
}
painter.setPen(textColor);
painter.setFont(font);
painter.drawText(rect, Qt::AlignCenter, layoutText);
}
const QIcon Flags::getIconWithText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig)
const QIcon Flags::getIconWithText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig, ColorType colorType)
{
const QString keySuffix(getPixmapKey(keyboardConfig));
const QString key(layoutUnit.toString() + keySuffix);
......@@ -261,7 +269,7 @@ const QIcon Flags::getIconWithText(const LayoutUnit& layoutUnit, const KeyboardC
painter.drawPixmap(pixmap.rect(), iconf.pixmap(TRAY_ICON_SIZE));
}
drawLabel(painter, layoutText, keyboardConfig.isFlagShown());
drawLabel(painter, layoutText, keyboardConfig.isFlagShown(), colorType);
painter.end();
......
......@@ -42,8 +42,13 @@ public:
Flags();
~Flags() override;
enum ColorType {
Plasma = Qt::UserRole,
ColorScheme
};
const QIcon getIcon(const QString& layout);
const QIcon getIconWithText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig);
const QIcon getIconWithText(const LayoutUnit& layoutUnit, const KeyboardConfig& keyboardConfig, ColorType colorType = ColorType::Plasma);
const QPixmap& getTransparentPixmap() const { return *transparentPixmap; }
static QString getLongText(const LayoutUnit& layoutUnit, const Rules* rules);
......@@ -60,7 +65,7 @@ Q_SIGNALS:
private:
QIcon createIcon(const QString& layout);
QString getCountryFromLayoutName(const QString& fullLayoutName) const;
void drawLabel(QPainter& painter, const QString& layoutText, bool flagShown);
void drawLabel(QPainter& painter, const QString& layoutText, bool flagShown, ColorType colorType);
Plasma::Svg* getSvg();
QMap<QString, QIcon> iconMap;
......
......@@ -134,7 +134,7 @@ QVariant LayoutsTableModel::data(const QModelIndex &index, int role) const
switch( index.column() ) {
case DISPLAY_NAME_COLUMN: {
// if(keyboardConfig->isFlagShown()) {
QIcon icon = countryFlags->getIconWithText(layoutUnit, *keyboardConfig);
QIcon icon = countryFlags->getIconWithText(layoutUnit, *keyboardConfig, Flags::ColorType::ColorScheme);
return icon.isNull() ? countryFlags->getTransparentPixmap() : icon;
// }
}
......
......@@ -104,7 +104,7 @@ void LayoutTrayIcon::layoutChanged()
const QIcon icon(getFlag(layoutUnit.layout()));
m_notifierItem->setToolTipIconByPixmap(icon);
QIcon textOrIcon = flags->getIconWithText(layoutUnit, keyboardConfig);
QIcon textOrIcon = flags->getIconWithText(layoutUnit, keyboardConfig, Flags::ColorType::Plasma);
m_notifierItem->setIconByPixmap( textOrIcon );
}
......
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