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:
@@ -50,6 +50,7 @@ const char M_TOOLS[] = "QtCreator.Menu.Tools";
|
||||
const char M_TOOLS_EXTERNAL[] = "QtCreator.Menu.Tools.External";
|
||||
const char M_WINDOW[] = "QtCreator.Menu.Window";
|
||||
const char M_WINDOW_PANES[] = "QtCreator.Menu.Window.Panes";
|
||||
const char M_WINDOW_MODESTYLES[] = "QtCreator.Menu.Window.ModeStyles";
|
||||
const char M_WINDOW_VIEWS[] = "QtCreator.Menu.Window.Views";
|
||||
const char M_HELP[] = "QtCreator.Menu.Help";
|
||||
|
||||
@@ -94,7 +95,8 @@ const char EXIT[] = "QtCreator.Exit";
|
||||
const char OPTIONS[] = "QtCreator.Options";
|
||||
const char TOGGLE_LEFT_SIDEBAR[] = "QtCreator.ToggleLeftSidebar";
|
||||
const char TOGGLE_RIGHT_SIDEBAR[] = "QtCreator.ToggleRightSidebar";
|
||||
const char TOGGLE_MODE_SELECTOR[] = "QtCreator.ToggleModeSelector";
|
||||
const char CYCLE_MODE_SELECTOR_STYLE[] =
|
||||
"QtCreator.CycleModeSelectorStyle";
|
||||
const char TOGGLE_FULLSCREEN[] = "QtCreator.ToggleFullScreen";
|
||||
const char THEMEOPTIONS[] = "QtCreator.ThemeOptions";
|
||||
|
||||
@@ -210,6 +212,7 @@ const char TR_CLEAR_MENU[] = QT_TRANSLATE_NOOP("Core", "Clear Menu");
|
||||
const char DEFAULT_BUILD_DIRECTORY[] = "../%{JS: Util.asciify(\"build-%{CurrentProject:Name}-%{CurrentKit:FileSystemName}-%{CurrentBuild:Name}\")}";
|
||||
|
||||
const int MODEBAR_ICON_SIZE = 34;
|
||||
const int MODEBAR_ICONSONLY_BUTTON_SIZE = MODEBAR_ICON_SIZE + 4;
|
||||
const int DEFAULT_MAX_LINE_COUNT = 100000;
|
||||
|
||||
} // namespace Constants
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -55,12 +55,15 @@ public:
|
||||
update();
|
||||
}
|
||||
|
||||
void setIconsOnly(bool iconsOnly);
|
||||
|
||||
static void hoverOverlay(QPainter *painter, const QRect &spanRect);
|
||||
|
||||
private:
|
||||
void actionChanged();
|
||||
|
||||
qreal m_fader = 0;
|
||||
bool m_iconsOnly = false;
|
||||
};
|
||||
|
||||
class FancyActionBar : public QWidget
|
||||
@@ -75,9 +78,11 @@ public:
|
||||
void addProjectSelector(QAction *action);
|
||||
QLayout *actionsLayout() const;
|
||||
QSize minimumSizeHint() const override;
|
||||
void setIconsOnly(bool iconsOnly);
|
||||
|
||||
private:
|
||||
QVBoxLayout *m_actionsLayout;
|
||||
bool m_iconsOnly = false;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -77,7 +77,6 @@ FancyTabBar::FancyTabBar(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
|
||||
setMinimumWidth(44);
|
||||
setAttribute(Qt::WA_Hover, true);
|
||||
setFocusPolicy(Qt::NoFocus);
|
||||
setMouseTracking(true); // Needed for hover events
|
||||
@@ -85,6 +84,11 @@ FancyTabBar::FancyTabBar(QWidget *parent)
|
||||
|
||||
QSize FancyTabBar::tabSizeHint(bool minimum) const
|
||||
{
|
||||
if (m_iconsOnly) {
|
||||
return {Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE,
|
||||
Core::Constants::MODEBAR_ICONSONLY_BUTTON_SIZE / (minimum ? 3 : 1)};
|
||||
}
|
||||
|
||||
QFont boldFont(font());
|
||||
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
||||
boldFont.setBold(true);
|
||||
@@ -271,6 +275,62 @@ static void paintSelectedTabBackground(QPainter *painter, const QRect &spanRect)
|
||||
painter->drawPixmap(spanRect.topLeft() + QPoint(0, -verticalOverlap), selection);
|
||||
}
|
||||
|
||||
static void paintIcon(QPainter *painter, const QRect &rect,
|
||||
const QIcon &icon,
|
||||
bool enabled, bool selected)
|
||||
{
|
||||
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
||||
: QIcon::Disabled;
|
||||
QRect iconRect(0, 0, Core::Constants::MODEBAR_ICON_SIZE, Core::Constants::MODEBAR_ICON_SIZE);
|
||||
iconRect.moveCenter(rect.center());
|
||||
iconRect = iconRect.intersected(rect);
|
||||
if (!enabled && !creatorTheme()->flag(Theme::FlatToolBars))
|
||||
painter->setOpacity(0.7);
|
||||
StyleHelper::drawIconWithShadow(icon, iconRect, painter, iconMode);
|
||||
}
|
||||
|
||||
static void paintIconAndText(QPainter *painter, const QRect &rect,
|
||||
const QIcon &icon, const QString &text,
|
||||
bool enabled, bool selected)
|
||||
{
|
||||
const bool drawIcon = rect.height() > 36;
|
||||
if (drawIcon) {
|
||||
const int textHeight =
|
||||
painter->fontMetrics().boundingRect(rect, Qt::TextWordWrap, text).height();
|
||||
const QRect tabIconRect(rect.adjusted(0, 4, 0, -textHeight));
|
||||
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
||||
: QIcon::Disabled;
|
||||
QRect iconRect(0, 0, Core::Constants::MODEBAR_ICON_SIZE, Core::Constants::MODEBAR_ICON_SIZE);
|
||||
iconRect.moveCenter(tabIconRect.center());
|
||||
iconRect = iconRect.intersected(tabIconRect);
|
||||
if (!enabled && !creatorTheme()->flag(Theme::FlatToolBars))
|
||||
painter->setOpacity(0.7);
|
||||
StyleHelper::drawIconWithShadow(icon, iconRect, painter, iconMode);
|
||||
}
|
||||
|
||||
painter->setOpacity(1.0); //FIXME: was 0.7 before?
|
||||
if (enabled) {
|
||||
painter->setPen(
|
||||
selected ? creatorTheme()->color(Theme::FancyTabWidgetEnabledSelectedTextColor)
|
||||
: creatorTheme()->color(Theme::FancyTabWidgetEnabledUnselectedTextColor));
|
||||
} else {
|
||||
painter->setPen(
|
||||
selected ? creatorTheme()->color(Theme::FancyTabWidgetDisabledSelectedTextColor)
|
||||
: creatorTheme()->color(Theme::FancyTabWidgetDisabledUnselectedTextColor));
|
||||
}
|
||||
|
||||
painter->translate(0, -1);
|
||||
QRect tabTextRect(rect);
|
||||
tabTextRect.translate(0, drawIcon ? -2 : 1);
|
||||
QFont boldFont(painter->font());
|
||||
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
||||
boldFont.setBold(true);
|
||||
painter->setFont(boldFont);
|
||||
const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter)
|
||||
| Qt::TextWordWrap;
|
||||
painter->drawText(tabTextRect, textFlags, text);
|
||||
}
|
||||
|
||||
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
{
|
||||
if (!validIndex(tabIndex)) {
|
||||
@@ -293,19 +353,6 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
}
|
||||
}
|
||||
|
||||
const QString tabText(tab->text);
|
||||
QRect tabTextRect(rect);
|
||||
const bool drawIcon = rect.height() > 36;
|
||||
QRect tabIconRect(tabTextRect);
|
||||
tabTextRect.translate(0, drawIcon ? -2 : 1);
|
||||
QFont boldFont(painter->font());
|
||||
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
|
||||
boldFont.setBold(true);
|
||||
painter->setFont(boldFont);
|
||||
painter->setPen(selected ? QColor(255, 255, 255, 160) : QColor(0, 0, 0, 110));
|
||||
const int textFlags = Qt::AlignCenter | (drawIcon ? Qt::AlignBottom : Qt::AlignVCenter)
|
||||
| Qt::TextWordWrap;
|
||||
|
||||
const qreal fader = tab->fader();
|
||||
if (fader > 0 && !HostOsInfo::isMacHost() && !selected && enabled) {
|
||||
painter->save();
|
||||
@@ -317,36 +364,10 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
if (!enabled && !creatorTheme()->flag(Theme::FlatToolBars))
|
||||
painter->setOpacity(0.7);
|
||||
|
||||
if (drawIcon) {
|
||||
const int textHeight = painter->fontMetrics()
|
||||
.boundingRect(QRect(0, 0, width(), height()),
|
||||
Qt::TextWordWrap,
|
||||
tabText)
|
||||
.height();
|
||||
tabIconRect.adjust(0, 4, 0, -textHeight);
|
||||
const QIcon::Mode iconMode = enabled ? (selected ? QIcon::Active : QIcon::Normal)
|
||||
: QIcon::Disabled;
|
||||
QRect iconRect(0, 0, Core::Constants::MODEBAR_ICON_SIZE, Core::Constants::MODEBAR_ICON_SIZE);
|
||||
iconRect.moveCenter(tabIconRect.center());
|
||||
iconRect = iconRect.intersected(tabIconRect);
|
||||
StyleHelper::drawIconWithShadow(tab->icon, iconRect, painter, iconMode);
|
||||
}
|
||||
|
||||
painter->setOpacity(1.0); //FIXME: was 0.7 before?
|
||||
if (enabled) {
|
||||
painter->setPen(
|
||||
selected ? creatorTheme()->color(Theme::FancyTabWidgetEnabledSelectedTextColor)
|
||||
: creatorTheme()->color(Theme::FancyTabWidgetEnabledUnselectedTextColor));
|
||||
} else {
|
||||
painter->setPen(
|
||||
selected ? creatorTheme()->color(Theme::FancyTabWidgetDisabledSelectedTextColor)
|
||||
: creatorTheme()->color(Theme::FancyTabWidgetDisabledUnselectedTextColor));
|
||||
}
|
||||
painter->translate(0, -1);
|
||||
painter->drawText(tabTextRect, textFlags, tabText);
|
||||
if (m_iconsOnly)
|
||||
paintIcon(painter, rect, tab->icon, enabled, selected);
|
||||
else
|
||||
paintIconAndText(painter, rect, tab->icon, tab->text, enabled, selected);
|
||||
|
||||
// menu arrow
|
||||
if (tab->hasMenu) {
|
||||
@@ -367,6 +388,12 @@ void FancyTabBar::setCurrentIndex(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void FancyTabBar::setIconsOnly(bool iconsOnly)
|
||||
{
|
||||
m_iconsOnly = iconsOnly;
|
||||
updateGeometry();
|
||||
}
|
||||
|
||||
void FancyTabBar::setTabEnabled(int index, bool enable)
|
||||
{
|
||||
Q_ASSERT(index < m_tabs.size());
|
||||
@@ -589,4 +616,9 @@ bool FancyTabWidget::isTabEnabled(int index) const
|
||||
return m_tabBar->isTabEnabled(index);
|
||||
}
|
||||
|
||||
void FancyTabWidget::setIconsOnly(bool iconsOnly)
|
||||
{
|
||||
m_tabBar->setIconsOnly(iconsOnly);
|
||||
}
|
||||
|
||||
#include "fancytabwidget.moc"
|
||||
|
||||
@@ -119,6 +119,8 @@ public:
|
||||
void setTabToolTip(int index, const QString &toolTip) { m_tabs[index]->toolTip = toolTip; }
|
||||
QString tabToolTip(int index) const { return m_tabs.at(index)->toolTip; }
|
||||
|
||||
void setIconsOnly(bool iconOnly);
|
||||
|
||||
int count() const { return m_tabs.count(); }
|
||||
QRect tabRect(int index) const;
|
||||
|
||||
@@ -130,6 +132,7 @@ private:
|
||||
QRect m_hoverRect;
|
||||
int m_hoverIndex = -1;
|
||||
int m_currentIndex = -1;
|
||||
bool m_iconsOnly = false;
|
||||
QList<FancyTab *> m_tabs;
|
||||
QSize tabSizeHint(bool minimum = false) const;
|
||||
};
|
||||
@@ -157,6 +160,8 @@ public:
|
||||
void setTabEnabled(int index, bool enable);
|
||||
bool isTabEnabled(int index) const;
|
||||
|
||||
void setIconsOnly(bool iconsOnly);
|
||||
|
||||
bool isSelectionWidgetVisible() const;
|
||||
|
||||
signals:
|
||||
|
||||
@@ -708,13 +708,7 @@ void MainWindow::registerDefaultActions()
|
||||
mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
|
||||
m_toggleRightSideBarButton->setEnabled(false);
|
||||
|
||||
// Show Mode Selector Action
|
||||
m_toggleModeSelectorAction = new QAction(tr("Show Mode Selector"), this);
|
||||
m_toggleModeSelectorAction->setCheckable(true);
|
||||
cmd = ActionManager::registerAction(m_toggleModeSelectorAction, Constants::TOGGLE_MODE_SELECTOR);
|
||||
connect(m_toggleModeSelectorAction, &QAction::triggered,
|
||||
ModeManager::instance(), &ModeManager::setModeSelectorVisible);
|
||||
mwindow->addAction(cmd, Constants::G_WINDOW_VIEWS);
|
||||
registerModeSelectorStyleActions();
|
||||
|
||||
// Window->Views
|
||||
ActionContainer *mviews = ActionManager::createMenu(Constants::M_WINDOW_VIEWS);
|
||||
@@ -760,6 +754,42 @@ void MainWindow::registerDefaultActions()
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::registerModeSelectorStyleActions()
|
||||
{
|
||||
ActionContainer *mwindow = ActionManager::actionContainer(Constants::M_WINDOW);
|
||||
|
||||
// Cycle Mode Selector Styles
|
||||
m_cycleModeSelectorStyleAction = new QAction(tr("Cycle Mode Selector Styles"), this);
|
||||
ActionManager::registerAction(m_cycleModeSelectorStyleAction, Constants::CYCLE_MODE_SELECTOR_STYLE);
|
||||
connect(m_cycleModeSelectorStyleAction, &QAction::triggered, this, [this] {
|
||||
ModeManager::cycleModeStyle();
|
||||
updateModeSelectorStyleMenu();
|
||||
});
|
||||
|
||||
// Mode Selector Styles
|
||||
ActionContainer *mmodeLayouts = ActionManager::createMenu(Constants::M_WINDOW_MODESTYLES);
|
||||
mwindow->addMenu(mmodeLayouts, Constants::G_WINDOW_VIEWS);
|
||||
QMenu *styleMenu = mmodeLayouts->menu();
|
||||
styleMenu->setTitle(tr("Mode Selector Style"));
|
||||
auto *stylesGroup = new QActionGroup(styleMenu);
|
||||
stylesGroup->setExclusive(true);
|
||||
|
||||
m_setModeSelectorStyleIconsAndTextAction = stylesGroup->addAction(tr("Icons and Text"));
|
||||
connect(m_setModeSelectorStyleIconsAndTextAction, &QAction::triggered,
|
||||
[] { ModeManager::setModeStyle(ModeManager::Style::IconsAndText); });
|
||||
m_setModeSelectorStyleIconsAndTextAction->setCheckable(true);
|
||||
m_setModeSelectorStyleIconsOnlyAction = stylesGroup->addAction(tr("Icons Only"));
|
||||
connect(m_setModeSelectorStyleIconsOnlyAction, &QAction::triggered,
|
||||
[] { ModeManager::setModeStyle(ModeManager::Style::IconsOnly); });
|
||||
m_setModeSelectorStyleIconsOnlyAction->setCheckable(true);
|
||||
m_setModeSelectorStyleHiddenAction = stylesGroup->addAction(tr("Hidden"));
|
||||
connect(m_setModeSelectorStyleHiddenAction, &QAction::triggered,
|
||||
[] { ModeManager::setModeStyle(ModeManager::Style::Hidden); });
|
||||
m_setModeSelectorStyleHiddenAction->setCheckable(true);
|
||||
|
||||
styleMenu->addActions(stylesGroup->actions());
|
||||
}
|
||||
|
||||
void MainWindow::openFile()
|
||||
{
|
||||
openFiles(EditorManager::getOpenFileNames(), ICore::SwitchMode);
|
||||
@@ -941,7 +971,7 @@ static const char settingsGroup[] = "MainWindow";
|
||||
static const char colorKey[] = "Color";
|
||||
static const char windowGeometryKey[] = "WindowGeometry";
|
||||
static const char windowStateKey[] = "WindowState";
|
||||
static const char modeSelectorVisibleKey[] = "ModeSelectorVisible";
|
||||
static const char modeSelectorLayoutKey[] = "ModeSelectorLayout";
|
||||
|
||||
void MainWindow::readSettings()
|
||||
{
|
||||
@@ -957,9 +987,20 @@ void MainWindow::readSettings()
|
||||
QColor(StyleHelper::DEFAULT_BASE_COLOR)).value<QColor>());
|
||||
}
|
||||
|
||||
bool modeSelectorVisible = settings->value(QLatin1String(modeSelectorVisibleKey), true).toBool();
|
||||
ModeManager::setModeSelectorVisible(modeSelectorVisible);
|
||||
m_toggleModeSelectorAction->setChecked(modeSelectorVisible);
|
||||
{
|
||||
ModeManager::Style modeStyle =
|
||||
ModeManager::Style(settings->value(modeSelectorLayoutKey, int(ModeManager::Style::IconsAndText)).toInt());
|
||||
|
||||
// Migrate legacy setting from Qt Creator 4.6 and earlier
|
||||
static const char modeSelectorVisibleKey[] = "ModeSelectorVisible";
|
||||
if (!settings->contains(modeSelectorLayoutKey) && settings->contains(modeSelectorVisibleKey)) {
|
||||
bool visible = settings->value(modeSelectorVisibleKey, true).toBool();
|
||||
modeStyle = visible ? ModeManager::Style::IconsAndText : ModeManager::Style::Hidden;
|
||||
}
|
||||
|
||||
ModeManager::setModeStyle(modeStyle);
|
||||
updateModeSelectorStyleMenu();
|
||||
}
|
||||
|
||||
settings->endGroup();
|
||||
|
||||
@@ -999,11 +1040,26 @@ void MainWindow::saveWindowSettings()
|
||||
setWindowState(windowState() & ~Qt::WindowFullScreen);
|
||||
settings->setValue(QLatin1String(windowGeometryKey), saveGeometry());
|
||||
settings->setValue(QLatin1String(windowStateKey), saveState());
|
||||
settings->setValue(QLatin1String(modeSelectorVisibleKey), ModeManager::isModeSelectorVisible());
|
||||
settings->setValue(modeSelectorLayoutKey, int(ModeManager::modeStyle()));
|
||||
|
||||
settings->endGroup();
|
||||
}
|
||||
|
||||
void MainWindow::updateModeSelectorStyleMenu()
|
||||
{
|
||||
switch (ModeManager::modeStyle()) {
|
||||
case ModeManager::Style::IconsAndText:
|
||||
m_setModeSelectorStyleIconsAndTextAction->setChecked(true);
|
||||
break;
|
||||
case ModeManager::Style::IconsOnly:
|
||||
m_setModeSelectorStyleIconsOnlyAction->setChecked(true);
|
||||
break;
|
||||
case ModeManager::Style::Hidden:
|
||||
m_setModeSelectorStyleHiddenAction->setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateAdditionalContexts(const Context &remove, const Context &add,
|
||||
ICore::ContextPriority priority)
|
||||
{
|
||||
|
||||
@@ -133,10 +133,13 @@ private:
|
||||
|
||||
void registerDefaultContainers();
|
||||
void registerDefaultActions();
|
||||
void registerModeSelectorStyleActions();
|
||||
|
||||
void readSettings();
|
||||
void saveWindowSettings();
|
||||
|
||||
void updateModeSelectorStyleMenu();
|
||||
|
||||
ICore *m_coreImpl = nullptr;
|
||||
QStringList m_aboutInformation;
|
||||
Context m_highPrioAdditionalContexts;
|
||||
@@ -179,7 +182,10 @@ private:
|
||||
QAction *m_optionsAction = nullptr;
|
||||
QAction *m_toggleLeftSideBarAction = nullptr;
|
||||
QAction *m_toggleRightSideBarAction = nullptr;
|
||||
QAction *m_toggleModeSelectorAction = nullptr;
|
||||
QAction *m_cycleModeSelectorStyleAction = nullptr;
|
||||
QAction *m_setModeSelectorStyleIconsAndTextAction = nullptr;
|
||||
QAction *m_setModeSelectorStyleHiddenAction = nullptr;
|
||||
QAction *m_setModeSelectorStyleIconsOnlyAction = nullptr;
|
||||
QAction *m_themeAction = nullptr;
|
||||
|
||||
QToolButton *m_toggleLeftSideBarButton = nullptr;
|
||||
|
||||
@@ -73,7 +73,7 @@ struct ModeManagerPrivate
|
||||
QVector<Command*> m_modeCommands;
|
||||
Context m_addedContexts;
|
||||
int m_oldCurrent;
|
||||
bool m_modeSelectorVisible;
|
||||
ModeManager::Style m_modeStyle = ModeManager::Style::IconsAndText;
|
||||
|
||||
bool m_startingUp = true;
|
||||
Id m_pendingFirstActiveMode; // Valid before extentionsInitialized.
|
||||
@@ -108,8 +108,7 @@ ModeManager::ModeManager(Internal::MainWindow *mainWindow,
|
||||
d->m_oldCurrent = -1;
|
||||
d->m_actionBar = new Internal::FancyActionBar(modeStack);
|
||||
d->m_modeStack->addCornerWidget(d->m_actionBar);
|
||||
d->m_modeSelectorVisible = true;
|
||||
d->m_modeStack->setSelectionWidgetVisible(d->m_modeSelectorVisible);
|
||||
setModeStyle(d->m_modeStyle);
|
||||
|
||||
connect(d->m_modeStack, &Internal::FancyTabWidget::currentAboutToShow,
|
||||
this, &ModeManager::currentTabAboutToChange);
|
||||
@@ -310,15 +309,26 @@ void ModeManager::setFocusToCurrentMode()
|
||||
}
|
||||
}
|
||||
|
||||
void ModeManager::setModeSelectorVisible(bool visible)
|
||||
void ModeManager::setModeStyle(ModeManager::Style style)
|
||||
{
|
||||
d->m_modeSelectorVisible = visible;
|
||||
const bool visible = style != Style::Hidden;
|
||||
const bool iconsOnly = style == Style::IconsOnly;
|
||||
|
||||
d->m_modeStyle = style;
|
||||
d->m_actionBar->setIconsOnly(iconsOnly);
|
||||
d->m_modeStack->setIconsOnly(iconsOnly);
|
||||
d->m_modeStack->setSelectionWidgetVisible(visible);
|
||||
}
|
||||
|
||||
bool ModeManager::isModeSelectorVisible()
|
||||
void ModeManager::cycleModeStyle()
|
||||
{
|
||||
return d->m_modeSelectorVisible;
|
||||
auto nextStyle = Style((int(modeStyle()) + 1) % 3);
|
||||
setModeStyle(nextStyle);
|
||||
}
|
||||
|
||||
ModeManager::Style ModeManager::modeStyle()
|
||||
{
|
||||
return d->m_modeStyle;
|
||||
}
|
||||
|
||||
ModeManager *ModeManager::instance()
|
||||
|
||||
@@ -46,6 +46,12 @@ class CORE_EXPORT ModeManager : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum class Style {
|
||||
IconsAndText,
|
||||
IconsOnly,
|
||||
Hidden
|
||||
};
|
||||
|
||||
static ModeManager *instance();
|
||||
|
||||
static Id currentMode();
|
||||
@@ -55,10 +61,11 @@ public:
|
||||
|
||||
static void activateMode(Id id);
|
||||
static void setFocusToCurrentMode();
|
||||
static bool isModeSelectorVisible();
|
||||
static enum Style modeStyle();
|
||||
|
||||
public slots:
|
||||
static void setModeSelectorVisible(bool visible);
|
||||
static void setModeStyle(enum Style layout);
|
||||
static void cycleModeStyle();
|
||||
|
||||
signals:
|
||||
void currentModeAboutToChange(Core::Id mode);
|
||||
|
||||
Reference in New Issue
Block a user