Move proxy widget from mainwindow to mainwidget
Mainly in preparation for editing different document types. Also fixes some issues wrt border sizing.
This commit is contained in:
@@ -19,6 +19,9 @@
|
|||||||
|
|
||||||
#include <QBitmap>
|
#include <QBitmap>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
#include <QGraphicsItem>
|
||||||
|
#include <QGraphicsProxyWidget>
|
||||||
|
#include <QGraphicsScene>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
@@ -405,3 +408,65 @@ void TeletextWidget::focusOutEvent(QFocusEvent *event)
|
|||||||
{
|
{
|
||||||
QFrame::focusOutEvent(event);
|
QFrame::focusOutEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
LevelOneScene::LevelOneScene(QWidget *levelOneWidget, QObject *parent) : QGraphicsScene(parent)
|
||||||
|
{
|
||||||
|
setSceneRect(0, 0, 600, 288);
|
||||||
|
m_fullScreenTopRectItem = new QGraphicsRectItem(0, 0, 600, 19);
|
||||||
|
m_fullScreenTopRectItem->setPen(Qt::NoPen);
|
||||||
|
m_fullScreenTopRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
||||||
|
addItem(m_fullScreenTopRectItem);
|
||||||
|
m_fullScreenBottomRectItem = new QGraphicsRectItem(0, 269, 600, 19);
|
||||||
|
m_fullScreenBottomRectItem->setPen(Qt::NoPen);
|
||||||
|
m_fullScreenBottomRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
||||||
|
addItem(m_fullScreenBottomRectItem);
|
||||||
|
|
||||||
|
for (int r=0; r<25; r++) {
|
||||||
|
m_fullRowLeftRectItem[r] = new QGraphicsRectItem(0, 19+r*10, 60, 10);
|
||||||
|
m_fullRowLeftRectItem[r]->setPen(Qt::NoPen);
|
||||||
|
m_fullRowLeftRectItem[r]->setBrush(QBrush(QColor(0, 0, 0)));
|
||||||
|
addItem(m_fullRowLeftRectItem[r]);
|
||||||
|
m_fullRowRightRectItem[r] = new QGraphicsRectItem(540, 19+r*10, 60, 10);
|
||||||
|
m_fullRowRightRectItem[r]->setPen(Qt::NoPen);
|
||||||
|
m_fullRowRightRectItem[r]->setBrush(QBrush(QColor(0, 0, 0)));
|
||||||
|
addItem(m_fullRowRightRectItem[r]);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_levelOneProxyWidget = addWidget(levelOneWidget);
|
||||||
|
m_levelOneProxyWidget->setPos(60, 19);
|
||||||
|
m_levelOneProxyWidget->setAutoFillBackground(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelOneScene::setDimensions(int sceneWidth, int sceneHeight, int widgetWidth)
|
||||||
|
{
|
||||||
|
setSceneRect(0, 0, sceneWidth, sceneHeight);
|
||||||
|
|
||||||
|
// Assume widget height is always 250
|
||||||
|
int topBottomBorders = (sceneHeight-250) / 2;
|
||||||
|
// 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
|
||||||
|
int leftRightBorders = (sceneWidth-widgetWidth) / 2;
|
||||||
|
|
||||||
|
m_levelOneProxyWidget->setPos(leftRightBorders, topBottomBorders);
|
||||||
|
|
||||||
|
m_fullScreenTopRectItem->setRect(0, 0, sceneWidth, topBottomBorders);
|
||||||
|
m_fullScreenBottomRectItem->setRect(0, 250+topBottomBorders, sceneWidth, topBottomBorders);
|
||||||
|
|
||||||
|
for (int r=0; r<25; r++) {
|
||||||
|
m_fullRowLeftRectItem[r]->setRect(0, topBottomBorders+r*10, leftRightBorders+1, 10);
|
||||||
|
m_fullRowRightRectItem[r]->setRect(sceneWidth-leftRightBorders-1, topBottomBorders+r*10, leftRightBorders+1, 10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelOneScene::setFullScreenColour(const QColor &newColor)
|
||||||
|
{
|
||||||
|
m_fullScreenTopRectItem->setBrush(QBrush(newColor));
|
||||||
|
m_fullScreenBottomRectItem->setBrush(QBrush(newColor));
|
||||||
|
}
|
||||||
|
|
||||||
|
void LevelOneScene::setFullRowColour(int row, const QColor &newColor)
|
||||||
|
{
|
||||||
|
m_fullRowLeftRectItem[row]->setBrush(QBrush(newColor));
|
||||||
|
m_fullRowRightRectItem[row]->setBrush(QBrush(newColor));
|
||||||
|
}
|
||||||
|
|||||||
20
mainwidget.h
20
mainwidget.h
@@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include <QBasicTimer>
|
#include <QBasicTimer>
|
||||||
#include <QFrame>
|
#include <QFrame>
|
||||||
|
#include <QGraphicsProxyWidget>
|
||||||
|
#include <QGraphicsScene>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -96,4 +98,22 @@ private:
|
|||||||
QPair<int, int> mouseToRowAndColumn(const QPoint &);
|
QPair<int, int> mouseToRowAndColumn(const QPoint &);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LevelOneScene : public QGraphicsScene
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
LevelOneScene(QWidget *, QObject *parent = nullptr);
|
||||||
|
void setDimensions(int, int, int);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void setFullScreenColour(const QColor &);
|
||||||
|
void setFullRowColour(int, const QColor &);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem;
|
||||||
|
QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25];
|
||||||
|
QGraphicsProxyWidget *m_levelOneProxyWidget;
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -152,31 +152,7 @@ void MainWindow::init()
|
|||||||
|
|
||||||
readSettings();
|
readSettings();
|
||||||
|
|
||||||
m_textScene = new QGraphicsScene(this);
|
m_textScene = new LevelOneScene(m_textWidget, this);
|
||||||
m_textScene->setSceneRect(0, 0, 600, 288);
|
|
||||||
m_fullScreenTopRectItem = new QGraphicsRectItem(0, 0, 600, 19);
|
|
||||||
m_fullScreenTopRectItem->setPen(Qt::NoPen);
|
|
||||||
m_fullScreenTopRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
|
||||||
m_textScene->addItem(m_fullScreenTopRectItem);
|
|
||||||
m_fullScreenBottomRectItem = new QGraphicsRectItem(0, 269, 600, 19);
|
|
||||||
m_fullScreenBottomRectItem->setPen(Qt::NoPen);
|
|
||||||
m_fullScreenBottomRectItem->setBrush(QBrush(QColor(0, 0, 0)));
|
|
||||||
m_textScene->addItem(m_fullScreenBottomRectItem);
|
|
||||||
|
|
||||||
for (int r=0; r<25; r++) {
|
|
||||||
m_fullRowLeftRectItem[r] = new QGraphicsRectItem(0, 19+r*10, 60, 10);
|
|
||||||
m_fullRowLeftRectItem[r]->setPen(Qt::NoPen);
|
|
||||||
m_fullRowLeftRectItem[r]->setBrush(QBrush(QColor(0, 0, 0)));
|
|
||||||
m_textScene->addItem(m_fullRowLeftRectItem[r]);
|
|
||||||
m_fullRowRightRectItem[r] = new QGraphicsRectItem(540, 19+r*10, 60, 10);
|
|
||||||
m_fullRowRightRectItem[r]->setPen(Qt::NoPen);
|
|
||||||
m_fullRowRightRectItem[r]->setBrush(QBrush(QColor(0, 0, 0)));
|
|
||||||
m_textScene->addItem(m_fullRowRightRectItem[r]);
|
|
||||||
}
|
|
||||||
|
|
||||||
m_textProxyWidget = m_textScene->addWidget(m_textWidget);
|
|
||||||
m_textProxyWidget->setPos(60, 19);
|
|
||||||
m_textProxyWidget->setAutoFillBackground(false);
|
|
||||||
|
|
||||||
m_textView = new QGraphicsView(this);
|
m_textView = new QGraphicsView(this);
|
||||||
m_textView->setScene(m_textScene);
|
m_textView->setScene(m_textScene);
|
||||||
@@ -190,26 +166,14 @@ void MainWindow::init()
|
|||||||
connect(m_textWidget->document(), &TeletextDocument::aboutToChangeSubPage, m_x26DockWidget, &X26DockWidget::unloadX26List);
|
connect(m_textWidget->document(), &TeletextDocument::aboutToChangeSubPage, m_x26DockWidget, &X26DockWidget::unloadX26List);
|
||||||
connect(m_textWidget->document(), &TeletextDocument::subPageSelected, this, &MainWindow::updatePageWidgets);
|
connect(m_textWidget->document(), &TeletextDocument::subPageSelected, this, &MainWindow::updatePageWidgets);
|
||||||
connect(m_textWidget, &TeletextWidget::sizeChanged, this, &MainWindow::setSceneDimensions);
|
connect(m_textWidget, &TeletextWidget::sizeChanged, this, &MainWindow::setSceneDimensions);
|
||||||
connect(m_textWidget->pageRender(), &TeletextPageRender::fullScreenColourChanged, this, &MainWindow::updateFullScreenRectItems);
|
connect(m_textWidget->pageRender(), &TeletextPageRender::fullScreenColourChanged, m_textScene, &LevelOneScene::setFullScreenColour);
|
||||||
connect(m_textWidget->pageRender(), &TeletextPageRender::fullRowColourChanged, this, &MainWindow::updateFullRowRectItems);
|
connect(m_textWidget->pageRender(), &TeletextPageRender::fullRowColourChanged, m_textScene, &LevelOneScene::setFullRowColour);
|
||||||
|
|
||||||
setUnifiedTitleAndToolBarOnMac(true);
|
setUnifiedTitleAndToolBarOnMac(true);
|
||||||
|
|
||||||
updatePageWidgets();
|
updatePageWidgets();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateFullScreenRectItems(QColor newColor)
|
|
||||||
{
|
|
||||||
m_fullScreenTopRectItem->setBrush(QBrush(newColor));
|
|
||||||
m_fullScreenBottomRectItem->setBrush(QBrush(newColor));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::updateFullRowRectItems(int row, QColor newColor)
|
|
||||||
{
|
|
||||||
m_fullRowLeftRectItem[row]->setBrush(QBrush(newColor));
|
|
||||||
m_fullRowRightRectItem[row]->setBrush(QBrush(newColor));
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::tile(const QMainWindow *previous)
|
void MainWindow::tile(const QMainWindow *previous)
|
||||||
{
|
{
|
||||||
//TODO sort out default tiling or positioning
|
//TODO sort out default tiling or positioning
|
||||||
@@ -392,8 +356,8 @@ void MainWindow::createActions()
|
|||||||
m_borderActs[0]->setStatusTip(tr("View with no border"));
|
m_borderActs[0]->setStatusTip(tr("View with no border"));
|
||||||
m_borderActs[1] = borderSubMenu->addAction(tr("Minimal"));
|
m_borderActs[1] = borderSubMenu->addAction(tr("Minimal"));
|
||||||
m_borderActs[1]->setStatusTip(tr("View with minimal border"));
|
m_borderActs[1]->setStatusTip(tr("View with minimal border"));
|
||||||
m_borderActs[2] = borderSubMenu->addAction(tr("Full"));
|
m_borderActs[2] = borderSubMenu->addAction(tr("Full TV"));
|
||||||
m_borderActs[2]->setStatusTip(tr("View with full overscan border"));
|
m_borderActs[2]->setStatusTip(tr("View with full TV overscan border"));
|
||||||
|
|
||||||
QMenu *aspectRatioSubMenu = viewMenu->addMenu(tr("Aspect ratio"));
|
QMenu *aspectRatioSubMenu = viewMenu->addMenu(tr("Aspect ratio"));
|
||||||
m_aspectRatioActs[0] = aspectRatioSubMenu->addAction(tr("4:3"));
|
m_aspectRatioActs[0] = aspectRatioSubMenu->addAction(tr("4:3"));
|
||||||
@@ -538,31 +502,22 @@ void MainWindow::setSceneDimensions()
|
|||||||
{
|
{
|
||||||
const float aspectRatioHorizontalScaling[4] = { 0.6, 0.6, 0.8, 0.5 };
|
const float aspectRatioHorizontalScaling[4] = { 0.6, 0.6, 0.8, 0.5 };
|
||||||
const int topBottomBorders[3] = { 0, 10, 19 };
|
const int topBottomBorders[3] = { 0, 10, 19 };
|
||||||
const int leftRightBorders[3][2] = { { 0, 0 }, { 24, 72 }, { 77, 183 } };
|
const int pillarBoxSizes[3] = { 672, 720, 854 };
|
||||||
|
const int leftRightBorders[3] = { 0, 24, 77 };
|
||||||
int newSceneWidth;
|
int newSceneWidth;
|
||||||
|
|
||||||
int newViewAspectRatio = m_viewAspectRatio; // In case we need to narrow the characters to fit wide side panels in 4:3
|
if (m_viewAspectRatio == 1)
|
||||||
if (m_viewBorder == 0)
|
// 16:9 pillar box aspect ratio, fixed horizontal size whatever the widget width is
|
||||||
newSceneWidth = m_textWidget->width();
|
newSceneWidth = pillarBoxSizes[m_viewBorder];
|
||||||
|
else if (m_viewBorder == 2)
|
||||||
|
// "Full TV" border, semi-fixed horizontal size to TV width
|
||||||
|
// Side panel width over 13 columns will cause this to widen a little
|
||||||
|
newSceneWidth = qMax(640, m_textWidget->width());
|
||||||
else
|
else
|
||||||
newSceneWidth = 480+leftRightBorders[m_viewBorder][newViewAspectRatio == 1]*2;
|
newSceneWidth = m_textWidget->width() + leftRightBorders[m_viewBorder]*2;
|
||||||
|
|
||||||
//FIXME find a better way of narrowing characters to squeeze in side panels
|
m_textScene->setDimensions(newSceneWidth, 250+topBottomBorders[m_viewBorder]*2, m_textWidget->width());
|
||||||
if (m_viewAspectRatio != 1 && m_textWidget->width() > 576)
|
m_textView->setTransform(QTransform((1+(float)m_viewZoom/2)*aspectRatioHorizontalScaling[m_viewAspectRatio], 0, 0, 1+(float)m_viewZoom/2, 0, 0));
|
||||||
newViewAspectRatio = 3;
|
|
||||||
|
|
||||||
m_textScene->setSceneRect(0, 0, newSceneWidth, 250+topBottomBorders[m_viewBorder]*2);
|
|
||||||
m_fullScreenTopRectItem->setRect(0, 0, newSceneWidth, topBottomBorders[m_viewBorder]);
|
|
||||||
m_fullScreenBottomRectItem->setRect(0, 250+topBottomBorders[m_viewBorder], newSceneWidth, topBottomBorders[m_viewBorder]);
|
|
||||||
m_textView->setTransform(QTransform((1+(float)m_viewZoom/2)*aspectRatioHorizontalScaling[newViewAspectRatio], 0, 0, 1+(float)m_viewZoom/2, 0, 0));
|
|
||||||
if (m_viewBorder == 0)
|
|
||||||
m_textProxyWidget->setPos(0, 0);
|
|
||||||
else
|
|
||||||
m_textProxyWidget->setPos(leftRightBorders[m_viewBorder][newViewAspectRatio == 1]-(m_textWidget->width()-480)/2, topBottomBorders[m_viewBorder]);
|
|
||||||
for (int r=0; r<25; r++) {
|
|
||||||
m_fullRowLeftRectItem[r]->setRect(0, topBottomBorders[m_viewBorder]+r*10, m_textWidget->x()+1, 10);
|
|
||||||
m_fullRowRightRectItem[r]->setRect(m_textWidget->x()+m_textWidget->width()-1, topBottomBorders[m_viewBorder]+r*10, m_textWidget->x()+1, 10);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::insertRow(bool copyRow)
|
void MainWindow::insertRow(bool copyRow)
|
||||||
|
|||||||
@@ -74,9 +74,6 @@ private slots:
|
|||||||
void zoomOut();
|
void zoomOut();
|
||||||
void zoomReset();
|
void zoomReset();
|
||||||
|
|
||||||
void updateFullScreenRectItems(QColor);
|
|
||||||
void updateFullRowRectItems(int, QColor);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum { m_MaxRecentFiles = 10 };
|
enum { m_MaxRecentFiles = 10 };
|
||||||
|
|
||||||
@@ -97,11 +94,8 @@ private:
|
|||||||
MainWindow *findMainWindow(const QString &fileName) const;
|
MainWindow *findMainWindow(const QString &fileName) const;
|
||||||
|
|
||||||
TeletextWidget *m_textWidget;
|
TeletextWidget *m_textWidget;
|
||||||
QGraphicsScene *m_textScene;
|
LevelOneScene *m_textScene;
|
||||||
QGraphicsProxyWidget *m_textProxyWidget;
|
|
||||||
QGraphicsView *m_textView;
|
QGraphicsView *m_textView;
|
||||||
QGraphicsRectItem *m_fullScreenTopRectItem, *m_fullScreenBottomRectItem;
|
|
||||||
QGraphicsRectItem *m_fullRowLeftRectItem[25], *m_fullRowRightRectItem[25];
|
|
||||||
|
|
||||||
int m_viewBorder, m_viewAspectRatio, m_viewZoom;
|
int m_viewBorder, m_viewAspectRatio, m_viewZoom;
|
||||||
PageOptionsDockWidget *m_pageOptionsDockWidget;
|
PageOptionsDockWidget *m_pageOptionsDockWidget;
|
||||||
|
|||||||
Reference in New Issue
Block a user