mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-07-30 10:08:54 -04:00
Add support for foreground and background entry colors
* Add foreground/background color elements to advanced tab * Center paperclip icon
This commit is contained in:
parent
6a85556b33
commit
ca30d1832d
5 changed files with 186 additions and 24 deletions
|
@ -700,7 +700,8 @@ Entry* KdbxXmlReader::parseEntry(bool history)
|
||||||
entry->setIcon(uuid);
|
entry->setIcon(uuid);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}if (m_xml.name() == "ForegroundColor") {
|
}
|
||||||
|
if (m_xml.name() == "ForegroundColor") {
|
||||||
entry->setForegroundColor(readColor());
|
entry->setForegroundColor(readColor());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <QTemporaryFile>
|
#include <QTemporaryFile>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
|
#include <QColorDialog>
|
||||||
|
|
||||||
#include "autotype/AutoType.h"
|
#include "autotype/AutoType.h"
|
||||||
#include "core/Config.h"
|
#include "core/Config.h"
|
||||||
|
@ -156,6 +157,8 @@ void EditEntryWidget::setupAdvanced()
|
||||||
connect(m_advancedUi->attributesView->selectionModel(),
|
connect(m_advancedUi->attributesView->selectionModel(),
|
||||||
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
|
||||||
SLOT(updateCurrentAttribute()));
|
SLOT(updateCurrentAttribute()));
|
||||||
|
connect(m_advancedUi->fgColorButton, SIGNAL(clicked()), SLOT(pickColor()));
|
||||||
|
connect(m_advancedUi->bgColorButton, SIGNAL(clicked()), SLOT(pickColor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditEntryWidget::setupIcon()
|
void EditEntryWidget::setupIcon()
|
||||||
|
@ -593,6 +596,8 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
|
||||||
editTriggers = QAbstractItemView::DoubleClicked;
|
editTriggers = QAbstractItemView::DoubleClicked;
|
||||||
}
|
}
|
||||||
m_advancedUi->attributesView->setEditTriggers(editTriggers);
|
m_advancedUi->attributesView->setEditTriggers(editTriggers);
|
||||||
|
setupColorButton(true, entry->foregroundColor());
|
||||||
|
setupColorButton(false, entry->backgroundColor());
|
||||||
m_iconsWidget->setEnabled(!m_history);
|
m_iconsWidget->setEnabled(!m_history);
|
||||||
m_autoTypeUi->sequenceEdit->setReadOnly(m_history);
|
m_autoTypeUi->sequenceEdit->setReadOnly(m_history);
|
||||||
m_autoTypeUi->windowTitleCombo->lineEdit()->setReadOnly(m_history);
|
m_autoTypeUi->windowTitleCombo->lineEdit()->setReadOnly(m_history);
|
||||||
|
@ -758,27 +763,36 @@ void EditEntryWidget::updateEntryData(Entry* entry) const
|
||||||
|
|
||||||
entry->setNotes(m_mainUi->notesEdit->toPlainText());
|
entry->setNotes(m_mainUi->notesEdit->toPlainText());
|
||||||
|
|
||||||
|
if (m_advancedUi->fgColorCheckBox->isChecked() &&
|
||||||
|
m_advancedUi->fgColorButton->property("color").isValid()) {
|
||||||
|
entry->setForegroundColor(QColor(m_advancedUi->fgColorButton->property("color").toString()));
|
||||||
|
} else {
|
||||||
|
entry->setForegroundColor(QColor());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_advancedUi->bgColorCheckBox->isChecked() &&
|
||||||
|
m_advancedUi->bgColorButton->property("color").isValid()) {
|
||||||
|
entry->setBackgroundColor(QColor(m_advancedUi->bgColorButton->property("color").toString()));
|
||||||
|
} else {
|
||||||
|
entry->setBackgroundColor(QColor());
|
||||||
|
}
|
||||||
|
|
||||||
IconStruct iconStruct = m_iconsWidget->state();
|
IconStruct iconStruct = m_iconsWidget->state();
|
||||||
|
|
||||||
if (iconStruct.number < 0) {
|
if (iconStruct.number < 0) {
|
||||||
entry->setIcon(Entry::DefaultIconNumber);
|
entry->setIcon(Entry::DefaultIconNumber);
|
||||||
}
|
} else if (iconStruct.uuid.isNull()) {
|
||||||
else if (iconStruct.uuid.isNull()) {
|
|
||||||
entry->setIcon(iconStruct.number);
|
entry->setIcon(iconStruct.number);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
entry->setIcon(iconStruct.uuid);
|
entry->setIcon(iconStruct.uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry->setAutoTypeEnabled(m_autoTypeUi->enableButton->isChecked());
|
entry->setAutoTypeEnabled(m_autoTypeUi->enableButton->isChecked());
|
||||||
if (m_autoTypeUi->inheritSequenceButton->isChecked()) {
|
if (m_autoTypeUi->inheritSequenceButton->isChecked()) {
|
||||||
entry->setDefaultAutoTypeSequence(QString());
|
entry->setDefaultAutoTypeSequence(QString());
|
||||||
}
|
} else if (AutoType::verifyAutoTypeSyntax(m_autoTypeUi->sequenceEdit->text())) {
|
||||||
else {
|
|
||||||
if (AutoType::verifyAutoTypeSyntax(m_autoTypeUi->sequenceEdit->text())) {
|
|
||||||
entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text());
|
entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
entry->autoTypeAssociations()->copyDataFrom(m_autoTypeAssoc);
|
entry->autoTypeAssociations()->copyDataFrom(m_autoTypeAssoc);
|
||||||
}
|
}
|
||||||
|
@ -1122,3 +1136,38 @@ QMenu* EditEntryWidget::createPresetsMenu()
|
||||||
expirePresetsMenu->addAction(tr("1 year"))->setData(QVariant::fromValue(TimeDelta::fromYears(1)));
|
expirePresetsMenu->addAction(tr("1 year"))->setData(QVariant::fromValue(TimeDelta::fromYears(1)));
|
||||||
return expirePresetsMenu;
|
return expirePresetsMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditEntryWidget::setupColorButton(bool foreground, QColor color)
|
||||||
|
{
|
||||||
|
QWidget* button = m_advancedUi->fgColorButton;
|
||||||
|
QCheckBox* checkBox = m_advancedUi->fgColorCheckBox;
|
||||||
|
if (!foreground) {
|
||||||
|
button = m_advancedUi->bgColorButton;
|
||||||
|
checkBox = m_advancedUi->bgColorCheckBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (color.isValid()) {
|
||||||
|
button->setStyleSheet(QString("background-color:%1").arg(color.name()));
|
||||||
|
button->setProperty("color", color.name());
|
||||||
|
checkBox->setChecked(true);
|
||||||
|
} else {
|
||||||
|
button->setStyleSheet("");
|
||||||
|
button->setProperty("color", QVariant());
|
||||||
|
checkBox->setChecked(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditEntryWidget::pickColor()
|
||||||
|
{
|
||||||
|
bool isForeground = (sender() == m_advancedUi->fgColorButton);
|
||||||
|
QColor oldColor = QColor(m_advancedUi->fgColorButton->property("color").toString());
|
||||||
|
if (!isForeground) {
|
||||||
|
oldColor = QColor(m_advancedUi->bgColorButton->property("color").toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
QColorDialog colorDialog;
|
||||||
|
QColor newColor = colorDialog.getColor(oldColor);
|
||||||
|
if (newColor.isValid()) {
|
||||||
|
setupColorButton(isForeground, newColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -99,6 +99,7 @@ private slots:
|
||||||
void updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous);
|
void updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous);
|
||||||
void useExpiryPreset(QAction* action);
|
void useExpiryPreset(QAction* action);
|
||||||
void toggleHideNotes(bool visible);
|
void toggleHideNotes(bool visible);
|
||||||
|
void pickColor();
|
||||||
#ifdef WITH_XC_SSHAGENT
|
#ifdef WITH_XC_SSHAGENT
|
||||||
void updateSSHAgent();
|
void updateSSHAgent();
|
||||||
void updateSSHAgentAttachment();
|
void updateSSHAgentAttachment();
|
||||||
|
@ -120,6 +121,7 @@ private:
|
||||||
#endif
|
#endif
|
||||||
void setupProperties();
|
void setupProperties();
|
||||||
void setupHistory();
|
void setupHistory();
|
||||||
|
void setupColorButton(bool foreground, QColor color);
|
||||||
|
|
||||||
bool passwordsEqual();
|
bool passwordsEqual();
|
||||||
void setForms(const Entry* entry, bool restore = false);
|
void setForms(const Entry* entry, bool restore = false);
|
||||||
|
|
|
@ -2,19 +2,15 @@
|
||||||
<ui version="4.0">
|
<ui version="4.0">
|
||||||
<class>EditEntryWidgetAdvanced</class>
|
<class>EditEntryWidgetAdvanced</class>
|
||||||
<widget class="QWidget" name="EditEntryWidgetAdvanced">
|
<widget class="QWidget" name="EditEntryWidgetAdvanced">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>532</width>
|
||||||
|
<height>364</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<property name="leftMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="topMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="rightMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<property name="bottomMargin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="attributesBox">
|
<widget class="QGroupBox" name="attributesBox">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
@ -157,6 +153,96 @@
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="colorsBox" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="fgColorCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Foreground Color:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="fgColorButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>25</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Maximum</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>30</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="bgColorCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Background Color:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="bgColorButton">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>25</width>
|
||||||
|
<height>25</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<property name="flat">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "EntryModel.h"
|
#include "EntryModel.h"
|
||||||
|
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
|
#include <QFontMetrics>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include <QPalette>
|
#include <QPalette>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
@ -263,10 +264,26 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
||||||
font.setStrikeOut(true);
|
font.setStrikeOut(true);
|
||||||
}
|
}
|
||||||
return font;
|
return font;
|
||||||
} else if (role == Qt::TextColorRole) {
|
} else if (role == Qt::ForegroundRole) {
|
||||||
if (entry->hasReferences()) {
|
if (entry->hasReferences()) {
|
||||||
QPalette p;
|
QPalette p;
|
||||||
return QVariant(p.color(QPalette::Active, QPalette::Mid));
|
return QVariant(p.color(QPalette::Active, QPalette::Mid));
|
||||||
|
} else if (entry->foregroundColor().isValid()) {
|
||||||
|
return QVariant(entry->foregroundColor());
|
||||||
|
}
|
||||||
|
} else if (role == Qt::BackgroundRole) {
|
||||||
|
if (entry->backgroundColor().isValid()) {
|
||||||
|
return QVariant(entry->backgroundColor());
|
||||||
|
}
|
||||||
|
} else if (role == Qt::TextAlignmentRole) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -275,7 +292,9 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
|
||||||
|
|
||||||
QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
{
|
{
|
||||||
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
|
Q_UNUSED(orientation);
|
||||||
|
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case ParentGroup:
|
case ParentGroup:
|
||||||
return tr("Group");
|
return tr("Group");
|
||||||
|
@ -302,6 +321,11 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
|
||||||
case Attachments:
|
case Attachments:
|
||||||
return tr("Attachments");
|
return tr("Attachments");
|
||||||
}
|
}
|
||||||
|
} else if (role == Qt::TextAlignmentRole) {
|
||||||
|
switch (section) {
|
||||||
|
case Paperclip:
|
||||||
|
return Qt::AlignCenter;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue