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-12-03 23:34:20 Functions: 100.0 % 2 2
Branches: 100.0 % 6 6

             Branch data     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                 :          24 : QPushButtonShowPassword::QPushButtonShowPassword(QLineEdit *line,
      12                 :          24 :                                                  QWidget *parent)
      13                 :             :     : QPushButton(parent),
      14                 :          48 :       iconEdit(QIcon::fromTheme("view-visible", QIcon(":/icons/view.svg"))),
      15                 :          24 :       iconEditPushed(
      16   [ +  +  +  + ]:          72 :           QIcon::fromTheme("view-hidden", QIcon(":/icons/hide.svg"))) {
      17                 :          24 :   setIcon(iconEdit);
      18                 :             :   // Icon-only: give screen readers and hovering users a name.
      19                 :          48 :   setToolTip(tr("Show password"));
      20                 :          24 :   setAccessibleName(tr("Show password"));
      21                 :          24 :   setForegroundRole(QPalette::ButtonText);
      22                 :          24 :   connect(this, &QPushButton::clicked, this,
      23                 :          24 :           &QPushButtonShowPassword::buttonClicked);
      24                 :          24 :   this->line = line;
      25                 :          24 : }
      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