QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
qpushbuttonwithclipboard.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2016 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
9#include <QTimer>
10#include <utility>
11
13 QWidget *parent)
14 : QPushButton(parent), textToCopy(std::move(textToCopy)),
15 iconEdit(QIcon::fromTheme("edit-copy", QIcon(":/icons/edit-copy.svg"))),
17 QIcon::fromTheme("document-new", QIcon(":/icons/document-new.svg"))) {
18 setIcon(iconEdit);
19 // Icon-only: give screen readers and hovering users a name.
20 setToolTip(tr("Copy to clipboard"));
21 setAccessibleName(tr("Copy to clipboard"));
22 setForegroundRole(QPalette::ButtonText);
23 connect(this, &QPushButton::clicked, this,
25}
26
28 return textToCopy;
29}
30
31void QPushButtonWithClipboard::setTextToCopy(const QString &value) {
32 textToCopy = value;
33}
34
36 setIcon(iconEditPushed);
37 QTimer::singleShot(500, this, &QPushButtonWithClipboard::changeIconDefault);
38 emit clicked(textToCopy);
39}
40
void clicked(const QString &text)
Emitted when the button is activated with the stored text.
void setTextToCopy(const QString &value)
Update the stored text used for copying.
void changeIconDefault()
Restores the default copy icon; fired by a single-shot timer 500 ms after a click.
void buttonClicked(bool checked)
Connected to QPushButton::clicked(bool); shows the pushed icon, arms the revert timer and re-emits cl...
QPushButtonWithClipboard(QString textToCopy="", QWidget *parent=nullptr)
Construct a QPushButtonWithClipboard with an optional initial text.
auto getTextToCopy() const -> QString
Return the stored text used for copying.
QIcon iconEditPushed
document-new icon flashed for 500 ms after a click.
QIcon iconEdit
edit-copy icon shown at rest.
QString textToCopy
Text handed to receivers on click; set by the owning panel.
Copy-to-clipboard icon button that carries the text of the field it sits next to.