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

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 "chareditor.hpp"
0010 
0011 // lib
0012 #include <abstractbytearrayview.hpp>
0013 // Okteta core
0014 #include <Okteta/CharCodec>
0015 // Qt
0016 #include <QKeyEvent>
0017 
0018 namespace Okteta {
0019 
0020 CharEditor::CharEditor(ByteArrayTableCursor* cursor, AbstractByteArrayView* view, AbstractController* parent)
0021     : AbstractEditor(cursor, view, parent)
0022 {
0023 }
0024 
0025 CharEditor::~CharEditor() = default;
0026 
0027 bool CharEditor::handleKeyPress(QKeyEvent* keyEvent)
0028 {
0029     bool keyUsed = false;
0030 
0031     const QString text = keyEvent->text();
0032 
0033     // some input that should be inserted?
0034     if (text.length() > 0
0035         && !(keyEvent->modifiers() & (Qt::CTRL | Qt::ALT | Qt::META))) {
0036 
0037         const QChar enteredChar = text.at(0);
0038         if (enteredChar.isPrint()) {
0039             Byte byte;
0040             if (mView->charCodec()->encode(&byte, enteredChar)) {
0041                 QByteArray data(1, byte);
0042                 mView->insert(data);
0043 
0044                 keyUsed = true;
0045             }
0046         }
0047     }
0048 
0049     return keyUsed ? true : AbstractEditor::handleKeyPress(keyEvent);
0050 }
0051 
0052 }