mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
GM Settings: Fix redrawing items when script updating state changes
This commit is contained in:
parent
80ad43ba42
commit
2f91f81089
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012-2013 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2012-2016 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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
|
||||
@ -155,17 +155,15 @@ void GM_Settings::loadScripts()
|
||||
QListWidgetItem* item = new QListWidgetItem(ui->listWidget);
|
||||
QIcon icon = QIcon(":/gm/data/script.png");
|
||||
item->setIcon(icon);
|
||||
|
||||
item->setText(script->name());
|
||||
item->setData(Qt::UserRole, script->version());
|
||||
item->setData(Qt::UserRole + 1, script->description());
|
||||
item->setData(Qt::UserRole + 2, !script->downloadUrl().isEmpty());
|
||||
item->setData(Qt::UserRole + 3, script->isUpdating());
|
||||
|
||||
item->setFlags(item->flags() | Qt::ItemIsUserCheckable);
|
||||
item->setCheckState(script->isEnabled() ? Qt::Checked : Qt::Unchecked);
|
||||
item->setData(Qt::UserRole + 10, QVariant::fromValue((void*)script));
|
||||
|
||||
connect(script, &GM_Script::updatingChanged, this, [this]() {
|
||||
ui->listWidget->viewport()->update();
|
||||
});
|
||||
|
||||
ui->listWidget->addItem(item);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2012-2016 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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
|
||||
@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "gm_settingslistdelegate.h"
|
||||
#include "gm_script.h"
|
||||
|
||||
#include "iconprovider.h"
|
||||
|
||||
@ -39,6 +40,10 @@ int GM_SettingsListDelegate::padding() const
|
||||
|
||||
void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
GM_Script *script = static_cast<GM_Script*>(index.data(Qt::UserRole + 10).value<void*>());
|
||||
if (!script)
|
||||
return;
|
||||
|
||||
QStyleOptionViewItemV4 opt = option;
|
||||
initStyleOption(&opt, index);
|
||||
|
||||
@ -64,7 +69,7 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
|
||||
|
||||
int leftPosition = m_padding;
|
||||
int rightPosition = opt.rect.right() - m_padding - 16; // 16 for remove button
|
||||
if (index.data(Qt::UserRole + 2).toBool())
|
||||
if (!script->downloadUrl().isEmpty())
|
||||
rightPosition -= m_padding + 16; // 16 for update button
|
||||
|
||||
// Draw background
|
||||
@ -98,25 +103,24 @@ void GM_SettingsListDelegate::paint(QPainter* painter, const QStyleOptionViewIte
|
||||
style->drawItemText(painter, nameRect, Qt::AlignLeft, opt.palette, true, name, colorRole);
|
||||
|
||||
// Draw version
|
||||
const QString version = index.data(Qt::UserRole).toString();
|
||||
QRect versionRect(nameRect.x() + leftPosForVersion, nameRect.y(), rightTitleEdge - leftPosForVersion, titleMetrics.height());
|
||||
QFont versionFont = titleFont;
|
||||
versionFont.setBold(false);
|
||||
painter->setFont(versionFont);
|
||||
style->drawItemText(painter, versionRect, Qt::AlignLeft, opt.palette, true, version, colorRole);
|
||||
style->drawItemText(painter, versionRect, Qt::AlignLeft, opt.palette, true, script->version(), colorRole);
|
||||
|
||||
// Draw description
|
||||
const int infoYPos = nameRect.bottom() + opt.fontMetrics.leading();
|
||||
QRect infoRect(nameRect.x(), infoYPos, nameRect.width(), opt.fontMetrics.height());
|
||||
const QString info = opt.fontMetrics.elidedText(index.data(Qt::UserRole + 1).toString(), Qt::ElideRight, infoRect.width());
|
||||
const QString info = opt.fontMetrics.elidedText(script->description(), Qt::ElideRight, infoRect.width());
|
||||
painter->setFont(opt.font);
|
||||
style->drawItemText(painter, infoRect, Qt::TextSingleLine | Qt::AlignLeft, opt.palette, true, info, colorRole);
|
||||
|
||||
// Draw update button
|
||||
if (index.data(Qt::UserRole + 2).toBool()) {
|
||||
if (!script->downloadUrl().isEmpty()) {
|
||||
const int updateIconSize = 16;
|
||||
const int updateIconYPos = center - (updateIconSize / 2);
|
||||
const QPixmap updatePixmap = m_updateIcon.pixmap(16, index.data(Qt::UserRole + 3).toBool() ? QIcon::Disabled : QIcon::Normal);
|
||||
const QPixmap updatePixmap = m_updateIcon.pixmap(16, script->isUpdating() ? QIcon::Disabled : QIcon::Normal);
|
||||
QRect updateIconRect(rightPosition, updateIconYPos, updateIconSize, updateIconSize);
|
||||
painter->drawPixmap(updateIconRect, updatePixmap);
|
||||
rightPosition += m_padding + 16;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/* ============================================================
|
||||
* GreaseMonkey plugin for QupZilla
|
||||
* Copyright (C) 2012 David Rosca <nowrep@gmail.com>
|
||||
* Copyright (C) 2012-2016 David Rosca <nowrep@gmail.com>
|
||||
*
|
||||
* 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
|
||||
@ -17,6 +17,7 @@
|
||||
* ============================================================ */
|
||||
#include "gm_settingslistwidget.h"
|
||||
#include "gm_settingslistdelegate.h"
|
||||
#include "gm_script.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
@ -72,7 +73,11 @@ bool GM_SettingsListWidget::containsRemoveIcon(const QPoint &pos) const
|
||||
bool GM_SettingsListWidget::containsUpdateIcon(const QPoint &pos) const
|
||||
{
|
||||
QListWidgetItem *item = itemAt(pos);
|
||||
if (!item || !item->data(Qt::UserRole + 2).toBool())
|
||||
if (!item)
|
||||
return false;
|
||||
|
||||
GM_Script *script = static_cast<GM_Script*>(item->data(Qt::UserRole + 10).value<void*>());
|
||||
if (!script || script->downloadUrl().isEmpty())
|
||||
return false;
|
||||
|
||||
const QRect rect = visualItemRect(item);
|
||||
|
Loading…
Reference in New Issue
Block a user