1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-24 12:46:35 +01:00

ComboTabBar: Update moving tab contents during drag

Unlike QTabBar, ComboTabBar now redraws contents of moving tab.
This commit is contained in:
David Rosca 2018-01-09 15:31:35 +01:00
parent d7146519b4
commit 5cd580d284
2 changed files with 23 additions and 2 deletions

View File

@ -36,6 +36,12 @@
#include <QApplication> #include <QApplication>
#include <QToolTip> #include <QToolTip>
class QMovableTabWidget : public QWidget
{
public:
QPixmap m_pixmap;
};
ComboTabBar::ComboTabBar(QWidget* parent) ComboTabBar::ComboTabBar(QWidget* parent)
: QWidget(parent) : QWidget(parent)
, m_mainTabBar(0) , m_mainTabBar(0)
@ -1344,6 +1350,21 @@ void TabBarHelper::paintEvent(QPaintEvent *)
} else { } else {
int taboverlap = style()->pixelMetric(QStyle::PM_TabBarTabOverlap, nullptr, this); int taboverlap = style()->pixelMetric(QStyle::PM_TabBarTabOverlap, nullptr, this);
m_movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0)); m_movingTab->setGeometry(tab.rect.adjusted(-taboverlap, 0, taboverlap, 0));
QRect grabRect = tabRect(selected);
grabRect.adjust(-taboverlap, 0, taboverlap, 0);
QPixmap grabImage(grabRect.size() * devicePixelRatioF());
grabImage.setDevicePixelRatio(devicePixelRatioF());
grabImage.fill(Qt::transparent);
QStylePainter p(&grabImage, this);
p.initFrom(this);
if (tabDragOffset != 0) {
tab.position = QStyleOptionTab::OnlyOneTab;
}
tab.rect.moveTopLeft(QPoint(taboverlap, 0));
p.drawControl(QStyle::CE_TabBarTab, tab);
m_movingTab->m_pixmap = grabImage;
m_movingTab->update();
} }
} }
@ -1409,7 +1430,7 @@ void TabBarHelper::mouseMoveEvent(QMouseEvent *event)
for (QObject *object : objects) { for (QObject *object : objects) {
QWidget *widget = qobject_cast<QWidget*>(object); QWidget *widget = qobject_cast<QWidget*>(object);
if (widget && widget->geometry() == grabRect) { if (widget && widget->geometry() == grabRect) {
m_movingTab = widget; m_movingTab = static_cast<QMovableTabWidget*>(widget);
break; break;
} }
} }

View File

@ -285,7 +285,7 @@ private:
int m_pressedIndex; int m_pressedIndex;
bool m_dragInProgress; bool m_dragInProgress;
QPoint m_dragStartPosition; QPoint m_dragStartPosition;
QWidget *m_movingTab = nullptr; class QMovableTabWidget *m_movingTab = nullptr;
bool m_activeTabBar; bool m_activeTabBar;
bool m_isPinnedTabBar; bool m_isPinnedTabBar;
bool m_useFastTabSizeHint; bool m_useFastTabSizeHint;