Skip to content

Commit

Permalink
API changes refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Dax89 committed Apr 12, 2022
1 parent 82e5882 commit 5bbbbd2
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 64 deletions.
2 changes: 0 additions & 2 deletions hooks/isurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class ISurface
public:
virtual ~ISurface() = default;
virtual void copy() const = 0;
virtual void linkTo(ISurface* s) = 0;
virtual void unlink() = 0;
virtual void goBack() = 0;
virtual void goForward() = 0;
virtual bool seek(rd_address address) = 0;
Expand Down
8 changes: 3 additions & 5 deletions renderer/surfaceqt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ QSize SurfaceQt::size() const
const QColor& SurfaceQt::baseColor() const { return m_basecolor; }
void SurfaceQt::setBaseColor(const QColor& c) { m_basecolor = c; }

void SurfaceQt::scroll(rd_address address, int ncols) { RDSurface_Scroll(m_surface.get(), address, ncols); }
void SurfaceQt::scroll(int nx, int ny) { RDSurface_Scroll(m_surface.get(), nx, ny); }
bool SurfaceQt::goTo(rd_address address) { return RDSurface_GoTo(m_surface.get(), address); }
void SurfaceQt::getScrollRange(rd_address* start, rd_address* end) const { RDSurface_GetScrollRange(m_surface.get(), start, end); }
void SurfaceQt::goBack() { RDSurface_GoBack(m_surface.get()); }
Expand Down Expand Up @@ -133,8 +133,6 @@ void SurfaceQt::selectAt(const QPointF& pt)
void SurfaceQt::resizeRange(rd_address startaddress, rd_address endaddress, int cols) { RDSurface_ResizeRange(m_surface.get(), startaddress, endaddress, cols); }
void SurfaceQt::resize(int row, int cols) { this->resize(QSizeF{ cols * m_cellsize.width(), row * m_cellsize.height() }); }
void SurfaceQt::resize() { this->resize(QSizeF{ static_cast<qreal>(this->widget()->width()), static_cast<qreal>(this->widget()->height()) }); }
void SurfaceQt::linkTo(SurfaceQt* s) { RDSurface_LinkTo(m_surface.get(), s->handle()); }
void SurfaceQt::unlink() { RDSurface_Unlink(m_surface.get()); }

void SurfaceQt::copy() const
{
Expand Down Expand Up @@ -174,8 +172,8 @@ bool SurfaceQt::getLabelAt(const QPointF& pt, rd_address* address) const
}

const char* SurfaceQt::getCurrentWord() const { return RDSurface_GetCurrentWord(m_surface.get()); }
const RDSurfacePos* SurfaceQt::selection() const { return RDSurface_GetSelection(m_surface.get()); }
const RDSurfacePos* SurfaceQt::position() const { return RDSurface_GetPosition(m_surface.get()); }
RDSurfacePos SurfaceQt::selection() const { return RDSurface_GetSelection(m_surface.get()); }
RDSurfacePos SurfaceQt::position() const { return RDSurface_GetPosition(m_surface.get()); }

QColor SurfaceQt::getBackground(const RDSurfaceCell* cell) const
{
Expand Down
8 changes: 3 additions & 5 deletions renderer/surfaceqt.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class SurfaceQt : public QObject
QString getCurrentLabel(rd_address* address) const;
bool getLabelAt(const QPointF& pt, rd_address* address) const;
const char* getCurrentWord() const;
const RDSurfacePos* selection() const;
const RDSurfacePos* position() const;
RDSurfacePos selection() const;
RDSurfacePos position() const;
RDSurfacePos mapPoint(const QPointF& pt) const;
bool seek(rd_address address);
bool goTo(rd_address address);
void getScrollRange(rd_address* start, rd_address* end) const;
void goBack();
void goForward();
void setBaseColor(const QColor& c);
void scroll(rd_address address, int ncols);
void scroll(int nx, int ny);
void moveTo(int row, int col);
void moveTo(const QPointF& pt);
void select(int row, int col);
Expand All @@ -57,8 +57,6 @@ class SurfaceQt : public QObject
void resizeRange(rd_address startaddress, rd_address endaddress, int cols);
void resize(int row, int cols);
void resize();
void linkTo(SurfaceQt* s);
void unlink();
void copy() const;

protected:
Expand Down
2 changes: 1 addition & 1 deletion widgets/listing/listinggraphview/listingblockitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int ListingBlockItem::currentRow() const
rd_address address = m_surface->currentAddress();

if((address != RD_NVAL) && this->contains(address))
return m_surface->position()->row - this->startRow();
return m_surface->position().row - this->startRow();

return GraphViewItem::currentRow();
}
Expand Down
3 changes: 0 additions & 3 deletions widgets/listing/listinggraphview/listinggraphview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ ListingGraphView::ListingGraphView(const RDContextPtr& ctx, QWidget *parent): Gr
connect(m_surface, &SurfaceQt::renderCompleted, this, [=]() { this->viewport()->update(); });
}

void ListingGraphView::linkTo(ISurface* s) { /* m_surface->linkTo(s->surface()); */ }
void ListingGraphView::unlink() { /* m_surface->unlink(); */ }

void ListingGraphView::goBack()
{
m_surface->goBack();
Expand Down
2 changes: 0 additions & 2 deletions widgets/listing/listinggraphview/listinggraphview.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class ListingGraphView : public GraphView, public ISurface
bool renderGraph(rd_address address);

public: // ISurface interface
void linkTo(ISurface* s) override;
void unlink() override;
void goBack() override;
void goForward() override;
void copy() const override;
Expand Down
2 changes: 1 addition & 1 deletion widgets/listing/listingtextview/listingpathwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void ListingPathWidget::paintEvent(QPaintEvent*)

bool ListingPathWidget::isPathSelected(const RDPathItem* item) const
{
int line = m_textview->surface()->position()->row;
int line = m_textview->surface()->position().row;
return (line == item->fromrow) || (line == item->torow);
}

Expand Down
2 changes: 0 additions & 2 deletions widgets/listing/listingtextview/listingtextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ ListingTextView::ListingTextView(const RDContextPtr& ctx, QWidget* parent): QSpl
ListingPathWidget *ListingTextView::columnWidget() { return m_columnview; }
ListingTextWidget *ListingTextView::textWidget() { return m_textwidget; }
void ListingTextView::copy() const { return m_textwidget->copy(); }
void ListingTextView::linkTo(ISurface* s) { Q_UNUSED(s); }
void ListingTextView::unlink() { }
void ListingTextView::goBack() { return m_textwidget->goBack(); }
void ListingTextView::goForward() { return m_textwidget->goForward(); }
bool ListingTextView::goTo(rd_address address) { return m_textwidget->goTo(address); }
Expand Down
2 changes: 0 additions & 2 deletions widgets/listing/listingtextview/listingtextview.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class ListingTextView : public QSplitter, public ISurface

public: // ISurface Implementation
void copy() const override;
void linkTo(ISurface* s) override;
void unlink() override;
void goBack() override;
void goForward() override;
bool goTo(rd_address address) override;
Expand Down
69 changes: 31 additions & 38 deletions widgets/listing/listingtextview/listingtextwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ void ListingTextWidget::setContext(const RDContextPtr& ctx)
if(!m_surface) return;

switch(action) {
case QScrollBar::SliderSingleStepAdd: m_surface->scroll(m_surface->currentAddress() + 1, 0); break;
case QScrollBar::SliderSingleStepSub: m_surface->scroll(m_surface->currentAddress() - 1, 0); break;
case QScrollBar::SliderSingleStepAdd: m_surface->scroll(0, 1); break;
case QScrollBar::SliderSingleStepSub: m_surface->scroll(0, -1); break;
case QScrollBar::SliderMove: m_surface->goTo(static_cast<rd_address>(this->verticalScrollBar()->sliderPosition())); break;
default: break;
}
Expand All @@ -90,9 +90,7 @@ void ListingTextWidget::goBack() { if(m_surface) m_surface->goBack(); }
void ListingTextWidget::goForward() { if(m_surface) m_surface->goForward(); }
bool ListingTextWidget::hasSelection() const { return m_surface ? m_surface->hasSelection() : false; }
void ListingTextWidget::copy() const { if(m_surface) m_surface->copy(); }
void ListingTextWidget::linkTo(ISurface* s) { if(m_surface) m_surface->linkTo(s->surface()); }
void ListingTextWidget::unlink() { if(m_surface) m_surface->unlink(); }
void ListingTextWidget::scrollContentsBy(int dx, int) { if(m_surface) m_surface->scroll(RD_NVAL, -dx); }
void ListingTextWidget::scrollContentsBy(int dx, int) { if(m_surface && dx) m_surface->scroll(-dx, 0); }

void ListingTextWidget::focusInEvent(QFocusEvent* event)
{
Expand Down Expand Up @@ -169,21 +167,16 @@ void ListingTextWidget::wheelEvent(QWheelEvent *event)
{
if(m_surface)
{
QPoint ndegrees = event->angleDelta() / 8;
auto delta = event->angleDelta();
int ncols = 0, offset = 0;

if(!ndegrees.isNull())
{
rd_offset offset = RD_NVAL;
int ncols = 0;
if(delta.y() > 0) offset = -DOCUMENT_WHEEL_UNIT;
else if(delta.y() < 0) offset = DOCUMENT_WHEEL_UNIT;

if(ndegrees.y() > 0) offset = m_surface->firstAddress() -DOCUMENT_WHEEL_UNIT;
else if(ndegrees.y() < 0) offset = m_surface->firstAddress() + DOCUMENT_WHEEL_UNIT;
if(delta.x() > 0) ncols = -1;
else if(delta.x() < 0) ncols = 1;

if(ndegrees.x() > 0) ncols = -1;
else if(ndegrees.x() < 0) ncols = 1;

m_surface->scroll(offset, ncols);
}
m_surface->scroll(ncols, offset);

event->accept();
return;
Expand All @@ -200,39 +193,39 @@ void ListingTextWidget::keyPressEvent(QKeyEvent *event)
return;
}

const RDSurfacePos* pos = m_surface->position();
RDSurfacePos pos = m_surface->position();

if(event->matches(QKeySequence::MoveToNextChar) || event->matches(QKeySequence::SelectNextChar))
{
if(event->matches(QKeySequence::MoveToNextChar)) m_surface->moveTo(pos->row, pos->col + 1);
else m_surface->select(pos->row, pos->col + 1);
if(event->matches(QKeySequence::MoveToNextChar)) m_surface->moveTo(pos.row, pos.col + 1);
else m_surface->select(pos.row, pos.col + 1);
}
else if(event->matches(QKeySequence::MoveToPreviousChar) || event->matches(QKeySequence::SelectPreviousChar))
{
if(event->matches(QKeySequence::MoveToPreviousChar)) m_surface->moveTo(pos->row, pos->col - 1);
else m_surface->select(pos->row, pos->col - 1);
if(event->matches(QKeySequence::MoveToPreviousChar)) m_surface->moveTo(pos.row, pos.col - 1);
else m_surface->select(pos.row, pos.col - 1);
}
else if(event->matches(QKeySequence::MoveToNextLine) || event->matches(QKeySequence::SelectNextLine))
{
int nextline = pos->row + 1;
if(event->matches(QKeySequence::MoveToNextLine)) m_surface->moveTo(nextline, pos->col);
else m_surface->select(nextline, pos->col);
int nextline = pos.row + 1;
if(event->matches(QKeySequence::MoveToNextLine)) m_surface->moveTo(nextline, pos.col);
else m_surface->select(nextline, pos.col);
}
else if(event->matches(QKeySequence::MoveToPreviousLine) || event->matches(QKeySequence::SelectPreviousLine))
{
int prevline = pos->row - 1;
if(event->matches(QKeySequence::MoveToPreviousLine)) m_surface->moveTo(prevline, pos->col);
else m_surface->select(prevline, pos->col);
int prevline = pos.row - 1;
if(event->matches(QKeySequence::MoveToPreviousLine)) m_surface->moveTo(prevline, pos.col);
else m_surface->select(prevline, pos.col);
}
else if(event->matches(QKeySequence::MoveToNextPage) || event->matches(QKeySequence::SelectNextPage))
{
if(event->matches(QKeySequence::MoveToNextPage)) m_surface->scroll(m_surface->rows(), 0);
else m_surface->select(m_surface->rows(), pos->col);
if(event->matches(QKeySequence::MoveToNextPage)) m_surface->scroll(0, m_surface->rows());
else m_surface->select(m_surface->rows(), pos.col);
}
else if(event->matches(QKeySequence::MoveToPreviousPage) || event->matches(QKeySequence::SelectPreviousPage))
{
if(event->matches(QKeySequence::MoveToPreviousPage)) m_surface->scroll(-m_surface->rows(), 0);
else m_surface->select(-m_surface->rows(), pos->col);
if(event->matches(QKeySequence::MoveToPreviousPage)) m_surface->scroll(0, -m_surface->rows());
else m_surface->select(-m_surface->rows(), pos.col);
}
else if(event->matches(QKeySequence::MoveToStartOfDocument) || event->matches(QKeySequence::SelectStartOfDocument))
{
Expand All @@ -241,18 +234,18 @@ void ListingTextWidget::keyPressEvent(QKeyEvent *event)
}
else if(event->matches(QKeySequence::MoveToEndOfDocument) || event->matches(QKeySequence::SelectEndOfDocument))
{
if(event->matches(QKeySequence::MoveToEndOfDocument)) m_surface->moveTo(-1, pos->col);
else m_surface->select(-1, pos->col);
if(event->matches(QKeySequence::MoveToEndOfDocument)) m_surface->moveTo(-1, pos.col);
else m_surface->select(-1, pos.col);
}
else if(event->matches(QKeySequence::MoveToStartOfLine) || event->matches(QKeySequence::SelectStartOfLine))
{
if(event->matches(QKeySequence::MoveToStartOfLine)) m_surface->moveTo(pos->row, 0);
else m_surface->select(pos->row, 0);
if(event->matches(QKeySequence::MoveToStartOfLine)) m_surface->moveTo(pos.row, 0);
else m_surface->select(pos.row, 0);
}
else if(event->matches(QKeySequence::MoveToEndOfLine) || event->matches(QKeySequence::SelectEndOfLine))
{
if(event->matches(QKeySequence::MoveToEndOfLine)) m_surface->moveTo(pos->row, -1);
else m_surface->select(pos->row, -1);
if(event->matches(QKeySequence::MoveToEndOfLine)) m_surface->moveTo(pos.row, -1);
else m_surface->select(pos.row, -1);
}
else if(event->key() == Qt::Key_Space) Q_EMIT switchView();
else QAbstractScrollArea::keyPressEvent(event);
Expand Down
2 changes: 0 additions & 2 deletions widgets/listing/listingtextview/listingtextwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class ListingTextWidget : public QAbstractScrollArea, public ISurface
const RDContextPtr& context() const override;
QWidget* widget() override;
void copy() const override;
void linkTo(ISurface* s) override;
void unlink() override;

protected:
void scrollContentsBy(int dx, int) override;
Expand Down

0 comments on commit 5bbbbd2

Please sign in to comment.