From 57394749573168867336cc443522324e17e2583a Mon Sep 17 00:00:00 2001 From: "G.K.MacGregor" Date: Mon, 26 Apr 2021 22:08:28 +0100 Subject: [PATCH] Move selection rectangle from widget to scene --- document.cpp | 4 ++++ mainwidget.cpp | 26 ++++++++++++++++++++------ mainwidget.h | 3 ++- mainwindow.cpp | 1 + 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/document.cpp b/document.cpp index e67377a..34943bc 100644 --- a/document.cpp +++ b/document.cpp @@ -73,6 +73,7 @@ void TeletextDocument::selectSubPageIndex(int newSubPageIndex, bool forceRefresh emit aboutToChangeSubPage(); m_currentSubPageIndex = newSubPageIndex; emit subPageSelected(); + emit selectionMoved(); return; } } @@ -83,6 +84,7 @@ void TeletextDocument::selectSubPageNext() emit aboutToChangeSubPage(); m_currentSubPageIndex++; emit subPageSelected(); + emit selectionMoved(); } } @@ -92,6 +94,7 @@ void TeletextDocument::selectSubPagePrevious() emit aboutToChangeSubPage(); m_currentSubPageIndex--; emit subPageSelected(); + emit selectionMoved(); } } @@ -224,6 +227,7 @@ void TeletextDocument::setSelection(int topRow, int leftColumn, int bottomRow, i void TeletextDocument::cancelSelection() { m_selectionSubPage = nullptr; + emit selectionMoved(); } int TeletextDocument::levelRequired() const diff --git a/mainwidget.cpp b/mainwidget.cpp index c37552c..92ed73c 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -58,7 +58,6 @@ TeletextWidget::TeletextWidget(QFrame *parent) : QFrame(parent) connect(m_teletextDocument, &TeletextDocument::subPageSelected, this, &TeletextWidget::subPageSelected); connect(m_teletextDocument, &TeletextDocument::contentsChange, this, &TeletextWidget::refreshRow); connect(m_teletextDocument, &TeletextDocument::refreshNeeded, this, &TeletextWidget::refreshPage); - connect(m_teletextDocument, &TeletextDocument::selectionMoved, this, QOverload<>::of(&TeletextWidget::update)); } TeletextWidget::~TeletextWidget() @@ -109,11 +108,6 @@ void TeletextWidget::paintEvent(QPaintEvent *event) widgetPainter.drawPixmap(0, 0, *m_pageRender.pagePixmap(m_flashPhase), 864-m_pageRender.leftSidePanelColumns()*12, 0, m_pageRender.leftSidePanelColumns()*12, 250); if (m_pageRender.rightSidePanelColumns()) widgetPainter.drawPixmap(480+m_pageRender.leftSidePanelColumns()*12, 0, *m_pageRender.pagePixmap(m_flashPhase), 480, 0, m_pageRender.rightSidePanelColumns()*12, 250); - if (m_teletextDocument->selectionActive()) { - widgetPainter.setPen(QPen(QColor(192, 192, 192, 224), 1, Qt::DashLine)); - widgetPainter.setBrush(QBrush(QColor(255, 255, 255, 64))); - widgetPainter.drawRect((m_teletextDocument->selectionLeftColumn()+m_pageRender.leftSidePanelColumns())*12, m_teletextDocument->selectionTopRow()*10, m_teletextDocument->selectionWidth()*12-1, m_teletextDocument->selectionHeight()*10-1); - } } void TeletextWidget::updateFlashTimer(int newFlashTimer) @@ -496,6 +490,13 @@ LevelOneScene::LevelOneScene(QWidget *levelOneWidget, QObject *parent) : QGraphi m_levelOneProxyWidget->setPos(60, 19); m_levelOneProxyWidget->setAutoFillBackground(false); + // Selection + m_selectionRectItem = new QGraphicsRectItem(0, 0, 12, 10); + m_selectionRectItem->setVisible(false); + m_selectionRectItem->setPen(QPen(QColor(192, 192, 192), 1, Qt::DashLine)); + m_selectionRectItem->setBrush(QBrush(QColor(255, 255, 255, 64))); + addItem(m_selectionRectItem); + // Cursor m_cursorRectItem = new QGraphicsRectItem(0, 0, 12, 10); m_cursorRectItem->setPen(Qt::NoPen); @@ -545,6 +546,7 @@ void LevelOneScene::setBorderDimensions(int sceneWidth, int sceneHeight, int wid m_mainGridItemGroup->setPos(leftRightBorders + leftSidePanelColumns*12, topBottomBorders); updateCursor(); + updateSelection(); // Grid for right side panel for (int c=0; c<16; c++) @@ -582,6 +584,18 @@ void LevelOneScene::updateCursor() m_cursorRectItem->setPos(m_mainGridItemGroup->pos().x() + static_cast(m_levelOneProxyWidget->widget())->document()->cursorColumn()*12, m_mainGridItemGroup->pos().y() + static_cast(m_levelOneProxyWidget->widget())->document()->cursorRow()*10); } +void LevelOneScene::updateSelection() +{ + if (!static_cast(m_levelOneProxyWidget->widget())->document()->selectionActive()) { + m_selectionRectItem->setVisible(false); + return; + } + + m_selectionRectItem->setRect(m_mainGridItemGroup->pos().x() + static_cast(m_levelOneProxyWidget->widget())->document()->selectionLeftColumn()*12, m_mainGridItemGroup->pos().y() + static_cast(m_levelOneProxyWidget->widget())->document()->selectionTopRow()*10, static_cast(m_levelOneProxyWidget->widget())->document()->selectionWidth()*12-1, static_cast(m_levelOneProxyWidget->widget())->document()->selectionHeight()*10-1); + + m_selectionRectItem->setVisible(true); +} + void LevelOneScene::toggleGrid(bool gridOn) { m_grid = gridOn; diff --git a/mainwidget.h b/mainwidget.h index 09a8567..b4b1316 100644 --- a/mainwidget.h +++ b/mainwidget.h @@ -110,6 +110,7 @@ public: public slots: void updateCursor(); + void updateSelection(); void toggleGrid(bool); void setFullScreenColour(const QColor &); void setFullRowColour(int, const QColor &); @@ -118,7 +119,7 @@ private: QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem; QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25]; QGraphicsProxyWidget *m_levelOneProxyWidget; - QGraphicsRectItem *m_cursorRectItem; + QGraphicsRectItem *m_cursorRectItem, *m_selectionRectItem; QGraphicsItemGroup *m_mainGridItemGroup, *m_sidePanelGridItemGroup[32]; bool m_grid, m_sidePanelGridNeeded[32]; }; diff --git a/mainwindow.cpp b/mainwindow.cpp index ec80bab..4fa0991 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -172,6 +172,7 @@ void MainWindow::init() setCentralWidget(m_textView); connect(m_textWidget->document(), &TeletextDocument::cursorMoved, this, &MainWindow::updateCursorPosition); + connect(m_textWidget->document(), &TeletextDocument::selectionMoved, m_textScene, &LevelOneScene::updateSelection); connect(m_textWidget->document()->undoStack(), &QUndoStack::cleanChanged, this, [=]() { setWindowModified(!m_textWidget->document()->undoStack()->isClean()); } ); connect(m_textWidget->document(), &TeletextDocument::aboutToChangeSubPage, m_x26DockWidget, &X26DockWidget::unloadX26List); connect(m_textWidget->document(), &TeletextDocument::subPageSelected, this, &MainWindow::updatePageWidgets);