File indexing completed on 2024-04-28 17:07:10
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 #ifndef OKTETA_VALUEEDITOR_HPP 0010 #define OKTETA_VALUEEDITOR_HPP 0011 0012 // lib 0013 #include "abstracteditor.hpp" 0014 // Okteta core 0015 #include <Okteta/Byte> 0016 // Qt 0017 #include <QString> 0018 0019 namespace Okteta { 0020 class AbstractByteArrayView; 0021 0022 class ValueEditor : public AbstractEditor 0023 { 0024 private: 0025 enum ValueEditAction 0026 { 0027 EnterValue, 0028 IncValue, 0029 DecValue, 0030 ValueAppend, 0031 ValueEdit, 0032 LeaveValue, 0033 ValueBackspace 0034 }; 0035 0036 public: 0037 ValueEditor(ByteArrayTableCursor* cursor, AbstractByteArrayView* view, AbstractController* parent); 0038 ~ValueEditor() override; 0039 0040 public: // AbstractController API 0041 bool handleKeyPress(QKeyEvent* keyEvent) override; 0042 0043 public: 0044 void reset(); 0045 0046 void adaptToValueCodecChange(); 0047 void finishEdit(); 0048 void cancelEdit(bool undoChanges = true); 0049 0050 public: 0051 bool isInEditMode() const; 0052 Byte value() const; 0053 QString valueAsString() const; 0054 0055 private: 0056 void startEdit(const QString& description); 0057 /** 0058 * executes keyboard Action \a Action. This is normally called by a key event handler. 0059 * @param action action to be done 0060 * @param input data to be used for the action 0061 */ 0062 void doValueEditAction(ValueEditAction action, int input = -1); 0063 0064 private: 0065 /** flag whether we are in editing mode */ 0066 bool mInEditMode : 1; 0067 /** flag whether byte edit mode was reached by inserting */ 0068 bool mEditModeByInsert : 1; 0069 /** */ 0070 Byte mEditValue; 0071 /** stores the old byte value */ 0072 Byte mOldValue; // TODO: this or rely on undo? 0073 /** */ 0074 unsigned int mInsertedDigitsCount; 0075 /** buffer with the */ 0076 QString mValueString; 0077 }; 0078 0079 inline bool ValueEditor::isInEditMode() const { return mInEditMode; } 0080 inline void ValueEditor::reset() { mInEditMode = false; } 0081 inline Byte ValueEditor::value() const { return mEditValue; } 0082 inline QString ValueEditor::valueAsString() const { return mValueString; } 0083 0084 } 0085 0086 #endif