1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 01:22:10 +01:00

VerticalTabs: Arrange pinned tabs vertically

BUG: 452818
FIXED-IN: 24.12.0

Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
Juraj Oravec 2024-08-11 20:27:01 +02:00
parent ccce0818cc
commit 95b1f3ce3c
3 changed files with 45 additions and 32 deletions

View File

@ -49,6 +49,8 @@ void TabListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
const QWidget *w = option.widget; const QWidget *w = option.widget;
const QStyle *style = w ? w->style() : m_view->style(); const QStyle *style = w ? w->style() : m_view->style();
const bool isRestoredTab = index.data(TabModel::RestoredRole).toBool();
QStyleOptionViewItem opt = option; QStyleOptionViewItem opt = option;
initStyleOption(&opt, index); initStyleOption(&opt, index);
m_view->adjustStyleOption(&opt); m_view->adjustStyleOption(&opt);
@ -56,7 +58,26 @@ void TabListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
const int height = opt.rect.height(); const int height = opt.rect.height();
const int center = height / 2 + opt.rect.top(); const int center = height / 2 + opt.rect.top();
painter->setRenderHint(QPainter::Antialiasing); int leftPosition = opt.rect.left() + m_padding;
int rightPosition = opt.rect.right() - m_padding * 2;
const QPalette::ColorRole colorRole = opt.state & QStyle::State_Selected ? QPalette::HighlightedText : QPalette::Text;
QPalette::ColorGroup cg = opt.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled;
if (!isRestoredTab) {
cg = QPalette::Disabled;
}
if (cg == QPalette::Normal && !(opt.state & QStyle::State_Active)) {
cg = QPalette::Inactive;
}
#ifdef Q_OS_WIN
opt.palette.setColor(QPalette::All, QPalette::HighlightedText, opt.palette.color(QPalette::Active, QPalette::Text));
opt.palette.setColor(QPalette::All, QPalette::Highlight, opt.palette.base().color().darker(108));
#endif
QPalette textPalette = opt.palette;
textPalette.setCurrentColorGroup(cg);
// Draw background // Draw background
style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w); style->drawPrimitive(QStyle::PE_PanelItemViewItem, &opt, painter, w);
@ -64,7 +85,7 @@ void TabListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
// Draw icon // Draw icon
const int iconSize = 16; const int iconSize = 16;
const int iconYPos = center - (iconSize / 2); const int iconYPos = center - (iconSize / 2);
QRect iconRect(opt.rect.left() + (opt.rect.width() - iconSize) / 2, iconYPos, iconSize, iconSize); QRect iconRect(leftPosition, iconYPos, iconSize, iconSize);
QPixmap pixmap; QPixmap pixmap;
if (index.data(TabModel::LoadingRole).toBool()) { if (index.data(TabModel::LoadingRole).toBool()) {
pixmap = m_loadingAnimator->pixmap(index); pixmap = m_loadingAnimator->pixmap(index);
@ -72,42 +93,24 @@ void TabListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &optio
pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize); pixmap = index.data(Qt::DecorationRole).value<QIcon>().pixmap(iconSize);
} }
painter->drawPixmap(iconRect, pixmap); painter->drawPixmap(iconRect, pixmap);
leftPosition += iconRect.width() + m_padding;
// Draw audio icon // Draw audio icon
const bool audioMuted = index.data(TabModel::AudioMutedRole).toBool(); const bool audioMuted = index.data(TabModel::AudioMutedRole).toBool();
const bool audioPlaying = index.data(TabModel::AudioPlayingRole).toBool(); const bool audioPlaying = index.data(TabModel::AudioPlayingRole).toBool();
if (audioMuted || audioPlaying) { if (audioMuted || audioPlaying) {
QSize audioSize(16, 16); QSize audioSize(16, 16);
QPoint pos(opt.rect.right() - audioSize.width(), center - audioSize.height() / 2); QPoint pos(rightPosition - audioSize.width(), center - audioSize.height() / 2);
QRect audioRect(pos, audioSize); QRect audioRect(pos, audioSize);
QColor c = opt.palette.color(QPalette::Window);
c.setAlpha(180);
painter->setPen(c);
painter->setBrush(c);
painter->drawEllipse(audioRect);
painter->drawPixmap(audioRect, audioMuted ? TabIcon::data()->audioMutedPixmap : TabIcon::data()->audioPlayingPixmap); painter->drawPixmap(audioRect, audioMuted ? TabIcon::data()->audioMutedPixmap : TabIcon::data()->audioPlayingPixmap);
rightPosition -= audioSize.width() + m_padding;
} }
// Draw background activity indicator // Draw title
const bool backgroundActivity = index.data(TabModel::BackgroundActivityRole).toBool(); QRect titleRect(leftPosition, center - opt.fontMetrics.height() / 2, opt.rect.width(), opt.fontMetrics.height());
if (backgroundActivity) { titleRect.setRight(rightPosition - m_padding);
QSize activitySize(7, 7); QString title = opt.fontMetrics.elidedText(index.data().toString(), Qt::ElideRight, titleRect.width());
QPoint pos(iconRect.center().x() - activitySize.width() / 2 + 1, iconRect.bottom() - 2); style->drawItemText(painter, titleRect, Qt::AlignLeft, textPalette, true, title, colorRole);
QRect activityRect(pos, activitySize);
QColor c1 = opt.palette.color(QPalette::Window);
c1.setAlpha(180);
painter->setPen(Qt::transparent);
painter->setBrush(c1);
painter->drawEllipse(activityRect);
const QRect r2 = activityRect.adjusted(1, 1, -1, -1);
painter->setPen(Qt::transparent);
painter->setBrush(opt.palette.color(QPalette::Text));
painter->drawEllipse(r2);
}
} }
QSize TabListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const QSize TabListDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const

View File

@ -24,6 +24,8 @@ class LoadingAnimator;
class TabListDelegate : public QStyledItemDelegate class TabListDelegate : public QStyledItemDelegate
{ {
Q_OBJECT
public: public:
explicit TabListDelegate(TabListView *view); explicit TabListDelegate(TabListView *view);

View File

@ -36,12 +36,13 @@ TabListView::TabListView(BrowserWindow *window, QWidget *parent)
setUniformItemSizes(true); setUniformItemSizes(true);
setDropIndicatorShown(true); setDropIndicatorShown(true);
setMouseTracking(true); setMouseTracking(true);
setFlow(QListView::LeftToRight); setFlow(QListView::TopToBottom);
setFocusPolicy(Qt::NoFocus); setFocusPolicy(Qt::NoFocus);
setFrameShape(QFrame::NoFrame); setFrameShape(QFrame::NoFrame);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);
m_delegate = new TabListDelegate(this); m_delegate = new TabListDelegate(this);
setItemDelegate(m_delegate); setItemDelegate(m_delegate);
@ -101,7 +102,7 @@ QModelIndex TabListView::indexAfter(const QModelIndex &index) const
return {}; return {};
} }
const QRect rect = visualRect(index); const QRect rect = visualRect(index);
return indexAt(QPoint(rect.right() + rect.width() / 2, rect.y())); return indexAt(QPoint(rect.x(), rect.bottom() + rect.height() / 2));
} }
QModelIndex TabListView::indexBefore(const QModelIndex &index) const QModelIndex TabListView::indexBefore(const QModelIndex &index) const
@ -110,7 +111,7 @@ QModelIndex TabListView::indexBefore(const QModelIndex &index) const
return {}; return {};
} }
const QRect rect = visualRect(index); const QRect rect = visualRect(index);
return indexAt(QPoint(rect.left() - rect.width() / 2, rect.y())); return indexAt(QPoint(rect.x(), rect.top() - rect.height() / 2));
} }
void TabListView::currentChanged(const QModelIndex &current, const QModelIndex &previous) void TabListView::currentChanged(const QModelIndex &current, const QModelIndex &previous)
@ -236,11 +237,18 @@ TabListView::DelegateButton TabListView::buttonAt(const QPoint &pos, const QMode
void TabListView::updateVisibility() void TabListView::updateVisibility()
{ {
setVisible(!m_hideWhenEmpty || model()->rowCount() > 0); setVisible(!m_hideWhenEmpty || model()->rowCount() > 0);
updateHeight();
} }
void TabListView::updateHeight() void TabListView::updateHeight()
{ {
QStyleOptionViewItem option; QStyleOptionViewItem option;
initViewItemOption(&option); initViewItemOption(&option);
setFixedHeight(m_delegate->sizeHint(option, QModelIndex()).height());
if (isVisible() && model()->rowCount() > 0) {
setFixedHeight(m_delegate->sizeHint(option, QModelIndex()).height() * model()->rowCount());
}
else {
setFixedHeight(m_delegate->sizeHint(option, QModelIndex()).height());
}
} }