QtPass Developer documentation
QtPass test coverage
Current view: top level - src/qpushbuttonasqrcode.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 Icon button that asks for a stored secret to be shown as a QR code.
       6              :  */
       7              : #ifndef SRC_QPUSHBUTTONASQRCODE_H_
       8              : #define SRC_QPUSHBUTTONASQRCODE_H_
       9              : 
      10              : #include <QPushButton>
      11              : 
      12              : /**
      13              :  * @class QPushButtonAsQRCode
      14              :  * @ingroup secrets
      15              :  * @brief QPushButton that presents a text payload as a QR code action.
      16              :  *
      17              :  * The button is icon-only (theme icon `qrcode`) and carries the text of the
      18              :  * field it sits next to. It does not render the QR code itself: on activation
      19              :  * it re-emits `clicked(const QString&)` with the stored text. The owning
      20              :  * PasswordDisplayPanel passes that on, and QtPass::showTextAsQRCode() opens
      21              :  * the QR dialog.
      22              :  */
      23              : class QWidget;
      24              : class QPushButtonAsQRCode : public QPushButton {
      25           36 :   Q_OBJECT
      26              : 
      27              : public:
      28              :   /**
      29              :    * @brief Construct a QPushButtonAsQRCode with an optional initial text.
      30              :    * @param textToCopy Initial text stored for QR-code use (may be empty).
      31              :    * @param parent Optional parent widget.
      32              :    */
      33            0 :   explicit QPushButtonAsQRCode(QString textToCopy = "",
      34              :                                QWidget *parent = nullptr);
      35              : 
      36              :   /**
      37              :    * @brief Return the stored text used for QR-code actions.
      38              :    * @return The current stored text.
      39              :    */
      40              :   [[nodiscard]] auto getTextToCopy() const -> QString;
      41              :   /**
      42              :    * @brief Update the stored text used for QR-code actions.
      43              :    * @param value New text to store.
      44              :    */
      45              :   void setTextToCopy(const QString &value);
      46              : 
      47              : signals:
      48              :   /**
      49              :    * @brief Emitted when the button is activated with the current text payload.
      50              :    * @param text The stored text.
      51              :    */
      52              :   void clicked(const QString &text);
      53              : 
      54              : private:
      55              :   /**
      56              :    * @brief Connected to `QPushButton::clicked(bool)`; re-emits the overload
      57              :    * carrying the stored text so receivers do not need to look it up.
      58              :    * @param checked Unused; the button is not checkable.
      59              :    */
      60              :   void buttonClicked(bool checked);
      61              : 
      62              : private:
      63              :   /** @brief Text to be rendered as a QR code; set by the owning panel. */
      64              :   QString textToCopy;
      65              :   /** @brief The `qrcode` icon shown on the button. */
      66              :   QIcon iconEdit;
      67              : };
      68              : 
      69              : #endif // SRC_QPUSHBUTTONASQRCODE_H_
        

Generated by: LCOV version 2.0-1