File indexing completed on 2024-11-24 04:16:56

0001 /*
0002   SPDX-FileCopyrightText: 2022-2024 Laurent Montel <montel@kde.org>
0003 
0004   SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "deeplengineconfigurewidget.h"
0008 
0009 #if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
0010 #include <TextAddonsWidgets/LineEditCatchReturnKey>
0011 #else
0012 #include <KLineEditEventHandler>
0013 #endif
0014 
0015 #include <KLocalizedString>
0016 #include <QCheckBox>
0017 #include <QFormLayout>
0018 #include <QLineEdit>
0019 
0020 DeeplEngineConfigureWidget::DeeplEngineConfigureWidget(QWidget *parent)
0021     : QWidget{parent}
0022     , mUseFreeLicense(new QCheckBox(i18n("Use Free License Key"), this))
0023     , mApiKey(new QLineEdit(this))
0024 {
0025     auto mainLayout = new QFormLayout(this);
0026     mainLayout->setObjectName(QStringLiteral("mainLayout"));
0027     mainLayout->setContentsMargins({});
0028 #if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
0029     new TextAddonsWidgets::LineEditCatchReturnKey(mApiKey, this);
0030 #else
0031     KLineEditEventHandler::catchReturnKey(mApiKey);
0032 #endif
0033     mUseFreeLicense->setObjectName(QStringLiteral("mUseFreeLicense"));
0034     mainLayout->addWidget(mUseFreeLicense);
0035 
0036     mApiKey->setObjectName(QStringLiteral("mApiKey"));
0037     mApiKey->setClearButtonEnabled(true);
0038     mainLayout->addRow(i18n("Api Key:"), mApiKey);
0039 }
0040 
0041 DeeplEngineConfigureWidget::~DeeplEngineConfigureWidget() = default;
0042 
0043 void DeeplEngineConfigureWidget::setUseFreeLicenceKey(bool b)
0044 {
0045     mUseFreeLicense->setChecked(b);
0046 }
0047 
0048 bool DeeplEngineConfigureWidget::useFreeLicenceKey() const
0049 {
0050     return mUseFreeLicense->isChecked();
0051 }
0052 
0053 QString DeeplEngineConfigureWidget::apiKey() const
0054 {
0055     return mApiKey->text();
0056 }
0057 
0058 void DeeplEngineConfigureWidget::setApiKey(const QString &key)
0059 {
0060     mApiKey->setText(key);
0061 }
0062 
0063 #include "moc_deeplengineconfigurewidget.cpp"