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