Move grid from widget to scene
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include <QBitmap>
|
#include <QBitmap>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
#include <QGraphicsItem>
|
#include <QGraphicsItem>
|
||||||
|
#include <QGraphicsItemGroup>
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
@@ -50,7 +51,6 @@ TeletextWidget::TeletextWidget(QFrame *parent) : QFrame(parent)
|
|||||||
m_pageRender.setTeletextPage(m_levelOnePage);
|
m_pageRender.setTeletextPage(m_levelOnePage);
|
||||||
m_insertMode = false;
|
m_insertMode = false;
|
||||||
m_selectionInProgress = false;
|
m_selectionInProgress = false;
|
||||||
m_grid = false;
|
|
||||||
setFocusPolicy(Qt::StrongFocus);
|
setFocusPolicy(Qt::StrongFocus);
|
||||||
m_flashTiming = m_flashPhase = 0;
|
m_flashTiming = m_flashPhase = 0;
|
||||||
connect(&m_pageRender, &TeletextPageRender::flashChanged, this, &TeletextWidget::updateFlashTimer);
|
connect(&m_pageRender, &TeletextPageRender::flashChanged, this, &TeletextWidget::updateFlashTimer);
|
||||||
@@ -161,14 +161,6 @@ void TeletextWidget::toggleMix(bool mixOn)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TeletextWidget::toggleGrid(bool gridOn)
|
|
||||||
{
|
|
||||||
m_grid = gridOn;
|
|
||||||
m_pageRender.setGrid(gridOn);
|
|
||||||
m_pageRender.renderPage();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
void TeletextWidget::setControlBit(int bitNumber, bool active)
|
void TeletextWidget::setControlBit(int bitNumber, bool active)
|
||||||
{
|
{
|
||||||
m_levelOnePage->setControlBit(bitNumber, active);
|
m_levelOnePage->setControlBit(bitNumber, active);
|
||||||
@@ -480,7 +472,12 @@ void TeletextWidget::focusOutEvent(QFocusEvent *event)
|
|||||||
|
|
||||||
LevelOneScene::LevelOneScene(QWidget *levelOneWidget, QObject *parent) : QGraphicsScene(parent)
|
LevelOneScene::LevelOneScene(QWidget *levelOneWidget, QObject *parent) : QGraphicsScene(parent)
|
||||||
{
|
{
|
||||||
|
m_grid = false;
|
||||||
|
|
||||||
|
// These dimensions are scratch, setBorderDimensions will get called straight away to adjust them
|
||||||
setSceneRect(0, 0, 600, 288);
|
setSceneRect(0, 0, 600, 288);
|
||||||
|
|
||||||
|
// Full screen colours
|
||||||
m_fullScreenTopRectItem = new QGraphicsRectItem(0, 0, 600, 19);
|
m_fullScreenTopRectItem = new QGraphicsRectItem(0, 0, 600, 19);
|
||||||
m_fullScreenTopRectItem->setPen(Qt::NoPen);
|
m_fullScreenTopRectItem->setPen(Qt::NoPen);
|
||||||
m_fullScreenTopRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
m_fullScreenTopRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
||||||
@@ -490,6 +487,7 @@ LevelOneScene::LevelOneScene(QWidget *levelOneWidget, QObject *parent) : QGraphi
|
|||||||
m_fullScreenBottomRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
m_fullScreenBottomRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
||||||
addItem(m_fullScreenBottomRectItem);
|
addItem(m_fullScreenBottomRectItem);
|
||||||
|
|
||||||
|
// Full row colours
|
||||||
for (int r=0; r<25; r++) {
|
for (int r=0; r<25; r++) {
|
||||||
m_fullRowLeftRectItem[r] = new QGraphicsRectItem(0, 19+r*10, 60, 10);
|
m_fullRowLeftRectItem[r] = new QGraphicsRectItem(0, 19+r*10, 60, 10);
|
||||||
m_fullRowLeftRectItem[r]->setPen(Qt::NoPen);
|
m_fullRowLeftRectItem[r]->setPen(Qt::NoPen);
|
||||||
@@ -501,16 +499,43 @@ LevelOneScene::LevelOneScene(QWidget *levelOneWidget, QObject *parent) : QGraphi
|
|||||||
addItem(m_fullRowRightRectItem[r]);
|
addItem(m_fullRowRightRectItem[r]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main text widget
|
||||||
m_levelOneProxyWidget = addWidget(levelOneWidget);
|
m_levelOneProxyWidget = addWidget(levelOneWidget);
|
||||||
m_levelOneProxyWidget->setPos(60, 19);
|
m_levelOneProxyWidget->setPos(60, 19);
|
||||||
m_levelOneProxyWidget->setAutoFillBackground(false);
|
m_levelOneProxyWidget->setAutoFillBackground(false);
|
||||||
|
|
||||||
|
// Optional grid overlay for text widget
|
||||||
|
m_mainGridItemGroup = new QGraphicsItemGroup;
|
||||||
|
m_mainGridItemGroup->setVisible(false);
|
||||||
|
addItem(m_mainGridItemGroup);
|
||||||
|
// Additional vertical pieces of grid for side panels
|
||||||
|
for (int i=0; i<32; i++) {
|
||||||
|
m_sidePanelGridNeeded[i] = false;
|
||||||
|
m_sidePanelGridItemGroup[i] = new QGraphicsItemGroup;
|
||||||
|
m_sidePanelGridItemGroup[i]->setVisible(false);
|
||||||
|
addItem(m_sidePanelGridItemGroup[i]);
|
||||||
|
}
|
||||||
|
for (int r=1; r<25; r++) {
|
||||||
|
for (int c=0; c<40; c++) {
|
||||||
|
QGraphicsRectItem *gridPiece = new QGraphicsRectItem(c*12, r*10, 12, 10);
|
||||||
|
gridPiece->setPen(QPen(QBrush(QColor(128, 128, 128, r<24 ? 192 : 128)), 0));
|
||||||
|
m_mainGridItemGroup->addToGroup(gridPiece);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LevelOneScene::setDimensions(int sceneWidth, int sceneHeight, int widgetWidth)
|
if (r < 24)
|
||||||
|
for (int c=0; c<32; c++) {
|
||||||
|
QGraphicsRectItem *gridPiece = new QGraphicsRectItem(0, r*10, 12, 10);
|
||||||
|
gridPiece->setPen(QPen(QBrush(QColor(128, 128, 128, 64)), 0));
|
||||||
|
m_sidePanelGridItemGroup[c]->addToGroup(gridPiece);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelOneScene::setBorderDimensions(int sceneWidth, int sceneHeight, int widgetWidth, int leftSidePanelColumns, int rightSidePanelColumns)
|
||||||
{
|
{
|
||||||
setSceneRect(0, 0, sceneWidth, sceneHeight);
|
setSceneRect(0, 0, sceneWidth, sceneHeight);
|
||||||
|
|
||||||
// Assume widget height is always 250
|
// Assume text widget height is always 250
|
||||||
int topBottomBorders = (sceneHeight-250) / 2;
|
int topBottomBorders = (sceneHeight-250) / 2;
|
||||||
// Ideally we'd use m_levelOneProxyWidget->size() to discover the widget width ourselves
|
// Ideally we'd use m_levelOneProxyWidget->size() to discover the widget width ourselves
|
||||||
// but this causes a stubborn segfault, so we have to receive the widgetWidth as a parameter
|
// but this causes a stubborn segfault, so we have to receive the widgetWidth as a parameter
|
||||||
@@ -518,15 +543,48 @@ void LevelOneScene::setDimensions(int sceneWidth, int sceneHeight, int widgetWid
|
|||||||
|
|
||||||
m_levelOneProxyWidget->setPos(leftRightBorders, topBottomBorders);
|
m_levelOneProxyWidget->setPos(leftRightBorders, topBottomBorders);
|
||||||
|
|
||||||
|
// Position grid to cover central 40 columns
|
||||||
|
m_mainGridItemGroup->setPos(leftRightBorders + leftSidePanelColumns*12, topBottomBorders);
|
||||||
|
// Grid for right side panel
|
||||||
|
for (int c=0; c<16; c++)
|
||||||
|
if (rightSidePanelColumns > c) {
|
||||||
|
m_sidePanelGridItemGroup[c]->setPos(leftRightBorders + leftSidePanelColumns*12 + 480 + c*12, topBottomBorders);
|
||||||
|
m_sidePanelGridItemGroup[c]->setVisible(m_grid);
|
||||||
|
m_sidePanelGridNeeded[c] = true;
|
||||||
|
} else {
|
||||||
|
m_sidePanelGridItemGroup[c]->setVisible(false);
|
||||||
|
m_sidePanelGridNeeded[c] = false;
|
||||||
|
}
|
||||||
|
// Grid for left side panel
|
||||||
|
for (int c=0; c<16; c++)
|
||||||
|
if (c < leftSidePanelColumns) {
|
||||||
|
m_sidePanelGridItemGroup[31-c]->setPos(leftRightBorders + (leftSidePanelColumns-c-1)*12, topBottomBorders);
|
||||||
|
m_sidePanelGridItemGroup[31-c]->setVisible(m_grid);
|
||||||
|
m_sidePanelGridNeeded[31-c] = true;
|
||||||
|
} else {
|
||||||
|
m_sidePanelGridItemGroup[31-c]->setVisible(false);
|
||||||
|
m_sidePanelGridNeeded[31-c] = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Full screen colours
|
||||||
m_fullScreenTopRectItem->setRect(0, 0, sceneWidth, topBottomBorders);
|
m_fullScreenTopRectItem->setRect(0, 0, sceneWidth, topBottomBorders);
|
||||||
m_fullScreenBottomRectItem->setRect(0, 250+topBottomBorders, sceneWidth, topBottomBorders);
|
m_fullScreenBottomRectItem->setRect(0, 250+topBottomBorders, sceneWidth, topBottomBorders);
|
||||||
|
// Full row colours
|
||||||
for (int r=0; r<25; r++) {
|
for (int r=0; r<25; r++) {
|
||||||
m_fullRowLeftRectItem[r]->setRect(0, topBottomBorders+r*10, leftRightBorders+1, 10);
|
m_fullRowLeftRectItem[r]->setRect(0, topBottomBorders+r*10, leftRightBorders+1, 10);
|
||||||
m_fullRowRightRectItem[r]->setRect(sceneWidth-leftRightBorders-1, topBottomBorders+r*10, leftRightBorders+1, 10);
|
m_fullRowRightRectItem[r]->setRect(sceneWidth-leftRightBorders-1, topBottomBorders+r*10, leftRightBorders+1, 10);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LevelOneScene::toggleGrid(bool gridOn)
|
||||||
|
{
|
||||||
|
m_grid = gridOn;
|
||||||
|
m_mainGridItemGroup->setVisible(gridOn);
|
||||||
|
for (int i=0; i<32; i++)
|
||||||
|
if (m_sidePanelGridNeeded[i])
|
||||||
|
m_sidePanelGridItemGroup[i]->setVisible(gridOn);
|
||||||
|
}
|
||||||
|
|
||||||
void LevelOneScene::setFullScreenColour(const QColor &newColor)
|
void LevelOneScene::setFullScreenColour(const QColor &newColor)
|
||||||
{
|
{
|
||||||
m_fullScreenTopRectItem->setBrush(QBrush(newColor));
|
m_fullScreenTopRectItem->setBrush(QBrush(newColor));
|
||||||
|
|||||||
11
mainwidget.h
11
mainwidget.h
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include <QBasicTimer>
|
#include <QBasicTimer>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
#include <QGraphicsItemGroup>
|
||||||
#include <QGraphicsProxyWidget>
|
#include <QGraphicsProxyWidget>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
@@ -62,7 +63,6 @@ public slots:
|
|||||||
void refreshPage();
|
void refreshPage();
|
||||||
void toggleReveal(bool);
|
void toggleReveal(bool);
|
||||||
void toggleMix(bool);
|
void toggleMix(bool);
|
||||||
void toggleGrid(bool);
|
|
||||||
void updateFlashTimer(int);
|
void updateFlashTimer(int);
|
||||||
void refreshRow(int);
|
void refreshRow(int);
|
||||||
|
|
||||||
@@ -91,14 +91,12 @@ protected:
|
|||||||
private:
|
private:
|
||||||
TeletextDocument* m_teletextDocument;
|
TeletextDocument* m_teletextDocument;
|
||||||
LevelOnePage* m_levelOnePage;
|
LevelOnePage* m_levelOnePage;
|
||||||
bool m_insertMode, m_grid, m_selectionInProgress;
|
bool m_insertMode, m_selectionInProgress;
|
||||||
QBasicTimer m_flashTimer;
|
QBasicTimer m_flashTimer;
|
||||||
int m_flashTiming, m_flashPhase;
|
int m_flashTiming, m_flashPhase;
|
||||||
|
|
||||||
void timerEvent(QTimerEvent *event) override;
|
void timerEvent(QTimerEvent *event) override;
|
||||||
|
|
||||||
void calculateDimensions();
|
|
||||||
|
|
||||||
QPair<int, int> mouseToRowAndColumn(const QPoint &);
|
QPair<int, int> mouseToRowAndColumn(const QPoint &);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,9 +106,10 @@ class LevelOneScene : public QGraphicsScene
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
LevelOneScene(QWidget *, QObject *parent = nullptr);
|
LevelOneScene(QWidget *, QObject *parent = nullptr);
|
||||||
void setDimensions(int, int, int);
|
void setBorderDimensions(int, int, int, int, int);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
void toggleGrid(bool);
|
||||||
void setFullScreenColour(const QColor &);
|
void setFullScreenColour(const QColor &);
|
||||||
void setFullRowColour(int, const QColor &);
|
void setFullRowColour(int, const QColor &);
|
||||||
|
|
||||||
@@ -118,6 +117,8 @@ private:
|
|||||||
QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem;
|
QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem;
|
||||||
QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25];
|
QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25];
|
||||||
QGraphicsProxyWidget *m_levelOneProxyWidget;
|
QGraphicsProxyWidget *m_levelOneProxyWidget;
|
||||||
|
QGraphicsItemGroup *m_mainGridItemGroup, *m_sidePanelGridItemGroup[32];
|
||||||
|
bool m_grid, m_sidePanelGridNeeded[32];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -157,13 +157,13 @@ void MainWindow::init()
|
|||||||
m_paletteDockWidget = new PaletteDockWidget(m_textWidget);
|
m_paletteDockWidget = new PaletteDockWidget(m_textWidget);
|
||||||
addDockWidget(Qt::RightDockWidgetArea, m_paletteDockWidget);
|
addDockWidget(Qt::RightDockWidgetArea, m_paletteDockWidget);
|
||||||
|
|
||||||
|
m_textScene = new LevelOneScene(m_textWidget, this);
|
||||||
|
|
||||||
createActions();
|
createActions();
|
||||||
createStatusBar();
|
createStatusBar();
|
||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
|
|
||||||
m_textScene = new LevelOneScene(m_textWidget, this);
|
|
||||||
|
|
||||||
m_textView = new QGraphicsView(this);
|
m_textView = new QGraphicsView(this);
|
||||||
m_textView->setScene(m_textScene);
|
m_textView->setScene(m_textScene);
|
||||||
m_textView->setRenderHints(QPainter::SmoothPixmapTransform);
|
m_textView->setRenderHints(QPainter::SmoothPixmapTransform);
|
||||||
@@ -374,7 +374,7 @@ void MainWindow::createActions()
|
|||||||
gridAct->setCheckable(true);
|
gridAct->setCheckable(true);
|
||||||
gridAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_G));
|
gridAct->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_G));
|
||||||
gridAct->setStatusTip(tr("Toggle the text grid"));
|
gridAct->setStatusTip(tr("Toggle the text grid"));
|
||||||
connect(gridAct, &QAction::toggled, m_textWidget, &TeletextWidget::toggleGrid);
|
connect(gridAct, &QAction::toggled, m_textScene, &LevelOneScene::toggleGrid);
|
||||||
|
|
||||||
QAction *showCodesAct = viewMenu->addAction(tr("Show codes"));
|
QAction *showCodesAct = viewMenu->addAction(tr("Show codes"));
|
||||||
showCodesAct->setCheckable(true);
|
showCodesAct->setCheckable(true);
|
||||||
@@ -568,7 +568,7 @@ void MainWindow::setSceneDimensions()
|
|||||||
else
|
else
|
||||||
newSceneWidth = m_textWidget->width() + leftRightBorders[m_viewBorder]*2;
|
newSceneWidth = m_textWidget->width() + leftRightBorders[m_viewBorder]*2;
|
||||||
|
|
||||||
m_textScene->setDimensions(newSceneWidth, 250+topBottomBorders[m_viewBorder]*2, m_textWidget->width());
|
m_textScene->setBorderDimensions(newSceneWidth, 250+topBottomBorders[m_viewBorder]*2, m_textWidget->width(), m_textWidget->pageRender()->leftSidePanelColumns(), m_textWidget->pageRender()->rightSidePanelColumns());
|
||||||
m_textView->setTransform(QTransform((1+(float)m_viewZoom/2)*aspectRatioHorizontalScaling[m_viewAspectRatio], 0, 0, 1+(float)m_viewZoom/2, 0, 0));
|
m_textView->setTransform(QTransform((1+(float)m_viewZoom/2)*aspectRatioHorizontalScaling[m_viewAspectRatio], 0, 0, 1+(float)m_viewZoom/2, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ TeletextPageRender::TeletextPageRender()
|
|||||||
for (int i=0; i<6; i++)
|
for (int i=0; i<6; i++)
|
||||||
m_pagePixmap[i] = new QPixmap(864, 250);
|
m_pagePixmap[i] = new QPixmap(864, 250);
|
||||||
m_pagePixmap[0]->fill(Qt::transparent);
|
m_pagePixmap[0]->fill(Qt::transparent);
|
||||||
m_grid = m_mix = m_reveal = m_showCodes = false;
|
m_mix = m_reveal = m_showCodes = false;
|
||||||
m_renderLevel = 0;
|
m_renderLevel = 0;
|
||||||
m_flashRequired = 0;
|
m_flashRequired = 0;
|
||||||
m_finalFullScreenColour = 0;
|
m_finalFullScreenColour = 0;
|
||||||
@@ -92,7 +92,6 @@ void TeletextPageRender::setRenderLevel(int newRenderLevel)
|
|||||||
renderPage();
|
renderPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TeletextPageRender::setGrid(bool newGrid) { m_grid = newGrid; }
|
|
||||||
void TeletextPageRender::setShowCodes(bool newShowCodes)
|
void TeletextPageRender::setShowCodes(bool newShowCodes)
|
||||||
{
|
{
|
||||||
m_showCodes = newShowCodes;
|
m_showCodes = newShowCodes;
|
||||||
@@ -360,12 +359,6 @@ void TeletextPageRender::renderPage(int r)
|
|||||||
else
|
else
|
||||||
pixmapPainter.drawRect(c*12, r*10+18, charWidth-1, 1);
|
pixmapPainter.drawRect(c*12, r*10+18, charWidth-1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_grid) {
|
|
||||||
pixmapPainter.setPen(QColor(128, 128, 128, (c <= 39) ? 192 : 64));
|
|
||||||
pixmapPainter.drawRect(c*12, r*10, 11, 9);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pixmapPainter.begin(m_pagePixmap[0]);
|
pixmapPainter.begin(m_pagePixmap[0]);
|
||||||
|
|||||||
2
render.h
2
render.h
@@ -217,7 +217,7 @@ protected:
|
|||||||
int m_finalFullScreenColour, m_renderLevel;
|
int m_finalFullScreenColour, m_renderLevel;
|
||||||
QColor m_finalFullScreenQColor;
|
QColor m_finalFullScreenQColor;
|
||||||
int m_leftSidePanelColumns, m_rightSidePanelColumns;
|
int m_leftSidePanelColumns, m_rightSidePanelColumns;
|
||||||
bool m_reveal, m_mix, m_grid, m_showCodes;
|
bool m_reveal, m_mix, m_showCodes;
|
||||||
Level1Layer m_level1Layer;
|
Level1Layer m_level1Layer;
|
||||||
std::vector<TextLayer *> m_textLayer;
|
std::vector<TextLayer *> m_textLayer;
|
||||||
const int m_foregroundRemap[8] = { 0, 0, 0, 8, 8, 16, 16, 16 };
|
const int m_foregroundRemap[8] = { 0, 0, 0, 8, 8, 16, 16, 16 };
|
||||||
|
|||||||
Reference in New Issue
Block a user