Implement zooming with Control key and mousewheel

This commit is contained in:
G.K.MacGregor
2021-05-04 21:52:51 +01:00
parent 9fa86f8c4c
commit 56e7b0500c
3 changed files with 28 additions and 0 deletions

View File

@@ -25,6 +25,7 @@
#include <QGraphicsItemGroup> #include <QGraphicsItemGroup>
#include <QGraphicsProxyWidget> #include <QGraphicsProxyWidget>
#include <QGraphicsScene> #include <QGraphicsScene>
#include <QGraphicsSceneEvent>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QMimeData> #include <QMimeData>
@@ -560,6 +561,8 @@ LevelOneScene::LevelOneScene(QWidget *levelOneWidget, QObject *parent) : QGraphi
m_sidePanelGridItemGroup[c]->addToGroup(gridPiece); m_sidePanelGridItemGroup[c]->addToGroup(gridPiece);
} }
} }
installEventFilter(this);
} }
void LevelOneScene::setBorderDimensions(int sceneWidth, int sceneHeight, int widgetWidth, int leftSidePanelColumns, int rightSidePanelColumns) void LevelOneScene::setBorderDimensions(int sceneWidth, int sceneHeight, int widgetWidth, int leftSidePanelColumns, int rightSidePanelColumns)
@@ -637,6 +640,22 @@ void LevelOneScene::toggleGrid(bool gridOn)
m_sidePanelGridItemGroup[i]->setVisible(gridOn); m_sidePanelGridItemGroup[i]->setVisible(gridOn);
} }
bool LevelOneScene::eventFilter(QObject *object, QEvent *event)
{
Q_UNUSED(object);
if (event->type() == QEvent::GraphicsSceneWheel && static_cast<QGraphicsSceneWheelEvent *>(event)->modifiers() == Qt::ControlModifier) {
if (static_cast<QGraphicsSceneWheelEvent *>(event)->delta() > 0)
emit mouseZoomIn();
else if (static_cast<QGraphicsSceneWheelEvent *>(event)->delta() < 0)
emit mouseZoomOut();
event->accept();
return true;
}
return false;
}
void LevelOneScene::setFullScreenColour(const QColor &newColor) void LevelOneScene::setFullScreenColour(const QColor &newColor)
{ {
m_fullScreenTopRectItem->setBrush(QBrush(newColor)); m_fullScreenTopRectItem->setBrush(QBrush(newColor));

View File

@@ -121,7 +121,13 @@ public slots:
void setFullScreenColour(const QColor &); void setFullScreenColour(const QColor &);
void setFullRowColour(int, const QColor &); void setFullRowColour(int, const QColor &);
signals:
void mouseZoomIn();
void mouseZoomOut();
private: private:
bool eventFilter(QObject *, QEvent *);
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;

View File

@@ -181,6 +181,9 @@ void MainWindow::init()
connect(m_textWidget->pageRender(), &TeletextPageRender::fullRowColourChanged, m_textScene, &LevelOneScene::setFullRowColour); connect(m_textWidget->pageRender(), &TeletextPageRender::fullRowColourChanged, m_textScene, &LevelOneScene::setFullRowColour);
connect(m_textWidget, &TeletextWidget::insertKeyPressed, this, &MainWindow::toggleInsertMode); connect(m_textWidget, &TeletextWidget::insertKeyPressed, this, &MainWindow::toggleInsertMode);
connect(m_textScene, &LevelOneScene::mouseZoomIn, this, &MainWindow::zoomIn);
connect(m_textScene, &LevelOneScene::mouseZoomOut, this, &MainWindow::zoomOut);
QShortcut *blockShortCut = new QShortcut(QKeySequence(Qt::Key_Escape, Qt::Key_J), m_textView); QShortcut *blockShortCut = new QShortcut(QKeySequence(Qt::Key_Escape, Qt::Key_J), m_textView);
connect(blockShortCut, &QShortcut::activated, [=]() { m_textWidget->setCharacter(0x7f); }); connect(blockShortCut, &QShortcut::activated, [=]() { m_textWidget->setCharacter(0x7f); });