void KNewPasswordWidget::KNewPasswordWidgetPrivate::init()
{
    ui.setupUi(q);

    const QString strengthBarWhatsThis(tr("The password strength meter gives an indication of the security "
                                          "of the password you have entered. To improve the strength of the password, try:"
                                          "<ul><li>using a longer password;</li>"
                                          "<li>using a mixture of upper- and lower-case letters;</li>"
                                          "<li>using numbers or symbols, such as #, as well as letters.</li></ul>",
                                          "@info:whatsthis"));
    ui.labelStrengthMeter->setWhatsThis(strengthBarWhatsThis);
    ui.strengthBar->setWhatsThis(strengthBarWhatsThis);

    QIcon visibilityIcon = QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg")));
    toggleEchoModeAction = ui.linePassword->addAction(visibilityIcon, QLineEdit::TrailingPosition);
    toggleEchoModeAction->setVisible(false);
    toggleEchoModeAction->setToolTip(tr("Change the visibility of the password"));
    connect(toggleEchoModeAction, SIGNAL(triggered(bool)), q, SLOT(_k_toggleEchoMode()));

    connect(ui.linePassword, SIGNAL(textChanged(QString)), q, SLOT(_k_showToggleEchoModeAction(QString)));
    connect(ui.linePassword, SIGNAL(textChanged(QString)), q, SLOT(_k_textChanged()));
    connect(ui.lineVerifyPassword, SIGNAL(textChanged(QString)), q, SLOT(_k_textChanged()));

    defaultBackgroundColor = q->palette().color(QPalette::Active, QPalette::Base);
    backgroundWarningColor = defaultBackgroundColor;

    _k_textChanged();
}
void KNewPasswordWidget::KNewPasswordWidgetPrivate::_k_toggleEchoMode()
{
    if (ui.linePassword->echoMode() == QLineEdit::Password) {
        ui.linePassword->setEchoMode(QLineEdit::Normal);
        ui.lineVerifyPassword->hide();
        ui.labelVerifyPassword->hide();
        toggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("hint"), QIcon(QStringLiteral(":/icons/hint.svg"))));
    } else if (ui.linePassword->echoMode() == QLineEdit::Normal) {
        ui.linePassword->setEchoMode(QLineEdit::Password);
        ui.lineVerifyPassword->show();
        ui.labelVerifyPassword->show();
        toggleEchoModeAction->setIcon(QIcon::fromTheme(QStringLiteral("visibility"), QIcon(QStringLiteral(":/icons/visibility.svg"))));
    }

    _k_textChanged();
}
Exemplo n.º 3
0
LabelEditWidget::LabelEditWidget( QWidget* parent )
    : QWidget( parent ),
      d( new Private() )
{
    d->q = this;

    d->m_labelContainer = new QWidget( this );
    d->m_label = new KSqueezedTextLabel( d->m_labelContainer );
    d->m_label->installEventFilter( this );
    d->m_button = new QToolButton( d->m_labelContainer );
    d->m_button->setIcon( KIcon( "edit-rename" ) );
    d->m_button->setAutoRaise( true );

    QHBoxLayout* lay = new QHBoxLayout( d->m_labelContainer );
    lay->setMargin( 0 );
    lay->addWidget( d->m_label );
    lay->addWidget( d->m_button );

    d->m_lineEdit = new KLineEdit( this );
    d->m_lineEdit->installEventFilter( this );

    d->m_stack = new QStackedLayout( this );
    d->m_stack->setMargin( 0 );
    d->m_stack->addWidget( d->m_labelContainer );
    d->m_stack->addWidget( d->m_lineEdit );

    connect( d->m_lineEdit, SIGNAL( textEdited(QString) ),
             this, SIGNAL( textEdited(QString) ) );
    connect( d->m_lineEdit, SIGNAL( textChanged(QString) ),
             this, SLOT( _k_textChanged(QString) ) );
    connect( d->m_lineEdit, SIGNAL( editingFinished() ),
             this, SLOT( _k_editingFinished() ) );
    connect( d->m_button, SIGNAL( clicked() ),
             this, SLOT( _k_buttonClicked() ) );

    d->m_stack->setCurrentWidget( d->m_labelContainer );
}