forked from qt-creator/qt-creator
Improve responsiveness of the sidebar
I added a zerotimer to make the sidebar emit currentChanged only after it has been updated as pressed.
This commit is contained in:
@@ -82,6 +82,10 @@ FancyTabBar::FancyTabBar(QWidget *parent)
|
|||||||
setAttribute(Qt::WA_Hover, true);
|
setAttribute(Qt::WA_Hover, true);
|
||||||
setFocusPolicy(Qt::NoFocus);
|
setFocusPolicy(Qt::NoFocus);
|
||||||
setMouseTracking(true); // Needed for hover events
|
setMouseTracking(true); // Needed for hover events
|
||||||
|
m_triggerTimer.setSingleShot(true);
|
||||||
|
|
||||||
|
// We use a zerotimer to keep the sidebar responsive
|
||||||
|
connect(&m_triggerTimer, SIGNAL(timeout()), this, SLOT(emitCurrentIndex()));
|
||||||
}
|
}
|
||||||
|
|
||||||
FancyTabBar::~FancyTabBar()
|
FancyTabBar::~FancyTabBar()
|
||||||
@@ -136,7 +140,6 @@ void FancyTabBar::mouseMoveEvent(QMouseEvent *e)
|
|||||||
|
|
||||||
if (validIndex(m_hoverIndex)) {
|
if (validIndex(m_hoverIndex)) {
|
||||||
m_tabs[m_hoverIndex]->fadeIn();
|
m_tabs[m_hoverIndex]->fadeIn();
|
||||||
QRect oldHoverRect = m_hoverRect;
|
|
||||||
m_hoverRect = tabRect(m_hoverIndex);
|
m_hoverRect = tabRect(m_hoverIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,6 +210,14 @@ QRect FancyTabBar::tabRect(int index) const
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This keeps the sidebar responsive since
|
||||||
|
// we get a repaint before loading the
|
||||||
|
// mode itself
|
||||||
|
void FancyTabBar::emitCurrentIndex()
|
||||||
|
{
|
||||||
|
emit currentChanged(m_currentIndex);
|
||||||
|
}
|
||||||
|
|
||||||
void FancyTabBar::mousePressEvent(QMouseEvent *e)
|
void FancyTabBar::mousePressEvent(QMouseEvent *e)
|
||||||
{
|
{
|
||||||
e->accept();
|
e->accept();
|
||||||
@@ -269,13 +280,19 @@ void FancyTabBar::paintTab(QPainter *painter, int tabIndex) const
|
|||||||
painter->save();
|
painter->save();
|
||||||
QColor whiteOverlay(Qt::white);
|
QColor whiteOverlay(Qt::white);
|
||||||
whiteOverlay.setAlpha(int(m_tabs[tabIndex]->fader()/2));
|
whiteOverlay.setAlpha(int(m_tabs[tabIndex]->fader()/2));
|
||||||
QRect roundRect = rect.adjusted(5, 3, -5, -3);
|
painter->fillRect(rect, whiteOverlay);
|
||||||
|
painter->setPen(whiteOverlay);
|
||||||
|
painter->drawLine(rect.topLeft(), rect.topRight());
|
||||||
|
painter->drawLine(rect.bottomLeft(), rect.bottomRight());
|
||||||
|
|
||||||
|
/* QRect roundRect = rect.adjusted(5, 3, -5, -3);
|
||||||
painter->translate(0.5, 0.5);
|
painter->translate(0.5, 0.5);
|
||||||
painter->setRenderHint(QPainter::Antialiasing);
|
painter->setRenderHint(QPainter::Antialiasing);
|
||||||
painter->setBrush(whiteOverlay);
|
painter->setBrush(whiteOverlay);
|
||||||
whiteOverlay.setAlpha(int(m_tabs[tabIndex]->fader()));
|
whiteOverlay.setAlpha(int(m_tabs[tabIndex]->fader()));
|
||||||
painter->setPen(whiteOverlay);
|
painter->setPen(whiteOverlay);
|
||||||
painter->drawRoundedRect(roundRect, 3, 3);
|
painter->drawRoundedRect(roundRect, 3, 3);
|
||||||
|
*/
|
||||||
painter->restore();
|
painter->restore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -312,7 +329,7 @@ void FancyTabBar::setCurrentIndex(int index) {
|
|||||||
if (isTabEnabled(index)) {
|
if (isTabEnabled(index)) {
|
||||||
m_currentIndex = index;
|
m_currentIndex = index;
|
||||||
update();
|
update();
|
||||||
emit currentChanged(index);
|
m_triggerTimer.start(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include <QtGui/QTabBar>
|
#include <QtGui/QTabBar>
|
||||||
#include <QtGui/QStyleOptionTabV2>
|
#include <QtGui/QStyleOptionTabV2>
|
||||||
#include <QtCore/QTimeLine>
|
#include <QtCore/QTimeLine>
|
||||||
|
#include <QtCore/QTimer>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QPainter;
|
class QPainter;
|
||||||
@@ -116,6 +117,7 @@ signals:
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void updateHover();
|
void updateHover();
|
||||||
|
void emitCurrentIndex();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int m_rounding;
|
static const int m_rounding;
|
||||||
@@ -124,7 +126,7 @@ private:
|
|||||||
int m_hoverIndex;
|
int m_hoverIndex;
|
||||||
int m_currentIndex;
|
int m_currentIndex;
|
||||||
QList<FancyTab*> m_tabs;
|
QList<FancyTab*> m_tabs;
|
||||||
|
QTimer m_triggerTimer;
|
||||||
QSize tabSizeHint(bool minimum = false) const;
|
QSize tabSizeHint(bool minimum = false) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/**************************************************************************
|
**************************************************************************
|
||||||
**
|
**
|
||||||
** This file is part of Qt Creator
|
** This file is part of Qt Creator
|
||||||
**
|
**
|
||||||
|
|||||||
Reference in New Issue
Block a user