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-11-14 13:19:18 Functions: 80.0 % 5 4

            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           39 : QPushButtonWithClipboard::QPushButtonWithClipboard(QString textToCopy,
      13           39 :                                                    QWidget *parent)
      14              :     : QPushButton(parent), textToCopy(std::move(textToCopy)),
      15           78 :       iconEdit(QIcon::fromTheme("edit-copy", QIcon(":/icons/edit-copy.svg"))),
      16           39 :       iconEditPushed(
      17          117 :           QIcon::fromTheme("document-new", QIcon(":/icons/document-new.svg"))) {
      18           39 :   setIcon(iconEdit);
      19              :   // Icon-only: give screen readers and hovering users a name.
      20           78 :   setToolTip(tr("Copy to clipboard"));
      21           39 :   setAccessibleName(tr("Copy to clipboard"));
      22           39 :   setForegroundRole(QPalette::ButtonText);
      23           39 :   connect(this, &QPushButton::clicked, this,
      24           39 :           &QPushButtonWithClipboard::buttonClicked);
      25           39 : }
      26              : 
      27            9 : auto QPushButtonWithClipboard::getTextToCopy() const -> QString {
      28            9 :   return textToCopy;
      29              : }
      30              : 
      31           11 : void QPushButtonWithClipboard::setTextToCopy(const QString &value) {
      32           11 :   textToCopy = value;
      33           11 : }
      34              : 
      35            4 : void QPushButtonWithClipboard::buttonClicked(bool /*unused*/) {
      36            4 :   setIcon(iconEditPushed);
      37            4 :   QTimer::singleShot(500, this, &QPushButtonWithClipboard::changeIconDefault);
      38            4 :   emit clicked(textToCopy);
      39            4 : }
      40              : 
      41            0 : void QPushButtonWithClipboard::changeIconDefault() { setIcon(iconEdit); }
        

Generated by: LCOV version 2.0-1