Add support for foreground and background entry colors

* Add foreground/background color elements to advanced tab
* Center paperclip icon
This commit is contained in:
Jonathan White 2018-02-19 14:59:04 -05:00 committed by Janek Bevendorff
parent 6a85556b33
commit ca30d1832d
5 changed files with 186 additions and 24 deletions

View File

@ -700,7 +700,8 @@ Entry* KdbxXmlReader::parseEntry(bool history)
entry->setIcon(uuid);
}
continue;
}if (m_xml.name() == "ForegroundColor") {
}
if (m_xml.name() == "ForegroundColor") {
entry->setForegroundColor(readColor());
continue;
}

View File

@ -31,6 +31,7 @@
#include <QTemporaryFile>
#include <QMimeData>
#include <QEvent>
#include <QColorDialog>
#include "autotype/AutoType.h"
#include "core/Config.h"
@ -156,6 +157,8 @@ void EditEntryWidget::setupAdvanced()
connect(m_advancedUi->attributesView->selectionModel(),
SIGNAL(currentChanged(QModelIndex,QModelIndex)),
SLOT(updateCurrentAttribute()));
connect(m_advancedUi->fgColorButton, SIGNAL(clicked()), SLOT(pickColor()));
connect(m_advancedUi->bgColorButton, SIGNAL(clicked()), SLOT(pickColor()));
}
void EditEntryWidget::setupIcon()
@ -593,6 +596,8 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
editTriggers = QAbstractItemView::DoubleClicked;
}
m_advancedUi->attributesView->setEditTriggers(editTriggers);
setupColorButton(true, entry->foregroundColor());
setupColorButton(false, entry->backgroundColor());
m_iconsWidget->setEnabled(!m_history);
m_autoTypeUi->sequenceEdit->setReadOnly(m_history);
m_autoTypeUi->windowTitleCombo->lineEdit()->setReadOnly(m_history);
@ -758,26 +763,35 @@ void EditEntryWidget::updateEntryData(Entry* entry) const
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();
if (iconStruct.number < 0) {
entry->setIcon(Entry::DefaultIconNumber);
}
else if (iconStruct.uuid.isNull()) {
} else if (iconStruct.uuid.isNull()) {
entry->setIcon(iconStruct.number);
}
else {
} else {
entry->setIcon(iconStruct.uuid);
}
entry->setAutoTypeEnabled(m_autoTypeUi->enableButton->isChecked());
if (m_autoTypeUi->inheritSequenceButton->isChecked()) {
entry->setDefaultAutoTypeSequence(QString());
}
else {
if (AutoType::verifyAutoTypeSyntax(m_autoTypeUi->sequenceEdit->text())) {
entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text());
}
} else if (AutoType::verifyAutoTypeSyntax(m_autoTypeUi->sequenceEdit->text())) {
entry->setDefaultAutoTypeSequence(m_autoTypeUi->sequenceEdit->text());
}
entry->autoTypeAssociations()->copyDataFrom(m_autoTypeAssoc);
@ -1122,3 +1136,38 @@ QMenu* EditEntryWidget::createPresetsMenu()
expirePresetsMenu->addAction(tr("1 year"))->setData(QVariant::fromValue(TimeDelta::fromYears(1)));
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);
}
}

View File

@ -99,6 +99,7 @@ private slots:
void updateHistoryButtons(const QModelIndex& current, const QModelIndex& previous);
void useExpiryPreset(QAction* action);
void toggleHideNotes(bool visible);
void pickColor();
#ifdef WITH_XC_SSHAGENT
void updateSSHAgent();
void updateSSHAgentAttachment();
@ -120,6 +121,7 @@ private:
#endif
void setupProperties();
void setupHistory();
void setupColorButton(bool foreground, QColor color);
bool passwordsEqual();
void setForms(const Entry* entry, bool restore = false);

View File

@ -2,19 +2,15 @@
<ui version="4.0">
<class>EditEntryWidgetAdvanced</class>
<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">
<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>
<widget class="QGroupBox" name="attributesBox">
<property name="title">
@ -157,6 +153,96 @@
</layout>
</widget>
</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>
</widget>
<customwidgets>

View File

@ -18,6 +18,7 @@
#include "EntryModel.h"
#include <QFont>
#include <QFontMetrics>
#include <QMimeData>
#include <QPalette>
#include <QDateTime>
@ -263,10 +264,26 @@ QVariant EntryModel::data(const QModelIndex& index, int role) const
font.setStrikeOut(true);
}
return font;
} else if (role == Qt::TextColorRole) {
} else if (role == Qt::ForegroundRole) {
if (entry->hasReferences()) {
QPalette p;
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
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
Q_UNUSED(orientation);
if (role == Qt::DisplayRole) {
switch (section) {
case ParentGroup:
return tr("Group");
@ -302,6 +321,11 @@ QVariant EntryModel::headerData(int section, Qt::Orientation orientation, int ro
case Attachments:
return tr("Attachments");
}
} else if (role == Qt::TextAlignmentRole) {
switch (section) {
case Paperclip:
return Qt::AlignCenter;
}
}
return QVariant();