File indexing completed on 2024-12-01 03:43:34
0001 /* 0002 klinkdialog 0003 SPDX-FileCopyrightText: 2008 Stephen Kelly <steveire@gmailcom> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include "klinkdialog_p.h" 0009 0010 #include <KLocalizedString> 0011 0012 #include <QDialogButtonBox> 0013 #include <QGridLayout> 0014 #include <QLabel> 0015 #include <QLineEdit> 0016 #include <QPushButton> 0017 #include <QVBoxLayout> 0018 0019 /** 0020 Private class that helps to provide binary compatibility between releases. 0021 @internal 0022 */ 0023 //@cond PRIVATE 0024 class KLinkDialogPrivate 0025 { 0026 public: 0027 QLabel *textLabel = nullptr; 0028 QLineEdit *textLineEdit = nullptr; 0029 QLabel *linkUrlLabel = nullptr; 0030 QLineEdit *linkUrlLineEdit = nullptr; 0031 QDialogButtonBox *buttonBox = nullptr; 0032 }; 0033 //@endcond 0034 0035 KLinkDialog::KLinkDialog(QWidget *parent) 0036 : QDialog(parent) 0037 , d(new KLinkDialogPrivate) 0038 { 0039 setWindowTitle(i18n("Manage Link")); 0040 setModal(true); 0041 0042 QVBoxLayout *layout = new QVBoxLayout(this); 0043 0044 QGridLayout *grid = new QGridLayout; 0045 0046 d->textLabel = new QLabel(i18n("Link Text:"), this); 0047 d->textLineEdit = new QLineEdit(this); 0048 d->textLineEdit->setClearButtonEnabled(true); 0049 d->linkUrlLabel = new QLabel(i18n("Link URL:"), this); 0050 d->linkUrlLineEdit = new QLineEdit(this); 0051 d->linkUrlLineEdit->setClearButtonEnabled(true); 0052 0053 grid->addWidget(d->textLabel, 0, 0); 0054 grid->addWidget(d->textLineEdit, 0, 1); 0055 grid->addWidget(d->linkUrlLabel, 1, 0); 0056 grid->addWidget(d->linkUrlLineEdit, 1, 1); 0057 0058 layout->addLayout(grid); 0059 0060 d->buttonBox = new QDialogButtonBox(this); 0061 d->buttonBox->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); 0062 connect(d->buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0063 connect(d->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0064 layout->addWidget(d->buttonBox); 0065 0066 d->textLineEdit->setFocus(); 0067 d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); 0068 connect(d->textLineEdit, &QLineEdit::textChanged, this, &KLinkDialog::slotTextChanged); 0069 } 0070 0071 KLinkDialog::~KLinkDialog() 0072 { 0073 delete d; 0074 } 0075 0076 void KLinkDialog::slotTextChanged(const QString &text) 0077 { 0078 d->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!text.trimmed().isEmpty()); 0079 } 0080 0081 void KLinkDialog::setLinkText(const QString &linkText) 0082 { 0083 d->textLineEdit->setText(linkText); 0084 if (!linkText.trimmed().isEmpty()) { 0085 d->linkUrlLineEdit->setFocus(); 0086 } 0087 } 0088 0089 void KLinkDialog::setLinkUrl(const QString &linkUrl) 0090 { 0091 d->linkUrlLineEdit->setText(linkUrl); 0092 } 0093 0094 QString KLinkDialog::linkText() const 0095 { 0096 return d->textLineEdit->text().trimmed(); 0097 } 0098 0099 QString KLinkDialog::linkUrl() const 0100 { 0101 return d->linkUrlLineEdit->text(); 0102 } 0103 0104 #include "moc_klinkdialog_p.cpp"