QtPass Developer documentation
QtPass test coverage
Current view: top level - src/qpushbuttonwithclipboard.h Coverage Total Hit
Test: QtPass Lines: 50.0 % 2 1
Test Date: 2026-12-03 23:34:20 Functions: - 0 0

            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 Copy-to-clipboard icon button that carries the text of the field it
       6              :  * sits next to.
       7              :  */
       8              : #ifndef SRC_QPUSHBUTTONWITHCLIPBOARD_H_
       9              : #define SRC_QPUSHBUTTONWITHCLIPBOARD_H_
      10              : 
      11              : #include <QPushButton>
      12              : 
      13              : /**
      14              :  * @class QPushButtonWithClipboard
      15              :  * @ingroup secrets
      16              :  * @brief QPushButton that stores a text payload and emits it when activated.
      17              :  *
      18              :  * The button does not touch the clipboard itself. On activation it briefly
      19              :  * swaps to a "done" icon (reverted after 500 ms) and re-emits
      20              :  * `textClicked(const QString&)` with the stored text; the receiver (normally
      21              :  * `ClipboardManager` via `PasswordDisplayPanel`) performs the copy and the
      22              :  * autoclear bookkeeping.
      23              :  */
      24              : class QWidget;
      25              : class QPushButtonWithClipboard : public QPushButton {
      26          106 :   Q_OBJECT
      27              : 
      28              : public:
      29              :   /**
      30              :    * @brief Construct a QPushButtonWithClipboard with an optional initial text.
      31              :    * @param textToCopy Initial text to store and emit on activation.
      32              :    * @param parent Optional parent widget.
      33              :    */
      34            0 :   explicit QPushButtonWithClipboard(QString textToCopy = "",
      35              :                                     QWidget *parent = nullptr);
      36              : 
      37              :   /**
      38              :    * @brief Return the stored text used for copying.
      39              :    * @return The current stored text.
      40              :    */
      41              :   [[nodiscard]] auto getTextToCopy() const -> QString;
      42              :   /**
      43              :    * @brief Update the stored text used for copying.
      44              :    * @param value The new text to store.
      45              :    */
      46              :   void setTextToCopy(const QString &value);
      47              : 
      48              : signals:
      49              :   /**
      50              :    * @brief Emitted when the button is activated with the stored text. Not
      51              :    * named clicked(): that would hide QAbstractButton::clicked(bool).
      52              :    * @param text The stored text associated with this button.
      53              :    */
      54              :   void textClicked(const QString &text);
      55              : 
      56              : private slots:
      57              :   /**
      58              :    * @brief Restores the default copy icon; fired by a single-shot timer
      59              :    * 500 ms after a click.
      60              :    */
      61              :   void changeIconDefault();
      62              :   /**
      63              :    * @brief Connected to `QPushButton::clicked(bool)`; shows the pushed icon,
      64              :    * arms the revert timer and emits textClicked() with the stored text.
      65              :    * @param checked Unused; the button is not checkable.
      66              :    */
      67              :   void buttonClicked(bool checked);
      68              : 
      69              : private:
      70              :   /** @brief Text handed to receivers on click; set by the owning panel. */
      71              :   QString textToCopy;
      72              :   /** @brief `edit-copy` icon shown at rest. */
      73              :   QIcon iconEdit;
      74              :   /** @brief `document-new` icon flashed for 500 ms after a click. */
      75              :   QIcon iconEditPushed;
      76              : };
      77              : 
      78              : #endif // SRC_QPUSHBUTTONWITHCLIPBOARD_H_
        

Generated by: LCOV version 2.0-1