mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
VerticalTabs: Fix rendering negative margins when updating single index
This commit is contained in:
parent
79d116d07c
commit
e5a55a6c69
@ -31,9 +31,7 @@ TabListDelegate::TabListDelegate(TabListView *view)
|
|||||||
m_padding = qMax(5, m_view->style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1);
|
m_padding = qMax(5, m_view->style()->pixelMetric(QStyle::PM_FocusFrameHMargin) + 1);
|
||||||
|
|
||||||
m_loadingAnimator = new LoadingAnimator(this);
|
m_loadingAnimator = new LoadingAnimator(this);
|
||||||
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, this, [this](const QModelIndex &index) {
|
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, m_view, &TabListView::updateIndex);
|
||||||
m_view->update(index);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QRect TabListDelegate::audioButtonRect(const QModelIndex &index) const
|
QRect TabListDelegate::audioButtonRect(const QModelIndex &index) const
|
||||||
|
@ -45,6 +45,18 @@ TabListView::TabListView(QWidget *parent)
|
|||||||
setFixedHeight(m_delegate->sizeHint(viewOptions(), QModelIndex()).height());
|
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)
|
void TabListView::adjustStyleOption(QStyleOptionViewItem *option)
|
||||||
{
|
{
|
||||||
const QModelIndex index = option->index;
|
const QModelIndex index = option->index;
|
||||||
|
@ -28,6 +28,7 @@ class TabListView : public QListView
|
|||||||
public:
|
public:
|
||||||
explicit TabListView(QWidget *parent = nullptr);
|
explicit TabListView(QWidget *parent = nullptr);
|
||||||
|
|
||||||
|
void updateIndex(const QModelIndex &index);
|
||||||
void adjustStyleOption(QStyleOptionViewItem *option);
|
void adjustStyleOption(QStyleOptionViewItem *option);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -94,9 +94,7 @@ TabTreeDelegate::TabTreeDelegate(TabTreeView *view)
|
|||||||
m_indentation = 15;
|
m_indentation = 15;
|
||||||
|
|
||||||
m_loadingAnimator = new LoadingAnimator(this);
|
m_loadingAnimator = new LoadingAnimator(this);
|
||||||
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, this, [this](const QModelIndex &index) {
|
connect(m_loadingAnimator, &LoadingAnimator::updateIndex, m_view, &TabTreeView::updateIndex);
|
||||||
m_view->update(index);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Needed to make it stylable the same way as real tabbar close button
|
// Needed to make it stylable the same way as real tabbar close button
|
||||||
QTabBar *tabBar = new QTabBar(m_view);
|
QTabBar *tabBar = new QTabBar(m_view);
|
||||||
|
@ -81,6 +81,18 @@ void TabTreeView::setTabsInOrder(bool enable)
|
|||||||
m_tabsInOrder = 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)
|
void TabTreeView::adjustStyleOption(QStyleOptionViewItem *option)
|
||||||
{
|
{
|
||||||
const QModelIndex index = option->index;
|
const QModelIndex index = option->index;
|
||||||
@ -155,7 +167,7 @@ bool TabTreeView::viewportEvent(QEvent *event)
|
|||||||
case QEvent::MouseButtonPress: {
|
case QEvent::MouseButtonPress: {
|
||||||
QMouseEvent *me = static_cast<QMouseEvent*>(event);
|
QMouseEvent *me = static_cast<QMouseEvent*>(event);
|
||||||
const QModelIndex index = indexAt(me->pos());
|
const QModelIndex index = indexAt(me->pos());
|
||||||
update(index);
|
updateIndex(index);
|
||||||
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
|
WebTab *tab = index.data(TabModel::WebTabRole).value<WebTab*>();
|
||||||
if (me->buttons() == Qt::MiddleButton && tab) {
|
if (me->buttons() == Qt::MiddleButton && tab) {
|
||||||
tab->closeTab();
|
tab->closeTab();
|
||||||
@ -200,7 +212,7 @@ bool TabTreeView::viewportEvent(QEvent *event)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
const QModelIndex index = indexAt(me->pos());
|
const QModelIndex index = indexAt(me->pos());
|
||||||
update(index);
|
updateIndex(index);
|
||||||
if (m_pressedIndex != index) {
|
if (m_pressedIndex != index) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -230,9 +242,9 @@ bool TabTreeView::viewportEvent(QEvent *event)
|
|||||||
case QEvent::HoverLeave:
|
case QEvent::HoverLeave:
|
||||||
case QEvent::HoverMove: {
|
case QEvent::HoverMove: {
|
||||||
QHoverEvent *he = static_cast<QHoverEvent*>(event);
|
QHoverEvent *he = static_cast<QHoverEvent*>(event);
|
||||||
update(m_hoveredIndex);
|
updateIndex(m_hoveredIndex);
|
||||||
m_hoveredIndex = indexAt(he->pos());
|
m_hoveredIndex = indexAt(he->pos());
|
||||||
update(m_hoveredIndex);
|
updateIndex(m_hoveredIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
bool areTabsInOrder() const;
|
bool areTabsInOrder() const;
|
||||||
void setTabsInOrder(bool enable);
|
void setTabsInOrder(bool enable);
|
||||||
|
|
||||||
|
void updateIndex(const QModelIndex &index);
|
||||||
void adjustStyleOption(QStyleOptionViewItem *option);
|
void adjustStyleOption(QStyleOptionViewItem *option);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user