File indexing completed on 2024-12-15 03:48:05
0001 /* 0002 SPDX-FileCopyrightText: 2008 Sascha Peilicke <sasch.pe@gmx.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "gameview.h" 0008 #include "gamescene.h" 0009 0010 #include <QResizeEvent> 0011 0012 namespace Kigo { 0013 0014 GameView::GameView(GameScene *scene, QWidget *parent) 0015 : QGraphicsView(scene, parent) 0016 , m_gameScene(scene) 0017 { 0018 setCacheMode(QGraphicsView::CacheBackground); 0019 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 0020 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); 0021 setFrameStyle(QFrame::NoFrame); 0022 setOptimizationFlags( 0023 QGraphicsView::DontSavePainterState | 0024 QGraphicsView::DontAdjustForAntialiasing); 0025 0026 connect(m_gameScene, &GameScene::cursorPixmapChanged, this, &GameView::changeCursor); 0027 } 0028 0029 void GameView::changeCursor(const QPixmap &cursorPixmap) 0030 { 0031 if (!isInteractive() || cursorPixmap.isNull()) { 0032 unsetCursor(); 0033 } else { 0034 setCursor(QCursor(cursorPixmap)); 0035 } 0036 } 0037 0038 void GameView::showEvent(QShowEvent *) 0039 { 0040 // Make sure that the game scene has the correct size according to the current view 0041 // This is necessary because one scene is shared by multiple views but changing them 0042 // creates no resizeEvent, so resize when another view is shown. 0043 m_gameScene->resizeScene(width(), height()); 0044 } 0045 0046 void GameView::resizeEvent(QResizeEvent *event) 0047 { 0048 m_gameScene->resizeScene(event->size().width(), event->size().height()); 0049 } 0050 0051 } // End of namespace Kigo 0052 0053 #include "moc_gameview.cpp"