Convert from unicode to image based paperclip

This commit is contained in:
Jonathan White 2018-02-22 23:19:26 -05:00 committed by Janek Bevendorff
parent 8c4df37062
commit fd71b4a22e
7 changed files with 23 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

View File

@ -22,12 +22,14 @@
#include <QMimeData>
#include <QPalette>
#include <QDateTime>
#include <QPainter>
#include "core/DatabaseIcons.h"
#include "core/Entry.h"
#include "core/Global.h"
#include "core/Group.h"
#include "core/Metadata.h"
#include "core/FilePath.h"
// String being displayed when hiding content
const QString EntryModel::HiddenContentDisplay(QString("\u25cf").repeated(6));
@ -35,15 +37,17 @@ const QString EntryModel::HiddenContentDisplay(QString("\u25cf").repeated(6));
// Format used to display dates
const Qt::DateFormat EntryModel::DateFormat = Qt::DefaultLocaleShortDate;
// Paperclip symbol
const QString EntryModel::PaperClipDisplay("\U0001f4ce");
EntryModel::EntryModel(QObject* parent)
: QAbstractTableModel(parent)
, m_group(nullptr)
, m_hideUsernames(false)
, m_hidePasswords(true)
, m_paperClipPixmap(FilePath::instance()->icon("actions", "paperclip").pixmap(16))
, m_paperClipPixmapCentered(24, 16)
{
m_paperClipPixmapCentered.fill(Qt::transparent);
QPainter painter(&m_paperClipPixmapCentered);
painter.drawPixmap(8, 0, m_paperClipPixmap);
}
Entry* EntryModel::entryFromIndex(const QModelIndex& index) const
@ -205,9 +209,6 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
case Accessed:
result = entry->timeInfo().lastAccessTime().toLocalTime().toString(EntryModel::DateFormat);
return result;
case Paperclip:
result = entry->attachments()->keys().isEmpty() ? QString() : EntryModel::PaperClipDisplay;
return result;
case Attachments:
// Display comma-separated list of attachments
QList<QString> attachments = entry->attachments()->keys();
@ -238,7 +239,7 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
case Paperclip:
// Display entries with attachments above those without when
// sorting ascendingly (and vice versa when sorting descendingly)
return entry->attachments()->keys().isEmpty() ? 1 : 0;
return entry->attachments()->isEmpty() ? 1 : 0;
default:
// For all other columns, simply use data provided by Qt::Display-
// Role for sorting
@ -257,6 +258,10 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
} else {
return entry->iconScaledPixmap();
}
case Paperclip:
if (!entry->attachments()->isEmpty()) {
return m_paperClipPixmapCentered;
}
}
} else if (role == Qt::FontRole) {
QFont font;
@ -279,12 +284,6 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
if (index.column() == Paperclip) {
return Qt::AlignCenter;
}
} else if (role == Qt::SizeHintRole) {
if (index.column() == Paperclip) {
QFont font;
QFontMetrics fm(font);
return fm.width(PaperClipDisplay) / 2;
}
}
return QVariant();
@ -316,15 +315,12 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
return tr("Modified");
case Accessed:
return tr("Accessed");
case Paperclip:
return EntryModel::PaperClipDisplay;
case Attachments:
return tr("Attachments");
}
} else if (role == Qt::TextAlignmentRole) {
switch (section) {
case Paperclip:
return Qt::AlignCenter;
} else if (role == Qt::DecorationRole) {
if (section == Paperclip) {
return m_paperClipPixmap;
}
}

View File

@ -19,6 +19,7 @@
#define KEEPASSX_ENTRYMODEL_H
#include <QAbstractTableModel>
#include <QPixmap>
class Entry;
class Group;
@ -95,9 +96,11 @@ private:
bool m_hideUsernames;
bool m_hidePasswords;
QPixmap m_paperClipPixmap;
QPixmap m_paperClipPixmapCentered;
static const QString HiddenContentDisplay;
static const Qt::DateFormat DateFormat;
static const QString PaperClipDisplay;
};
#endif // KEEPASSX_ENTRYMODEL_H

View File

@ -72,6 +72,10 @@ EntryView::EntryView(QWidget* parent)
m_columnActions->setExclusive(false);
for (int columnIndex = 1; columnIndex < header()->count(); ++columnIndex) {
QString caption = m_model->headerData(columnIndex, Qt::Horizontal, Qt::DisplayRole).toString();
if (columnIndex == EntryModel::Paperclip) {
caption = tr("Attachments (icon)");
}
QAction* action = m_headerMenu->addAction(caption);
action->setCheckable(true);
action->setData(columnIndex);