summaryrefslogtreecommitdiffstats
path: root/src/qpushbuttonshowpassword.cpp
blob: 8a92c611f97b3cda1654c7ab1a9aed2f9363962a (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
#include "qpushbuttonshowpassword.h"
#include <QTimer>

/**
 * @brief QPushButtonAsQRCode::QPushButtonAsQRCode
 *  basic constructor
 * @param textToCopy
 *  the text to display as qrcode
 * @param parent
 *  the parent window
 */
QPushButtonShowPassword::QPushButtonShowPassword(QLineEdit *line,
                                                 QWidget *parent)
    : QPushButton(parent),
      iconEdit(QIcon::fromTheme("show", QIcon(":/icons/view.svg"))),
      iconEditPushed(QIcon::fromTheme("hide-new", QIcon(":/icons/hide.svg"))) {
  setIcon(iconEdit);
  connect(this, SIGNAL(clicked(bool)), this, SLOT(buttonClicked(bool)));
  this->line = line;
}

/**
 * @brief QPushButtonAsQRCode::buttonClicked handles clicked event by
 * emitting clicked(QString) with string provided to constructor
 */
void QPushButtonShowPassword::buttonClicked(bool) {
  if (this->line->echoMode() == QLineEdit::Password) {
    this->line->setEchoMode(QLineEdit::Normal);
    setIcon(iconEditPushed);
  } else {
    this->line->setEchoMode(QLineEdit::Password);
    setIcon(iconEdit);
  }
}