forked from qt-creator/qt-creator
Add option to hide individual modes
With e.g. the Extensions mode we add a mode that is probably not interesting most of the times for most people. The only way to get rid of modes currently is to disable the plugin that provides it. Instead add the option to hide modes via the View > Modes menu. Modes reappear if they are switched to (either via the short cut or other means, like Debug mode when starting the debugger, or edit mode when pressing escape often enough). Change-Id: I56e20849a1f810aea9b5993b04892c915278845f Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -91,25 +91,37 @@ void FancyTabBar::paintEvent(QPaintEvent *event)
|
||||
p.fillRect(event->rect(), StyleHelper::baseColor());
|
||||
}
|
||||
|
||||
for (int i = 0; i < count(); ++i)
|
||||
int visibleIndex = 0;
|
||||
int visibleCurrentIndex = -1;
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
if (!m_tabs.at(i)->visible)
|
||||
continue;
|
||||
if (i != currentIndex())
|
||||
paintTab(&p, i);
|
||||
paintTab(&p, i, visibleIndex);
|
||||
else
|
||||
visibleCurrentIndex = visibleIndex;
|
||||
++visibleIndex;
|
||||
}
|
||||
|
||||
// paint active tab last, since it overlaps the neighbors
|
||||
if (currentIndex() != -1)
|
||||
paintTab(&p, currentIndex());
|
||||
paintTab(&p, currentIndex(), visibleCurrentIndex);
|
||||
}
|
||||
|
||||
// Handle hover events for mouse fade ins
|
||||
void FancyTabBar::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
int newHover = -1;
|
||||
int visibleIndex = 0;
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
const QRect area = tabRect(i);
|
||||
if (!m_tabs.at(i)->visible)
|
||||
continue;
|
||||
const QRect area = tabRect(visibleIndex);
|
||||
if (area.contains(event->pos())) {
|
||||
newHover = i;
|
||||
break;
|
||||
}
|
||||
++visibleIndex;
|
||||
}
|
||||
if (newHover == m_hoverIndex)
|
||||
return;
|
||||
@@ -121,7 +133,7 @@ void FancyTabBar::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
if (validIndex(m_hoverIndex)) {
|
||||
m_tabs[m_hoverIndex]->fadeIn();
|
||||
m_hoverRect = tabRect(m_hoverIndex);
|
||||
m_hoverRect = tabRect(visibleIndex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,21 +181,36 @@ QSize FancyTabBar::minimumSizeHint() const
|
||||
return {sh.width(), sh.height() * int(m_tabs.count())};
|
||||
}
|
||||
|
||||
QRect FancyTabBar::tabRect(int index) const
|
||||
QRect FancyTabBar::tabRect(int visibleIndex) const
|
||||
{
|
||||
QSize sh = tabSizeHint();
|
||||
|
||||
if (sh.height() * m_tabs.count() > height())
|
||||
sh.setHeight(height() / m_tabs.count());
|
||||
|
||||
return {0, index * sh.height(), sh.width(), sh.height()};
|
||||
return {0, visibleIndex * sh.height(), sh.width(), sh.height()};
|
||||
}
|
||||
|
||||
int FancyTabBar::visibleIndex(int index) const
|
||||
{
|
||||
int vIndex = 0;
|
||||
for (int i = 0; i < m_tabs.size(); ++i) {
|
||||
if (i == index)
|
||||
return vIndex;
|
||||
if (m_tabs.at(i)->visible)
|
||||
++vIndex;
|
||||
}
|
||||
return vIndex;
|
||||
}
|
||||
|
||||
void FancyTabBar::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
int visibleIndex = 0;
|
||||
for (int index = 0; index < m_tabs.count(); ++index) {
|
||||
const QRect rect = tabRect(index);
|
||||
if (!m_tabs.at(index)->visible)
|
||||
continue;
|
||||
const QRect rect = tabRect(visibleIndex);
|
||||
if (rect.contains(event->pos())) {
|
||||
if (isTabEnabled(index)) {
|
||||
if (m_tabs.at(index)->hasMenu
|
||||
@@ -202,6 +229,7 @@ void FancyTabBar::mousePressEvent(QMouseEvent *event)
|
||||
}
|
||||
break;
|
||||
}
|
||||
++visibleIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +350,7 @@ static void paintIconAndText(QPainter *painter, const QRect &rect,
|
||||
painter->drawText(tabTextRect, textFlags, text);
|
||||
}
|
||||
|
||||
void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
void FancyTabBar::paintTab(QPainter *painter, int tabIndex, int visibleIndex) const
|
||||
{
|
||||
if (!validIndex(tabIndex)) {
|
||||
qWarning("invalid index");
|
||||
@@ -331,7 +359,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
painter->save();
|
||||
|
||||
const FancyTab *tab = m_tabs.at(tabIndex);
|
||||
const QRect rect = tabRect(tabIndex);
|
||||
const QRect rect = tabRect(visibleIndex);
|
||||
const bool selected = (tabIndex == m_currentIndex);
|
||||
const bool enabled = isTabEnabled(tabIndex);
|
||||
|
||||
@@ -372,7 +400,7 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
||||
|
||||
void FancyTabBar::setCurrentIndex(int index)
|
||||
{
|
||||
if (isTabEnabled(index) && index != m_currentIndex) {
|
||||
if ((index == -1 || isTabEnabled(index)) && index != m_currentIndex) {
|
||||
emit currentAboutToChange(index);
|
||||
m_currentIndex = index;
|
||||
update();
|
||||
@@ -393,7 +421,8 @@ void FancyTabBar::setTabEnabled(int index, bool enable)
|
||||
|
||||
if (index < m_tabs.size() && index >= 0) {
|
||||
m_tabs[index]->enabled = enable;
|
||||
update(tabRect(index));
|
||||
if (m_tabs[index]->visible)
|
||||
update(tabRect(visibleIndex(index)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,6 +437,15 @@ bool FancyTabBar::isTabEnabled(int index) const
|
||||
return false;
|
||||
}
|
||||
|
||||
void FancyTabBar::setTabVisible(int index, bool visible)
|
||||
{
|
||||
QTC_ASSERT(index < m_tabs.size(), return);
|
||||
QTC_ASSERT(index >= 0, return);
|
||||
|
||||
m_tabs[index]->visible = visible;
|
||||
update();
|
||||
}
|
||||
|
||||
class FancyColorButton : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -455,6 +493,7 @@ FancyTabWidget::FancyTabWidget(QWidget *parent)
|
||||
connect(fancyButton, &FancyColorButton::clicked, this, &FancyTabWidget::topAreaClicked);
|
||||
|
||||
m_modesStack = new QStackedLayout;
|
||||
m_modesStack->addWidget(new QWidget(this));
|
||||
m_statusBar = new QStatusBar;
|
||||
m_statusBar->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
|
||||
|
||||
@@ -505,13 +544,13 @@ bool FancyTabWidget::isSelectionWidgetVisible() const
|
||||
|
||||
void FancyTabWidget::insertTab(int index, QWidget *tab, const QIcon &icon, const QString &label, bool hasMenu)
|
||||
{
|
||||
m_modesStack->insertWidget(index, tab);
|
||||
m_modesStack->insertWidget(index + 1, tab);
|
||||
m_tabBar->insertTab(index, icon, label, hasMenu);
|
||||
}
|
||||
|
||||
void FancyTabWidget::removeTab(int index)
|
||||
{
|
||||
m_modesStack->removeWidget(m_modesStack->widget(index));
|
||||
m_modesStack->removeWidget(m_modesStack->widget(index + 1));
|
||||
m_tabBar->removeTab(index);
|
||||
}
|
||||
|
||||
@@ -589,7 +628,7 @@ void FancyTabWidget::setCurrentIndex(int index)
|
||||
|
||||
void FancyTabWidget::showWidget(int index)
|
||||
{
|
||||
m_modesStack->setCurrentIndex(index);
|
||||
m_modesStack->setCurrentIndex(index + 1);
|
||||
QWidget *w = m_modesStack->currentWidget();
|
||||
if (QTC_GUARD(w)) {
|
||||
if (QWidget *focusWidget = w->focusWidget())
|
||||
@@ -614,6 +653,11 @@ bool FancyTabWidget::isTabEnabled(int index) const
|
||||
return m_tabBar->isTabEnabled(index);
|
||||
}
|
||||
|
||||
void FancyTabWidget::setTabVisible(int index, bool visible)
|
||||
{
|
||||
m_tabBar->setTabVisible(index, visible);
|
||||
}
|
||||
|
||||
void FancyTabWidget::setIconsOnly(bool iconsOnly)
|
||||
{
|
||||
m_tabBar->setIconsOnly(iconsOnly);
|
||||
|
||||
Reference in New Issue
Block a user