Commit 20d67451 authored by Laurent Montel's avatar Laurent Montel 😁

Create private class for moving it in kf5 in the future

parent 456e53e0
...@@ -27,72 +27,83 @@ ...@@ -27,72 +27,83 @@
using namespace PimCommon; using namespace PimCommon;
class PimCommon::LineEditPassword::LineEditPasswordPrivate
{
public:
LineEditPasswordPrivate()
{
}
QLineEdit *mPasswordLineEdit = nullptr;
QAction *mToggleEchoModeAction = nullptr;
bool mIsToggleEchoModeAvailable = true;
};
LineEditPassword::LineEditPassword(QWidget *parent) LineEditPassword::LineEditPassword(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, mIsToggleEchoModeAvailable(true) , d(new LineEditPasswordPrivate)
{ {
QHBoxLayout *mainLayout = new QHBoxLayout(this); QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setObjectName(QStringLiteral("mainlayout")); mainLayout->setObjectName(QStringLiteral("mainlayout"));
mainLayout->setMargin(0); mainLayout->setMargin(0);
mPasswordLineEdit = new QLineEdit(this); d->mPasswordLineEdit = new QLineEdit(this);
mPasswordLineEdit->setObjectName(QStringLiteral("passwordlineedit")); d->mPasswordLineEdit->setObjectName(QStringLiteral("passwordlineedit"));
mPasswordLineEdit->setEchoMode(QLineEdit::Password); d->mPasswordLineEdit->setEchoMode(QLineEdit::Password);
mainLayout->addWidget(mPasswordLineEdit); mainLayout->addWidget(d->mPasswordLineEdit);
initialize(); initialize();
} }
LineEditPassword::~LineEditPassword() LineEditPassword::~LineEditPassword()
{ {
delete d;
} }
void LineEditPassword::initialize() void LineEditPassword::initialize()
{ {
QIcon visibilityIcon = QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg"))); QIcon visibilityIcon = QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg")));
mToggleEchoModeAction = mPasswordLineEdit->addAction(visibilityIcon, QLineEdit::TrailingPosition); d->mToggleEchoModeAction = d->mPasswordLineEdit->addAction(visibilityIcon, QLineEdit::TrailingPosition);
mToggleEchoModeAction->setObjectName(QStringLiteral("visibilityAction")); d->mToggleEchoModeAction->setObjectName(QStringLiteral("visibilityAction"));
mToggleEchoModeAction->setVisible(false); d->mToggleEchoModeAction->setVisible(false);
mToggleEchoModeAction->setToolTip(i18n("Change the visibility of the password")); d->mToggleEchoModeAction->setToolTip(i18n("Change the visibility of the password"));
connect(mToggleEchoModeAction, &QAction::triggered, this, &LineEditPassword::toggleEchoMode); connect(d->mToggleEchoModeAction, &QAction::triggered, this, &LineEditPassword::toggleEchoMode);
connect(mPasswordLineEdit, &QLineEdit::textChanged, this, &LineEditPassword::showToggleEchoModeAction); connect(d->mPasswordLineEdit, &QLineEdit::textChanged, this, &LineEditPassword::showToggleEchoModeAction);
} }
void LineEditPassword::toggleEchoMode() void LineEditPassword::toggleEchoMode()
{ {
if (mPasswordLineEdit->echoMode() == QLineEdit::Password) { if (d->mPasswordLineEdit->echoMode() == QLineEdit::Password) {
mPasswordLineEdit->setEchoMode(QLineEdit::Normal); d->mPasswordLineEdit->setEchoMode(QLineEdit::Normal);
mToggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("hint"), QIcon(QStringLiteral(":/icons/hint.svg")))); d->mToggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("hint"), QIcon(QStringLiteral(":/icons/hint.svg"))));
} } else if (d->mPasswordLineEdit->echoMode() == QLineEdit::Normal) {
else if (mPasswordLineEdit->echoMode() == QLineEdit::Normal) { d->mPasswordLineEdit->setEchoMode(QLineEdit::Password);
mPasswordLineEdit->setEchoMode(QLineEdit::Password); d->mToggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg"))));
mToggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg"))));
} }
} }
void LineEditPassword::setPassword(const QString &p) void LineEditPassword::setPassword(const QString &p)
{ {
mIsToggleEchoModeAvailable = p.isEmpty(); d->mIsToggleEchoModeAvailable = p.isEmpty();
mPasswordLineEdit->setText(p); d->mPasswordLineEdit->setText(p);
} }
QString LineEditPassword::password() const QString LineEditPassword::password() const
{ {
return mPasswordLineEdit->text(); return d->mPasswordLineEdit->text();
} }
void LineEditPassword::showToggleEchoModeAction(const QString &text) void LineEditPassword::showToggleEchoModeAction(const QString &text)
{ {
mToggleEchoModeAction->setVisible(mIsToggleEchoModeAvailable && (mPasswordLineEdit->echoMode() == QLineEdit::Normal || !text.isEmpty())); d->mToggleEchoModeAction->setVisible(d->mIsToggleEchoModeAvailable && (d->mPasswordLineEdit->echoMode() == QLineEdit::Normal || !text.isEmpty()));
} }
QLineEdit *LineEditPassword::passwordLineEdit() const QLineEdit *LineEditPassword::passwordLineEdit() const
{ {
return mPasswordLineEdit; return d->mPasswordLineEdit;
} }
QAction *LineEditPassword::toggleEchoModeAction() const QAction *LineEditPassword::toggleEchoModeAction() const
{ {
return mToggleEchoModeAction; return d->mToggleEchoModeAction;
} }
...@@ -24,6 +24,7 @@ class QLineEdit; ...@@ -24,6 +24,7 @@ class QLineEdit;
class QAction; class QAction;
namespace PimCommon namespace PimCommon
{ {
class LineEditPasswordPrivate;
class PIMCOMMON_EXPORT LineEditPassword : public QWidget class PIMCOMMON_EXPORT LineEditPassword : public QWidget
{ {
public: public:
...@@ -41,9 +42,8 @@ private: ...@@ -41,9 +42,8 @@ private:
void initialize(); void initialize();
void toggleEchoMode(); void toggleEchoMode();
void showToggleEchoModeAction(const QString &text); void showToggleEchoModeAction(const QString &text);
QLineEdit *mPasswordLineEdit = nullptr; class LineEditPasswordPrivate;
QAction *mToggleEchoModeAction = nullptr; LineEditPasswordPrivate *const d;
bool mIsToggleEchoModeAvailable;
}; };
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment