summaryrefslogtreecommitdiffstats
path: root/src/qpushbuttonwithclipboard.cpp
blob: 9ca1e7bde0c88572dc395b5c9e65b5190090093b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "qpushbuttonwithclipboard.h"
#include <QTimer>

/**
 * @brief QPushButtonWithClipboard::QPushButtonWithClipboard
 *  basic constructor
 * @param textToCopy
 *  the text to paste into the clipboard
 * @param parent
 *  the parent window
 */
QPushButtonWithClipboard::QPushButtonWithClipboard(const QString &textToCopy,
                                                   QWidget *parent)
    : QPushButton(parent), textToCopy(textToCopy),
      iconEdit(QIcon::fromTheme("edit-copy", QIcon(":/icons/edit-copy.svg"))),
      iconEditPushed(
          QIcon::fromTheme("document-new", QIcon(":/icons/document-new.svg"))) {
  setIcon(iconEdit);
  connect(this, SIGNAL(clicked(bool)), this, SLOT(buttonClicked(bool)));
}

/**
 * @brief QPushButtonWithClipboard::getTextToCopy returns the text of
 * associated text field
 * @return QString textToCopy
 */
QString QPushButtonWithClipboard::getTextToCopy() const { return textToCopy; }

/**
 * @brief QPushButtonWithClipboard::setTextToCopy sets text from associated
 * text field
 * @param value QString text to be copied
 */
void QPushButtonWithClipboard::setTextToCopy(const QString &value) {
  textToCopy = value;
}

/**
 * @brief QPushButtonWithClipboard::buttonClicked handles clicked event by
 * emitting clicked(QString) with string provided to constructor
 */
void QPushButtonWithClipboard::buttonClicked(bool) {
  setIcon(iconEditPushed);
  QTimer::singleShot(500, this, SLOT(changeIconDefault()));
  emit clicked(textToCopy);
}

/**
 * @brief QPushButtonWithClipboard::changeIconDefault change the icon back to
 * the default copy icon
 */
void QPushButtonWithClipboard::changeIconDefault() { this->setIcon(iconEdit); }