summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-04-27 15:34:50 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-04-27 16:14:22 (GMT)
commit8af3500125a03a54dddb8c46ee709b7b8d257f27 (patch)
treea62d474028858dddd5f6f80b4a7c3f2270af343d /src
parent3cdde3b112f0c69e497d72d195b9ccc44d0048ab (diff)
downloadQt-8af3500125a03a54dddb8c46ee709b7b8d257f27.zip
Qt-8af3500125a03a54dddb8c46ee709b7b8d257f27.tar.gz
Qt-8af3500125a03a54dddb8c46ee709b7b8d257f27.tar.bz2
Fixes QLabel:hover{color:...} for simple text
(This was only working if the QLabel had a QTextControl) Also rename the QStyleSheetStyle::focusPalette to ...::styleSheetPalette Reviewed-by: Jens Bache-Wiig
Diffstat (limited to 'src')
-rw-r--r--src/gui/styles/qstylesheetstyle.cpp10
-rw-r--r--src/gui/styles/qstylesheetstyle_p.h2
-rw-r--r--src/gui/widgets/qlabel.cpp23
-rw-r--r--src/gui/widgets/qlineedit.cpp2
4 files changed, 16 insertions, 21 deletions
diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp
index 5756dba..f480008 100644
--- a/src/gui/styles/qstylesheetstyle.cpp
+++ b/src/gui/styles/qstylesheetstyle.cpp
@@ -5872,13 +5872,11 @@ void QStyleSheetStyle::clearWidgetFont(QWidget* w) const
w->setProperty("_q_styleSheetWidgetFont", QVariant(QVariant::Invalid));
}
-// Returns the palette that should be used when the particular widget is focused.
-// This needs to be called by some widgets that do drawing themselves instead
-// of through the style.
-// ### This should be removed ideally by Qt 4.5, and at least by Qt 5, and fixed
-// for good by letting the style draw everything.
+// Polish palette that should be used for a particular widget, with particular states
+// (eg. :focus, :hover, ...)
+// this is called by widgets that paint themself in their paint event
// Returns true if there is a new palette in pal.
-bool QStyleSheetStyle::focusPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)
+bool QStyleSheetStyle::styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal)
{
if (!w || !opt || !pal)
return false;
diff --git a/src/gui/styles/qstylesheetstyle_p.h b/src/gui/styles/qstylesheetstyle_p.h
index 1f61445..e057274 100644
--- a/src/gui/styles/qstylesheetstyle_p.h
+++ b/src/gui/styles/qstylesheetstyle_p.h
@@ -131,7 +131,7 @@ public:
void saveWidgetFont(QWidget* w, const QFont& font) const;
void clearWidgetFont(QWidget* w) const;
- bool focusPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal);
+ bool styleSheetPalette(const QWidget* w, const QStyleOption* opt, QPalette* pal);
protected Q_SLOTS:
QIcon standardIconImplementation(StandardPixmap standardIcon, const QStyleOption *opt = 0,
diff --git a/src/gui/widgets/qlabel.cpp b/src/gui/widgets/qlabel.cpp
index 63c1315..e510c7d 100644
--- a/src/gui/widgets/qlabel.cpp
+++ b/src/gui/widgets/qlabel.cpp
@@ -52,7 +52,6 @@
#include <qdebug.h>
#include <qurl.h>
#include "qlabel_p.h"
-#include "private/qstylesheetstyle_p.h"
QT_BEGIN_NAMESPACE
@@ -971,6 +970,13 @@ void QLabel::paintEvent(QPaintEvent *)
#endif
if (d->isTextLabel) {
QRectF lr = d->layoutRect();
+ QStyleOption opt;
+ opt.initFrom(this);
+#ifndef QT_NO_STYLE_STYLESHEET
+ if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) {
+ cssStyle->styleSheetPalette(this, &opt, &opt.palette);
+ }
+#endif
if (d->control) {
#ifndef QT_NO_SHORTCUT
const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0);
@@ -984,11 +990,9 @@ void QLabel::paintEvent(QPaintEvent *)
d->ensureTextLayouted();
QAbstractTextDocumentLayout::PaintContext context;
- QStyleOption opt(0);
- opt.init(this);
if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
- context.palette = palette();
+ context.palette = opt.palette;
context.palette.setColor(QPalette::Text, context.palette.light().color());
painter.save();
painter.translate(lr.x() + 1, lr.y() + 1);
@@ -999,12 +1003,7 @@ void QLabel::paintEvent(QPaintEvent *)
}
// Adjust the palette
- context.palette = palette();
-#ifndef QT_NO_STYLE_STYLESHEET
- if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style)) {
- cssStyle->focusPalette(this, &opt, &context.palette);
- }
-#endif
+ context.palette = opt.palette;
if (foregroundRole() != QPalette::Text && isEnabled())
context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole()));
@@ -1019,12 +1018,10 @@ void QLabel::paintEvent(QPaintEvent *)
int flags = align;
if (d->hasShortcut) {
flags |= Qt::TextShowMnemonic;
- QStyleOption opt;
- opt.initFrom(this);
if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
flags |= Qt::TextHideMnemonic;
}
- style->drawItemText(&painter, lr.toRect(), flags, palette(), isEnabled(), d->text, foregroundRole());
+ style->drawItemText(&painter, lr.toRect(), flags, opt.palette, isEnabled(), d->text, foregroundRole());
}
} else
#ifndef QT_NO_PICTURE
diff --git a/src/gui/widgets/qlineedit.cpp b/src/gui/widgets/qlineedit.cpp
index e243ad0..d16ed10 100644
--- a/src/gui/widgets/qlineedit.cpp
+++ b/src/gui/widgets/qlineedit.cpp
@@ -2518,7 +2518,7 @@ void QLineEdit::paintEvent(QPaintEvent *)
// draw text, selections and cursors
#ifndef QT_NO_STYLE_STYLESHEET
if (QStyleSheetStyle* cssStyle = qobject_cast<QStyleSheetStyle*>(style())) {
- cssStyle->focusPalette(this, &panel, &pal);
+ cssStyle->styleSheetPalette(this, &panel, &pal);
}
#endif
p.setPen(pal.text().color());