mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Show Row-Backgroundcolor in a column
Fixes #6553 Allow users to choose to show the entry background color as a column instead of changing the background of the entire row.
This commit is contained in:
parent
1919c23c09
commit
27c5c5d464
@ -3840,6 +3840,10 @@ Error: %1</source>
|
|||||||
<source>Has TOTP</source>
|
<source>Has TOTP</source>
|
||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
|
<message>
|
||||||
|
<source>Background Color</source>
|
||||||
|
<translation type="unfinished"></translation>
|
||||||
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
<name>EntryPreviewWidget</name>
|
<name>EntryPreviewWidget</name>
|
||||||
|
@ -116,7 +116,7 @@ int EntryModel::columnCount(const QModelIndex& parent) const
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 15;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant EntryModel::data(const QModelIndex& index, int role) const
|
QVariant EntryModel::data(const QModelIndex& index, int role) const
|
||||||
@ -230,6 +230,13 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
case Color:
|
||||||
|
QColor backgroundColor;
|
||||||
|
backgroundColor.setNamedColor(entry->backgroundColor());
|
||||||
|
if (backgroundColor.isValid()) {
|
||||||
|
result = "▍";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (role == Qt::UserRole) { // Qt::UserRole is used as sort role, see EntryView::EntryView()
|
} else if (role == Qt::UserRole) { // Qt::UserRole is used as sort role, see EntryView::EntryView()
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
@ -314,6 +321,15 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
|||||||
}
|
}
|
||||||
return font;
|
return font;
|
||||||
} else if (role == Qt::ForegroundRole) {
|
} else if (role == Qt::ForegroundRole) {
|
||||||
|
|
||||||
|
if (index.column() == Color) {
|
||||||
|
QColor backgroundColor;
|
||||||
|
backgroundColor.setNamedColor(entry->backgroundColor());
|
||||||
|
if (backgroundColor.isValid()) {
|
||||||
|
return backgroundColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QColor foregroundColor;
|
QColor foregroundColor;
|
||||||
foregroundColor.setNamedColor(entry->foregroundColor());
|
foregroundColor.setNamedColor(entry->foregroundColor());
|
||||||
if (entry->hasReferences()) {
|
if (entry->hasReferences()) {
|
||||||
@ -327,11 +343,13 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
|||||||
return QVariant(foregroundColor);
|
return QVariant(foregroundColor);
|
||||||
}
|
}
|
||||||
} else if (role == Qt::BackgroundRole) {
|
} else if (role == Qt::BackgroundRole) {
|
||||||
|
if (m_backgroundColorVisible) {
|
||||||
QColor backgroundColor;
|
QColor backgroundColor;
|
||||||
backgroundColor.setNamedColor(entry->backgroundColor());
|
backgroundColor.setNamedColor(entry->backgroundColor());
|
||||||
if (backgroundColor.isValid()) {
|
if (backgroundColor.isValid()) {
|
||||||
return QVariant(backgroundColor);
|
return QVariant(backgroundColor);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (role == Qt::ToolTipRole) {
|
} else if (role == Qt::ToolTipRole) {
|
||||||
if (index.column() == PasswordStrength && !entry->password().isEmpty() && !entry->excludeFromReports()) {
|
if (index.column() == PasswordStrength && !entry->password().isEmpty() && !entry->excludeFromReports()) {
|
||||||
return entry->passwordHealth()->scoreReason();
|
return entry->passwordHealth()->scoreReason();
|
||||||
@ -414,6 +432,8 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
|
|||||||
return tr("Has attachments");
|
return tr("Has attachments");
|
||||||
case Totp:
|
case Totp:
|
||||||
return tr("Has TOTP");
|
return tr("Has TOTP");
|
||||||
|
case Color:
|
||||||
|
return tr("Background Color");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -596,3 +616,7 @@ void EntryModel::makeConnections(const Group* group)
|
|||||||
connect(group, SIGNAL(entryMovedDown()), SLOT(entryMovedDown()));
|
connect(group, SIGNAL(entryMovedDown()), SLOT(entryMovedDown()));
|
||||||
connect(group, SIGNAL(entryDataChanged(Entry*)), SLOT(entryDataChanged(Entry*)));
|
connect(group, SIGNAL(entryDataChanged(Entry*)), SLOT(entryDataChanged(Entry*)));
|
||||||
}
|
}
|
||||||
|
void EntryModel::setBackgroundColorVisible(bool visible)
|
||||||
|
{
|
||||||
|
m_backgroundColorVisible = visible;
|
||||||
|
}
|
||||||
|
@ -48,7 +48,8 @@ public:
|
|||||||
Attachments = 11,
|
Attachments = 11,
|
||||||
Totp = 12,
|
Totp = 12,
|
||||||
Size = 13,
|
Size = 13,
|
||||||
PasswordStrength = 14
|
PasswordStrength = 14,
|
||||||
|
Color = 15
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit EntryModel(QObject* parent = nullptr);
|
explicit EntryModel(QObject* parent = nullptr);
|
||||||
@ -67,6 +68,7 @@ public:
|
|||||||
|
|
||||||
void setGroup(Group* group);
|
void setGroup(Group* group);
|
||||||
void setEntries(const QList<Entry*>& entries);
|
void setEntries(const QList<Entry*>& entries);
|
||||||
|
void setBackgroundColorVisible(bool visible);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void entryAboutToAdd(Entry* entry);
|
void entryAboutToAdd(Entry* entry);
|
||||||
@ -85,6 +87,7 @@ private:
|
|||||||
void severConnections();
|
void severConnections();
|
||||||
void makeConnections(const Group* group);
|
void makeConnections(const Group* group);
|
||||||
|
|
||||||
|
bool m_backgroundColorVisible = true;
|
||||||
Group* m_group;
|
Group* m_group;
|
||||||
QList<Entry*> m_entries;
|
QList<Entry*> m_entries;
|
||||||
QList<Entry*> m_orgEntries;
|
QList<Entry*> m_orgEntries;
|
||||||
|
@ -335,6 +335,7 @@ bool EntryView::setViewState(const QByteArray& state)
|
|||||||
bool status = header()->restoreState(state);
|
bool status = header()->restoreState(state);
|
||||||
resetFixedColumns();
|
resetFixedColumns();
|
||||||
m_columnsNeedRelayout = state.isEmpty();
|
m_columnsNeedRelayout = state.isEmpty();
|
||||||
|
onHeaderChanged();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,6 +376,9 @@ void EntryView::toggleColumnVisibility(QAction* action)
|
|||||||
// least one visible column remains, as the table header will disappear
|
// least one visible column remains, as the table header will disappear
|
||||||
// entirely when all columns are hidden
|
// entirely when all columns are hidden
|
||||||
int columnIndex = action->data().toInt();
|
int columnIndex = action->data().toInt();
|
||||||
|
if (columnIndex == EntryModel::Color) {
|
||||||
|
m_model->setBackgroundColorVisible(!action->isChecked());
|
||||||
|
}
|
||||||
if (action->isChecked()) {
|
if (action->isChecked()) {
|
||||||
header()->showSection(columnIndex);
|
header()->showSection(columnIndex);
|
||||||
if (header()->sectionSize(columnIndex) == 0) {
|
if (header()->sectionSize(columnIndex) == 0) {
|
||||||
@ -446,6 +450,8 @@ void EntryView::resetFixedColumns()
|
|||||||
header()->resizeSection(col, width);
|
header()->resizeSection(col, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
header()->setMinimumSectionSize(1);
|
||||||
|
header()->resizeSection(EntryModel::Color, ICON_ONLY_SECTION_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -474,6 +480,8 @@ void EntryView::resetViewToDefaults()
|
|||||||
header()->hideSection(EntryModel::Attachments);
|
header()->hideSection(EntryModel::Attachments);
|
||||||
header()->hideSection(EntryModel::Size);
|
header()->hideSection(EntryModel::Size);
|
||||||
header()->hideSection(EntryModel::PasswordStrength);
|
header()->hideSection(EntryModel::PasswordStrength);
|
||||||
|
header()->hideSection(EntryModel::Color);
|
||||||
|
onHeaderChanged();
|
||||||
|
|
||||||
// Reset column order to logical indices
|
// Reset column order to logical indices
|
||||||
for (int i = 0; i < header()->count(); ++i) {
|
for (int i = 0; i < header()->count(); ++i) {
|
||||||
@ -501,6 +509,11 @@ void EntryView::resetViewToDefaults()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EntryView::onHeaderChanged()
|
||||||
|
{
|
||||||
|
m_model->setBackgroundColorVisible(isColumnHidden(EntryModel::Color));
|
||||||
|
}
|
||||||
|
|
||||||
void EntryView::showEvent(QShowEvent* event)
|
void EntryView::showEvent(QShowEvent* event)
|
||||||
{
|
{
|
||||||
QTreeView::showEvent(event);
|
QTreeView::showEvent(event);
|
||||||
|
@ -76,6 +76,7 @@ private slots:
|
|||||||
private:
|
private:
|
||||||
void resetFixedColumns();
|
void resetFixedColumns();
|
||||||
bool isColumnHidden(int logicalIndex);
|
bool isColumnHidden(int logicalIndex);
|
||||||
|
void onHeaderChanged();
|
||||||
|
|
||||||
EntryModel* const m_model;
|
EntryModel* const m_model;
|
||||||
SortFilterHideProxyModel* const m_sortModel;
|
SortFilterHideProxyModel* const m_sortModel;
|
||||||
|
@ -313,15 +313,11 @@ void TestEntryModel::testProxyModel()
|
|||||||
|
|
||||||
modelSource->setGroup(db->rootGroup());
|
modelSource->setGroup(db->rootGroup());
|
||||||
|
|
||||||
/**
|
// Test hiding and showing a column
|
||||||
* @author Fonic <https://github.com/fonic>
|
auto columnCount = modelProxy->columnCount();
|
||||||
* Update comparison value of modelProxy->columnCount() to account for
|
|
||||||
* additional columns 'Password', 'Notes', 'Expires', 'Created', 'Modified',
|
|
||||||
* 'Accessed', 'Paperclip', 'Attachments', and TOTP
|
|
||||||
*/
|
|
||||||
QSignalSpy spyColumnRemove(modelProxy, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)));
|
QSignalSpy spyColumnRemove(modelProxy, SIGNAL(columnsAboutToBeRemoved(QModelIndex, int, int)));
|
||||||
modelProxy->hideColumn(0, true);
|
modelProxy->hideColumn(0, true);
|
||||||
QCOMPARE(modelProxy->columnCount(), 14);
|
QCOMPARE(modelProxy->columnCount(), columnCount - 1);
|
||||||
QVERIFY(!spyColumnRemove.isEmpty());
|
QVERIFY(!spyColumnRemove.isEmpty());
|
||||||
|
|
||||||
int oldSpyColumnRemoveSize = spyColumnRemove.size();
|
int oldSpyColumnRemoveSize = spyColumnRemove.size();
|
||||||
@ -335,15 +331,9 @@ void TestEntryModel::testProxyModel()
|
|||||||
entryList << entry;
|
entryList << entry;
|
||||||
modelSource->setEntries(entryList);
|
modelSource->setEntries(entryList);
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Fonic <https://github.com/fonic>
|
|
||||||
* Update comparison value of modelProxy->columnCount() to account for
|
|
||||||
* additional columns 'Password', 'Notes', 'Expires', 'Created', 'Modified',
|
|
||||||
* 'Accessed', 'Paperclip', 'Attachments', and TOTP
|
|
||||||
*/
|
|
||||||
QSignalSpy spyColumnInsert(modelProxy, SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)));
|
QSignalSpy spyColumnInsert(modelProxy, SIGNAL(columnsAboutToBeInserted(QModelIndex, int, int)));
|
||||||
modelProxy->hideColumn(0, false);
|
modelProxy->hideColumn(0, false);
|
||||||
QCOMPARE(modelProxy->columnCount(), 15);
|
QCOMPARE(modelProxy->columnCount(), columnCount);
|
||||||
QVERIFY(!spyColumnInsert.isEmpty());
|
QVERIFY(!spyColumnInsert.isEmpty());
|
||||||
|
|
||||||
int oldSpyColumnInsertSize = spyColumnInsert.size();
|
int oldSpyColumnInsertSize = spyColumnInsert.size();
|
||||||
|
Loading…
Reference in New Issue
Block a user