File indexing completed on 2024-04-28 05:52:37

0001 /*
0002     This file is part of the Okteta Gui library, made within the KDE community.
0003 
0004     SPDX-FileCopyrightText: 2004, 2008 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 "tabcontroller.hpp"
0010 
0011 // lib
0012 #include <abstractbytearrayview.hpp>
0013 // Qt
0014 #include <QKeyEvent>
0015 
0016 namespace Okteta {
0017 
0018 TabController::TabController(AbstractByteArrayView* view, AbstractController* parent)
0019     : AbstractController(parent)
0020     , mView(view)
0021     , mTabChangesFocus(true)
0022 {
0023 }
0024 
0025 bool TabController::handleKeyPress(QKeyEvent* keyEvent)
0026 {
0027     bool keyUsed = false;
0028 
0029     const bool tabPressed = (keyEvent->key() == Qt::Key_Tab);
0030     const bool backTabPressed = (keyEvent->key() == Qt::Key_Backtab);
0031 
0032     if (tabPressed || backTabPressed) {
0033         const int visibleCodings = mView->visibleCodings();
0034         // are we in the char column?
0035         if (mView->activeCoding() == AbstractByteArrayView::CharCodingId) {
0036             // in last column we care about tab changes focus
0037             if ((visibleCodings & AbstractByteArrayView::ValueCodingId) && (!mTabChangesFocus || backTabPressed)) {
0038                 mView->setActiveCoding(AbstractByteArrayView::ValueCodingId);
0039                 keyUsed = true;
0040             }
0041         }
0042         // value column then
0043         else {
0044             // in last column we care about tab changes focus
0045             if ((visibleCodings & AbstractByteArrayView::CharCodingId) && (!mTabChangesFocus || tabPressed)) {
0046                 mView->setActiveCoding(AbstractByteArrayView::CharCodingId);
0047                 keyUsed = true;
0048             }
0049         }
0050     }
0051 
0052     return keyUsed ? true : AbstractController::handleKeyPress(keyEvent);
0053 }
0054 
0055 }