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/**
20 Private class that helps to provide binary compatibility between releases.
21 @internal
22*/
23//@cond PRIVATE
24class KLinkDialogPrivate
25{
26public:
27 QLabel *textLabel = nullptr;
28 QLineEdit *textLineEdit = nullptr;
29 QLabel *linkUrlLabel = nullptr;
30 QLineEdit *linkUrlLineEdit = nullptr;
31 QDialogButtonBox *buttonBox = nullptr;
32};
33//@endcond
34
35KLinkDialog::KLinkDialog(QWidget *parent)
36 : QDialog(parent)
37 , d(new KLinkDialogPrivate)
38{
39 setWindowTitle(i18n("Manage Link"));
40 setModal(true);
41
42 QVBoxLayout *layout = new QVBoxLayout(this);
43
44 QGridLayout *grid = new QGridLayout;
45
46 d->textLabel = new QLabel(i18n("Link Text:"), this);
47 d->textLineEdit = new QLineEdit(this);
48 d->textLineEdit->setClearButtonEnabled(true);
49 d->linkUrlLabel = new QLabel(i18n("Link URL:"), this);
50 d->linkUrlLineEdit = new QLineEdit(this);
51 d->linkUrlLineEdit->setClearButtonEnabled(true);
52
53 grid->addWidget(d->textLabel, row: 0, column: 0);
54 grid->addWidget(d->textLineEdit, row: 0, column: 1);
55 grid->addWidget(d->linkUrlLabel, row: 1, column: 0);
56 grid->addWidget(d->linkUrlLineEdit, row: 1, column: 1);
57
58 layout->addLayout(layout: grid);
59
60 d->buttonBox = new QDialogButtonBox(this);
61 d->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
62 connect(sender: d->buttonBox, signal: &QDialogButtonBox::accepted, context: this, slot: &QDialog::accept);
63 connect(sender: d->buttonBox, signal: &QDialogButtonBox::rejected, context: this, slot: &QDialog::reject);
64 layout->addWidget(d->buttonBox);
65
66 d->textLineEdit->setFocus();
67 d->buttonBox->button(which: QDialogButtonBox::Ok)->setEnabled(false);
68 connect(sender: d->textLineEdit, signal: &QLineEdit::textChanged, context: this, slot: &KLinkDialog::slotTextChanged);
69}
70
71KLinkDialog::~KLinkDialog()
72{
73 delete d;
74}
75
76void KLinkDialog::slotTextChanged(const QString &text)
77{
78 d->buttonBox->button(which: QDialogButtonBox::Ok)->setEnabled(!text.trimmed().isEmpty());
79}
80
81void KLinkDialog::setLinkText(const QString &linkText)
82{
83 d->textLineEdit->setText(linkText);
84 if (!linkText.trimmed().isEmpty()) {
85 d->linkUrlLineEdit->setFocus();
86 }
87}
88
89void KLinkDialog::setLinkUrl(const QString &linkUrl)
90{
91 d->linkUrlLineEdit->setText(linkUrl);
92}
93
94QString KLinkDialog::linkText() const
95{
96 return d->textLineEdit->text().trimmed();
97}
98
99QString KLinkDialog::linkUrl() const
100{
101 return d->linkUrlLineEdit->text();
102}
103
104#include "moc_klinkdialog_p.cpp"
105

source code of ktextwidgets/src/dialogs/klinkdialog.cpp