1 /* 2 This file is part of the Okteta Gui library, made within the KDE community. 3 4 SPDX-FileCopyrightText: 2008-2010 Friedrich W. H. Kossebau <kossebau@kde.org> 5 6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 7 */ 8 9 #ifndef OKTETA_ABSTRACTBYTEARRAYVIEW_P_HPP 10 #define OKTETA_ABSTRACTBYTEARRAYVIEW_P_HPP 11 12 // lib 13 #include "columnsview_p.hpp" 14 #include "abstractbytearrayview.hpp" 15 #include "bytearraytablecursor.hpp" 16 #include "bytearraytableranges.hpp" 17 #include "bytearraytablelayout.hpp" 18 #include "controller/valueeditor.hpp" 19 #include "controller/tabcontroller.hpp" 20 #include "offsetcolumnrenderer.hpp" 21 // Okteta core 22 #include <Okteta/AbstractByteArrayModel> 23 #include <Okteta/CharCodec> 24 25 namespace Okteta { 26 27 class ClipboardController; 28 class UndoRedoController; 29 class KeyNavigator; 30 class CharEditor; 31 32 class ZoomPinchController; 33 class TapNavigator; 34 class Dropper; 35 36 class AbstractMouseController; 37 class MouseNavigator; 38 class MousePaster; 39 40 class ZoomWheelController; 41 42 class WidgetColumnStylist; 43 class Cursor; 44 class BorderColumnRenderer; 45 46 class AbstractByteArrayViewPrivate : public ColumnsViewPrivate 47 { 48 public: 49 explicit AbstractByteArrayViewPrivate(AbstractByteArrayView* parent); 50 AbstractByteArrayViewPrivate() = delete; 51 52 ~AbstractByteArrayViewPrivate() override; 53 54 public: // value access 55 AbstractByteArrayModel* byteArrayModel() const; 56 57 // TODO: needed? 58 bool isModified() const; 59 60 bool isOverwriteMode() const; 61 bool isOverwriteOnly() const; 62 bool isViewReadOnly() const; 63 bool isEffectiveReadOnly() const; 64 65 /** returns the index of the cursor position */ 66 Address cursorPosition() const; 67 /***/ 68 bool isCursorBehind() const; 69 70 bool offsetColumnVisible() const; 71 AbstractByteArrayView::OffsetCoding offsetCoding() const; 72 73 int noOfBytesPerLine() const; 74 Address startOffset() const; 75 Address firstLineOffset() const; 76 77 AbstractByteArrayView::LayoutStyle layoutStyle() const; 78 79 bool tabChangesFocus() const; 80 81 bool hasSelectedData() const; 82 AddressRange selection() const; 83 QByteArray selectedData() const; 84 QMimeData* selectionAsMimeData() const; 85 86 AddressRange marking() const; 87 88 AbstractController* controller() const; 89 AbstractWheelController* wheelController() const; 90 91 ValueEditor* valueEditor() const; 92 Dropper* dropper() const; 93 94 ByteArrayTableLayout* layout() const; 95 ByteArrayTableCursor* tableCursor() const; 96 ByteArrayTableRanges* tableRanges() const; 97 98 const ValueCodec* valueCodec() const; 99 AbstractByteArrayView::ValueCoding valueCoding() const; 100 const CharCodec* charCodec() const; 101 AbstractByteArrayView::CharCoding charCoding() const; 102 const QString& charCodingName() const; 103 104 double zoomLevel() const; 105 106 public: 107 void init(); 108 void setByteArrayModel(AbstractByteArrayModel* byteArrayModel); 109 // TODO: delete old controller? 110 void setController(AbstractController* controller); 111 void setWheelController(AbstractWheelController* wheelController); 112 void setReadOnly(bool readOnly); 113 void setOverwriteOnly(bool overwriteOnly); 114 void setOverwriteMode(bool overwriteMode); 115 116 public: // setting parameters 117 void setValueCoding(AbstractByteArrayView::ValueCoding valueCoding); 118 void setCharCoding(AbstractByteArrayView::CharCoding charCoding); 119 void setCharCoding(const QString& charCodingName); 120 void setLayoutStyle(AbstractByteArrayView::LayoutStyle layoutStyle); 121 void setNoOfBytesPerLine(int noOfBytesPerLine); 122 void setStartOffset(Address startOffset); 123 void setFirstLineOffset(Address firstLineOffset); 124 void setModified(bool modified); 125 126 void setTabChangesFocus(bool tabChangesFocus = true); 127 128 void setMarking(Address start, Address end); 129 void setMarking(const AddressRange& marking); 130 131 void toggleOffsetColumn(bool offsetColumnVisible); 132 void setOffsetCoding(AbstractByteArrayView::OffsetCoding offsetCoding); 133 134 public: // zooming 135 void zoomIn(int pointInc); 136 void zoomIn(); 137 void zoomOut(int pointDec); 138 void zoomOut(); 139 void zoomTo(int pointSize); 140 void unZoom(); 141 void setZoomLevel(double level); 142 143 public: // interaction 144 void selectAll(bool select); 145 bool selectWord(Address index /*, Chartype*/); 146 void setSelection(const AddressRange& selection); 147 148 void setCursorPosition(Address index, bool isBehind); 149 void setSelectionCursorPosition(Address index); 150 151 public: 152 QMenu* createStandardContextMenu(QPoint position); 153 154 public: // API to be implemented 155 virtual void ensureVisible(const AddressRange& range, bool ensureStartVisible) = 0; 156 virtual void ensureCursorVisible() = 0; 157 virtual void placeCursor(QPoint point) = 0; 158 virtual QRect cursorRect() const = 0; 159 virtual Address indexByPoint(QPoint point) const = 0; 160 virtual void blinkCursor() = 0; 161 162 public: // events 163 bool event(QEvent* event); 164 void changeEvent(QEvent* event); 165 void resizeEvent(QResizeEvent* resizeEvent); 166 void focusInEvent(QFocusEvent* focusEvent); 167 void focusOutEvent(QFocusEvent* focusEvent); 168 void dragEnterEvent(QDragEnterEvent* dragEnterEvent); 169 void dragMoveEvent(QDragMoveEvent* dragMoveEvent); 170 void dragLeaveEvent(QDragLeaveEvent* dragLeaveEvent); 171 void dropEvent(QDropEvent* dropEvent); 172 void contextMenuEvent(QContextMenuEvent* contextMenuEvent); 173 void timerEvent(QTimerEvent* timerEvent); 174 bool viewportEvent(QEvent* event); 175 176 void mousePressEvent(QMouseEvent* mousePressEvent); 177 void mouseReleaseEvent(QMouseEvent* mouseReleaseEvent); 178 void mouseMoveEvent(QMouseEvent* mouseMoveEvent); 179 void mouseDoubleClickEvent(QMouseEvent* mouseDoubleClickEvent); 180 181 public: // slots 182 void onContentsChanged(const ArrayChangeMetricsList& changeList); 183 void onBookmarksChange(const QVector<Bookmark>& bookmarks); 184 void onRevertedToVersionIndex(int versionIndex); 185 void onByteArrayReadOnlyChange(bool isByteArrayReadOnly); 186 // void onClipboardChanged(); 187 188 protected: 189 /** handles screen update in case of a change to any of the width sizes 190 */ 191 void updateViewByWidth(); 192 void adjustLayoutToSize(); 193 void adaptController(); 194 void cancelByteEditor(); 195 void finishByteEditor(); 196 void initPainterFromWidget(QPainter* painter) const; 197 198 protected: 199 bool getNextChangedRange(CoordRange* changedRange, const CoordRange& visibleRange) const; 200 bool isByteEditorActive() const; 201 202 protected: 203 void removeSelectedData(); 204 void insert(const QByteArray& data); 205 void pasteData(const QMimeData* data); 206 bool canReadData(const QMimeData* data) const; 207 208 protected: // clipboard interaction 209 void cutToClipboard(QClipboard::Mode mode = QClipboard::Clipboard); 210 void copyToClipboard(QClipboard::Mode mode = QClipboard::Clipboard) const; 211 void pasteFromClipboard(QClipboard::Mode mode = QClipboard::Clipboard); 212 213 protected: // cursor control 214 void startCursor(); 215 void stopCursor(); 216 void unpauseCursor(); 217 218 protected: // API to be implemented 219 // cursor control 220 virtual void pauseCursor() = 0; 221 virtual void updateCursors() = 0; 222 223 virtual void setActiveCoding(AbstractByteArrayView::CodingTypeId codingId) = 0; 224 virtual void setVisibleCodings(int visibleCodings) = 0; 225 226 protected: // API to be implemented 227 virtual AbstractByteArrayView::CodingTypeId activeCoding() const = 0; 228 virtual AbstractByteArrayView::CodingTypes visibleCodings() const = 0; 229 virtual int fittingBytesPerLine() const = 0; 230 /** recalcs all dependent values with the actual NoOfBytesPerLine */ 231 virtual void adjustToLayoutNoOfBytesPerLine() = 0; 232 /** repaints all the parts that are signed as changed */ 233 virtual void updateChanged() = 0; 234 235 private: 236 /** Emits updates on selection & cursor position after a change */ 237 void emitSelectionUpdates(); 238 void endViewUpdate(); 239 void onCursorFlashTimeChanged(int flashTime); 240 241 protected: 242 AbstractByteArrayModel* mByteArrayModel; 243 244 /** the current input controller */ 245 AbstractController* mController; 246 AbstractMouseController* mMouseController; 247 AbstractWheelController* mWheelController; 248 249 /** holds the logical layout */ 250 ByteArrayTableLayout* mTableLayout; 251 /** */ 252 ByteArrayTableCursor* mTableCursor; 253 /** */ 254 ByteArrayTableRanges* mTableRanges; 255 256 OffsetColumnRenderer* mOffsetColumn; 257 BorderColumnRenderer* mOffsetBorderColumn; 258 259 protected: 260 /** */ 261 TabController* mTabController; 262 /** */ 263 UndoRedoController* mUndoRedoController; 264 /** */ 265 KeyNavigator* mKeyNavigator; 266 /** */ 267 ClipboardController* mClipboardController; 268 /** */ 269 ValueEditor* mValueEditor; 270 /** */ 271 CharEditor* mCharEditor; 272 273 Dropper* mDropper; 274 275 MouseNavigator* mMouseNavigator; 276 MousePaster* mMousePaster; 277 278 ZoomWheelController* mZoomWheelController; 279 280 ZoomPinchController* mZoomPinchController; 281 TapNavigator* mTapNavigator; 282 283 WidgetColumnStylist* mStylist; 284 285 protected: 286 /** Timer that controls the blinking of the cursor */ 287 int mCursorBlinkTimerId = 0; 288 289 /** object to store the blinking cursor pixmaps */ 290 Cursor* mCursorPixmaps; 291 292 protected: 293 /** flag whether the widget is set to readonly. Cannot override the databuffer's setting, of course. */ 294 bool mReadOnly : 1; 295 /** flag if only overwrite is allowed */ 296 bool mOverWriteOnly : 1; 297 /** flag if overwrite mode is active */ 298 bool mOverWrite : 1; 299 /** flag whether the font is changed due to a zooming */ 300 bool mInZooming : 1; 301 /** flag if the cursor should be invisible */ 302 bool mCursorPaused : 1; 303 /** flag if the cursor is visible when blinking */ 304 bool mBlinkCursorVisible : 1; 305 /** flag if the cursor is visible */ 306 bool mCursorVisible : 1; 307 308 /** font size as set by user (used for zooming) */ 309 int mDefaultFontSize; 310 double mZoomLevel = 1.0; 311 312 // parameters 313 /** */ 314 ValueCodec* mValueCodec; 315 /** */ 316 AbstractByteArrayView::ValueCoding mValueCoding; 317 /** */ 318 CharCodec* mCharCodec; 319 /** */ 320 AbstractByteArrayView::CharCoding mCharCoding; 321 /** style of resizing */ 322 AbstractByteArrayView::LayoutStyle mResizeStyle; 323 324 private: 325 Q_DECLARE_PUBLIC(AbstractByteArrayView) 326 }; 327 byteArrayModel() const328inline AbstractByteArrayModel* AbstractByteArrayViewPrivate::byteArrayModel() const { return mByteArrayModel; } controller() const329inline AbstractController* AbstractByteArrayViewPrivate::controller() const { return mController; } wheelController() const330inline AbstractWheelController* AbstractByteArrayViewPrivate::wheelController() const { return mWheelController; } 331 isOverwriteMode() const332inline bool AbstractByteArrayViewPrivate::isOverwriteMode() const { return mOverWrite; } isOverwriteOnly() const333inline bool AbstractByteArrayViewPrivate::isOverwriteOnly() const { return mOverWriteOnly; } isViewReadOnly() const334inline bool AbstractByteArrayViewPrivate::isViewReadOnly() const { return mReadOnly; } isEffectiveReadOnly() const335inline bool AbstractByteArrayViewPrivate::isEffectiveReadOnly() const { return mReadOnly || mByteArrayModel->isReadOnly(); } zoomLevel() const336inline double AbstractByteArrayViewPrivate::zoomLevel() const { return mZoomLevel; } 337 layout() const338inline ByteArrayTableLayout* AbstractByteArrayViewPrivate::layout() const { return mTableLayout; } tableCursor() const339inline ByteArrayTableCursor* AbstractByteArrayViewPrivate::tableCursor() const { return mTableCursor; } tableRanges() const340inline ByteArrayTableRanges* AbstractByteArrayViewPrivate::tableRanges() const { return mTableRanges; } 341 valueCodec() const342inline const ValueCodec* AbstractByteArrayViewPrivate::valueCodec() const { return mValueCodec; } valueCoding() const343inline AbstractByteArrayView::ValueCoding AbstractByteArrayViewPrivate::valueCoding() const { return mValueCoding; } charCodec() const344inline const CharCodec* AbstractByteArrayViewPrivate::charCodec() const { return mCharCodec; } charCoding() const345inline AbstractByteArrayView::CharCoding AbstractByteArrayViewPrivate::charCoding() const 346 { 347 return (AbstractByteArrayView::CharCoding)mCharCoding; 348 } charCodingName() const349inline const QString& AbstractByteArrayViewPrivate::charCodingName() const { return mCharCodec->name(); } layoutStyle() const350inline AbstractByteArrayView::LayoutStyle AbstractByteArrayViewPrivate::layoutStyle() const { return mResizeStyle; } cursorPosition() const351inline Address AbstractByteArrayViewPrivate::cursorPosition() const { return mTableCursor->realIndex(); } isCursorBehind() const352inline bool AbstractByteArrayViewPrivate::isCursorBehind() const { return mTableCursor->isBehind(); } isModified() const353inline bool AbstractByteArrayViewPrivate::isModified() const { return mByteArrayModel->isModified(); } noOfBytesPerLine() const354inline int AbstractByteArrayViewPrivate::noOfBytesPerLine() const { return mTableLayout->noOfBytesPerLine(); } firstLineOffset() const355inline Address AbstractByteArrayViewPrivate::firstLineOffset() const { return mTableLayout->firstLineOffset(); } startOffset() const356inline Address AbstractByteArrayViewPrivate::startOffset() const { return mTableLayout->startOffset(); } 357 selection() const358inline AddressRange AbstractByteArrayViewPrivate::selection() const { return mTableRanges->selection(); } hasSelectedData() const359inline bool AbstractByteArrayViewPrivate::hasSelectedData() const { return mTableRanges->hasSelection(); } 360 marking() const361inline AddressRange AbstractByteArrayViewPrivate::marking() const { return mTableRanges->marking(); } 362 tabChangesFocus() const363inline bool AbstractByteArrayViewPrivate::tabChangesFocus() const { return mTabController->tabChangesFocus(); } isByteEditorActive() const364inline bool AbstractByteArrayViewPrivate::isByteEditorActive() const { return mValueEditor->isInEditMode(); } valueEditor() const365inline ValueEditor* AbstractByteArrayViewPrivate::valueEditor() const { return mValueEditor; } dropper() const366inline Dropper* AbstractByteArrayViewPrivate::dropper() const { return mDropper; } offsetColumnVisible() const367inline bool AbstractByteArrayViewPrivate::offsetColumnVisible() const { return mOffsetColumn->isVisible(); } offsetCoding() const368inline AbstractByteArrayView::OffsetCoding AbstractByteArrayViewPrivate::offsetCoding() const 369 { 370 return (AbstractByteArrayView::OffsetCoding)mOffsetColumn->format(); 371 } 372 cancelByteEditor()373inline void AbstractByteArrayViewPrivate::cancelByteEditor() 374 { 375 mValueEditor->cancelEdit(false); 376 } finishByteEditor()377inline void AbstractByteArrayViewPrivate::finishByteEditor() 378 { 379 mValueEditor->finishEdit(); 380 } setTabChangesFocus(bool tabChangesFocus)381inline void AbstractByteArrayViewPrivate::setTabChangesFocus(bool tabChangesFocus) 382 { 383 mTabController->setTabChangesFocus(tabChangesFocus); 384 } 385 setController(AbstractController * controller)386inline void AbstractByteArrayViewPrivate::setController(AbstractController* controller) { mController = controller; } setWheelController(AbstractWheelController * wheelController)387inline void AbstractByteArrayViewPrivate::setWheelController(AbstractWheelController* wheelController) { mWheelController = wheelController; } setModified(bool modified)388inline void AbstractByteArrayViewPrivate::setModified(bool modified) { mByteArrayModel->setModified(modified); } 389 390 } 391 392 #endif 393