File indexing completed on 2025-01-05 05:23:37

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2009 Friedrich W. H. Kossebau <kossebau@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #include "selectrangecontroller.hpp"
0010 
0011 // controller
0012 #include "selectrangetoolview.hpp"
0013 #include "selectrangetool.hpp"
0014 // Kasten gui
0015 #include <Kasten/ToolInlineViewable>
0016 // KF
0017 #include <KXMLGUIClient>
0018 #include <KLocalizedString>
0019 #include <KActionCollection>
0020 // Qt
0021 #include <QAction>
0022 
0023 namespace Kasten {
0024 
0025 // TODO: a tool(view) might perhaps be invoked indirectly by asking for a tool for the object, here select
0026 // so the status bar selection indicator can invoke the same tool, without knowing about it
0027 SelectRangeController::SelectRangeController(If::ToolInlineViewable* toolInlineViewable, KXMLGUIClient* guiClient)
0028     : mToolInlineViewable(toolInlineViewable)
0029 {
0030     KActionCollection* actionCollection = guiClient->actionCollection();
0031 
0032     mSelectAction = new QAction(QIcon::fromTheme(QStringLiteral("select-rectangular")),
0033                                 i18nc("@action:inmenu", "&Select Range..."), this);
0034     connect(mSelectAction, &QAction::triggered, this, &SelectRangeController::select);
0035     actionCollection->setDefaultShortcut(mSelectAction, QKeySequence(Qt::CTRL | Qt::Key_E));
0036 
0037     actionCollection->addAction(QStringLiteral("edit_select"), mSelectAction);
0038 
0039     mTool = new SelectRangeTool();
0040     connect(mTool, &SelectRangeTool::isUsableChanged,
0041             mSelectAction, &QAction::setEnabled);
0042     mSelectAction->setEnabled(mTool->isUsable());
0043 
0044     mView = new SelectRangeToolView(mTool);
0045 }
0046 
0047 SelectRangeController::~SelectRangeController()
0048 {
0049     if (mToolInlineViewable->currentToolInlineView() == mView) {
0050         mToolInlineViewable->setCurrentToolInlineView(nullptr);
0051     }
0052 
0053     delete mView;
0054     delete mTool;
0055 }
0056 
0057 void SelectRangeController::setTargetModel(AbstractModel* model)
0058 {
0059     mTool->setTargetModel(model);
0060 }
0061 
0062 void SelectRangeController::select()
0063 {
0064 //     mView->activate(); // TODO: show would be better here, or should instead toolInlineViewable be asked?
0065     mToolInlineViewable->setCurrentToolInlineView(mView);
0066 }
0067 
0068 }
0069 
0070 #include "moc_selectrangecontroller.cpp"