KPimTextEdit

klinkdialog.cpp
1/**
2 * klinkdialog
3 *
4 * SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmailcom>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-or-later
7 */
8
9#include "klinkdialog_p.h"
10
11#include <KLocalizedString>
12
13#include <QDialogButtonBox>
14#include <QGridLayout>
15#include <QLabel>
16#include <QLineEdit>
17#include <QPushButton>
18#include <QVBoxLayout>
19
20using namespace KPIMTextEdit;
21
22KLinkDialog::KLinkDialog(QWidget *parent)
23 : QDialog(parent)
24 , textLabel(new QLabel(i18nc("@label:textbox", "Link Text:"), this))
25 , textLineEdit(new QLineEdit(this))
26 , linkUrlLabel(new QLabel(i18nc("@label:textbox", "Link URL:"), this))
27 , linkUrlLineEdit(new QLineEdit(this))
28 , buttonBox(new QDialogButtonBox(this))
29{
30 setWindowTitle(i18nc("@title:window", "Manage Link"));
31 setModal(true);
32
33 auto layout = new QVBoxLayout(this);
34
35 auto grid = new QGridLayout;
36
37 textLineEdit->setClearButtonEnabled(true);
38 linkUrlLineEdit->setClearButtonEnabled(true);
39
40 grid->addWidget(textLabel, 0, 0);
41 grid->addWidget(textLineEdit, 0, 1);
42 grid->addWidget(linkUrlLabel, 1, 0);
43 grid->addWidget(linkUrlLineEdit, 1, 1);
44
45 layout->addLayout(grid);
46
47 buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
50 layout->addWidget(buttonBox);
51
52 textLineEdit->setFocus();
53 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
54 connect(textLineEdit, &QLineEdit::textChanged, this, &KLinkDialog::slotTextChanged);
55}
56
57KLinkDialog::~KLinkDialog() = default;
58
59void KLinkDialog::slotTextChanged(const QString &text)
60{
61 buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.trimmed().isEmpty());
62}
63
64void KLinkDialog::setLinkText(const QString &linkText)
65{
66 textLineEdit->setText(linkText);
67 if (!linkText.trimmed().isEmpty()) {
68 linkUrlLineEdit->setFocus();
69 }
70}
71
72void KLinkDialog::setLinkUrl(const QString &linkUrl)
73{
74 linkUrlLineEdit->setText(linkUrl);
75}
76
77QString KLinkDialog::linkText() const
78{
79 return textLineEdit->text().trimmed();
80}
81
82QString KLinkDialog::linkUrl() const
83{
84 return linkUrlLineEdit->text();
85}
86
87#include "moc_klinkdialog_p.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
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 Mon Nov 4 2024 16:35:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.