File indexing completed on 2024-04-14 15:52:51
0001 /* 0002 This file is part of the Okteta Gui library, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2008-2010 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_ABSTRACTBYTEARRAYVIEW_P_HPP 0010 #define OKTETA_ABSTRACTBYTEARRAYVIEW_P_HPP 0011 0012 // lib 0013 #include "columnsview_p.hpp" 0014 #include "abstractbytearrayview.hpp" 0015 #include "bytearraytablecursor.hpp" 0016 #include "bytearraytableranges.hpp" 0017 #include "bytearraytablelayout.hpp" 0018 #include "controller/valueeditor.hpp" 0019 #include "controller/tabcontroller.hpp" 0020 #include "offsetcolumnrenderer.hpp" 0021 // Okteta core 0022 #include <Okteta/AbstractByteArrayModel> 0023 #include <Okteta/CharCodec> 0024 0025 namespace Okteta { 0026 0027 class ClipboardController; 0028 class UndoRedoController; 0029 class KeyNavigator; 0030 class CharEditor; 0031 0032 class ZoomPinchController; 0033 class TapNavigator; 0034 class Dropper; 0035 0036 class AbstractMouseController; 0037 class MouseNavigator; 0038 class MousePaster; 0039 0040 class ZoomWheelController; 0041 0042 class WidgetColumnStylist; 0043 class Cursor; 0044 class BorderColumnRenderer; 0045 0046 class AbstractByteArrayViewPrivate : public ColumnsViewPrivate 0047 { 0048 public: 0049 explicit AbstractByteArrayViewPrivate(AbstractByteArrayView* parent); 0050 0051 ~AbstractByteArrayViewPrivate() override; 0052 0053 public: // value access 0054 AbstractByteArrayModel* byteArrayModel() const; 0055 0056 // TODO: needed? 0057 bool isModified() const; 0058 0059 bool isOverwriteMode() const; 0060 bool isOverwriteOnly() const; 0061 bool isViewReadOnly() const; 0062 bool isEffectiveReadOnly() const; 0063 0064 /** returns the index of the cursor position */ 0065 Address cursorPosition() const; 0066 /***/ 0067 bool isCursorBehind() const; 0068 0069 bool offsetColumnVisible() const; 0070 AbstractByteArrayView::OffsetCoding offsetCoding() const; 0071 0072 int noOfBytesPerLine() const; 0073 Address startOffset() const; 0074 Address firstLineOffset() const; 0075 0076 AbstractByteArrayView::LayoutStyle layoutStyle() const; 0077 0078 bool tabChangesFocus() const; 0079 0080 bool hasSelectedData() const; 0081 AddressRange selection() const; 0082 QByteArray selectedData() const; 0083 QMimeData* selectionAsMimeData() const; 0084 0085 AddressRange marking() const; 0086 0087 AbstractController* controller() const; 0088 AbstractWheelController* wheelController() const; 0089 0090 ValueEditor* valueEditor() const; 0091 Dropper* dropper() const; 0092 0093 ByteArrayTableLayout* layout() const; 0094 ByteArrayTableCursor* tableCursor() const; 0095 ByteArrayTableRanges* tableRanges() const; 0096 0097 const ValueCodec* valueCodec() const; 0098 AbstractByteArrayView::ValueCoding valueCoding() const; 0099 const CharCodec* charCodec() const; 0100 AbstractByteArrayView::CharCoding charCoding() const; 0101 const QString& charCodingName() const; 0102 0103 double zoomLevel() const; 0104 0105 public: 0106 void init(); 0107 void setByteArrayModel(AbstractByteArrayModel* byteArrayModel); 0108 // TODO: delete old controller? 0109 void setController(AbstractController* controller); 0110 void setWheelController(AbstractWheelController* wheelController); 0111 void setReadOnly(bool readOnly); 0112 void setOverwriteOnly(bool overwriteOnly); 0113 void setOverwriteMode(bool overwriteMode); 0114 0115 public: // setting parameters 0116 void setValueCoding(AbstractByteArrayView::ValueCoding valueCoding); 0117 void setCharCoding(AbstractByteArrayView::CharCoding charCoding); 0118 void setCharCoding(const QString& charCodingName); 0119 void setLayoutStyle(AbstractByteArrayView::LayoutStyle layoutStyle); 0120 void setNoOfBytesPerLine(int noOfBytesPerLine); 0121 void setStartOffset(Address startOffset); 0122 void setFirstLineOffset(Address firstLineOffset); 0123 void setModified(bool modified); 0124 0125 void setTabChangesFocus(bool tabChangesFocus = true); 0126 0127 void setMarking(Address start, Address end); 0128 void setMarking(const AddressRange& marking); 0129 0130 void toggleOffsetColumn(bool offsetColumnVisible); 0131 void setOffsetCoding(AbstractByteArrayView::OffsetCoding offsetCoding); 0132 0133 public: // zooming 0134 void zoomIn(int pointInc); 0135 void zoomIn(); 0136 void zoomOut(int pointDec); 0137 void zoomOut(); 0138 void zoomTo(int pointSize); 0139 void unZoom(); 0140 void setZoomLevel(double level); 0141 0142 public: // interaction 0143 void selectAll(bool select); 0144 bool selectWord(Address index /*, Chartype*/); 0145 void setSelection(const AddressRange& selection); 0146 0147 void setCursorPosition(Address index, bool isBehind); 0148 void setSelectionCursorPosition(Address index); 0149 0150 public: 0151 QMenu* createStandardContextMenu(QPoint position); 0152 0153 public: // API to be implemented 0154 virtual void ensureVisible(const AddressRange& range, bool ensureStartVisible) = 0; 0155 virtual void ensureCursorVisible() = 0; 0156 virtual void placeCursor(QPoint point) = 0; 0157 virtual QRect cursorRect() const = 0; 0158 virtual Address indexByPoint(QPoint point) const = 0; 0159 virtual void blinkCursor() = 0; 0160 0161 public: // events 0162 bool event(QEvent* event); 0163 void changeEvent(QEvent* event); 0164 void resizeEvent(QResizeEvent* resizeEvent); 0165 void focusInEvent(QFocusEvent* focusEvent); 0166 void focusOutEvent(QFocusEvent* focusEvent); 0167 void dragEnterEvent(QDragEnterEvent* dragEnterEvent); 0168 void dragMoveEvent(QDragMoveEvent* dragMoveEvent); 0169 void dragLeaveEvent(QDragLeaveEvent* dragLeaveEvent); 0170 void dropEvent(QDropEvent* dropEvent); 0171 void contextMenuEvent(QContextMenuEvent* contextMenuEvent); 0172 void timerEvent(QTimerEvent* timerEvent); 0173 bool viewportEvent(QEvent* event); 0174 0175 void mousePressEvent(QMouseEvent* mousePressEvent); 0176 void mouseReleaseEvent(QMouseEvent* mouseReleaseEvent); 0177 void mouseMoveEvent(QMouseEvent* mouseMoveEvent); 0178 void mouseDoubleClickEvent(QMouseEvent* mouseDoubleClickEvent); 0179 0180 public: // slots 0181 void onContentsChanged(const ArrayChangeMetricsList& changeList); 0182 void onBookmarksChange(const QVector<Bookmark>& bookmarks); 0183 void onRevertedToVersionIndex(int versionIndex); 0184 void onByteArrayReadOnlyChange(bool isByteArrayReadOnly); 0185 // void onClipboardChanged(); 0186 0187 protected: 0188 /** handles screen update in case of a change to any of the width sizes 0189 */ 0190 void updateViewByWidth(); 0191 void adjustLayoutToSize(); 0192 void adaptController(); 0193 void cancelByteEditor(); 0194 void finishByteEditor(); 0195 void initPainterFromWidget(QPainter* painter) const; 0196 0197 protected: 0198 bool getNextChangedRange(CoordRange* changedRange, const CoordRange& visibleRange) const; 0199 bool isByteEditorActive() const; 0200 0201 protected: 0202 void removeSelectedData(); 0203 void insert(const QByteArray& data); 0204 void pasteData(const QMimeData* data); 0205 bool canReadData(const QMimeData* data) const; 0206 0207 protected: // clipboard interaction 0208 void cutToClipboard(QClipboard::Mode mode = QClipboard::Clipboard); 0209 void copyToClipboard(QClipboard::Mode mode = QClipboard::Clipboard) const; 0210 void pasteFromClipboard(QClipboard::Mode mode = QClipboard::Clipboard); 0211 0212 protected: // cursor control 0213 void startCursor(); 0214 void stopCursor(); 0215 void unpauseCursor(); 0216 0217 protected: // API to be implemented 0218 // cursor control 0219 virtual void pauseCursor() = 0; 0220 virtual void updateCursors() = 0; 0221 0222 virtual void setActiveCoding(AbstractByteArrayView::CodingTypeId codingId) = 0; 0223 virtual void setVisibleCodings(int visibleCodings) = 0; 0224 0225 protected: // API to be implemented 0226 virtual AbstractByteArrayView::CodingTypeId activeCoding() const = 0; 0227 virtual AbstractByteArrayView::CodingTypes visibleCodings() const = 0; 0228 virtual int fittingBytesPerLine() const = 0; 0229 /** recalcs all dependent values with the actual NoOfBytesPerLine */ 0230 virtual void adjustToLayoutNoOfBytesPerLine() = 0; 0231 /** repaints all the parts that are signed as changed */ 0232 virtual void updateChanged() = 0; 0233 0234 private: 0235 /** Emits updates on selection & cursor position after a change */ 0236 void emitSelectionUpdates(); 0237 void endViewUpdate(); 0238 void onCursorFlashTimeChanged(int flashTime); 0239 0240 protected: 0241 AbstractByteArrayModel* mByteArrayModel; 0242 0243 /** the current input controller */ 0244 AbstractController* mController; 0245 AbstractMouseController* mMouseController; 0246 AbstractWheelController* mWheelController; 0247 0248 /** holds the logical layout */ 0249 ByteArrayTableLayout* mTableLayout; 0250 /** */ 0251 ByteArrayTableCursor* mTableCursor; 0252 /** */ 0253 ByteArrayTableRanges* mTableRanges; 0254 0255 OffsetColumnRenderer* mOffsetColumn; 0256 BorderColumnRenderer* mOffsetBorderColumn; 0257 0258 protected: 0259 /** */ 0260 TabController* mTabController; 0261 /** */ 0262 UndoRedoController* mUndoRedoController; 0263 /** */ 0264 KeyNavigator* mKeyNavigator; 0265 /** */ 0266 ClipboardController* mClipboardController; 0267 /** */ 0268 ValueEditor* mValueEditor; 0269 /** */ 0270 CharEditor* mCharEditor; 0271 0272 Dropper* mDropper; 0273 0274 MouseNavigator* mMouseNavigator; 0275 MousePaster* mMousePaster; 0276 0277 ZoomWheelController* mZoomWheelController; 0278 0279 ZoomPinchController* mZoomPinchController; 0280 TapNavigator* mTapNavigator; 0281 0282 WidgetColumnStylist* mStylist; 0283 0284 protected: 0285 /** Timer that controls the blinking of the cursor */ 0286 int mCursorBlinkTimerId = 0; 0287 0288 /** object to store the blinking cursor pixmaps */ 0289 Cursor* mCursorPixmaps; 0290 0291 protected: 0292 /** flag whether the widget is set to readonly. Cannot override the databuffer's setting, of course. */ 0293 bool mReadOnly : 1; 0294 /** flag if only overwrite is allowed */ 0295 bool mOverWriteOnly : 1; 0296 /** flag if overwrite mode is active */ 0297 bool mOverWrite : 1; 0298 /** flag whether the font is changed due to a zooming */ 0299 bool mInZooming : 1; 0300 /** flag if the cursor should be invisible */ 0301 bool mCursorPaused : 1; 0302 /** flag if the cursor is visible when blinking */ 0303 bool mBlinkCursorVisible : 1; 0304 /** flag if the cursor is visible */ 0305 bool mCursorVisible : 1; 0306 0307 /** font size as set by user (used for zooming) */ 0308 int mDefaultFontSize; 0309 double mZoomLevel = 1.0; 0310 0311 // parameters 0312 /** */ 0313 ValueCodec* mValueCodec; 0314 /** */ 0315 AbstractByteArrayView::ValueCoding mValueCoding; 0316 /** */ 0317 CharCodec* mCharCodec; 0318 /** */ 0319 AbstractByteArrayView::CharCoding mCharCoding; 0320 /** style of resizing */ 0321 AbstractByteArrayView::LayoutStyle mResizeStyle; 0322 0323 private: 0324 Q_DECLARE_PUBLIC(AbstractByteArrayView) 0325 }; 0326 0327 inline AbstractByteArrayModel* AbstractByteArrayViewPrivate::byteArrayModel() const { return mByteArrayModel; } 0328 inline AbstractController* AbstractByteArrayViewPrivate::controller() const { return mController; } 0329 inline AbstractWheelController* AbstractByteArrayViewPrivate::wheelController() const { return mWheelController; } 0330 0331 inline bool AbstractByteArrayViewPrivate::isOverwriteMode() const { return mOverWrite; } 0332 inline bool AbstractByteArrayViewPrivate::isOverwriteOnly() const { return mOverWriteOnly; } 0333 inline bool AbstractByteArrayViewPrivate::isViewReadOnly() const { return mReadOnly; } 0334 inline bool AbstractByteArrayViewPrivate::isEffectiveReadOnly() const { return mReadOnly || mByteArrayModel->isReadOnly(); } 0335 inline double AbstractByteArrayViewPrivate::zoomLevel() const { return mZoomLevel; } 0336 0337 inline ByteArrayTableLayout* AbstractByteArrayViewPrivate::layout() const { return mTableLayout; } 0338 inline ByteArrayTableCursor* AbstractByteArrayViewPrivate::tableCursor() const { return mTableCursor; } 0339 inline ByteArrayTableRanges* AbstractByteArrayViewPrivate::tableRanges() const { return mTableRanges; } 0340 0341 inline const ValueCodec* AbstractByteArrayViewPrivate::valueCodec() const { return mValueCodec; } 0342 inline AbstractByteArrayView::ValueCoding AbstractByteArrayViewPrivate::valueCoding() const { return mValueCoding; } 0343 inline const CharCodec* AbstractByteArrayViewPrivate::charCodec() const { return mCharCodec; } 0344 inline AbstractByteArrayView::CharCoding AbstractByteArrayViewPrivate::charCoding() const 0345 { 0346 return (AbstractByteArrayView::CharCoding)mCharCoding; 0347 } 0348 inline const QString& AbstractByteArrayViewPrivate::charCodingName() const { return mCharCodec->name(); } 0349 inline AbstractByteArrayView::LayoutStyle AbstractByteArrayViewPrivate::layoutStyle() const { return mResizeStyle; } 0350 inline Address AbstractByteArrayViewPrivate::cursorPosition() const { return mTableCursor->realIndex(); } 0351 inline bool AbstractByteArrayViewPrivate::isCursorBehind() const { return mTableCursor->isBehind(); } 0352 inline bool AbstractByteArrayViewPrivate::isModified() const { return mByteArrayModel->isModified(); } 0353 inline int AbstractByteArrayViewPrivate::noOfBytesPerLine() const { return mTableLayout->noOfBytesPerLine(); } 0354 inline Address AbstractByteArrayViewPrivate::firstLineOffset() const { return mTableLayout->firstLineOffset(); } 0355 inline Address AbstractByteArrayViewPrivate::startOffset() const { return mTableLayout->startOffset(); } 0356 0357 inline AddressRange AbstractByteArrayViewPrivate::selection() const { return mTableRanges->selection(); } 0358 inline bool AbstractByteArrayViewPrivate::hasSelectedData() const { return mTableRanges->hasSelection(); } 0359 0360 inline AddressRange AbstractByteArrayViewPrivate::marking() const { return mTableRanges->marking(); } 0361 0362 inline bool AbstractByteArrayViewPrivate::tabChangesFocus() const { return mTabController->tabChangesFocus(); } 0363 inline bool AbstractByteArrayViewPrivate::isByteEditorActive() const { return mValueEditor->isInEditMode(); } 0364 inline ValueEditor* AbstractByteArrayViewPrivate::valueEditor() const { return mValueEditor; } 0365 inline Dropper* AbstractByteArrayViewPrivate::dropper() const { return mDropper; } 0366 inline bool AbstractByteArrayViewPrivate::offsetColumnVisible() const { return mOffsetColumn->isVisible(); } 0367 inline AbstractByteArrayView::OffsetCoding AbstractByteArrayViewPrivate::offsetCoding() const 0368 { 0369 return (AbstractByteArrayView::OffsetCoding)mOffsetColumn->format(); 0370 } 0371 0372 inline void AbstractByteArrayViewPrivate::cancelByteEditor() 0373 { 0374 mValueEditor->cancelEdit(false); 0375 } 0376 inline void AbstractByteArrayViewPrivate::finishByteEditor() 0377 { 0378 mValueEditor->finishEdit(); 0379 } 0380 inline void AbstractByteArrayViewPrivate::setTabChangesFocus(bool tabChangesFocus) 0381 { 0382 mTabController->setTabChangesFocus(tabChangesFocus); 0383 } 0384 0385 inline void AbstractByteArrayViewPrivate::setController(AbstractController* controller) { mController = controller; } 0386 inline void AbstractByteArrayViewPrivate::setWheelController(AbstractWheelController* wheelController) { mWheelController = wheelController; } 0387 inline void AbstractByteArrayViewPrivate::setModified(bool modified) { mByteArrayModel->setModified(modified); } 0388 0389 } 0390 0391 #endif