1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
/*
quickclientitemmodel.cpp
This file is part of GammaRay, the Qt application inspection and manipulation tool.
SPDX-FileCopyrightText: 2014 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Author: Volker Krause <volker.krause@kdab.com>
SPDX-License-Identifier: GPL-2.0-or-later
Contact KDAB at <info@kdab.com> for commercial licensing options.
*/
#include "quickclientitemmodel.h"
#include "quickitemmodelroles.h"
#include <QApplication>
#include <QPalette>
#include <QIcon>
#include <QBuffer>
using namespace GammaRay;
QuickClientItemModel::QuickClientItemModel(QObject *parent)
: ClientDecorationIdentityProxyModel(parent)
{
}
QuickClientItemModel::~QuickClientItemModel() = default;
QVariant QuickClientItemModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::ForegroundRole || role == Qt::ToolTipRole) {
int flags = ClientDecorationIdentityProxyModel::data(index, QuickItemModelRole::ItemFlags).value<int>();
// Grey out invisible items
if (role == Qt::ForegroundRole
&& (flags & (QuickItemModelRole::Invisible | QuickItemModelRole::ZeroSize)))
return qApp->palette().color(QPalette::Disabled, QPalette::Text);
// Adjust tooltip to show information about items
if (role == Qt::ToolTipRole && flags) {
QString tooltip = ClientDecorationIdentityProxyModel::data(index, role).toString();
tooltip.append("<p style='white-space:pre'>");
// if flags has OutOfView it has also PartiallyOutOfView, no need to test both
if ((flags & QuickItemModelRole::PartiallyOutOfView)
&& (~flags & QuickItemModelRole::Invisible)) {
QByteArray byteArray;
QBuffer buffer(&byteArray);
QIcon::fromTheme(QStringLiteral("dialog-warning")).pixmap(16, 16).save(&buffer, "PNG");
tooltip.append("<img src=\"data:image/png;base64,").append(byteArray.toBase64());
if (flags & QuickItemModelRole::OutOfView)
tooltip.append("\"> Item is visible, but out of view.");
else
tooltip.append("\"> Item is visible, but partially out of view.");
flags &= ~QuickItemModelRole::OutOfView;
flags &= ~QuickItemModelRole::PartiallyOutOfView;
if (flags)
tooltip.append("\n");
}
if (flags) {
QStringList flagStrings;
if (flags & QuickItemModelRole::Invisible)
flagStrings << tr("is invisible");
if (flags & QuickItemModelRole::ZeroSize)
flagStrings << tr("has a size of zero");
if (flags & QuickItemModelRole::OutOfView)
flagStrings << tr("is out of view");
else if (flags & QuickItemModelRole::PartiallyOutOfView)
flagStrings << tr("is partially out of view");
if (flags & QuickItemModelRole::HasFocus
&& ~flags & QuickItemModelRole::HasActiveFocus)
flagStrings << tr("has inactive focus");
if (flags & QuickItemModelRole::HasActiveFocus)
flagStrings << tr("has active focus");
if (flags & QuickItemModelRole::JustRecievedEvent)
flagStrings << tr("just received an event");
QByteArray byteArray;
QBuffer buffer(&byteArray);
QIcon::fromTheme(QStringLiteral("dialog-information")).pixmap(16, 16).save(&buffer, "PNG");
tooltip.append(QStringLiteral("<img src=\"data:image/png;base64,").append(byteArray.toBase64()).append("\"> Item %1.").arg(flagStrings.join(QStringLiteral(", "))));
}
tooltip.append("</p>");
return tooltip;
}
}
return ClientDecorationIdentityProxyModel::data(index, role);
}
|