diff options
author | Tobias Leupold <tl@l3u.de> | 2022-02-19 15:13:33 +0100 |
---|---|---|
committer | Tobias Leupold <tl@l3u.de> | 2022-02-19 15:13:33 +0100 |
commit | 6d470ce651c780279df0944bc3b4c470c3a4dd9a (patch) | |
tree | 81dfd9e7291e77bc909c55491a325feae7af1aef | |
parent | 89e759b9b141c2f2cf670eea4194222201c8ff2b (diff) |
Allow setting a monospace font for displaying pass files
-rw-r--r-- | src/configdialog.cpp | 2 | ||||
-rw-r--r-- | src/configdialog.ui | 26 | ||||
-rw-r--r-- | src/mainwindow.cpp | 18 | ||||
-rw-r--r-- | src/qtpasssettings.cpp | 9 | ||||
-rw-r--r-- | src/qtpasssettings.h | 3 | ||||
-rw-r--r-- | src/settingsconstants.cpp | 1 | ||||
-rw-r--r-- | src/settingsconstants.h | 1 |
7 files changed, 57 insertions, 3 deletions
diff --git a/src/configdialog.cpp b/src/configdialog.cpp index ecdeeb83..28d8d5a1 100644 --- a/src/configdialog.cpp +++ b/src/configdialog.cpp @@ -37,6 +37,7 @@ ConfigDialog::ConfigDialog(MainWindow *parent) QtPassSettings::getAutoclearPanelSeconds()); ui->checkBoxHidePassword->setChecked(QtPassSettings::isHidePassword()); ui->checkBoxHideContent->setChecked(QtPassSettings::isHideContent()); + ui->checkBoxUseMonospace->setChecked(QtPassSettings::isUseMonospace()); ui->checkBoxAddGPGId->setChecked(QtPassSettings::isAddGPGId(true)); if (QSystemTrayIcon::isSystemTrayAvailable()) { @@ -203,6 +204,7 @@ void ConfigDialog::on_accepted() { ui->spinBoxAutoclearPanelSeconds->value()); QtPassSettings::setHidePassword(ui->checkBoxHidePassword->isChecked()); QtPassSettings::setHideContent(ui->checkBoxHideContent->isChecked()); + QtPassSettings::setUseMonospace(ui->checkBoxUseMonospace->isChecked()); QtPassSettings::setAddGPGId(ui->checkBoxAddGPGId->isChecked()); QtPassSettings::setUseTrayIcon(ui->checkBoxUseTrayIcon->isEnabled() && ui->checkBoxUseTrayIcon->isChecked()); diff --git a/src/configdialog.ui b/src/configdialog.ui index 939fd54d..02ef9bc0 100644 --- a/src/configdialog.ui +++ b/src/configdialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>659</width> - <height>650</height> + <height>728</height> </rect> </property> <property name="sizePolicy"> @@ -212,6 +212,30 @@ </item> </layout> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_19"> + <item> + <widget class="QCheckBox" name="checkBoxUseMonospace"> + <property name="text"> + <string>Use a monospace font</string> + </property> + </widget> + </item> + <item> + <spacer name="horizontalSpacer_9"> + <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> + </item> </layout> </item> <item> diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d792c6ed..c715df35 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -87,6 +87,9 @@ MainWindow::MainWindow(const QString &searchText, QWidget *parent) connect(ui->treeView, &DeselectableTreeView::emptyClicked, this, &MainWindow::deselect); + if (QtPassSettings::isUseMonospace()) { + ui->textBrowser->setFont(QFont(QStringLiteral("Monospace"))); + } ui->textBrowser->setOpenExternalLinks(true); ui->textBrowser->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->textBrowser, &QWidget::customContextMenuRequested, this, @@ -239,6 +242,13 @@ void MainWindow::config() { d->wizard(); // does shit if (d->exec()) { if (d->result() == QDialog::Accepted) { + // Update the textBrowser font + if (QtPassSettings::isUseMonospace()) { + ui->textBrowser->setFont(QFont(QStringLiteral("Monospace"))); + } else { + ui->textBrowser->setFont(QFont()); + } + if (QtPassSettings::isAlwaysOnTop()) { Qt::WindowFlags flags = windowFlags(); this->setWindowFlags(flags | Qt::WindowStaysOnTopHint); @@ -1098,13 +1108,17 @@ void MainWindow::addToGridLayout(int position, const QString &field, } // set the echo mode to password, if the field is "password" + const QString lineStyle = QtPassSettings::isUseMonospace() + ? "border-style: none; background: transparent; font-family: monospace;" + : "border-style: none; background: transparent;"; + if (QtPassSettings::isHidePassword() && trimmedField == tr("Password")) { auto *line = new QLineEdit(); line->setObjectName(trimmedField); line->setText(trimmedValue); line->setReadOnly(true); - line->setStyleSheet("border-style: none ; background: transparent;"); + line->setStyleSheet(lineStyle); line->setContentsMargins(0, 0, 0, 0); line->setEchoMode(QLineEdit::Password); QPushButtonShowPassword *showButton = @@ -1128,7 +1142,7 @@ void MainWindow::addToGridLayout(int position, const QString &field, R"(<a href="\1">\1</a>)"); line->setText(trimmedValue); line->setReadOnly(true); - line->setStyleSheet("border-style: none ; background: transparent;"); + line->setStyleSheet(lineStyle); line->setContentsMargins(0, 0, 0, 0); frame->layout()->addWidget(line); } diff --git a/src/qtpasssettings.cpp b/src/qtpasssettings.cpp index 20d7b5cb..57fe4415 100644 --- a/src/qtpasssettings.cpp +++ b/src/qtpasssettings.cpp @@ -242,6 +242,15 @@ void QtPassSettings::setHideContent(const bool &hideContent) { getInstance()->setValue(SettingsConstants::hideContent, hideContent); } +bool QtPassSettings::isUseMonospace(const bool &defaultValue) { + return getInstance() + ->value(SettingsConstants::useMonospace, defaultValue) + .toBool(); +} +void QtPassSettings::setUseMonospace(const bool &useMonospace) { + getInstance()->setValue(SettingsConstants::useMonospace, useMonospace); +} + bool QtPassSettings::isAddGPGId(const bool &defaultValue) { return getInstance() ->value(SettingsConstants::addGPGId, defaultValue) diff --git a/src/qtpasssettings.h b/src/qtpasssettings.h index 74532233..46667c9e 100644 --- a/src/qtpasssettings.h +++ b/src/qtpasssettings.h @@ -92,6 +92,9 @@ public: static bool isHideContent(const bool &defaultValue = QVariant().toBool()); static void setHideContent(const bool &hideContent); + static bool isUseMonospace(const bool &defaultValue = QVariant().toBool()); + static void setUseMonospace(const bool &hideContent); + static bool isAddGPGId(const bool &defaultValue = QVariant().toBool()); static void setAddGPGId(const bool &addGPGId); diff --git a/src/settingsconstants.cpp b/src/settingsconstants.cpp index 7b6ed696..2def87c5 100644 --- a/src/settingsconstants.cpp +++ b/src/settingsconstants.cpp @@ -27,6 +27,7 @@ const QString SettingsConstants::autoclearPanelSeconds = "autoclearPanelSeconds"; const QString SettingsConstants::hidePassword = "hidePassword"; const QString SettingsConstants::hideContent = "hideContent"; +const QString SettingsConstants::useMonospace = "useMonospace"; const QString SettingsConstants::addGPGId = "addGPGId"; const QString SettingsConstants::passStore = "passStore"; const QString SettingsConstants::passExecutable = "passExecutable"; diff --git a/src/settingsconstants.h b/src/settingsconstants.h index bb43fb55..b5847fe4 100644 --- a/src/settingsconstants.h +++ b/src/settingsconstants.h @@ -26,6 +26,7 @@ public: const static QString autoclearPanelSeconds; const static QString hidePassword; const static QString hideContent; + const static QString useMonospace; const static QString addGPGId; const static QString passStore; const static QString passExecutable; |