diff options
author | Anne Jan Brouwer <brouwer@annejan.com> | 2023-01-28 20:03:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-28 20:03:42 +0100 |
commit | bc2c04c6f2e3fcdecc36221d393aa2f253df5790 (patch) | |
tree | e12932f5364ac24fbdadd3ff4972533a4ac5f040 /src | |
parent | 00eac1e33d3e895eaeb5fcb685680579c6584893 (diff) | |
parent | c384deefa1172d8e42b1049163e3abcd8de36a2d (diff) |
Merge pull request #587 from l3u/display_options
Add more options for the password displaying
Diffstat (limited to 'src')
-rw-r--r-- | src/configdialog.cpp | 6 | ||||
-rw-r--r-- | src/configdialog.ui | 40 | ||||
-rw-r--r-- | src/mainwindow.cpp | 29 | ||||
-rw-r--r-- | src/qtpasssettings.cpp | 27 | ||||
-rw-r--r-- | src/qtpasssettings.h | 9 | ||||
-rw-r--r-- | src/settingsconstants.cpp | 3 | ||||
-rw-r--r-- | src/settingsconstants.h | 3 |
7 files changed, 113 insertions, 4 deletions
diff --git a/src/configdialog.cpp b/src/configdialog.cpp index ecdeeb83..4a711b03 100644 --- a/src/configdialog.cpp +++ b/src/configdialog.cpp @@ -37,6 +37,9 @@ ConfigDialog::ConfigDialog(MainWindow *parent) QtPassSettings::getAutoclearPanelSeconds()); ui->checkBoxHidePassword->setChecked(QtPassSettings::isHidePassword()); ui->checkBoxHideContent->setChecked(QtPassSettings::isHideContent()); + ui->checkBoxUseMonospace->setChecked(QtPassSettings::isUseMonospace()); + ui->checkBoxDisplayAsIs->setChecked(QtPassSettings::isDisplayAsIs()); + ui->checkBoxNoLineWrapping->setChecked(QtPassSettings::isNoLineWrapping()); ui->checkBoxAddGPGId->setChecked(QtPassSettings::isAddGPGId(true)); if (QSystemTrayIcon::isSystemTrayAvailable()) { @@ -203,6 +206,9 @@ void ConfigDialog::on_accepted() { ui->spinBoxAutoclearPanelSeconds->value()); QtPassSettings::setHidePassword(ui->checkBoxHidePassword->isChecked()); QtPassSettings::setHideContent(ui->checkBoxHideContent->isChecked()); + QtPassSettings::setUseMonospace(ui->checkBoxUseMonospace->isChecked()); + QtPassSettings::setDisplayAsIs(ui->checkBoxDisplayAsIs->isChecked()); + QtPassSettings::setNoLineWrapping(ui->checkBoxNoLineWrapping->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..874bbb3f 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,44 @@ </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> + <widget class="QCheckBox" name="checkBoxDisplayAsIs"> + <property name="text"> + <string>Display the files content as-is</string> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBoxNoLineWrapping"> + <property name="text"> + <string>No line wrapping</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 bc359f06..53469272 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -87,6 +87,12 @@ MainWindow::MainWindow(const QString &searchText, QWidget *parent) connect(ui->treeView, &DeselectableTreeView::emptyClicked, this, &MainWindow::deselect); + if (QtPassSettings::isUseMonospace()) { + ui->textBrowser->setFont(QFont(QStringLiteral("Monospace"))); + } + if (QtPassSettings::isNoLineWrapping()) { + ui->textBrowser->setLineWrapMode(QTextBrowser::NoWrap); + } ui->textBrowser->setOpenExternalLinks(true); ui->textBrowser->setContextMenuPolicy(Qt::CustomContextMenu); connect(ui->textBrowser, &QWidget::customContextMenuRequested, this, @@ -239,6 +245,19 @@ 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()); + } + // Update the textBrowser line wrap mode + if (QtPassSettings::isNoLineWrapping()) { + ui->textBrowser->setLineWrapMode(QTextBrowser::NoWrap); + } else { + ui->textBrowser->setLineWrapMode(QTextBrowser::WidgetWidth); + } + if (QtPassSettings::isAlwaysOnTop()) { Qt::WindowFlags flags = windowFlags(); this->setWindowFlags(flags | Qt::WindowStaysOnTopHint); @@ -385,7 +404,7 @@ void MainWindow::passShowHandler(const QString &p_output) { // show what is needed: if (QtPassSettings::isHideContent()) { output = "***" + tr("Content hidden") + "***"; - } else { + } else if (! QtPassSettings::isDisplayAsIs()) { if (!password.isEmpty()) { // set the password, it is hidden if needed in addToGridLayout addToGridLayout(0, tr("Password"), password); @@ -1099,13 +1118,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 = @@ -1129,7 +1152,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..b32a6525 100644 --- a/src/qtpasssettings.cpp +++ b/src/qtpasssettings.cpp @@ -242,6 +242,33 @@ 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::isDisplayAsIs(const bool &defaultValue) { + return getInstance() + ->value(SettingsConstants::displayAsIs, defaultValue) + .toBool(); +} +void QtPassSettings::setDisplayAsIs(const bool &displayAsIs) { + getInstance()->setValue(SettingsConstants::displayAsIs, displayAsIs); +} + +bool QtPassSettings::isNoLineWrapping(const bool &defaultValue) { + return getInstance() + ->value(SettingsConstants::noLineWrapping, defaultValue) + .toBool(); +} +void QtPassSettings::setNoLineWrapping(const bool &noLineWrapping) { + getInstance()->setValue(SettingsConstants::noLineWrapping, noLineWrapping); +} + bool QtPassSettings::isAddGPGId(const bool &defaultValue) { return getInstance() ->value(SettingsConstants::addGPGId, defaultValue) diff --git a/src/qtpasssettings.h b/src/qtpasssettings.h index 74532233..e3d5b3f0 100644 --- a/src/qtpasssettings.h +++ b/src/qtpasssettings.h @@ -92,6 +92,15 @@ 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 &useMonospace); + + static bool isDisplayAsIs(const bool &defaultValue = QVariant().toBool()); + static void setDisplayAsIs(const bool &displayAsIs); + + static bool isNoLineWrapping(const bool &defaultValue = QVariant().toBool()); + static void setNoLineWrapping(const bool &noLineWrapping); + 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..863d110f 100644 --- a/src/settingsconstants.cpp +++ b/src/settingsconstants.cpp @@ -27,6 +27,9 @@ const QString SettingsConstants::autoclearPanelSeconds = "autoclearPanelSeconds"; const QString SettingsConstants::hidePassword = "hidePassword"; const QString SettingsConstants::hideContent = "hideContent"; +const QString SettingsConstants::useMonospace = "useMonospace"; +const QString SettingsConstants::displayAsIs = "displayAsIs"; +const QString SettingsConstants::noLineWrapping = "noLineWrapping"; 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..bb237ab3 100644 --- a/src/settingsconstants.h +++ b/src/settingsconstants.h @@ -26,6 +26,9 @@ public: const static QString autoclearPanelSeconds; const static QString hidePassword; const static QString hideContent; + const static QString useMonospace; + const static QString displayAsIs; + const static QString noLineWrapping; const static QString addGPGId; const static QString passStore; const static QString passExecutable; |