Commit 156c9629 authored by Arjen Hiemstra's avatar Arjen Hiemstra

Fix toolbuttons with menus using newer Breeze

Now that Breeze has a toolbutton-with-instant-menu style, clean up the
things needed for Kirigami to use it. This involves removing some extra
spacing, making sure we do not set AutoRaise for non-flat buttons and
exposing the menu property as an actual property on the background. The
last one is done because setting a property on the properties map breaks
all bindings.
parent 818d158a
......@@ -42,14 +42,23 @@ T.ToolButton {
on: controlRoot.pressed || (controlRoot.checkable && controlRoot.checked)
hover: controlRoot.hovered
text: controlRoot.Kirigami.MnemonicData.mnemonicLabel
hasFocus: false
hasFocus: !controlRoot.flat && (controlRoot.pressed || controlRoot.hovered)
activeControl: controlRoot.isDefault ? "default" : "f"
raised: !controlRoot.flat
// Set this to true to have the style render a menu arrow for the
// ToolButton.
// Note: If you use this, ensure you check whether your background item
// has this property at all, otherwise things will break with different
// QtQuick styles!
property bool showMenuArrow: false
properties: {
"icon": controlRoot.icon ? (controlRoot.icon.name || controlRoot.icon.source) : "",
"iconColor": controlRoot.icon && controlRoot.icon.color.a > 0? controlRoot.icon.color : Kirigami.Theme.textColor,
"iconWidth": controlRoot.icon ? controlRoot.icon.width : 0,
"iconHeight": controlRoot.icon ? controlRoot.icon.height : 0,
"menu": showMenuArrow,
"toolButtonStyle": controlRoot.display == T.ToolButton.IconOnly
? Qt.ToolButtonIconOnly :
controlRoot.display == T.ToolButton.TextOnly
......
......@@ -296,7 +296,7 @@ void KQuickStyleItem::initStyleOption()
qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption);
opt->subControls = QStyle::SC_ToolButton;
if (!m_raised || m_on) {
if (!m_raised) {
opt->state |= QStyle::State_AutoRaise;
}
......@@ -321,7 +321,7 @@ void KQuickStyleItem::initStyleOption()
opt->iconSize = iconSize;
if (m_properties.value(QStringLiteral("menu")).toBool()) {
opt->features = QStyleOptionToolButton::Menu;
opt->features |= QStyleOptionToolButton::HasMenu;
}
const int toolButtonStyle = m_properties.value(QStringLiteral("toolButtonStyle")).toInt();
......@@ -703,10 +703,13 @@ void KQuickStyleItem::initStyleOption()
} else {
m_styleoption->palette.setCurrentColorGroup(QPalette::Disabled);
}
if (m_active)
if (m_active) {
m_styleoption->state |= QStyle::State_Active;
else
} else {
m_styleoption->palette.setCurrentColorGroup(QPalette::Inactive);
}
if (m_sunken)
m_styleoption->state |= QStyle::State_Sunken;
if (m_raised)
......@@ -968,9 +971,6 @@ QSize KQuickStyleItem::sizeFromContents(int width, int height)
h = textSize.height();
}
}
if (btn->features & QStyleOptionToolButton::Menu) {
w += KQuickStyleItem::style()->subControlRect(QStyle::CC_ToolButton, btn, QStyle::SC_ToolButtonMenu).width();
}
btn->rect.setSize(QSize(w, h));
size = KQuickStyleItem::style()->sizeFromContents(QStyle::CT_ToolButton, m_styleoption, QSize(w, h)); }
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment