mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
ComboTabBar: Add tabPixmap method to render single tab
This commit is contained in:
parent
08c0b480c1
commit
fe396e64ff
@ -1,7 +1,7 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* Falkon - Qt web browser
|
||||||
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||||
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
|
* Copyright (C) 2014-2018 David Rosca <nowrep@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -218,6 +218,11 @@ QRect ComboTabBar::tabRect(int index) const
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap ComboTabBar::tabPixmap(int index) const
|
||||||
|
{
|
||||||
|
return localTabBar(index)->tabPixmap(toLocalIndex(index));
|
||||||
|
}
|
||||||
|
|
||||||
int ComboTabBar::tabAt(const QPoint &pos) const
|
int ComboTabBar::tabAt(const QPoint &pos) const
|
||||||
{
|
{
|
||||||
QWidget* w = QApplication::widgetAt(mapToGlobal(pos));
|
QWidget* w = QApplication::widgetAt(mapToGlobal(pos));
|
||||||
@ -1007,6 +1012,40 @@ QSize TabBarHelper::baseClassTabSizeHint(int index) const
|
|||||||
return QTabBar::tabSizeHint(index);
|
return QTabBar::tabSizeHint(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QPixmap TabBarHelper::tabPixmap(int index) const
|
||||||
|
{
|
||||||
|
QStyleOptionTab tab;
|
||||||
|
initStyleOption(&tab, index);
|
||||||
|
|
||||||
|
tab.state &= ~QStyle::State_MouseOver;
|
||||||
|
tab.leftButtonSize = QSize();
|
||||||
|
tab.rightButtonSize = QSize();
|
||||||
|
|
||||||
|
QWidget *iconButton = tabButton(index, m_comboTabBar->iconButtonPosition());
|
||||||
|
QWidget *closeButton = tabButton(index, m_comboTabBar->closeButtonPosition());
|
||||||
|
|
||||||
|
if (iconButton) {
|
||||||
|
const QPixmap pix = iconButton->grab();
|
||||||
|
tab.icon = pix;
|
||||||
|
tab.iconSize = pix.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (closeButton) {
|
||||||
|
const int width = tab.fontMetrics.width(tab.text) + closeButton->width();
|
||||||
|
tab.text = tab.fontMetrics.elidedText(tabText(index), Qt::ElideRight, width);
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap out(tab.rect.size());
|
||||||
|
out.fill(Qt::transparent);
|
||||||
|
tab.rect = QRect(QPoint(0, 0), out.size());
|
||||||
|
|
||||||
|
QPainter p(&out);
|
||||||
|
style()->drawControl(QStyle::CE_TabBarTab, &tab, &p, this);
|
||||||
|
p.end();
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
bool TabBarHelper::isActiveTabBar()
|
bool TabBarHelper::isActiveTabBar()
|
||||||
{
|
{
|
||||||
return m_activeTabBar;
|
return m_activeTabBar;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/* ============================================================
|
/* ============================================================
|
||||||
* Falkon - Qt web browser
|
* Falkon - Qt web browser
|
||||||
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
* Copyright (C) 2013-2014 S. Razi Alavizadeh <s.r.alavizadeh@gmail.com>
|
||||||
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
|
* Copyright (C) 2014-2018 David Rosca <nowrep@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -75,6 +75,7 @@ public:
|
|||||||
void setTabTextColor(int index, const QColor &color);
|
void setTabTextColor(int index, const QColor &color);
|
||||||
|
|
||||||
QRect tabRect(int index) const;
|
QRect tabRect(int index) const;
|
||||||
|
QPixmap tabPixmap(int index) const;
|
||||||
|
|
||||||
// Returns tab index at pos, or -1
|
// Returns tab index at pos, or -1
|
||||||
int tabAt(const QPoint &pos) const;
|
int tabAt(const QPoint &pos) const;
|
||||||
@ -234,6 +235,8 @@ public:
|
|||||||
QSize tabSizeHint(int index) const;
|
QSize tabSizeHint(int index) const;
|
||||||
QSize baseClassTabSizeHint(int index) const;
|
QSize baseClassTabSizeHint(int index) const;
|
||||||
|
|
||||||
|
QPixmap tabPixmap(int index) const;
|
||||||
|
|
||||||
bool isActiveTabBar();
|
bool isActiveTabBar();
|
||||||
void setActiveTabBar(bool activate);
|
void setActiveTabBar(bool activate);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user