File indexing completed on 2024-04-21 05:53:05

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 #include "abstractbytearrayview.hpp"
0010 #include "abstractbytearrayview_p.hpp"
0011 
0012 // lib
0013 #include "controller/abstractcontroller.hpp"
0014 #include "controller/abstractwheelcontroller.hpp"
0015 #include "bytearraytablelayout.hpp"
0016  // Okteta core
0017 #include <Okteta/Bookmark>
0018 
0019 namespace Okteta {
0020 
0021 AbstractByteArrayView::AbstractByteArrayView(AbstractByteArrayViewPrivate* dd, QWidget* parent)
0022     : ColumnsView(dd, parent)
0023 {
0024     Q_D(AbstractByteArrayView);
0025     d->init();
0026 }
0027 
0028 AbstractByteArrayView::~AbstractByteArrayView() = default;
0029 
0030 Okteta::AbstractByteArrayModel* AbstractByteArrayView::byteArrayModel() const
0031 {
0032     Q_D(const AbstractByteArrayView);
0033     return d->byteArrayModel();
0034 }
0035 bool AbstractByteArrayView::isOverwriteMode() const
0036 {
0037     Q_D(const AbstractByteArrayView);
0038     return d->isOverwriteMode();
0039 }
0040 bool AbstractByteArrayView::isOverwriteOnly() const
0041 {
0042     Q_D(const AbstractByteArrayView);
0043     return d->isOverwriteOnly();
0044 }
0045 bool AbstractByteArrayView::isReadOnly() const
0046 {
0047     Q_D(const AbstractByteArrayView);
0048     return d->isEffectiveReadOnly();
0049 }
0050 bool AbstractByteArrayView::isModified() const
0051 {
0052     Q_D(const AbstractByteArrayView);
0053     return d->isModified();
0054 }
0055 
0056 double AbstractByteArrayView::zoomLevel() const
0057 {
0058     Q_D(const AbstractByteArrayView);
0059     return d->zoomLevel();
0060 }
0061 ByteArrayTableLayout* AbstractByteArrayView::layout() const
0062 {
0063     Q_D(const AbstractByteArrayView);
0064     return d->layout();
0065 }
0066 AbstractByteArrayView::ValueCoding AbstractByteArrayView::valueCoding() const
0067 {
0068     Q_D(const AbstractByteArrayView);
0069     return d->valueCoding();
0070 }
0071 const Okteta::ValueCodec* AbstractByteArrayView::valueCodec() const
0072 {
0073     Q_D(const AbstractByteArrayView);
0074     return d->valueCodec();
0075 }
0076 AbstractByteArrayView::CharCoding AbstractByteArrayView::charCoding() const
0077 {
0078     Q_D(const AbstractByteArrayView);
0079     return d->charCoding();
0080 }
0081 QString AbstractByteArrayView::charCodingName() const
0082 {
0083     Q_D(const AbstractByteArrayView);
0084     return d->charCodingName();
0085 }
0086 const Okteta::CharCodec* AbstractByteArrayView::charCodec() const
0087 {
0088     Q_D(const AbstractByteArrayView);
0089     return d->charCodec();
0090 }
0091 
0092 ByteArrayTableCursor* AbstractByteArrayView::tableCursor() const
0093 {
0094     Q_D(const AbstractByteArrayView);
0095     return d->tableCursor();
0096 }
0097 ByteArrayTableRanges* AbstractByteArrayView::tableRanges() const
0098 {
0099     Q_D(const AbstractByteArrayView);
0100     return d->tableRanges();
0101 }
0102 
0103 int AbstractByteArrayView::noOfBytesPerLine() const
0104 {
0105     Q_D(const AbstractByteArrayView);
0106     return d->noOfBytesPerLine();
0107 }
0108 Address AbstractByteArrayView::firstLineOffset()  const
0109 {
0110     Q_D(const AbstractByteArrayView);
0111     return d->firstLineOffset();
0112 }
0113 Address AbstractByteArrayView::startOffset() const
0114 {
0115     Q_D(const AbstractByteArrayView);
0116     return d->startOffset();
0117 }
0118 
0119 Address AbstractByteArrayView::cursorPosition() const
0120 {
0121     Q_D(const AbstractByteArrayView);
0122     return d->cursorPosition();
0123 }
0124 bool AbstractByteArrayView::isCursorBehind() const
0125 {
0126     Q_D(const AbstractByteArrayView);
0127     return d->isCursorBehind();
0128 }
0129 AbstractByteArrayView::LayoutStyle AbstractByteArrayView::layoutStyle() const
0130 {
0131     Q_D(const AbstractByteArrayView);
0132     return d->layoutStyle();
0133 }
0134 
0135 bool AbstractByteArrayView::offsetColumnVisible() const
0136 {
0137     Q_D(const AbstractByteArrayView);
0138     return d->offsetColumnVisible();
0139 }
0140 
0141 AbstractByteArrayView::OffsetCoding AbstractByteArrayView::offsetCoding() const
0142 {
0143     Q_D(const AbstractByteArrayView);
0144     return d->offsetCoding();
0145 }
0146 
0147 AddressRange AbstractByteArrayView::selection() const
0148 {
0149     Q_D(const AbstractByteArrayView);
0150     return d->selection();
0151 }
0152 bool AbstractByteArrayView::hasSelectedData() const
0153 {
0154     Q_D(const AbstractByteArrayView);
0155     return d->hasSelectedData();
0156 }
0157 
0158 QByteArray AbstractByteArrayView::selectedData() const
0159 {
0160     Q_D(const AbstractByteArrayView);
0161     return d->selectedData();
0162 }
0163 QMimeData* AbstractByteArrayView::selectionAsMimeData() const
0164 {
0165     Q_D(const AbstractByteArrayView);
0166     return d->selectionAsMimeData();
0167 }
0168 
0169 AddressRange AbstractByteArrayView::marking() const
0170 {
0171     Q_D(const AbstractByteArrayView);
0172     return d->marking();
0173 }
0174 
0175 void AbstractByteArrayView::pasteData(const QMimeData* data)
0176 {
0177     Q_D(AbstractByteArrayView);
0178     d->pasteData(data);
0179 }
0180 
0181 bool AbstractByteArrayView::canReadData(const QMimeData* data) const
0182 {
0183     Q_D(const AbstractByteArrayView);
0184     return d->canReadData(data);
0185 }
0186 
0187 void AbstractByteArrayView::cut()
0188 {
0189     Q_D(AbstractByteArrayView);
0190     d->cutToClipboard();
0191 }
0192 
0193 void AbstractByteArrayView::copy()
0194 {
0195     Q_D(AbstractByteArrayView);
0196     d->copyToClipboard();
0197 }
0198 
0199 void AbstractByteArrayView::paste()
0200 {
0201     Q_D(AbstractByteArrayView);
0202     d->pasteFromClipboard();
0203 }
0204 
0205 void AbstractByteArrayView::insert(const QByteArray& data)
0206 {
0207     Q_D(AbstractByteArrayView);
0208     d->insert(data);
0209 }
0210 
0211 void AbstractByteArrayView::removeSelectedData()
0212 {
0213     Q_D(AbstractByteArrayView);
0214     d->removeSelectedData();
0215 }
0216 
0217 void AbstractByteArrayView::setByteArrayModel(Okteta::AbstractByteArrayModel* byteArrayModel)
0218 {
0219     Q_D(AbstractByteArrayView);
0220     d->setByteArrayModel(byteArrayModel);
0221 }
0222 
0223 void AbstractByteArrayView::setModified(bool modified)
0224 {
0225     Q_D(AbstractByteArrayView);
0226     d->setModified(modified);
0227 }
0228 
0229 void AbstractByteArrayView::setOverwriteMode(bool overwriteMode)
0230 {
0231     Q_D(AbstractByteArrayView);
0232     d->setOverwriteMode(overwriteMode);
0233 }
0234 
0235 void AbstractByteArrayView::setOverwriteOnly(bool overwriteOnly)
0236 {
0237     Q_D(AbstractByteArrayView);
0238     d->setOverwriteOnly(overwriteOnly);
0239 }
0240 
0241 void AbstractByteArrayView::setLayoutStyle(LayoutStyle layoutStyle)
0242 {
0243     Q_D(AbstractByteArrayView);
0244     d->setLayoutStyle(layoutStyle);
0245 }
0246 
0247 void AbstractByteArrayView::setNoOfBytesPerLine(int noOfBytesPerLine)
0248 {
0249     Q_D(AbstractByteArrayView);
0250     d->setNoOfBytesPerLine(noOfBytesPerLine);
0251 }
0252 
0253 void AbstractByteArrayView::setStartOffset(Address startOffset)
0254 {
0255     Q_D(AbstractByteArrayView);
0256     d->setStartOffset(startOffset);
0257 }
0258 
0259 void AbstractByteArrayView::setFirstLineOffset(Address firstLineOffset)
0260 {
0261     Q_D(AbstractByteArrayView);
0262     d->setFirstLineOffset(firstLineOffset);
0263 }
0264 
0265 void AbstractByteArrayView::setReadOnly(bool readOnly)
0266 {
0267     Q_D(AbstractByteArrayView);
0268     d->setReadOnly(readOnly);
0269 }
0270 
0271 AbstractByteArrayView::CodingTypes AbstractByteArrayView::visibleCodings() const
0272 {
0273     Q_D(const AbstractByteArrayView);
0274     return d->visibleCodings();
0275 }
0276 bool AbstractByteArrayView::tabChangesFocus() const
0277 {
0278     Q_D(const AbstractByteArrayView);
0279     return d->tabChangesFocus();
0280 }
0281 AbstractByteArrayView::CodingTypeId AbstractByteArrayView::activeCoding() const
0282 {
0283     Q_D(const AbstractByteArrayView);
0284     return d->activeCoding();
0285 }
0286 
0287 void AbstractByteArrayView::setVisibleCodings(int visibleCodings)
0288 {
0289     Q_D(AbstractByteArrayView);
0290     d->setVisibleCodings(visibleCodings);
0291 }
0292 void AbstractByteArrayView::setActiveCoding(CodingTypeId codingId)
0293 {
0294     Q_D(AbstractByteArrayView);
0295     d->setActiveCoding(codingId);
0296 }
0297 
0298 void AbstractByteArrayView::setTabChangesFocus(bool tabChangesFocus)
0299 {
0300     Q_D(AbstractByteArrayView);
0301     d->setTabChangesFocus(tabChangesFocus);
0302 }
0303 
0304 void AbstractByteArrayView::toggleOffsetColumn(bool offsetColumnVisible)
0305 {
0306     Q_D(AbstractByteArrayView);
0307     d->toggleOffsetColumn(offsetColumnVisible);
0308 }
0309 
0310 void AbstractByteArrayView::setOffsetCoding(AbstractByteArrayView::OffsetCoding offsetCoding)
0311 {
0312     Q_D(AbstractByteArrayView);
0313     d->setOffsetCoding(offsetCoding);
0314 }
0315 
0316 void AbstractByteArrayView::selectAll(bool select)
0317 {
0318     Q_D(AbstractByteArrayView);
0319     d->selectAll(select);
0320 }
0321 
0322 bool AbstractByteArrayView::selectWord(Address index)
0323 {
0324     Q_D(AbstractByteArrayView);
0325     return d->selectWord(index);
0326 }
0327 
0328 void AbstractByteArrayView::setCursorPosition(Address index, bool isBehind)
0329 {
0330     Q_D(AbstractByteArrayView);
0331     d->setCursorPosition(index, isBehind);
0332 }
0333 
0334 void AbstractByteArrayView::setSelectionCursorPosition(Address index)
0335 {
0336     Q_D(AbstractByteArrayView);
0337     d->setSelectionCursorPosition(index);
0338 }
0339 
0340 void AbstractByteArrayView::setSelection(Address start, Address end)
0341 {
0342     Q_D(AbstractByteArrayView);
0343     d->setSelection(AddressRange(start, end));
0344 }
0345 
0346 void AbstractByteArrayView::setSelection(const AddressRange& selection)
0347 {
0348     Q_D(AbstractByteArrayView);
0349     d->setSelection(selection);
0350 }
0351 
0352 void AbstractByteArrayView::setMarking(Address start, Address end)
0353 {
0354     Q_D(AbstractByteArrayView);
0355     d->setMarking(AddressRange(start, end));
0356 }
0357 
0358 void AbstractByteArrayView::setMarking(const AddressRange& marking)
0359 {
0360     Q_D(AbstractByteArrayView);
0361     d->setMarking(marking);
0362 }
0363 
0364 void AbstractByteArrayView::ensureVisible(const AddressRange& range, bool ensureStartVisible)
0365 {
0366     Q_D(AbstractByteArrayView);
0367     d->ensureVisible(range, ensureStartVisible);
0368 }
0369 
0370 void AbstractByteArrayView::ensureCursorVisible()
0371 {
0372     Q_D(AbstractByteArrayView);
0373     d->ensureCursorVisible();
0374 }
0375 
0376 void AbstractByteArrayView::placeCursor(QPoint point)
0377 {
0378     Q_D(AbstractByteArrayView);
0379     d->placeCursor(point);
0380 }
0381 
0382 void AbstractByteArrayView::startCursor()
0383 {
0384     Q_D(AbstractByteArrayView);
0385     d->startCursor();
0386 }
0387 
0388 void AbstractByteArrayView::unpauseCursor()
0389 {
0390     Q_D(AbstractByteArrayView);
0391     d->unpauseCursor();
0392 }
0393 
0394 void AbstractByteArrayView::stopCursor()
0395 {
0396     Q_D(AbstractByteArrayView);
0397     d->stopCursor();
0398 }
0399 
0400 void AbstractByteArrayView::pauseCursor()
0401 {
0402     Q_D(AbstractByteArrayView);
0403     d->pauseCursor();
0404 }
0405 
0406 void AbstractByteArrayView::zoomIn(int pointInc)
0407 {
0408     Q_D(AbstractByteArrayView);
0409     d->zoomIn(pointInc);
0410 }
0411 void AbstractByteArrayView::zoomIn()
0412 {
0413     Q_D(AbstractByteArrayView);
0414     d->zoomIn();
0415 }
0416 void AbstractByteArrayView::zoomOut(int pointDec)
0417 {
0418     Q_D(AbstractByteArrayView);
0419     d->zoomOut(pointDec);
0420 }
0421 void AbstractByteArrayView::zoomOut()
0422 {
0423     Q_D(AbstractByteArrayView);
0424     d->zoomOut();
0425 }
0426 void AbstractByteArrayView::zoomTo(int pointSize)
0427 {
0428     Q_D(AbstractByteArrayView);
0429     d->zoomTo(pointSize);
0430 }
0431 void AbstractByteArrayView::unZoom()
0432 {
0433     Q_D(AbstractByteArrayView);
0434     d->unZoom();
0435 }
0436 void AbstractByteArrayView::setZoomLevel(double zoomLevel)
0437 {
0438     Q_D(AbstractByteArrayView);
0439     d->setZoomLevel(zoomLevel);
0440 }
0441 
0442 void AbstractByteArrayView::setNoOfLines(int newNoOfLines)
0443 {
0444     ColumnsView::setNoOfLines(newNoOfLines > 1 ? newNoOfLines : 1);
0445 }
0446 
0447 void AbstractByteArrayView::changeEvent(QEvent* event)
0448 {
0449     Q_D(AbstractByteArrayView);
0450     d->changeEvent(event);
0451 }
0452 
0453 QSize AbstractByteArrayView::sizeHint() const
0454 {
0455     // TODO: calculate a sensible hint based on dynamic layout settings
0456     return {400, 120};  // {columnsWidth(), columnsHeight()};
0457 }
0458 
0459 Address AbstractByteArrayView::indexByPoint(QPoint point) const
0460 {
0461     Q_D(const AbstractByteArrayView);
0462     return d->indexByPoint(point);
0463 }
0464 
0465 void AbstractByteArrayView::finishByteEdit()
0466 {
0467     Q_D(AbstractByteArrayView);
0468     d->finishByteEditor();
0469 }
0470 
0471 // TODO: remove me!
0472 void AbstractByteArrayView::emitSelectionSignals()
0473 {
0474     Q_D(AbstractByteArrayView);
0475 
0476     d->emitSelectionUpdates();
0477 }
0478 
0479 void AbstractByteArrayView::updateChanged()
0480 {
0481     Q_D(AbstractByteArrayView);
0482     d->updateChanged();
0483 }
0484 
0485 void AbstractByteArrayView::copyToClipboard(QClipboard::Mode mode) const
0486 {
0487     Q_D(const AbstractByteArrayView);
0488     d->copyToClipboard(mode);
0489 }
0490 
0491 void AbstractByteArrayView::pasteFromClipboard(QClipboard::Mode mode)
0492 {
0493     Q_D(AbstractByteArrayView);
0494     d->pasteFromClipboard(mode);
0495 }
0496 
0497 QRect AbstractByteArrayView::cursorRect() const
0498 {
0499     Q_D(const AbstractByteArrayView);
0500     return d->cursorRect();
0501 }
0502 
0503 QMenu* AbstractByteArrayView::createStandardContextMenu(QPoint position)
0504 {
0505     Q_D(AbstractByteArrayView);
0506     return d->createStandardContextMenu(position);
0507 }
0508 
0509 bool AbstractByteArrayView::event(QEvent* event)
0510 {
0511     Q_D(AbstractByteArrayView);
0512     return d->event(event);
0513 }
0514 
0515 void AbstractByteArrayView::showEvent(QShowEvent* showEvent)
0516 {
0517     ColumnsView::showEvent(showEvent);
0518     // TODO: why is this needed?
0519     layout()->setNoOfLinesPerPage(noOfLinesPerPage());
0520 }
0521 
0522 void AbstractByteArrayView::resizeEvent(QResizeEvent* resizeEvent)
0523 {
0524     Q_D(AbstractByteArrayView);
0525     d->resizeEvent(resizeEvent);
0526 }
0527 
0528 void AbstractByteArrayView::focusInEvent(QFocusEvent* focusEvent)
0529 {
0530     Q_D(AbstractByteArrayView);
0531 
0532     d->focusInEvent(focusEvent);
0533 }
0534 
0535 void AbstractByteArrayView::focusOutEvent(QFocusEvent* focusEvent)
0536 {
0537     Q_D(AbstractByteArrayView);
0538 
0539     d->focusOutEvent(focusEvent);
0540 }
0541 
0542 void AbstractByteArrayView::keyPressEvent(QKeyEvent* keyEvent)
0543 {
0544     Q_D(AbstractByteArrayView);
0545     if (!d->controller()->handleKeyPress(keyEvent)) {
0546         ColumnsView::keyPressEvent(keyEvent);
0547     }
0548 }
0549 
0550 void AbstractByteArrayView::mousePressEvent(QMouseEvent* mousePressEvent)
0551 {
0552     Q_D(AbstractByteArrayView);
0553     d->mousePressEvent(mousePressEvent);
0554 }
0555 
0556 void AbstractByteArrayView::mouseMoveEvent(QMouseEvent* mouseMoveEvent)
0557 {
0558     Q_D(AbstractByteArrayView);
0559     d->mouseMoveEvent(mouseMoveEvent);
0560 }
0561 
0562 void AbstractByteArrayView::mouseReleaseEvent(QMouseEvent* mouseReleaseEvent)
0563 {
0564     Q_D(AbstractByteArrayView);
0565     d->mouseReleaseEvent(mouseReleaseEvent);
0566 }
0567 
0568 // gets called after press and release instead of a plain press event (?)
0569 void AbstractByteArrayView::mouseDoubleClickEvent(QMouseEvent* mouseDoubleClickEvent)
0570 {
0571     Q_D(AbstractByteArrayView);
0572     d->mouseDoubleClickEvent(mouseDoubleClickEvent);
0573 }
0574 
0575 void AbstractByteArrayView::wheelEvent(QWheelEvent* wheelEvent)
0576 {
0577     Q_D(AbstractByteArrayView);
0578     if (!d->wheelController()->handleWheelEvent(wheelEvent)) {
0579         ColumnsView::wheelEvent(wheelEvent);
0580     }
0581 }
0582 
0583 void AbstractByteArrayView::dragEnterEvent(QDragEnterEvent* dragEnterEvent)
0584 {
0585     Q_D(AbstractByteArrayView);
0586     d->dragEnterEvent(dragEnterEvent);
0587 }
0588 void AbstractByteArrayView::dragMoveEvent(QDragMoveEvent* dragMoveEvent)
0589 {
0590     Q_D(AbstractByteArrayView);
0591     d->dragMoveEvent(dragMoveEvent);
0592 }
0593 void AbstractByteArrayView::dragLeaveEvent(QDragLeaveEvent* dragLeaveEvent)
0594 {
0595     Q_D(AbstractByteArrayView);
0596     d->dragLeaveEvent(dragLeaveEvent);
0597 }
0598 void AbstractByteArrayView::dropEvent(QDropEvent* dropEvent)
0599 {
0600     Q_D(AbstractByteArrayView);
0601     d->dropEvent(dropEvent);
0602 }
0603 void AbstractByteArrayView::contextMenuEvent(QContextMenuEvent* contextMenuEvent)
0604 {
0605     Q_D(AbstractByteArrayView);
0606     d->contextMenuEvent(contextMenuEvent);
0607 }
0608 
0609 void AbstractByteArrayView::timerEvent(QTimerEvent* timerEvent)
0610 {
0611     Q_D(AbstractByteArrayView);
0612     d->timerEvent(timerEvent);
0613 }
0614 
0615 bool AbstractByteArrayView::viewportEvent(QEvent* event)
0616 {
0617     Q_D(AbstractByteArrayView);
0618     return d->viewportEvent(event);
0619 }
0620 
0621 }
0622 
0623 // have to include this because of Q_PRIVATE_SLOT
0624 #include "moc_abstractbytearrayview.cpp"