mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-11-26 09:36:33 -05:00
Removing QWidget dependency from src/core.
This commit is contained in:
parent
6f5bbf7ad1
commit
004f2b6801
46 changed files with 298 additions and 313 deletions
|
|
@ -19,11 +19,20 @@
|
|||
#include "Icons.h"
|
||||
|
||||
#include <QIconEngine>
|
||||
#include <QImageReader>
|
||||
#include <QPaintDevice>
|
||||
#include <QPainter>
|
||||
|
||||
#include "config-keepassx.h"
|
||||
#include "core/Config.h"
|
||||
#include "gui/DatabaseIcons.h"
|
||||
#include "gui/MainWindow.h"
|
||||
#include "gui/osutils/OSUtils.h"
|
||||
|
||||
#ifdef WITH_XC_KEESHARE
|
||||
#include "keeshare/KeeShare.h"
|
||||
#endif
|
||||
|
||||
class AdaptiveIconEngine : public QIconEngine
|
||||
{
|
||||
public:
|
||||
|
|
@ -206,3 +215,97 @@ Icons* Icons::instance()
|
|||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
QPixmap Icons::customIconPixmap(const Database* db, const QUuid& uuid, IconSize size)
|
||||
{
|
||||
if (!db->metadata()->hasCustomIcon(uuid)) {
|
||||
return {};
|
||||
}
|
||||
// Generate QIcon with pre-baked resolutions
|
||||
auto icon = QImage::fromData(db->metadata()->customIcon(uuid));
|
||||
auto basePixmap = QPixmap::fromImage(icon.scaled(64, 64, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
|
||||
return QIcon(basePixmap).pixmap(databaseIcons()->iconSize(size));
|
||||
}
|
||||
|
||||
QHash<QUuid, QPixmap> Icons::customIconsPixmaps(const Database* db, IconSize size)
|
||||
{
|
||||
QHash<QUuid, QPixmap> result;
|
||||
|
||||
for (const QUuid& uuid : db->metadata()->customIconsOrder()) {
|
||||
result.insert(uuid, Icons::customIconPixmap(db, uuid, size));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QPixmap Icons::entryIconPixmap(const Entry* entry, IconSize size)
|
||||
{
|
||||
QPixmap icon(size, size);
|
||||
if (entry->iconUuid().isNull()) {
|
||||
icon = databaseIcons()->icon(entry->iconNumber(), size);
|
||||
} else {
|
||||
Q_ASSERT(entry->database());
|
||||
if (entry->database()) {
|
||||
icon = Icons::customIconPixmap(entry->database(), entry->iconUuid(), size);
|
||||
}
|
||||
}
|
||||
|
||||
if (entry->isExpired()) {
|
||||
icon = databaseIcons()->applyBadge(icon, DatabaseIcons::Badges::Expired);
|
||||
}
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
QPixmap Icons::groupIconPixmap(const Group* group, IconSize size)
|
||||
{
|
||||
QPixmap icon(size, size);
|
||||
if (group->iconUuid().isNull()) {
|
||||
icon = databaseIcons()->icon(group->iconNumber(), size);
|
||||
} else {
|
||||
Q_ASSERT(group->database());
|
||||
if (group->database()) {
|
||||
icon = Icons::customIconPixmap(group->database(), group->iconUuid(), size);
|
||||
}
|
||||
}
|
||||
|
||||
if (group->isExpired()) {
|
||||
icon = databaseIcons()->applyBadge(icon, DatabaseIcons::Badges::Expired);
|
||||
}
|
||||
#ifdef WITH_XC_KEESHARE
|
||||
else if (KeeShare::isShared(group)) {
|
||||
icon = KeeShare::indicatorBadge(group, icon);
|
||||
}
|
||||
#endif
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
QString Icons::imageFormatsFilter()
|
||||
{
|
||||
const QList<QByteArray> formats = QImageReader::supportedImageFormats();
|
||||
QStringList formatsStringList;
|
||||
|
||||
for (const QByteArray& format : formats) {
|
||||
for (char codePoint : format) {
|
||||
if (!QChar(codePoint).isLetterOrNumber()) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
formatsStringList.append("*." + QString::fromLatin1(format).toLower());
|
||||
}
|
||||
|
||||
return formatsStringList.join(" ");
|
||||
}
|
||||
|
||||
QByteArray Icons::saveToBytes(const QImage& image)
|
||||
{
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
// TODO: check !icon.save()
|
||||
image.save(&buffer, "PNG");
|
||||
buffer.close();
|
||||
return ba;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue