Mac style: Update appearance of 'button with menu'
Most of the logic was still following the 10.6 UI guidelines, and had not yet been upgraded to the 10.7 new button look. We tried to keep 10.6 compatibility were possible, and improve 'small' and 'mini' Aqua sizes support. Change-Id: I64139f24cccd095e9349b27a987395210b55c586 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
This commit is contained in:
parent
08be36c176
commit
16413d8bd1
@ -1660,7 +1660,20 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
|
|||||||
extraHeight = 0,
|
extraHeight = 0,
|
||||||
finalyoff = 0;
|
finalyoff = 0;
|
||||||
|
|
||||||
const QStyleOptionComboBox *combo = qstyleoption_cast<const QStyleOptionComboBox *>(opt);
|
const bool combo = opt->type == QStyleOption::SO_ComboBox;
|
||||||
|
const bool button = opt->type == QStyleOption::SO_Button;
|
||||||
|
const bool pressed = bdi->state == kThemeStatePressed;
|
||||||
|
|
||||||
|
if (button && pressed) {
|
||||||
|
if (bdi->kind == kThemePushButton) {
|
||||||
|
extraHeight = 2;
|
||||||
|
} else if (bdi->kind == kThemePushButtonSmall) {
|
||||||
|
xoff = 1;
|
||||||
|
extraWidth = 2;
|
||||||
|
extraHeight = 5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int width = int(macRect.size.width) + extraWidth;
|
int width = int(macRect.size.width) + extraWidth;
|
||||||
int height = int(macRect.size.height) + extraHeight;
|
int height = int(macRect.size.height) + extraHeight;
|
||||||
|
|
||||||
@ -1668,8 +1681,9 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
|
|||||||
return; // nothing to draw
|
return; // nothing to draw
|
||||||
|
|
||||||
QString key = QLatin1String("$qt_mac_style_ctb_") + QString::number(bdi->kind) + QLatin1Char('_')
|
QString key = QLatin1String("$qt_mac_style_ctb_") + QString::number(bdi->kind) + QLatin1Char('_')
|
||||||
+ QString::number(bdi->value) + QLatin1Char('_') + QString::number(width)
|
+ QString::number(bdi->value) + QLatin1Char('_')
|
||||||
+ QLatin1Char('_') + QString::number(height);
|
+ (button ? QString::number(bdi->state) + QLatin1Char('_') : QString())
|
||||||
|
+ QLatin1Char('_') + QString::number(width) + QLatin1Char('_') + QString::number(height);
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
if (!QPixmapCache::find(key, pm)) {
|
if (!QPixmapCache::find(key, pm)) {
|
||||||
QPixmap activePixmap(width, height);
|
QPixmap activePixmap(width, height);
|
||||||
@ -1680,17 +1694,18 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
|
|||||||
// ourselves, if a scaled version is needed.
|
// ourselves, if a scaled version is needed.
|
||||||
QPainter tmpPainter(&activePixmap);
|
QPainter tmpPainter(&activePixmap);
|
||||||
QMacStylePrivate::drawCombobox(macRect, *bdi, &tmpPainter);
|
QMacStylePrivate::drawCombobox(macRect, *bdi, &tmpPainter);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
QMacCGContext cg(&activePixmap);
|
QMacCGContext cg(&activePixmap);
|
||||||
HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height);
|
HIRect newRect = CGRectMake(xoff, yoff, macRect.size.width, macRect.size.height);
|
||||||
|
if (button && pressed)
|
||||||
|
bdi->state = kThemeStateActive;
|
||||||
HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0);
|
HIThemeDrawButton(&newRect, bdi, cg, kHIThemeOrientationNormal, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!combo && bdi->value == kThemeButtonOff) {
|
if (!combo && !button && bdi->value == kThemeButtonOff) {
|
||||||
pm = activePixmap;
|
pm = activePixmap;
|
||||||
} else if (combo) {
|
} else if (combo || button) {
|
||||||
QImage image = activePixmap.toImage();
|
QImage image = activePixmap.toImage();
|
||||||
|
|
||||||
for (int y = 0; y < height; ++y) {
|
for (int y = 0; y < height; ++y) {
|
||||||
@ -1711,6 +1726,8 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
|
|||||||
qSwap(darkest, mid);
|
qSwap(darkest, mid);
|
||||||
|
|
||||||
int gray = (mid + 2 * lightest) / 3;
|
int gray = (mid + 2 * lightest) / 3;
|
||||||
|
if (pressed)
|
||||||
|
gray *= 0.88;
|
||||||
pixel = qRgba(gray, gray, gray, qAlpha(pixel));
|
pixel = qRgba(gray, gray, gray, qAlpha(pixel));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1753,7 +1770,7 @@ void QMacStylePrivate::drawColorlessButton(const HIRect &macRect, HIThemeButtonD
|
|||||||
}
|
}
|
||||||
QPixmapCache::insert(key, pm);
|
QPixmapCache::insert(key, pm);
|
||||||
}
|
}
|
||||||
p->drawPixmap(int(macRect.origin.x), int(macRect.origin.y) + finalyoff, width, height, pm);
|
p->drawPixmap(int(macRect.origin.x) - xoff, int(macRect.origin.y) + finalyoff, width, height, pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
QMacStyle::QMacStyle()
|
QMacStyle::QMacStyle()
|
||||||
@ -3539,23 +3556,52 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
|
|||||||
newRect.origin.y += QMacStylePrivate::PushButtonTopOffset;
|
newRect.origin.y += QMacStylePrivate::PushButtonTopOffset;
|
||||||
newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4;
|
newRect.size.width -= QMacStylePrivate::PushButtonRightOffset - 4;
|
||||||
}
|
}
|
||||||
HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0);
|
|
||||||
|
|
||||||
if (btn->features & QStyleOptionButton::HasMenu) {
|
bool hasMenu = btn->features & QStyleOptionButton::HasMenu;
|
||||||
|
if (hasMenu && bdi.state == kThemeStatePressed && QSysInfo::macVersion() > QSysInfo::MV_10_6)
|
||||||
|
d->drawColorlessButton(newRect, &bdi, p, opt);
|
||||||
|
else
|
||||||
|
HIThemeDrawButton(&newRect, &bdi, cg, kHIThemeOrientationNormal, 0);
|
||||||
|
|
||||||
|
if (hasMenu) {
|
||||||
int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
|
int mbi = proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator, btn, w);
|
||||||
QRect ir = btn->rect;
|
QRect ir = btn->rect;
|
||||||
int arrowYOffset = bdi.kind == kThemePushButton ? 4 : 2;
|
int arrowXOffset = 0;
|
||||||
HIRect arrowRect = CGRectMake(ir.right() - mbi - QMacStylePrivate::PushButtonRightOffset,
|
if (QSysInfo::macVersion() > QSysInfo::MV_10_6)
|
||||||
ir.height() / 2 - arrowYOffset, mbi, ir.height() / 2);
|
arrowXOffset = bdi.kind == kThemePushButton ? 6 :
|
||||||
|
bdi.kind == kThemePushButtonSmall ? 7 : 8;
|
||||||
|
int arrowYOffset;
|
||||||
|
if (QSysInfo::macVersion() > QSysInfo::MV_10_6)
|
||||||
|
arrowYOffset = bdi.kind == kThemePushButton ? 3 :
|
||||||
|
bdi.kind == kThemePushButtonSmall ? 1 : 2;
|
||||||
|
else
|
||||||
|
arrowYOffset = bdi.kind == kThemePushButton ? 4 : 2;
|
||||||
|
if (!w) {
|
||||||
|
// adjustment for Qt Quick Controls
|
||||||
|
arrowYOffset -= ir.top();
|
||||||
|
if (bdi.kind == kThemePushButtonSmall)
|
||||||
|
arrowYOffset += 1;
|
||||||
|
}
|
||||||
|
QRect ar = QRect(ir.right() - mbi - QMacStylePrivate::PushButtonRightOffset,
|
||||||
|
ir.height() / 2 - arrowYOffset, mbi, ir.height() / 2);
|
||||||
|
ar = visualRect(btn->direction, ir, ar);
|
||||||
|
HIRect arrowRect = CGRectMake(ar.x() + arrowXOffset, ar.y(), ar.width(), ar.height());
|
||||||
|
|
||||||
HIThemePopupArrowDrawInfo pdi;
|
HIThemePopupArrowDrawInfo pdi;
|
||||||
pdi.version = qt_mac_hitheme_version;
|
pdi.version = qt_mac_hitheme_version;
|
||||||
pdi.state = tds == kThemeStateInactive ? kThemeStateActive : tds;
|
pdi.state = tds == kThemeStateInactive ? kThemeStateActive : tds;
|
||||||
pdi.orientation = kThemeArrowDown;
|
pdi.orientation = kThemeArrowDown;
|
||||||
if (arrowRect.size.width < 8.)
|
if (QSysInfo::macVersion() > QSysInfo::MV_10_6) {
|
||||||
pdi.size = kThemeArrow5pt;
|
if (bdi.kind == kThemePushButtonMini)
|
||||||
else
|
pdi.size = kThemeArrow5pt;
|
||||||
pdi.size = kThemeArrow9pt;
|
else if (bdi.kind == kThemePushButton || bdi.kind == kThemePushButtonSmall)
|
||||||
|
pdi.size = kThemeArrow7pt;
|
||||||
|
} else {
|
||||||
|
if (arrowRect.size.width < 8.)
|
||||||
|
pdi.size = kThemeArrow5pt;
|
||||||
|
else
|
||||||
|
pdi.size = kThemeArrow9pt;
|
||||||
|
}
|
||||||
HIThemeDrawPopupArrow(&arrowRect, &pdi, cg, kHIThemeOrientationNormal);
|
HIThemeDrawPopupArrow(&arrowRect, &pdi, cg, kHIThemeOrientationNormal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3621,8 +3667,12 @@ void QMacStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter
|
|||||||
QRect freeContentRect = btn->rect;
|
QRect freeContentRect = btn->rect;
|
||||||
QRect textRect = itemTextRect(
|
QRect textRect = itemTextRect(
|
||||||
btn->fontMetrics, freeContentRect, Qt::AlignCenter, btn->state & State_Enabled, btn->text);
|
btn->fontMetrics, freeContentRect, Qt::AlignCenter, btn->state & State_Enabled, btn->text);
|
||||||
if (hasMenu)
|
if (hasMenu) {
|
||||||
textRect.adjust(-1, 0, -1, 0);
|
if (QSysInfo::macVersion() > QSysInfo::MV_10_6)
|
||||||
|
textRect.moveTo(w ? 15 : 11, textRect.top()); // Supports Qt Quick Controls
|
||||||
|
else
|
||||||
|
textRect.adjust(-1, 0, -1, 0);
|
||||||
|
}
|
||||||
// Draw the icon:
|
// Draw the icon:
|
||||||
if (hasIcon) {
|
if (hasIcon) {
|
||||||
int contentW = textRect.width();
|
int contentW = textRect.width();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user