1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36: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:
nowrep 2014-03-31 09:45:41 +02:00
parent b26d9b06ab
commit da6ccdcee5
3 changed files with 49 additions and 6 deletions

View File

@ -617,8 +617,8 @@ bool ComboTabBar::eventFilter(QObject* obj, QEvent* ev)
}
}
// Handle wheel events exclusively in ComboTabBar
if (ev->type() == QEvent::Wheel) {
// Handle wheel events exclusively in ComboTabBar
wheelEvent(static_cast<QWheelEvent*>(ev));
return true;
}
@ -626,6 +626,40 @@ bool ComboTabBar::eventFilter(QObject* obj, QEvent* 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
{
switch (sizeType) {
@ -972,7 +1006,7 @@ bool TabBarHelper::event(QEvent* ev)
return false;
}
// taken from qtabbar.cpp
// Taken from qtabbar.cpp
void TabBarHelper::initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size)
{
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)
{
if (m_bluredBackground) {
@ -1015,7 +1049,7 @@ void TabBarHelper::paintEvent(QPaintEvent* event)
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) {
QTabBar::paintEvent(event);
return;
@ -1090,6 +1124,7 @@ void TabBarHelper::paintEvent(QPaintEvent* event)
p.drawControl(QStyle::CE_TabBarTab, tb);
// Draw the tab without selected state
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
{
return m_usesScrollButtons;

View File

@ -164,6 +164,7 @@ protected:
void enterEvent(QEvent* event);
void leaveEvent(QEvent* event);
bool eventFilter(QObject* obj, QEvent* ev);
void paintEvent(QPaintEvent* ev);
virtual int comboTabBarPixelMetric(SizeType sizeType) const;
virtual QSize tabSizeHint(int index, bool fast = false) const;
@ -220,6 +221,8 @@ public:
bool isDragInProgress() const;
void enableBluredBackground(bool enable);
static void initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size);
public slots:
void setCurrentIndex(int index);
@ -227,7 +230,6 @@ private slots:
void resetDragState();
private:
void initStyleBaseOption(QStyleOptionTabBarBaseV2* optTabBase, QTabBar* tabbar, QSize size);
bool event(QEvent* ev);
void paintEvent(QPaintEvent* event);
void mousePressEvent(QMouseEvent* event);
@ -271,6 +273,7 @@ public:
void scrollByWheel(QWheelEvent* event);
int scrollButtonsWidth() const;
bool usesScrollButtons() const;
void setUsesScrollButtons(bool useButtons);

View File

@ -41,7 +41,6 @@ TabStackedWidget::TabStackedWidget(QWidget* parent)
m_mainLayout->addWidget(m_stack);
setLayout(m_mainLayout);
setTabBar(new ComboTabBar);
connect(m_stack, SIGNAL(widgetRemoved(int)), this, SLOT(tabWasRemoved(int)));
}