1 | /* |
2 | klinkdialog |
3 | SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmailcom> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.1-or-later |
6 | */ |
7 | |
8 | #include "klinkdialog_p.h" |
9 | |
10 | #include <KLocalizedString> |
11 | |
12 | #include <QDialogButtonBox> |
13 | #include <QGridLayout> |
14 | #include <QLabel> |
15 | #include <QLineEdit> |
16 | #include <QPushButton> |
17 | #include <QVBoxLayout> |
18 | |
19 | class KLinkDialogPrivate |
20 | { |
21 | public: |
22 | QLabel *textLabel = nullptr; |
23 | QLineEdit *textLineEdit = nullptr; |
24 | QLabel *linkUrlLabel = nullptr; |
25 | QLineEdit *linkUrlLineEdit = nullptr; |
26 | QDialogButtonBox *buttonBox = nullptr; |
27 | }; |
28 | |
29 | KLinkDialog::KLinkDialog(QWidget *parent) |
30 | : QDialog(parent) |
31 | , d(new KLinkDialogPrivate) |
32 | { |
33 | setWindowTitle(i18n("Manage Link" )); |
34 | setModal(true); |
35 | |
36 | QVBoxLayout *layout = new QVBoxLayout(this); |
37 | |
38 | QGridLayout *grid = new QGridLayout; |
39 | |
40 | d->textLabel = new QLabel(i18n("Link Text:" ), this); |
41 | d->textLineEdit = new QLineEdit(this); |
42 | d->textLineEdit->setClearButtonEnabled(true); |
43 | d->linkUrlLabel = new QLabel(i18n("Link URL:" ), this); |
44 | d->linkUrlLineEdit = new QLineEdit(this); |
45 | d->linkUrlLineEdit->setClearButtonEnabled(true); |
46 | |
47 | grid->addWidget(d->textLabel, row: 0, column: 0); |
48 | grid->addWidget(d->textLineEdit, row: 0, column: 1); |
49 | grid->addWidget(d->linkUrlLabel, row: 1, column: 0); |
50 | grid->addWidget(d->linkUrlLineEdit, row: 1, column: 1); |
51 | |
52 | layout->addLayout(layout: grid); |
53 | |
54 | d->buttonBox = new QDialogButtonBox(this); |
55 | d->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); |
56 | connect(sender: d->buttonBox, signal: &QDialogButtonBox::accepted, context: this, slot: &QDialog::accept); |
57 | connect(sender: d->buttonBox, signal: &QDialogButtonBox::rejected, context: this, slot: &QDialog::reject); |
58 | layout->addWidget(d->buttonBox); |
59 | |
60 | d->textLineEdit->setFocus(); |
61 | d->buttonBox->button(which: QDialogButtonBox::Ok)->setEnabled(false); |
62 | connect(sender: d->textLineEdit, signal: &QLineEdit::textChanged, context: this, slot: &KLinkDialog::slotTextChanged); |
63 | } |
64 | |
65 | KLinkDialog::~KLinkDialog() |
66 | { |
67 | delete d; |
68 | } |
69 | |
70 | void KLinkDialog::slotTextChanged(const QString &text) |
71 | { |
72 | d->buttonBox->button(which: QDialogButtonBox::Ok)->setEnabled(!text.trimmed().isEmpty()); |
73 | } |
74 | |
75 | void KLinkDialog::setLinkText(const QString &linkText) |
76 | { |
77 | d->textLineEdit->setText(linkText); |
78 | if (!linkText.trimmed().isEmpty()) { |
79 | d->linkUrlLineEdit->setFocus(); |
80 | } |
81 | } |
82 | |
83 | void KLinkDialog::setLinkUrl(const QString &linkUrl) |
84 | { |
85 | d->linkUrlLineEdit->setText(linkUrl); |
86 | } |
87 | |
88 | QString KLinkDialog::linkText() const |
89 | { |
90 | return d->textLineEdit->text().trimmed(); |
91 | } |
92 | |
93 | QString KLinkDialog::linkUrl() const |
94 | { |
95 | return d->linkUrlLineEdit->text(); |
96 | } |
97 | |
98 | #include "moc_klinkdialog_p.cpp" |
99 | |