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

VerticalTabs: Fix rendering negative margins when updating single index

This commit is contained in:
David Rosca 2018-02-03 16:35:20 +01:00
parent 79d116d07c
commit e5a55a6c69
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
6 changed files with 32 additions and 10 deletions

View File

@ -31,9 +31,7 @@ TabListDelegate::TabListDelegate(TabListView *view)
m_padding = qMax(5, m_view->style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1);
m_loadingAnimator = new LoadingAnimator(this);
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, this, [this](const QModelIndex &index) {
m_view->update(index);
});
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, m_view, &TabListView::updateIndex);
}
QRect TabListDelegate::audioButtonRect(const QModelIndex &index) const

View File

@ -45,6 +45,18 @@ TabListView::TabListView(QWidget *parent)
setFixedHeight(m_delegate->sizeHint(viewOptions(), QModelIndex()).height());
}
void TabListView::updateIndex(const QModelIndex &index)
{
QRect rect = visualRect(index);
if (!rect.isValid()) {
return;
}
// Need to update a little above/under to account for negative margins
rect.moveTop(rect.y() - rect.height() / 2);
rect.setHeight(rect.height() * 2);
viewport()->update(rect);
}
void TabListView::adjustStyleOption(QStyleOptionViewItem *option)
{
const QModelIndex index = option->index;

View File

@ -28,6 +28,7 @@ class TabListView : public QListView
public:
explicit TabListView(QWidget *parent = nullptr);
void updateIndex(const QModelIndex &index);
void adjustStyleOption(QStyleOptionViewItem *option);
private:

View File

@ -94,9 +94,7 @@ TabTreeDelegate::TabTreeDelegate(TabTreeView *view)
m_indentation = 15;
m_loadingAnimator = new LoadingAnimator(this);
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, this, [this](const QModelIndex &index) {
m_view->update(index);
});
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, m_view, &TabTreeView::updateIndex);
// Needed to make it stylable the same way as real tabbar close button
QTabBar *tabBar = new QTabBar(m_view);

View File

@ -81,6 +81,18 @@ void TabTreeView::setTabsInOrder(bool enable)
m_tabsInOrder = enable;
}
void TabTreeView::updateIndex(const QModelIndex &index)
{
QRect rect = visualRect(index);
if (!rect.isValid()) {
return;
}
// Need to update a little above/under to account for negative margins
rect.moveTop(rect.y() - rect.height() / 2);
rect.setHeight(rect.height() * 2);
viewport()->update(rect);
}
void TabTreeView::adjustStyleOption(QStyleOptionViewItem *option)
{
const QModelIndex index = option->index;
@ -155,7 +167,7 @@ bool TabTreeView::viewportEvent(QEvent *event)
case QEvent::MouseButtonPress: {
QMouseEvent *me = static_cast<QMouseEvent*>(event);
const QModelIndex index = indexAt(me->pos());
update(index);
updateIndex(index);
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
if (me->buttons() == Qt::MiddleButton && tab) {
tab->closeTab();
@ -200,7 +212,7 @@ bool TabTreeView::viewportEvent(QEvent *event)
break;
}
const QModelIndex index = indexAt(me->pos());
update(index);
updateIndex(index);
if (m_pressedIndex != index) {
break;
}
@ -230,9 +242,9 @@ bool TabTreeView::viewportEvent(QEvent *event)
case QEvent::HoverLeave:
case QEvent::HoverMove: {
QHoverEvent *he = static_cast<QHoverEvent*>(event);
update(m_hoveredIndex);
updateIndex(m_hoveredIndex);
m_hoveredIndex = indexAt(he->pos());
update(m_hoveredIndex);
updateIndex(m_hoveredIndex);
break;
}

View File

@ -40,6 +40,7 @@ public:
bool areTabsInOrder() const;
void setTabsInOrder(bool enable);
void updateIndex(const QModelIndex &index);
void adjustStyleOption(QStyleOptionViewItem *option);
private: