Warning, file /utilities/okteta/kasten/gui/view/bytearrayjanusview.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 This file is part of the Okteta Kasten module, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2008-2012 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 "bytearrayjanusview.hpp" 0010 0011 // Okteta gui 0012 #include <Okteta/ByteArrayColumnView> 0013 #include <Okteta/ByteArrayRowView> 0014 // Qt 0015 #include <QHBoxLayout> 0016 #include <QScrollBar> 0017 0018 namespace Okteta { 0019 0020 ByteArrayJanusView::ByteArrayJanusView(QWidget* parent) 0021 : QWidget(parent) 0022 { 0023 mLayout = new QHBoxLayout(this); 0024 mLayout->setContentsMargins(0, 0, 0, 0); 0025 setViewModus(ColumnViewId); 0026 } 0027 0028 ByteArrayJanusView::~ByteArrayJanusView() = default; 0029 0030 void ByteArrayJanusView::setByteArrayModel(AbstractByteArrayModel* byteArrayModel) 0031 { 0032 mView->setByteArrayModel(byteArrayModel); 0033 } 0034 0035 void ByteArrayJanusView::setViewModus(int viewModus) 0036 { 0037 if (viewModus == mViewModus) { 0038 return; 0039 } 0040 0041 AbstractByteArrayView* newView = (viewModus == ColumnViewId) ? 0042 (AbstractByteArrayView*)new ByteArrayColumnView(this) : 0043 (AbstractByteArrayView*)new ByteArrayRowView(this); 0044 0045 const bool hasFocus = mView ? mView->hasFocus() : false; 0046 if (mView) { 0047 newView->setFont(mView->font()); 0048 0049 newView->setByteArrayModel(mView->byteArrayModel()); 0050 newView->setReadOnly(mView->isReadOnly()); 0051 newView->setOverwriteMode(mView->isOverwriteMode()); 0052 newView->setZoomLevel(mView->zoomLevel()); 0053 newView->setShowsNonprinting(mView->showsNonprinting()); 0054 newView->setValueCoding(mView->valueCoding()); 0055 newView->setCharCoding(mView->charCodingName()); 0056 newView->setVisibleCodings(mView->visibleCodings()); 0057 newView->setActiveCoding(mView->activeCoding()); 0058 newView->toggleOffsetColumn(mView->offsetColumnVisible()); 0059 newView->setOffsetCoding(mView->offsetCoding()); 0060 newView->setStartOffset(mView->startOffset()); 0061 newView->setFirstLineOffset(mView->firstLineOffset()); 0062 newView->setNoOfBytesPerLine(mView->noOfBytesPerLine()); 0063 newView->setNoOfGroupedBytes(mView->noOfGroupedBytes()); 0064 newView->setLayoutStyle(mView->layoutStyle()); 0065 newView->setSubstituteChar(mView->substituteChar()); 0066 newView->setUndefinedChar(mView->undefinedChar()); 0067 newView->setCursorPosition(mView->cursorPosition()); 0068 newView->setSelection(mView->selection()); 0069 newView->setMarking(mView->marking()); 0070 0071 mLayout->removeWidget(mView); 0072 delete mView; 0073 } 0074 0075 mView = newView; 0076 0077 mLayout->addWidget(mView); 0078 setFocusProxy(mView); 0079 if (hasFocus) { 0080 mView->setFocus(); 0081 } 0082 mViewModus = viewModus; 0083 0084 mView->setContextMenuPolicy(Qt::CustomContextMenu); 0085 connect(mView, &QWidget::customContextMenuRequested, this, &ByteArrayJanusView::viewContextMenuRequested); 0086 0087 connect(mView, &AbstractByteArrayView::hasSelectedDataChanged, this, &ByteArrayJanusView::hasSelectedDataChanged); 0088 connect(mView, &AbstractByteArrayView::selectionChanged, this, &ByteArrayJanusView::selectionChanged); 0089 connect(mView, &AbstractByteArrayView::readOnlyChanged, this, &ByteArrayJanusView::readOnlyChanged); 0090 connect(mView, &AbstractByteArrayView::overwriteModeChanged, this, &ByteArrayJanusView::overwriteModeChanged); 0091 connect(mView, &AbstractByteArrayView::cursorPositionChanged, this, &ByteArrayJanusView::cursorPositionChanged); 0092 connect(mView, &AbstractByteArrayView::valueCodingChanged, this, &ByteArrayJanusView::valueCodingChanged); 0093 connect(mView, &AbstractByteArrayView::charCodecChanged, this, &ByteArrayJanusView::charCodecChanged); 0094 connect(mView, &AbstractByteArrayView::focusChanged, this, &ByteArrayJanusView::focusChanged); 0095 0096 connect(mView, &AbstractByteArrayView::offsetColumnVisibleChanged, this, &ByteArrayJanusView::offsetColumnVisibleChanged); 0097 connect(mView, &AbstractByteArrayView::offsetCodingChanged, this, &ByteArrayJanusView::offsetCodingChanged); 0098 connect(mView, &AbstractByteArrayView::visibleByteArrayCodingsChanged, this, &ByteArrayJanusView::visibleByteArrayCodingsChanged); 0099 connect(mView, &AbstractByteArrayView::layoutStyleChanged, this, &ByteArrayJanusView::layoutStyleChanged); 0100 connect(mView, &AbstractByteArrayView::noOfBytesPerLineChanged, this, &ByteArrayJanusView::noOfBytesPerLineChanged); 0101 connect(mView, &AbstractByteArrayView::showsNonprintingChanged, this, &ByteArrayJanusView::showsNonprintingChanged); 0102 connect(mView, &AbstractByteArrayView::substituteCharChanged, this, &ByteArrayJanusView::substituteCharChanged); 0103 connect(mView, &AbstractByteArrayView::undefinedCharChanged, this, &ByteArrayJanusView::undefinedCharChanged); 0104 connect(mView, &AbstractByteArrayView::noOfGroupedBytesChanged, this, &ByteArrayJanusView::noOfGroupedBytesChanged); 0105 connect(mView, &AbstractByteArrayView::zoomLevelChanged, this, &ByteArrayJanusView::zoomLevelChanged); 0106 0107 emit viewModusChanged(mViewModus); 0108 } 0109 0110 bool ByteArrayJanusView::isReadOnly() const { return mView->isReadOnly(); } 0111 void ByteArrayJanusView::setReadOnly(bool isReadOnly) { mView->setReadOnly(isReadOnly); } 0112 0113 void ByteArrayJanusView::setZoomLevel(double Level) 0114 { 0115 mView->setZoomLevel(Level); 0116 } 0117 0118 double ByteArrayJanusView::zoomLevel() const 0119 { 0120 return mView->zoomLevel(); 0121 } 0122 0123 void ByteArrayJanusView::selectAll(bool selectAll) 0124 { 0125 mView->selectAll(selectAll); 0126 } 0127 0128 bool ByteArrayJanusView::hasSelectedData() const 0129 { 0130 return mView->hasSelectedData(); 0131 } 0132 0133 QMimeData* ByteArrayJanusView::selectionAsMimeData() const 0134 { 0135 return mView->selectionAsMimeData(); 0136 } 0137 0138 void ByteArrayJanusView::pasteData(const QMimeData* data) 0139 { 0140 mView->pasteData(data); 0141 } 0142 0143 void ByteArrayJanusView::removeSelectedData() 0144 { 0145 mView->removeSelectedData(); 0146 } 0147 0148 bool ByteArrayJanusView::canReadData(const QMimeData* data) const 0149 { 0150 return mView->canReadData(data); 0151 } 0152 0153 void ByteArrayJanusView::setCursorPosition(Address cursorPosition) 0154 { 0155 mView->setCursorPosition(cursorPosition); 0156 } 0157 void ByteArrayJanusView::setSelectionCursorPosition(Address index) 0158 { 0159 mView->setSelectionCursorPosition(index); 0160 } 0161 Address ByteArrayJanusView::cursorPosition() const 0162 { 0163 return mView->cursorPosition(); 0164 } 0165 QRect ByteArrayJanusView::cursorRect() const 0166 { 0167 // Okteta Gui uses viewport coordinates like QTextEdit, 0168 // but here view coordinates are used, so map the rect as needed 0169 QRect cursorRect = mView->cursorRect(); 0170 const QPoint viewTopLeft = mView->viewport()->mapToParent(cursorRect.topLeft()); 0171 cursorRect.moveTopLeft(viewTopLeft); 0172 return cursorRect; 0173 } 0174 0175 void ByteArrayJanusView::setStartOffset(Address startOffset) 0176 { 0177 mView->setStartOffset(startOffset); 0178 } 0179 void ByteArrayJanusView::setFirstLineOffset(Address firstLineOffset) 0180 { 0181 mView->setFirstLineOffset(firstLineOffset); 0182 } 0183 void ByteArrayJanusView::setNoOfBytesPerLine(int noOfBytesPerLine) 0184 { 0185 mView->setNoOfBytesPerLine(noOfBytesPerLine); 0186 } 0187 Address ByteArrayJanusView::startOffset() const 0188 { 0189 return mView->startOffset(); 0190 } 0191 Address ByteArrayJanusView::firstLineOffset() const 0192 { 0193 return mView->firstLineOffset(); 0194 } 0195 int ByteArrayJanusView::noOfBytesPerLine() const 0196 { 0197 return mView->noOfBytesPerLine(); 0198 } 0199 0200 int ByteArrayJanusView::valueCoding() const 0201 { 0202 return mView->valueCoding(); 0203 } 0204 0205 QString ByteArrayJanusView::charCodingName() const 0206 { 0207 return mView->charCodingName(); 0208 } 0209 0210 void ByteArrayJanusView::setValueCoding(int valueCoding) 0211 { 0212 mView->setValueCoding((AbstractByteArrayView::ValueCoding)valueCoding); 0213 } 0214 0215 void ByteArrayJanusView::setCharCoding(const QString& charCodingName) 0216 { 0217 mView->setCharCoding(charCodingName); 0218 } 0219 0220 AddressRange ByteArrayJanusView::selection() const 0221 { 0222 return mView->selection(); 0223 } 0224 0225 void ByteArrayJanusView::setSelection(Address start, Address end) 0226 { 0227 mView->setSelection(start, end); 0228 } 0229 0230 void ByteArrayJanusView::setMarking(const AddressRange& marking) 0231 { 0232 mView->setMarking(marking); 0233 } 0234 0235 void ByteArrayJanusView::ensureVisible(const AddressRange& range) 0236 { 0237 mView->ensureVisible(range); 0238 } 0239 0240 void ByteArrayJanusView::insert(const QByteArray& byteArray) 0241 { 0242 mView->insert(byteArray); 0243 } 0244 0245 bool ByteArrayJanusView::showsNonprinting() const 0246 { 0247 return false; // TODOSHOWNONPRINTING pin to false for now return mView->showsNonprinting(); 0248 } 0249 0250 bool ByteArrayJanusView::offsetColumnVisible() const 0251 { 0252 return mView->offsetColumnVisible(); 0253 } 0254 0255 int ByteArrayJanusView::offsetCoding() const 0256 { 0257 return mView->offsetCoding(); 0258 } 0259 0260 int ByteArrayJanusView::layoutStyle() const 0261 { 0262 return (int)mView->layoutStyle(); 0263 } 0264 0265 int ByteArrayJanusView::visibleCodings() const 0266 { 0267 return (int)mView->visibleCodings(); 0268 } 0269 0270 bool ByteArrayJanusView::isOverwriteMode() const 0271 { 0272 return mView->isOverwriteMode(); 0273 } 0274 0275 void ByteArrayJanusView::setShowsNonprinting(bool on) 0276 { 0277 Q_UNUSED(on); 0278 // TODOSHOWNONPRINTING mView->setShowsNonprinting(on); 0279 } 0280 0281 void ByteArrayJanusView::setNoOfGroupedBytes(int noOfGroupedBytes) 0282 { 0283 mView->setNoOfGroupedBytes(noOfGroupedBytes); 0284 } 0285 0286 void ByteArrayJanusView::setSubstituteChar(QChar substituteChar) 0287 { 0288 mView->setSubstituteChar(substituteChar); 0289 } 0290 0291 void ByteArrayJanusView::setUndefinedChar(QChar undefinedChar) 0292 { 0293 mView->setUndefinedChar(undefinedChar); 0294 } 0295 0296 void ByteArrayJanusView::toggleOffsetColumn(bool on) 0297 { 0298 mView->toggleOffsetColumn(on); 0299 } 0300 0301 void ByteArrayJanusView::setOffsetCoding(int offsetCoding) 0302 { 0303 mView->setOffsetCoding((AbstractByteArrayView::OffsetCoding)offsetCoding); 0304 } 0305 0306 void ByteArrayJanusView::setLayoutStyle(int layoutStyle) 0307 { 0308 mView->setLayoutStyle((AbstractByteArrayView::LayoutStyle)layoutStyle); 0309 } 0310 0311 void ByteArrayJanusView::setVisibleCodings(int visibleColumns) 0312 { 0313 mView->setVisibleCodings(visibleColumns); 0314 } 0315 0316 QChar ByteArrayJanusView::substituteChar() const 0317 { 0318 return mView->substituteChar(); 0319 } 0320 QChar ByteArrayJanusView::undefinedChar() const 0321 { 0322 return mView->undefinedChar(); 0323 } 0324 0325 int ByteArrayJanusView::byteSpacingWidth() const 0326 { 0327 return mView->byteSpacingWidth(); 0328 } 0329 int ByteArrayJanusView::noOfGroupedBytes() const 0330 { 0331 return mView->noOfGroupedBytes(); 0332 } 0333 int ByteArrayJanusView::groupSpacingWidth() const 0334 { 0335 return mView->groupSpacingWidth(); 0336 } 0337 int ByteArrayJanusView::binaryGapWidth() const 0338 { 0339 return mView->binaryGapWidth(); 0340 } 0341 0342 bool ByteArrayJanusView::isOverwriteOnly() const 0343 { 0344 return mView->isOverwriteOnly(); 0345 } 0346 0347 void ByteArrayJanusView::setOverwriteMode(bool overwriteMode) 0348 { 0349 mView->setOverwriteMode(overwriteMode); 0350 } 0351 0352 void ByteArrayJanusView::setViewPos(QPoint pos) 0353 { 0354 mView->horizontalScrollBar()->setValue(pos.x()); 0355 mView->verticalScrollBar()->setValue(pos.y()); 0356 } 0357 QRect ByteArrayJanusView::viewRect() const 0358 { 0359 // TODO: find why mView->viewport()->rect() doesn't work but is always at pos (0.0) 0360 const QRect result( 0361 QPoint(mView->horizontalScrollBar()->value(), mView->verticalScrollBar()->value()), 0362 mView->viewport()->size()); 0363 return result; 0364 } 0365 0366 void ByteArrayJanusView::propagateFont(const QFont& font) 0367 { 0368 setFont(font); 0369 mView->setFont(font); 0370 } 0371 0372 } 0373 0374 #include "moc_bytearrayjanusview.cpp"