QtPass Developer documentation
QtPass test coverage
Current view: top level - src/qpushbuttonwithclipboard.cpp (source / functions) Coverage Total Hit
Test: QtPass Lines: 95.7 % 23 22
Test Date: 2026-12-03 23:34:20 Functions: 80.0 % 5 4
Branches: 100.0 % 4 4

             Branch data     Line data    Source code
       1                 :             : // SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
       2                 :             : // SPDX-License-Identifier: GPL-3.0-or-later
       3                 :             : /**
       4                 :             :  * @file
       5                 :             :  * @brief Implements QPushButtonWithClipboard: click re-emit and the 500 ms
       6                 :             :  * icon flash.
       7                 :             :  */
       8                 :             : #include "qpushbuttonwithclipboard.h"
       9                 :             : #include <QTimer>
      10                 :             : #include <utility>
      11                 :             : 
      12                 :          53 : QPushButtonWithClipboard::QPushButtonWithClipboard(QString textToCopy,
      13                 :          53 :                                                    QWidget *parent)
      14                 :             :     : QPushButton(parent), textToCopy(std::move(textToCopy)),
      15                 :         106 :       iconEdit(QIcon::fromTheme("edit-copy", QIcon(":/icons/edit-copy.svg"))),
      16                 :          53 :       iconEditPushed(
      17   [ +  +  +  + ]:         159 :           QIcon::fromTheme("document-new", QIcon(":/icons/document-new.svg"))) {
      18                 :          53 :   setIcon(iconEdit);
      19                 :             :   // Icon-only: give screen readers and hovering users a name.
      20                 :         106 :   setToolTip(tr("Copy to clipboard"));
      21                 :          53 :   setAccessibleName(tr("Copy to clipboard"));
      22                 :          53 :   setForegroundRole(QPalette::ButtonText);
      23                 :          53 :   connect(this, &QPushButton::clicked, this,
      24                 :          53 :           &QPushButtonWithClipboard::buttonClicked);
      25                 :          53 : }
      26                 :             : 
      27                 :          32 : auto QPushButtonWithClipboard::getTextToCopy() const -> QString {
      28                 :          32 :   return textToCopy;
      29                 :             : }
      30                 :             : 
      31                 :          15 : void QPushButtonWithClipboard::setTextToCopy(const QString &value) {
      32                 :          15 :   textToCopy = value;
      33                 :          15 : }
      34                 :             : 
      35                 :           4 : void QPushButtonWithClipboard::buttonClicked(bool /*unused*/) {
      36                 :           4 :   setIcon(iconEditPushed);
      37                 :           4 :   QTimer::singleShot(500, this, &QPushButtonWithClipboard::changeIconDefault);
      38                 :           4 :   emit textClicked(textToCopy);
      39                 :           4 : }
      40                 :             : 
      41                 :           0 : void QPushButtonWithClipboard::changeIconDefault() { setIcon(iconEdit); }
        

Generated by: LCOV version 2.0-1