mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01: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:
parent
6a48f4d862
commit
4e988ac8f2
@ -985,7 +985,6 @@ TabBarHelper::TabBarHelper(bool isPinnedTabBar, ComboTabBar* comboTabBar)
|
||||
, m_comboTabBar(comboTabBar)
|
||||
, m_scrollArea(0)
|
||||
, m_pressedIndex(-1)
|
||||
, m_pressedGlobalX(-1)
|
||||
, m_dragInProgress(false)
|
||||
, m_activeTabBar(false)
|
||||
, m_isPinnedTabBar(isPinnedTabBar)
|
||||
@ -1202,6 +1201,9 @@ void TabBarHelper::paintEvent(QPaintEvent *event)
|
||||
if (m_dragInProgress) {
|
||||
// Still needs to be called because it updates movingTab geometry
|
||||
QTabBar::paintEvent(event);
|
||||
|
||||
QPainter p(this);
|
||||
p.fillRect(rect(), palette().color(QPalette::Background));
|
||||
}
|
||||
|
||||
// Hack to get dragOffset from QTabBar internals
|
||||
@ -1233,7 +1235,7 @@ void TabBarHelper::paintEvent(QPaintEvent *event)
|
||||
optTabBase.selectedTabRect = tabRect(selected);
|
||||
}
|
||||
|
||||
if (!m_dragInProgress && drawBase()) {
|
||||
if (drawBase()) {
|
||||
p.drawPrimitive(QStyle::PE_FrameTabBarBase, optTabBase);
|
||||
}
|
||||
|
||||
@ -1281,6 +1283,11 @@ void TabBarHelper::paintEvent(QPaintEvent *event)
|
||||
QStyleOptionTab tab;
|
||||
initStyleOption(&tab, selected);
|
||||
|
||||
const int tabDragOffset = dragOffset(&tab, selected);
|
||||
if (tabDragOffset != 0) {
|
||||
tab.rect.moveLeft(tab.rect.x() + tabDragOffset);
|
||||
}
|
||||
|
||||
// Update mouseover state when scrolling
|
||||
if (selected == indexUnderMouse) {
|
||||
tab.state |= QStyle::State_MouseOver;
|
||||
@ -1337,7 +1344,6 @@ void TabBarHelper::mousePressEvent(QMouseEvent* event)
|
||||
if (event->buttons() == Qt::LeftButton) {
|
||||
m_pressedIndex = tabAt(event->pos());
|
||||
if (m_pressedIndex != -1) {
|
||||
m_pressedGlobalX = event->globalX();
|
||||
m_dragInProgress = true;
|
||||
// virtualize selecting tab by click
|
||||
if (m_pressedIndex == currentIndex() && !m_activeTabBar) {
|
||||
@ -1352,18 +1358,13 @@ void TabBarHelper::mousePressEvent(QMouseEvent* event)
|
||||
void TabBarHelper::mouseReleaseEvent(QMouseEvent* event)
|
||||
{
|
||||
event->ignore();
|
||||
if (event->button() != Qt::LeftButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_pressedIndex = -1;
|
||||
m_dragInProgress = false;
|
||||
|
||||
QTabBar::mouseReleaseEvent(event);
|
||||
|
||||
if (m_pressedIndex >= 0 && m_pressedIndex < count()) {
|
||||
QTimer::singleShot(ComboTabBar::slideAnimationDuration(), this, &TabBarHelper::resetDragState);
|
||||
|
||||
m_pressedIndex = -1;
|
||||
m_pressedGlobalX = -1;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (m_pressedIndex != -1) {
|
||||
|
@ -261,7 +261,6 @@ public slots:
|
||||
void setCurrentIndex(int index);
|
||||
|
||||
private slots:
|
||||
void resetDragState();
|
||||
void tabWasMoved(int from, int to);
|
||||
|
||||
private:
|
||||
@ -280,7 +279,6 @@ private:
|
||||
|
||||
int m_tabPadding = -1;
|
||||
int m_pressedIndex;
|
||||
int m_pressedGlobalX;
|
||||
bool m_dragInProgress;
|
||||
bool m_activeTabBar;
|
||||
bool m_isPinnedTabBar;
|
||||
|
Loading…
Reference in New Issue
Block a user