File indexing completed on 2025-01-19 04:46:47
0001 /* 0002 SPDX-FileCopyrightText: 2015-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "translatorview.h" 0008 #include <TextTranslator/TranslatorWidget> 0009 0010 #include <KActionCollection> 0011 #include <KLocalizedString> 0012 #include <KToggleAction> 0013 #include <QHBoxLayout> 0014 0015 TranslatorView::TranslatorView(KActionCollection *ac, QWidget *parent) 0016 : PimCommon::CustomToolsViewInterface(parent) 0017 , mTranslatorWidget(new TextTranslator::TranslatorWidget(this)) 0018 { 0019 auto layout = new QHBoxLayout(this); 0020 layout->setContentsMargins({}); 0021 connect(mTranslatorWidget, &TextTranslator::TranslatorWidget::toolsWasClosed, this, &TranslatorView::toolsWasClosed); 0022 0023 layout->addWidget(mTranslatorWidget); 0024 createAction(ac); 0025 } 0026 0027 TranslatorView::~TranslatorView() = default; 0028 0029 void TranslatorView::setText(const QString &text) 0030 { 0031 mTranslatorWidget->setTextToTranslate(text); 0032 } 0033 0034 KToggleAction *TranslatorView::action() const 0035 { 0036 return mAction; 0037 } 0038 0039 void TranslatorView::slotActivateTranslator(bool state) 0040 { 0041 if (state) { 0042 mTranslatorWidget->show(); 0043 Q_EMIT activateView(this); 0044 } else { 0045 mTranslatorWidget->hide(); 0046 Q_EMIT activateView(nullptr); 0047 } 0048 } 0049 0050 void TranslatorView::createAction(KActionCollection *ac) 0051 { 0052 mAction = new KToggleAction(i18n("&Translator"), this); 0053 connect(mAction, &KToggleAction::triggered, this, &TranslatorView::slotActivateTranslator); 0054 if (ac) { 0055 ac->addAction(QStringLiteral("translator"), mAction); 0056 ac->setDefaultShortcut(mAction, QKeySequence(Qt::CTRL | Qt::ALT | Qt::Key_T)); 0057 } 0058 mAction->setChecked(false); 0059 } 0060 0061 #include "moc_translatorview.cpp"