* Use correct font for size hint in Frame
* Use correct font in IconWidget setLayoutOptions * layout fonts are set in IconWidget setLayoutOptions and layoutTextItems. No need to set them in paint. * Fix using QGraphicsWidget font when customFont == true in several widgets. svn path=/trunk/KDE/kdelibs/; revision=1047017
This commit is contained in:
parent
de056072d7
commit
71fa982797
@ -42,7 +42,7 @@ public:
|
||||
ComboBoxPrivate(ComboBox *comboBox)
|
||||
: q(comboBox),
|
||||
background(0),
|
||||
customFont(0),
|
||||
customFont(false),
|
||||
underMouse(false)
|
||||
{
|
||||
}
|
||||
@ -101,9 +101,9 @@ void ComboBoxPrivate::syncBorders()
|
||||
|
||||
KComboBox *native = q->nativeWidget();
|
||||
if (customFont) {
|
||||
native->setFont(Theme::defaultTheme()->font(Theme::DefaultFont));
|
||||
} else {
|
||||
native->setFont(q->font());
|
||||
} else {
|
||||
native->setFont(Theme::defaultTheme()->font(Theme::DefaultFont));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,8 @@ public:
|
||||
: q(parent),
|
||||
svg(0),
|
||||
image(0),
|
||||
pixmap(0)
|
||||
pixmap(0),
|
||||
customFont(false)
|
||||
{
|
||||
}
|
||||
|
||||
@ -53,6 +54,7 @@ public:
|
||||
}
|
||||
|
||||
void syncBorders();
|
||||
QFont widgetFont() const;
|
||||
|
||||
Frame *q;
|
||||
FrameSvg *svg;
|
||||
@ -66,6 +68,15 @@ public:
|
||||
bool customFont;
|
||||
};
|
||||
|
||||
QFont FramePrivate::widgetFont() const
|
||||
{
|
||||
if (customFont) {
|
||||
return q->font();
|
||||
} else {
|
||||
return Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
}
|
||||
}
|
||||
|
||||
void FramePrivate::syncBorders()
|
||||
{
|
||||
//set margins from the normal element
|
||||
@ -73,15 +84,8 @@ void FramePrivate::syncBorders()
|
||||
|
||||
svg->getMargins(left, top, right, bottom);
|
||||
|
||||
QFont widgetFont;
|
||||
if (customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = q->font();
|
||||
}
|
||||
|
||||
if (!text.isNull()) {
|
||||
QFontMetricsF fm(widgetFont);
|
||||
QFontMetricsF fm(widgetFont());
|
||||
top += fm.height();
|
||||
}
|
||||
|
||||
@ -225,18 +229,11 @@ void Frame::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWi
|
||||
|
||||
d->svg->paintFrame(painter);
|
||||
|
||||
QFont widgetFont;
|
||||
if (d->customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = font();
|
||||
}
|
||||
|
||||
if (!d->text.isNull()) {
|
||||
QFontMetricsF fm(widgetFont);
|
||||
QFontMetricsF fm(d->widgetFont());
|
||||
QRectF textRect = d->svg->contentsRect();
|
||||
textRect.setHeight(fm.height());
|
||||
painter->setFont(widgetFont);
|
||||
painter->setFont(d->widgetFont());
|
||||
painter->setPen(Plasma::Theme::defaultTheme()->color(Theme::TextColor));
|
||||
painter->drawText(textRect, Qt::AlignHCenter|Qt::AlignTop, d->text);
|
||||
}
|
||||
@ -264,7 +261,7 @@ QSizeF Frame::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const
|
||||
QSizeF hint = QGraphicsWidget::sizeHint(which, constraint);
|
||||
|
||||
if (!d->image && !layout()) {
|
||||
QFontMetricsF fm(QApplication::font());
|
||||
QFontMetricsF fm(d->widgetFont());
|
||||
|
||||
qreal left, top, right, bottom;
|
||||
d->svg->getMargins(left, top, right, bottom);
|
||||
|
@ -118,6 +118,15 @@ void IconWidgetPrivate::iconConfigChanged()
|
||||
}
|
||||
}
|
||||
|
||||
QFont IconWidgetPrivate::widgetFont() const
|
||||
{
|
||||
if (customFont) {
|
||||
return q->font();
|
||||
} else {
|
||||
return Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
}
|
||||
}
|
||||
|
||||
IconAction::IconAction(IconWidget *icon, QAction *action)
|
||||
: m_icon(icon),
|
||||
m_action(action),
|
||||
@ -477,16 +486,9 @@ QSizeF IconWidgetPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option
|
||||
horizontalMargin[IconWidgetPrivate::TextMargin].left -
|
||||
horizontalMargin[IconWidgetPrivate::TextMargin].right;
|
||||
|
||||
QFont widgetFont;
|
||||
if (customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = q->font();
|
||||
}
|
||||
|
||||
//allow only five lines of text
|
||||
const qreal maxHeight =
|
||||
numDisplayLines * QFontMetrics(widgetFont).lineSpacing();
|
||||
numDisplayLines * QFontMetrics(widgetFont()).lineSpacing();
|
||||
|
||||
// To compute the nominal size for the label + info, we'll just append
|
||||
// the information string to the label
|
||||
@ -496,7 +498,7 @@ QSizeF IconWidgetPrivate::displaySizeHint(const QStyleOptionGraphicsItem *option
|
||||
|
||||
QTextLayout layout;
|
||||
setLayoutOptions(layout, option, q->orientation());
|
||||
layout.setFont(widgetFont);
|
||||
layout.setFont(widgetFont());
|
||||
QSizeF size = layoutText(layout, option, label, QSizeF(textWidth, maxHeight));
|
||||
|
||||
return addMargin(size, TextMargin);
|
||||
@ -540,15 +542,7 @@ void IconWidgetPrivate::layoutIcons(const QStyleOptionGraphicsItem *option)
|
||||
}
|
||||
iconWidth -= horizontalMargin[IconWidgetPrivate::ItemMargin].left + horizontalMargin[IconWidgetPrivate::ItemMargin].right;
|
||||
} else {
|
||||
QFont widgetFont;
|
||||
if (customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = q->font();
|
||||
}
|
||||
//Horizontal layout
|
||||
QFontMetricsF fm = QFontMetrics(widgetFont);
|
||||
|
||||
//if there is text resize the icon in order to make room for the text
|
||||
if (text.isEmpty() && infoText.isEmpty()) {
|
||||
// with no text, we just take up the whole geometry
|
||||
@ -1010,20 +1004,10 @@ void IconWidget::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
|
||||
}
|
||||
}
|
||||
|
||||
QFont widgetFont;
|
||||
if (d->customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = font();
|
||||
}
|
||||
|
||||
// Draw text last because it is overlayed
|
||||
QTextLayout labelLayout, infoLayout;
|
||||
labelLayout.setFont(widgetFont);
|
||||
infoLayout.setFont(widgetFont);
|
||||
QRectF textBoundingRect;
|
||||
|
||||
|
||||
d->layoutTextItems(option, icon, &labelLayout, &infoLayout, &textBoundingRect);
|
||||
|
||||
QImage shadow(textBoundingRect.size().toSize() + QSize(4, 4),
|
||||
@ -1352,14 +1336,7 @@ QSizeF IconWidget::sizeFromIconSize(const qreal iconWidth) const
|
||||
IconWidgetPrivate::ItemMargin);
|
||||
}
|
||||
|
||||
QFont widgetFont;
|
||||
if (d->customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = font();
|
||||
}
|
||||
|
||||
QFontMetricsF fm(widgetFont);
|
||||
QFontMetricsF fm(d->widgetFont());
|
||||
qreal width = 0;
|
||||
|
||||
if (d->orientation == Qt::Vertical) {
|
||||
|
@ -187,6 +187,7 @@ public:
|
||||
void readColors();
|
||||
void colorConfigChanged();
|
||||
void iconConfigChanged();
|
||||
QFont widgetFont() const;
|
||||
void hoverAnimationUpdate(qreal progress);
|
||||
void init();
|
||||
void layoutIcons(const QStyleOptionGraphicsItem *option);
|
||||
@ -246,7 +247,7 @@ void IconWidgetPrivate::setLayoutOptions(QTextLayout &layout,
|
||||
|
||||
textoption.setWrapMode(QTextOption::WordWrap); // NOTE: assumption as well
|
||||
|
||||
layout.setFont(QApplication::font()); // NOTE: find better ways to get the font
|
||||
layout.setFont(widgetFont());
|
||||
layout.setTextOption(textoption);
|
||||
}
|
||||
|
||||
|
@ -410,9 +410,9 @@ void PushButton::paint(QPainter *painter,
|
||||
|
||||
QFont widgetFont;
|
||||
if (d->customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = font();
|
||||
} else {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
}
|
||||
|
||||
//if there is not enough room for the text make it to fade out
|
||||
|
@ -77,7 +77,7 @@ public:
|
||||
newPage(0),
|
||||
oldPageAnimId(-1),
|
||||
newPageAnimId(-1),
|
||||
customFont(true)
|
||||
customFont(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -365,9 +365,9 @@ void ToolButton::paint(QPainter *painter,
|
||||
|
||||
QFont widgetFont;
|
||||
if (d->customFont) {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
} else {
|
||||
widgetFont = font();
|
||||
} else {
|
||||
widgetFont = Plasma::Theme::defaultTheme()->font(Plasma::Theme::DefaultFont);
|
||||
}
|
||||
buttonOpt.font = widgetFont;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user