KTextWidgets

klinkdialog.cpp
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, 0, 0);
54 grid->addWidget(d->textLineEdit, 0, 1);
55 grid->addWidget(d->linkUrlLabel, 1, 0);
56 grid->addWidget(d->linkUrlLineEdit, 1, 1);
57
58 layout->addLayout(grid);
59
60 d->buttonBox = new QDialogButtonBox(this);
61 d->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
64 layout->addWidget(d->buttonBox);
65
66 d->textLineEdit->setFocus();
67 d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
68 connect(d->textLineEdit, &QLineEdit::textChanged, this, &KLinkDialog::slotTextChanged);
69}
70
71KLinkDialog::~KLinkDialog()
72{
73 delete d;
74}
75
76void KLinkDialog::slotTextChanged(const QString &text)
77{
78 d->buttonBox->button(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"
QString i18n(const char *text, const TYPE &arg...)
void addLayout(QLayout *layout, int stretch)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
virtual void accept()
virtual void reject()
void addWidget(QWidget *widget, int fromRow, int fromColumn, int rowSpan, int columnSpan, Qt::Alignment alignment)
void textChanged(const QString &text)
bool isEmpty() const const
QString trimmed() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:00:56 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.