1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-21 17:52:10 +02:00

ComboTabBar: Fixes in drawing tabs with drag offset

m_dragInProgress is now only true when dragging tab, not during
the tab sliding to target position animation.
This commit is contained in:
David Rosca 2018-01-08 12:22:49 +01:00
parent 6a48f4d862
commit 4e988ac8f2
2 changed files with 13 additions and 22 deletions

View File

@ -985,7 +985,6 @@ TabBarHelper::TabBarHelper(bool isPinnedTabBar, ComboTabBar* comboTabBar)
, m_comboTabBar(comboTabBar) , m_comboTabBar(comboTabBar)
, m_scrollArea(0) , m_scrollArea(0)
, m_pressedIndex(-1) , m_pressedIndex(-1)
, m_pressedGlobalX(-1)
, m_dragInProgress(false) , m_dragInProgress(false)
, m_activeTabBar(false) , m_activeTabBar(false)
, m_isPinnedTabBar(isPinnedTabBar) , m_isPinnedTabBar(isPinnedTabBar)
@ -1202,6 +1201,9 @@ void TabBarHelper::paintEvent(QPaintEvent *event)
if (m_dragInProgress) { if (m_dragInProgress) {
// Still needs to be called because it updates movingTab geometry // Still needs to be called because it updates movingTab geometry
QTabBar::paintEvent(event); QTabBar::paintEvent(event);
QPainter p(this);
p.fillRect(rect(), palette().color(QPalette::Background));
} }
// Hack to get dragOffset from QTabBar internals // Hack to get dragOffset from QTabBar internals
@ -1233,7 +1235,7 @@ void TabBarHelper::paintEvent(QPaintEvent *event)
optTabBase.selectedTabRect = tabRect(selected); optTabBase.selectedTabRect = tabRect(selected);
} }
if (!m_dragInProgress && drawBase()) { if (drawBase()) {
p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase); p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase);
} }
@ -1281,6 +1283,11 @@ void TabBarHelper::paintEvent(QPaintEvent *event)
QStyleOptionTab tab; QStyleOptionTab tab;
initStyleOption(&tab, selected); initStyleOption(&tab, selected);
const int tabDragOffset = dragOffset(&tab, selected);
if (tabDragOffset != 0) {
tab.rect.moveLeft(tab.rect.x() + tabDragOffset);
}
// Update mouseover state when scrolling // Update mouseover state when scrolling
if (selected == indexUnderMouse) { if (selected == indexUnderMouse) {
tab.state |= QStyle::State_MouseOver; tab.state |= QStyle::State_MouseOver;
@ -1337,7 +1344,6 @@ void TabBarHelper::mousePressEvent(QMouseEvent* event)
if (event->buttons() == Qt::LeftButton) { if (event->buttons() == Qt::LeftButton) {
m_pressedIndex = tabAt(event->pos()); m_pressedIndex = tabAt(event->pos());
if (m_pressedIndex != -1) { if (m_pressedIndex != -1) {
m_pressedGlobalX = event->globalX();
m_dragInProgress = true; m_dragInProgress = true;
// virtualize selecting tab by click // virtualize selecting tab by click
if (m_pressedIndex == currentIndex() && !m_activeTabBar) { if (m_pressedIndex == currentIndex() && !m_activeTabBar) {
@ -1352,18 +1358,13 @@ void TabBarHelper::mousePressEvent(QMouseEvent* event)
void TabBarHelper::mouseReleaseEvent(QMouseEvent* event) void TabBarHelper::mouseReleaseEvent(QMouseEvent* event)
{ {
event->ignore(); event->ignore();
if (event->button() != Qt::LeftButton) {
return; m_pressedIndex = -1;
} m_dragInProgress = false;
QTabBar::mouseReleaseEvent(event); QTabBar::mouseReleaseEvent(event);
if (m_pressedIndex >= 0 && m_pressedIndex < count()) { update();
QTimer::singleShot(ComboTabBar::slideAnimationDuration(), this, &TabBarHelper::resetDragState);
m_pressedIndex = -1;
m_pressedGlobalX = -1;
}
} }
void TabBarHelper::initStyleOption(QStyleOptionTab* option, int tabIndex) const void TabBarHelper::initStyleOption(QStyleOptionTab* option, int tabIndex) const
@ -1401,14 +1402,6 @@ void TabBarHelper::initStyleOption(QStyleOptionTab* option, int tabIndex) const
} }
} }
void TabBarHelper::resetDragState()
{
if (m_pressedIndex == -1) {
m_dragInProgress = false;
update();
}
}
void TabBarHelper::tabWasMoved(int from, int to) void TabBarHelper::tabWasMoved(int from, int to)
{ {
if (m_pressedIndex != -1) { if (m_pressedIndex != -1) {

View File

@ -261,7 +261,6 @@ public slots:
void setCurrentIndex(int index); void setCurrentIndex(int index);
private slots: private slots:
void resetDragState();
void tabWasMoved(int from, int to); void tabWasMoved(int from, int to);
private: private:
@ -280,7 +279,6 @@ private:
int m_tabPadding = -1; int m_tabPadding = -1;
int m_pressedIndex; int m_pressedIndex;
int m_pressedGlobalX;
bool m_dragInProgress; bool m_dragInProgress;
bool m_activeTabBar; bool m_activeTabBar;
bool m_isPinnedTabBar; bool m_isPinnedTabBar;