mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
[ComboTabBar] Draw TabBarBase also on parts that are not QTabBar
Draw TabBarBase on left/right corner widgets and left/right scroll buttons.
This commit is contained in:
parent
b26d9b06ab
commit
da6ccdcee5
@ -617,8 +617,8 @@ bool ComboTabBar::eventFilter(QObject* obj, QEvent* ev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle wheel events exclusively in ComboTabBar
|
||||||
if (ev->type() == QEvent::Wheel) {
|
if (ev->type() == QEvent::Wheel) {
|
||||||
// Handle wheel events exclusively in ComboTabBar
|
|
||||||
wheelEvent(static_cast<QWheelEvent*>(ev));
|
wheelEvent(static_cast<QWheelEvent*>(ev));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -626,6 +626,40 @@ bool ComboTabBar::eventFilter(QObject* obj, QEvent* ev)
|
|||||||
return QWidget::eventFilter(obj, ev);
|
return QWidget::eventFilter(obj, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ComboTabBar::paintEvent(QPaintEvent* ev)
|
||||||
|
{
|
||||||
|
QWidget::paintEvent(ev);
|
||||||
|
|
||||||
|
// Draw tabbar base even on parts of ComboTabBar that are not directly QTabBar
|
||||||
|
QPainter p(this);
|
||||||
|
QStyleOptionTabBarBaseV2 opt;
|
||||||
|
TabBarHelper::initStyleBaseOption(&opt, m_mainTabBar, size());
|
||||||
|
|
||||||
|
// Left container
|
||||||
|
opt.rect.setX(m_leftContainer->x());
|
||||||
|
opt.rect.setWidth(m_leftContainer->width());
|
||||||
|
style()->drawPrimitive(QStyle::PE_FrameTabBarBase, &opt, &p);
|
||||||
|
|
||||||
|
// Right container
|
||||||
|
opt.rect.setX(m_rightContainer->x());
|
||||||
|
opt.rect.setWidth(m_rightContainer->width());
|
||||||
|
style()->drawPrimitive(QStyle::PE_FrameTabBarBase, &opt, &p);
|
||||||
|
|
||||||
|
if (m_mainBarOverFlowed) {
|
||||||
|
const int scrollButtonWidth = m_mainTabBarWidget->scrollButtonsWidth();
|
||||||
|
|
||||||
|
// Left scroll button
|
||||||
|
opt.rect.setX(m_mainTabBarWidget->x());
|
||||||
|
opt.rect.setWidth(scrollButtonWidth);
|
||||||
|
style()->drawPrimitive(QStyle::PE_FrameTabBarBase, &opt, &p);
|
||||||
|
|
||||||
|
// Right scroll button
|
||||||
|
opt.rect.setX(m_mainTabBarWidget->x() + m_mainTabBarWidget->width() - scrollButtonWidth);
|
||||||
|
opt.rect.setWidth(scrollButtonWidth);
|
||||||
|
style()->drawPrimitive(QStyle::PE_FrameTabBarBase, &opt, &p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int ComboTabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
|
int ComboTabBar::comboTabBarPixelMetric(ComboTabBar::SizeType sizeType) const
|
||||||
{
|
{
|
||||||
switch (sizeType) {
|
switch (sizeType) {
|
||||||
@ -972,7 +1006,7 @@ bool TabBarHelper::event(QEvent* ev)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// taken from qtabbar.cpp
|
// Taken from qtabbar.cpp
|
||||||
void TabBarHelper::initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size)
|
void TabBarHelper::initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size)
|
||||||
{
|
{
|
||||||
QStyleOptionTab tabOverlap;
|
QStyleOptionTab tabOverlap;
|
||||||
@ -1006,7 +1040,7 @@ void TabBarHelper::initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// some codes were taken from qtabbar.cpp
|
// Adapted from qtabbar.cpp
|
||||||
void TabBarHelper::paintEvent(QPaintEvent* event)
|
void TabBarHelper::paintEvent(QPaintEvent* event)
|
||||||
{
|
{
|
||||||
if (m_bluredBackground) {
|
if (m_bluredBackground) {
|
||||||
@ -1015,7 +1049,7 @@ void TabBarHelper::paintEvent(QPaintEvent* event)
|
|||||||
p.fillRect(event->rect(), QColor(0, 0, 0, 0));
|
p.fillRect(event->rect(), QColor(0, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: this code doesn't support vertical tabs
|
// Note: this code doesn't support vertical tabs
|
||||||
if (m_dragInProgress) {
|
if (m_dragInProgress) {
|
||||||
QTabBar::paintEvent(event);
|
QTabBar::paintEvent(event);
|
||||||
return;
|
return;
|
||||||
@ -1090,6 +1124,7 @@ void TabBarHelper::paintEvent(QPaintEvent* event)
|
|||||||
p.drawControl(QStyle::CE_TabBarTab, tb);
|
p.drawControl(QStyle::CE_TabBarTab, tb);
|
||||||
|
|
||||||
// Draw the tab without selected state
|
// Draw the tab without selected state
|
||||||
|
|
||||||
tab.state = tab.state & ~QStyle::State_Selected;
|
tab.state = tab.state & ~QStyle::State_Selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1373,6 +1408,12 @@ void TabBarScrollWidget::scrollByWheel(QWheelEvent* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TabBarScrollWidget::scrollButtonsWidth() const
|
||||||
|
{
|
||||||
|
// Assumes both buttons have the same width
|
||||||
|
return m_leftScrollButton->width();
|
||||||
|
}
|
||||||
|
|
||||||
bool TabBarScrollWidget::usesScrollButtons() const
|
bool TabBarScrollWidget::usesScrollButtons() const
|
||||||
{
|
{
|
||||||
return m_usesScrollButtons;
|
return m_usesScrollButtons;
|
||||||
|
@ -164,6 +164,7 @@ protected:
|
|||||||
void enterEvent(QEvent* event);
|
void enterEvent(QEvent* event);
|
||||||
void leaveEvent(QEvent* event);
|
void leaveEvent(QEvent* event);
|
||||||
bool eventFilter(QObject* obj, QEvent* ev);
|
bool eventFilter(QObject* obj, QEvent* ev);
|
||||||
|
void paintEvent(QPaintEvent* ev);
|
||||||
|
|
||||||
virtual int comboTabBarPixelMetric(SizeType sizeType) const;
|
virtual int comboTabBarPixelMetric(SizeType sizeType) const;
|
||||||
virtual QSize tabSizeHint(int index, bool fast = false) const;
|
virtual QSize tabSizeHint(int index, bool fast = false) const;
|
||||||
@ -220,6 +221,8 @@ public:
|
|||||||
bool isDragInProgress() const;
|
bool isDragInProgress() const;
|
||||||
void enableBluredBackground(bool enable);
|
void enableBluredBackground(bool enable);
|
||||||
|
|
||||||
|
static void initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setCurrentIndex(int index);
|
void setCurrentIndex(int index);
|
||||||
|
|
||||||
@ -227,7 +230,6 @@ private slots:
|
|||||||
void resetDragState();
|
void resetDragState();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size);
|
|
||||||
bool event(QEvent* ev);
|
bool event(QEvent* ev);
|
||||||
void paintEvent(QPaintEvent* event);
|
void paintEvent(QPaintEvent* event);
|
||||||
void mousePressEvent(QMouseEvent* event);
|
void mousePressEvent(QMouseEvent* event);
|
||||||
@ -271,6 +273,7 @@ public:
|
|||||||
|
|
||||||
void scrollByWheel(QWheelEvent* event);
|
void scrollByWheel(QWheelEvent* event);
|
||||||
|
|
||||||
|
int scrollButtonsWidth() const;
|
||||||
bool usesScrollButtons() const;
|
bool usesScrollButtons() const;
|
||||||
void setUsesScrollButtons(bool useButtons);
|
void setUsesScrollButtons(bool useButtons);
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ TabStackedWidget::TabStackedWidget(QWidget* parent)
|
|||||||
m_mainLayout->addWidget(m_stack);
|
m_mainLayout->addWidget(m_stack);
|
||||||
setLayout(m_mainLayout);
|
setLayout(m_mainLayout);
|
||||||
|
|
||||||
setTabBar(new ComboTabBar);
|
|
||||||
connect(m_stack, SIGNAL(widgetRemoved(int)), this, SLOT(tabWasRemoved(int)));
|
connect(m_stack, SIGNAL(widgetRemoved(int)), this, SLOT(tabWasRemoved(int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user