From 748f2b83bc4e296901b8b658486a90f5b55fa5cb Mon Sep 17 00:00:00 2001
From: "r.dorokhova" <r.dorokhova@drweb.com>
Date: Fri, 28 Nov 2014 20:37:16 +0300
Subject: [PATCH] qcommandlinkbutton in high contrast fixed

---
 qtbase/src/widgets/styles/qcommonstyle.cpp        | 22 ++++++++++++++
 qtbase/src/widgets/styles/qgtkstyle.cpp           | 35 +++++++++++++++++++++++
 qtbase/src/widgets/styles/qstyle.h                |  2 ++
 qtbase/src/widgets/widgets/qcommandlinkbutton.cpp | 11 ++++---
 4 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/qtbase/src/widgets/styles/qcommonstyle.cpp b/qtbase/src/widgets/styles/qcommonstyle.cpp
index d7030c5..2b7411d 100644
--- a/qtbase/src/widgets/styles/qcommonstyle.cpp
+++ b/qtbase/src/widgets/styles/qcommonstyle.cpp
@@ -1287,6 +1287,28 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt,
                          button->text, QPalette::ButtonText);
         }
         break;
+    case CE_ButtonText:
+           if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
+               QRect textRect = button->rect;
+               uint tf = Qt::TextShowMnemonic;
+               if (!proxy()->styleHint(SH_UnderlineShortcut, button, widget))
+                   tf |= Qt::TextHideMnemonic;
+
+               if (button->state & (State_On | State_Sunken))
+                   textRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
+                                proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
+
+               if (button->features & QStyleOptionButton::HasMenu) {
+                   int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget);
+                   if (button->direction == Qt::LeftToRight)
+                       textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
+                   else
+                       textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
+               }
+               proxy()->drawItemText(p, textRect, tf, button->palette, (button->state & State_Enabled),
+                            button->text, QPalette::ButtonText);
+           }
+           break;
     case CE_RadioButton:
     case CE_CheckBox:
         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
diff --git a/qtbase/src/widgets/styles/qgtkstyle.cpp b/qtbase/src/widgets/styles/qgtkstyle.cpp
index 9fa0569..afc1091 100644
--- a/qtbase/src/widgets/styles/qgtkstyle.cpp
+++ b/qtbase/src/widgets/styles/qgtkstyle.cpp
@@ -2796,6 +2796,41 @@ void QGtkStyle::drawControl(ControlElement element,
         }
         break;
 
+    case CE_ButtonText:
+        if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) {
+            QRect ir = button->rect;
+            uint tf = Qt::TextShowMnemonic;
+            QPoint buttonShift;
+
+            if (option->state & State_Sunken)
+                buttonShift = QPoint(pixelMetric(PM_ButtonShiftHorizontal, option, widget),
+                                     proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget));
+
+            if (proxy()->styleHint(SH_UnderlineShortcut, button, widget))
+                tf |= Qt::TextShowMnemonic;
+            else
+                tf |= Qt::TextHideMnemonic;
+
+            ir.translate(buttonShift);
+
+            if (button->features & QStyleOptionButton::HasMenu)
+                ir = ir.adjusted(0, 0, -pixelMetric(PM_MenuButtonIndicator, button, widget), 0);
+
+            GtkWidget *gtkButton = d->gtkWidget("GtkButton");
+            QPalette pal = button->palette;
+            int labelState = GTK_STATE_INSENSITIVE;
+            if (option->state & State_Enabled)
+                labelState = (option->state & State_MouseOver && !(option->state & State_Sunken)) ?
+                             GTK_STATE_PRELIGHT : GTK_STATE_NORMAL;
+
+            GdkColor gdkText = d->gtk_widget_get_style(gtkButton)->fg[labelState];
+            QColor textColor = QColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
+            pal.setBrush(QPalette::ButtonText, textColor);
+            proxy()->drawItemText(painter, ir, tf, pal, (button->state & State_Enabled),
+                         button->text, QPalette::ButtonText);
+        }
+        break;
+
     case CE_RadioButton: // Fall through
     case CE_CheckBox:
         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
diff --git a/qtbase/src/widgets/styles/qstyle.h b/qtbase/src/widgets/styles/qstyle.h
index 136daa9..e6e542e 100644
--- a/qtbase/src/widgets/styles/qstyle.h
+++ b/qtbase/src/widgets/styles/qstyle.h
@@ -263,6 +263,8 @@ public:
 
         CE_ShapedFrame,
 
+        CE_ButtonText,
+
         // do not add any values below/greater than this
         CE_CustomBase = 0xf0000000
     };
diff --git a/qtbase/src/widgets/widgets/qcommandlinkbutton.cpp b/qtbase/src/widgets/widgets/qcommandlinkbutton.cpp
index 18f7b17..ffc9a90 100644
--- a/qtbase/src/widgets/widgets/qcommandlinkbutton.cpp
+++ b/qtbase/src/widgets/widgets/qcommandlinkbutton.cpp
@@ -388,14 +388,17 @@ void QCommandLinkButton::paintEvent(QPaintEvent *)
         textflags |= Qt::TextHideMnemonic;
 
     p.setFont(d->titleFont());
-    p.drawItemText(d->titleRect().translated(hOffset, vOffset),
-                    textflags, option.palette, isEnabled(), text(), QPalette::ButtonText);
+    option.text = text();
+    option.rect = d->titleRect().translated(hOffset, vOffset);
+    p.drawControl(QStyle::CE_ButtonText, option);
 
     //Draw description
     textflags |= Qt::TextWordWrap | Qt::ElideRight;
+    option.text = description();
+    option.rect = d->descriptionRect().translated(hOffset, vOffset);
     p.setFont(d->descriptionFont());
-    p.drawItemText(d->descriptionRect().translated(hOffset, vOffset), textflags,
-                    option.palette, isEnabled(), description(), QPalette::ButtonText);
+    p.drawControl(QStyle::CE_ButtonText, option);
+
     p.restore();
 }
 
-- 
2.1.3

