QtPass Developer documentation
QtPass test coverage
Current view: top level - src/qpushbuttonshowpassword.cpp (source / functions) Coverage Total Hit
Test: QtPass Lines: 100.0 % 24 24
Test Date: 2026-11-14 13:19:18 Functions: 100.0 % 2 2

            Line data    Source code
       1              : // SPDX-FileCopyrightText: 2020 Anne Jan Brouwer
       2              : // SPDX-License-Identifier: GPL-3.0-or-later
       3              : /**
       4              :  * @file
       5              :  * @brief Implements QPushButtonShowPassword: the echo-mode toggle and the
       6              :  * matching icon and tooltip swap.
       7              :  */
       8              : #include "qpushbuttonshowpassword.h"
       9              : #include <QTimer>
      10              : 
      11           20 : QPushButtonShowPassword::QPushButtonShowPassword(QLineEdit *line,
      12           20 :                                                  QWidget *parent)
      13              :     : QPushButton(parent),
      14           40 :       iconEdit(QIcon::fromTheme("view-visible", QIcon(":/icons/view.svg"))),
      15           20 :       iconEditPushed(
      16           60 :           QIcon::fromTheme("view-hidden", QIcon(":/icons/hide.svg"))) {
      17           20 :   setIcon(iconEdit);
      18              :   // Icon-only: give screen readers and hovering users a name.
      19           40 :   setToolTip(tr("Show password"));
      20           20 :   setAccessibleName(tr("Show password"));
      21           20 :   setForegroundRole(QPalette::ButtonText);
      22           20 :   connect(this, &QPushButton::clicked, this,
      23           20 :           &QPushButtonShowPassword::buttonClicked);
      24           20 :   this->line = line;
      25           20 : }
      26              : 
      27            5 : void QPushButtonShowPassword::buttonClicked(bool /*unused*/) {
      28            5 :   if (this->line->echoMode() == QLineEdit::Password) {
      29            3 :     this->line->setEchoMode(QLineEdit::Normal);
      30            3 :     setIcon(iconEditPushed);
      31            6 :     setToolTip(tr("Hide password"));
      32            6 :     setAccessibleName(tr("Hide password"));
      33              :   } else {
      34            2 :     this->line->setEchoMode(QLineEdit::Password);
      35            2 :     setIcon(iconEdit);
      36            4 :     setToolTip(tr("Show password"));
      37            4 :     setAccessibleName(tr("Show password"));
      38              :   }
      39            5 : }
        

Generated by: LCOV version 2.0-1