Skip to content

Commit f66ac2c

Browse files
authored
passdialog: create form from ui file (#904)
1 parent a4f98bb commit f66ac2c

File tree

4 files changed

+123
-39
lines changed

4 files changed

+123
-39
lines changed

src/passdialog.cpp

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,47 +20,15 @@
2020

2121
#include "passdialog.h"
2222

23-
#include <QCheckBox>
24-
#include <QHBoxLayout>
25-
#include <QLabel>
26-
#include <QLayout>
27-
#include <QLineEdit>
28-
#include <QPushButton>
29-
#include <QVBoxLayout>
30-
3123
PassDialog::PassDialog(const QString &jid, QWidget *parent) : QDialog(parent)
3224
{
25+
m_ui.setupUi(this);
3326
setWindowTitle(tr("Wrong Account Password"));
34-
35-
QVBoxLayout *mainLayout = new QVBoxLayout(this);
36-
mainLayout->setContentsMargins(6, 6, 6, 6);
37-
mainLayout->setSpacing(6);
38-
QHBoxLayout *botLayout = new QHBoxLayout();
39-
40-
le_password = new QLineEdit();
41-
le_password->setEchoMode(QLineEdit::Password);
42-
43-
cb_savePassword = new QCheckBox(tr("Save Password"));
44-
botLayout->addWidget(cb_savePassword);
45-
botLayout->addStretch(1);
46-
47-
QPushButton *pb_ok = new QPushButton(tr("OK"));
48-
pb_ok->setDefault(true);
49-
botLayout->addWidget(pb_ok);
50-
51-
QPushButton *pb_cancel = new QPushButton(tr("Cancel"));
52-
botLayout->addWidget(pb_cancel);
53-
54-
mainLayout->addWidget(new QLabel(tr("Please enter your password for %1:").arg(jid)));
55-
mainLayout->addWidget(le_password);
56-
mainLayout->addLayout(botLayout);
57-
58-
connect(pb_cancel, SIGNAL(clicked()), this, SLOT(reject()));
59-
connect(pb_ok, SIGNAL(clicked()), this, SLOT(accept()));
27+
m_ui.labelAcc->setText(tr("Please enter your password for %1:").arg(jid));
6028
}
6129

62-
bool PassDialog::savePassword() const { return cb_savePassword->isChecked(); }
30+
bool PassDialog::savePassword() const { return m_ui.cb_savePassword->isChecked(); }
6331

64-
void PassDialog::setSavePassword(bool save) { cb_savePassword->setChecked(save); }
32+
void PassDialog::setSavePassword(bool save) { m_ui.cb_savePassword->setChecked(save); }
6533

66-
QString PassDialog::password() const { return le_password->text(); }
34+
QString PassDialog::password() const { return m_ui.le_password->text(); }

src/passdialog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#ifndef PASSDIALOG_H
2222
#define PASSDIALOG_H
2323

24+
#include "ui_password.h"
25+
2426
#include <QDialog>
2527

2628
class QCheckBox;
@@ -36,8 +38,7 @@ class PassDialog : public QDialog {
3638
void setSavePassword(bool save);
3739

3840
private:
39-
QCheckBox *cb_savePassword;
40-
QLineEdit *le_password;
41+
Ui::PasswordDialog m_ui;
4142
};
4243

4344
#endif // PASSDIALOG_H

src/password.ui

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>PasswordDialog</class>
4+
<widget class="QDialog" name="PasswordDialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>600</width>
10+
<height>180</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Wrong Account Password</string>
15+
</property>
16+
<layout class="QVBoxLayout" name="mainLayout">
17+
<property name="spacing">
18+
<number>6</number>
19+
</property>
20+
<property name="leftMargin">
21+
<number>6</number>
22+
</property>
23+
<property name="topMargin">
24+
<number>6</number>
25+
</property>
26+
<property name="rightMargin">
27+
<number>6</number>
28+
</property>
29+
<property name="bottomMargin">
30+
<number>6</number>
31+
</property>
32+
<item>
33+
<widget class="QLabel" name="labelAcc">
34+
<property name="text">
35+
<string>Please enter your password for %1:</string>
36+
</property>
37+
</widget>
38+
</item>
39+
<item>
40+
<widget class="QLineEdit" name="le_password">
41+
<property name="echoMode">
42+
<enum>QLineEdit::Password</enum>
43+
</property>
44+
</widget>
45+
</item>
46+
<item>
47+
<layout class="QHBoxLayout" name="botLayout">
48+
<item>
49+
<widget class="QCheckBox" name="cb_savePassword">
50+
<property name="text">
51+
<string>Save Password</string>
52+
</property>
53+
</widget>
54+
</item>
55+
<item>
56+
<spacer name="horizontalSpacer">
57+
<property name="orientation">
58+
<enum>Qt::Horizontal</enum>
59+
</property>
60+
<property name="sizeHint" stdset="0">
61+
<size>
62+
<width>40</width>
63+
<height>20</height>
64+
</size>
65+
</property>
66+
</spacer>
67+
</item>
68+
<item>
69+
<widget class="QDialogButtonBox" name="buttonBox">
70+
<property name="standardButtons">
71+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
72+
</property>
73+
</widget>
74+
</item>
75+
</layout>
76+
</item>
77+
</layout>
78+
</widget>
79+
<resources/>
80+
<connections>
81+
<connection>
82+
<sender>buttonBox</sender>
83+
<signal>accepted()</signal>
84+
<receiver>PasswordDialog</receiver>
85+
<slot>accept()</slot>
86+
<hints>
87+
<hint type="sourcelabel">
88+
<x>20</x>
89+
<y>20</y>
90+
</hint>
91+
<hint type="destinationlabel">
92+
<x>20</x>
93+
<y>20</y>
94+
</hint>
95+
</hints>
96+
</connection>
97+
<connection>
98+
<sender>buttonBox</sender>
99+
<signal>rejected()</signal>
100+
<receiver>PasswordDialog</receiver>
101+
<slot>reject()</slot>
102+
<hints>
103+
<hint type="sourcelabel">
104+
<x>20</x>
105+
<y>20</y>
106+
</hint>
107+
<hint type="destinationlabel">
108+
<x>20</x>
109+
<y>20</y>
110+
</hint>
111+
</hints>
112+
</connection>
113+
</connections>
114+
</ui>

src/src.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ list(APPEND FORMS
5555
mucreasonseditor.ui
5656
multifiletransferdlg.ui
5757
optioneditor.ui
58+
password.ui
5859
pgpkey.ui
5960
profilemanage.ui
6061
profilenew.ui

0 commit comments

Comments
 (0)