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

0001 /*
0002     This file is part of the Okteta Kasten module, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2006-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 "gotooffsetcontroller.hpp"
0010 
0011 // controller
0012 #include "gotooffsettoolview.hpp"
0013 #include "gotooffsettool.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: for docked widgets signal widgets if embedded or floating, if horizontal/vertical
0026 GotoOffsetController::GotoOffsetController(If::ToolInlineViewable* toolInlineViewable, KXMLGUIClient* guiClient)
0027     : mToolInlineViewable(toolInlineViewable)
0028 {
0029     KActionCollection* actionCollection = guiClient->actionCollection();
0030 
0031     mGotoOffsetAction = new QAction(QIcon::fromTheme(QStringLiteral("go-jump")),
0032                                     i18nc("@action:inmenu", "&Go to Offset..."), this);
0033     connect(mGotoOffsetAction, &QAction::triggered,this, &GotoOffsetController::gotoOffset);
0034     actionCollection->setDefaultShortcut(mGotoOffsetAction, QKeySequence(Qt::CTRL | Qt::Key_G));
0035 
0036     actionCollection->addAction(QStringLiteral("goto_offset"), mGotoOffsetAction);
0037 
0038     mTool = new GotoOffsetTool();
0039     connect(mTool, &GotoOffsetTool::isUsableChanged,
0040             mGotoOffsetAction, &QAction::setEnabled);
0041     mGotoOffsetAction->setEnabled(mTool->isUsable());
0042 
0043     mView = new GotoOffsetToolView(mTool);
0044 }
0045 
0046 GotoOffsetController::~GotoOffsetController()
0047 {
0048     if (mToolInlineViewable->currentToolInlineView() == mView) {
0049         mToolInlineViewable->setCurrentToolInlineView(nullptr);
0050     }
0051 
0052     delete mView;
0053     delete mTool;
0054 }
0055 
0056 void GotoOffsetController::setTargetModel(AbstractModel* model)
0057 {
0058     mTool->setTargetModel(model);
0059 }
0060 
0061 void GotoOffsetController::gotoOffset()
0062 {
0063     mToolInlineViewable->setCurrentToolInlineView(mView);
0064 }
0065 
0066 }
0067 
0068 #include "moc_gotooffsetcontroller.cpp"