File indexing completed on 2024-05-05 05:21:41
0001 /* 0002 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 0006 */ 0007 0008 #include "insertimagedialog.h" 0009 #include "insertimagewidget.h" 0010 0011 #include <KLocalizedString> 0012 0013 #include <QCheckBox> 0014 #include <QDialogButtonBox> 0015 #include <QPushButton> 0016 #include <QVBoxLayout> 0017 0018 namespace KPIMTextEdit 0019 { 0020 class InsertImageDialogPrivate 0021 { 0022 public: 0023 explicit InsertImageDialogPrivate(InsertImageDialog *qq) 0024 : q(qq) 0025 { 0026 auto vbox = new QVBoxLayout(q); 0027 q->setWindowTitle(i18nc("@title:window", "Insert Image")); 0028 0029 imageWidget = new InsertImageWidget(q); 0030 vbox->addWidget(imageWidget); 0031 q->connect(imageWidget, &InsertImageWidget::enableButtonOk, q, [this](bool b) { 0032 _k_slotEnabledButtonChanged(b); 0033 }); 0034 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, q); 0035 okButton = buttonBox->button(QDialogButtonBox::Ok); 0036 okButton->setText(i18n("Insert")); 0037 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0038 vbox->addWidget(buttonBox); 0039 0040 q->connect(buttonBox, &QDialogButtonBox::accepted, q, &QDialog::accept); 0041 q->connect(buttonBox, &QDialogButtonBox::rejected, q, &QDialog::reject); 0042 okButton->setEnabled(false); 0043 } 0044 0045 void _k_slotEnabledButtonChanged(bool enabled) 0046 { 0047 okButton->setEnabled(enabled); 0048 } 0049 0050 InsertImageWidget *imageWidget = nullptr; 0051 QPushButton *okButton = nullptr; 0052 InsertImageDialog *const q; 0053 }; 0054 0055 InsertImageDialog::InsertImageDialog(QWidget *parent) 0056 : QDialog(parent) 0057 , d(new InsertImageDialogPrivate(this)) 0058 { 0059 } 0060 0061 InsertImageDialog::~InsertImageDialog() = default; 0062 0063 int InsertImageDialog::imageWidth() const 0064 { 0065 return d->imageWidget->imageWidth(); 0066 } 0067 0068 int InsertImageDialog::imageHeight() const 0069 { 0070 return d->imageWidget->imageHeight(); 0071 } 0072 0073 void InsertImageDialog::setImageWidth(int value) 0074 { 0075 d->imageWidget->setImageWidth(value); 0076 } 0077 0078 void InsertImageDialog::setImageHeight(int value) 0079 { 0080 d->imageWidget->setImageHeight(value); 0081 } 0082 0083 QUrl InsertImageDialog::imageUrl() const 0084 { 0085 return d->imageWidget->imageUrl(); 0086 } 0087 0088 void InsertImageDialog::setImageUrl(const QUrl &url) 0089 { 0090 d->imageWidget->setImageUrl(url); 0091 } 0092 0093 bool InsertImageDialog::keepOriginalSize() const 0094 { 0095 return d->imageWidget->keepOriginalSize(); 0096 } 0097 } 0098 #include "moc_insertimagedialog.cpp"