forked from qt-creator/qt-creator
Core: Icon-only option for the mode selection bar
This adds an icon-only mode to the mode selection bar (and action bar). A newly introduced Action can cycle between icon+text, icon-only and hidden. Also, the "Window" Application menu gets a submenu with the three styles. Task-number: QTCREATORBUG-18845 Change-Id: I4e0c453f6d920dfbfd795b8b054f6ff392a8700a Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -135,8 +135,6 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
|
||||
QPainter painter(this);
|
||||
|
||||
// draw borders
|
||||
const bool isTitledAction = defaultAction()->property("titledAction").toBool();
|
||||
|
||||
if (!HostOsInfo::isMacHost() // Mac UIs usually don't hover
|
||||
&& m_fader > 0 && isEnabled() && !isDown() && !isChecked()) {
|
||||
painter.save();
|
||||
@@ -177,8 +175,10 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
|
||||
? ((isDown() || isChecked()) ? QIcon::Active : QIcon::Normal)
|
||||
: QIcon::Disabled;
|
||||
QRect iconRect(0, 0, Constants::MODEBAR_ICON_SIZE, Constants::MODEBAR_ICON_SIZE);
|
||||
|
||||
const bool isTitledAction = defaultAction()->property("titledAction").toBool();
|
||||
// draw popup texts
|
||||
if (isTitledAction) {
|
||||
if (isTitledAction && !m_iconsOnly) {
|
||||
QFont normalFont(painter.font());
|
||||
QRect centerRect = rect();
|
||||
normalFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
||||
@@ -244,17 +244,19 @@ void FancyToolButton::paintEvent(QPaintEvent *event)
|
||||
painter.drawText(buildConfigRect[i], textFlags, buildConfigText);
|
||||
}
|
||||
|
||||
// pop up arrow next to icon
|
||||
if (isEnabled() && !icon().isNull()) {
|
||||
QStyleOption opt;
|
||||
opt.initFrom(this);
|
||||
opt.rect = rect().adjusted(rect().width() - 16, 0, -8, 0);
|
||||
StyleHelper::drawArrow(QStyle::PE_IndicatorArrowRight, &painter, &opt);
|
||||
}
|
||||
} else {
|
||||
iconRect.moveCenter(rect().center());
|
||||
StyleHelper::drawIconWithShadow(icon(), iconRect, &painter, iconMode);
|
||||
}
|
||||
|
||||
// pop up arrow next to icon
|
||||
if (isTitledAction && isEnabled() && !icon().isNull()) {
|
||||
QStyleOption opt;
|
||||
opt.initFrom(this);
|
||||
opt.rect = rect().adjusted(rect().width() -
|
||||
(m_iconsOnly ? 6 : 16), 0, -(m_iconsOnly ? 0 : 8), 0);
|
||||
StyleHelper::drawArrow(QStyle::PE_IndicatorArrowRight, &painter, &opt);
|
||||
}
|
||||
}
|
||||
|
||||
void FancyActionBar::paintEvent(QPaintEvent *event)
|
||||
@@ -278,6 +280,11 @@ void FancyActionBar::paintEvent(QPaintEvent *event)
|
||||
|
||||
QSize FancyToolButton::sizeHint() const
|
||||
{
|
||||
if (m_iconsOnly) {
|
||||
return {Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE,
|
||||
Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE};
|
||||
}
|
||||
|
||||
QSizeF buttonSize = iconSize().expandedTo(QSize(64, 38));
|
||||
if (defaultAction()->property("titledAction").toBool()) {
|
||||
QFont boldFont(font());
|
||||
@@ -300,6 +307,12 @@ QSize FancyToolButton::minimumSizeHint() const
|
||||
return {8, 8};
|
||||
}
|
||||
|
||||
void FancyToolButton::setIconsOnly(bool iconsOnly)
|
||||
{
|
||||
m_iconsOnly = iconsOnly;
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void FancyToolButton::hoverOverlay(QPainter *painter, const QRect &spanRect)
|
||||
{
|
||||
const QSize logicalSize = spanRect.size();
|
||||
@@ -346,23 +359,22 @@ FancyActionBar::FancyActionBar(QWidget *parent)
|
||||
{
|
||||
setObjectName("actionbar");
|
||||
m_actionsLayout = new QVBoxLayout;
|
||||
auto spacerLayout = new QVBoxLayout;
|
||||
spacerLayout->addLayout(m_actionsLayout);
|
||||
const int sbh = 8;
|
||||
spacerLayout->addSpacing(sbh);
|
||||
spacerLayout->setMargin(0);
|
||||
spacerLayout->setSpacing(0);
|
||||
setLayout(spacerLayout);
|
||||
setContentsMargins(0, 2, 0, 0);
|
||||
m_actionsLayout->setMargin(0);
|
||||
m_actionsLayout->setSpacing(0);
|
||||
setLayout(m_actionsLayout);
|
||||
setContentsMargins(0, 2, 0, 8);
|
||||
}
|
||||
|
||||
void FancyActionBar::addProjectSelector(QAction *action)
|
||||
{
|
||||
m_actionsLayout->insertWidget(0, new FancyToolButton(action, this));
|
||||
insertAction(0, action);
|
||||
}
|
||||
|
||||
void FancyActionBar::insertAction(int index, QAction *action)
|
||||
{
|
||||
m_actionsLayout->insertWidget(index, new FancyToolButton(action, this));
|
||||
auto *button = new FancyToolButton(action, this);
|
||||
button->setIconsOnly(m_iconsOnly);
|
||||
m_actionsLayout->insertWidget(index, button);
|
||||
}
|
||||
|
||||
QLayout *FancyActionBar::actionsLayout() const
|
||||
@@ -375,5 +387,15 @@ QSize FancyActionBar::minimumSizeHint() const
|
||||
return sizeHint();
|
||||
}
|
||||
|
||||
void FancyActionBar::setIconsOnly(bool iconsOnly)
|
||||
{
|
||||
m_iconsOnly = iconsOnly;
|
||||
for (int i = 0, c = m_actionsLayout->count(); i < c; ++i) {
|
||||
if (auto *button = qobject_cast<FancyToolButton*>(m_actionsLayout->itemAt(i)->widget()))
|
||||
button->setIconsOnly(iconsOnly);
|
||||
}
|
||||
setContentsMargins(0, iconsOnly ? 7 : 2, 0, iconsOnly ? 2 : 8);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Core
|
||||
|
||||
Reference in New Issue
Block a user