File indexing completed on 2024-04-21 04:02:09

0001 /******************************************************************************
0002 *   KBlocks, a falling blocks game by KDE                                     *
0003 *   SPDX-FileCopyrightText: 2010-2021 Mauricio Piacentini <mauricio@tabuleiro.com>      *
0004 *                           Zhongjie Cai <squall.leonhart.cai@gmail.com>      *
0005 *                           Julian Helfferich <julian.helfferich@mailbox.org> *
0006 *                                                                             *
0007 *   SPDX-License-Identifier: GPL-2.0-or-later
0008 ******************************************************************************/
0009 #include <QResizeEvent>
0010 
0011 #include "KBlocksView.h"
0012 #include "SceneInterface.h"
0013 
0014 KBlocksView::KBlocksView(SceneInterface *scene, QWidget *parent): QGraphicsView(scene, parent)
0015 {
0016     //setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
0017     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
0018     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
0019     setFrameStyle(QFrame::NoFrame);
0020 
0021     setOptimizationFlags(
0022                          QGraphicsView::DontSavePainterState /*|
0023                           QGraphicsView::DontAdjustForAntialiasing*/);
0024 
0025     setCacheMode(QGraphicsView::CacheBackground);
0026     setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
0027 }
0028 
0029 KBlocksView::~KBlocksView()
0030 {
0031 }
0032 
0033 void KBlocksView::loadTheme(const KGameTheme *theme)
0034 {
0035     SceneInterface* s = dynamic_cast<SceneInterface*>(scene());
0036     if (s) {
0037         s->loadTheme(theme);
0038     }
0039     fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
0040 }
0041 
0042 void KBlocksView::settingsChanged()
0043 {
0044     SceneInterface* s = dynamic_cast<SceneInterface*>(scene());
0045     if (s) {
0046         s->readSettings();
0047     }
0048     fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
0049 }
0050 
0051 void KBlocksView::focusInEvent(QFocusEvent *)
0052 {
0053     Q_EMIT focusEvent(false);
0054 }
0055 
0056 void KBlocksView::focusOutEvent(QFocusEvent *)
0057 {
0058     Q_EMIT focusEvent(true);
0059 }
0060 
0061 void KBlocksView::resizeEvent(QResizeEvent *event)
0062 {
0063     fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
0064     event->accept();
0065 }
0066 
0067 #include "moc_KBlocksView.cpp"