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-11-14 13:19:18 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              :  * `clicked(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           78 :   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.
      51              :    * @param text The stored text associated with this button.
      52              :    */
      53              :   void clicked(const QString &text);
      54              : 
      55              : private slots:
      56              :   /**
      57              :    * @brief Restores the default copy icon; fired by a single-shot timer
      58              :    * 500 ms after a click.
      59              :    */
      60              :   void changeIconDefault();
      61              :   /**
      62              :    * @brief Connected to `QPushButton::clicked(bool)`; shows the pushed icon,
      63              :    * arms the revert timer and re-emits `clicked` with the stored text.
      64              :    * @param checked Unused; the button is not checkable.
      65              :    */
      66              :   void buttonClicked(bool checked);
      67              : 
      68              : private:
      69              :   /** @brief Text handed to receivers on click; set by the owning panel. */
      70              :   QString textToCopy;
      71              :   /** @brief `edit-copy` icon shown at rest. */
      72              :   QIcon iconEdit;
      73              :   /** @brief `document-new` icon flashed for 500 ms after a click. */
      74              :   QIcon iconEditPushed;
      75              : };
      76              : 
      77              : #endif // SRC_QPUSHBUTTONWITHCLIPBOARD_H_
        

Generated by: LCOV version 2.0-1