1 /******************************************************************************
2 *   KBlocks, a falling blocks game by KDE                                     *
3 *   Copyright (C) 2010-2021 Mauricio Piacentini <mauricio@tabuleiro.com>      *
4 *                           Zhongjie Cai <squall.leonhart.cai@gmail.com>      *
5 *                           Julian Helfferich <julian.helfferich@mailbox.org> *
6 *                                                                             *
7 *   This program is free software; you can redistribute it and/or modify      *
8 *   it under the terms of the GNU General Public License as published by      *
9 *   the Free Software Foundation; either version 2 of the License, or         *
10 *   (at your option) any later version.                                       *
11 ******************************************************************************/
12 #include <QResizeEvent>
13 
14 #include "KBlocksView.h"
15 #include "SceneInterface.h"
16 
KBlocksView(SceneInterface * scene,QWidget * parent)17 KBlocksView::KBlocksView(SceneInterface *scene, QWidget *parent): QGraphicsView(scene, parent)
18 {
19     //setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
20     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
21     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
22     setFrameStyle(QFrame::NoFrame);
23 
24     setOptimizationFlags(
25                          QGraphicsView::DontSavePainterState /*|
26                           QGraphicsView::DontAdjustForAntialiasing*/);
27 
28     setCacheMode(QGraphicsView::CacheBackground);
29     setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
30 }
31 
~KBlocksView()32 KBlocksView::~KBlocksView()
33 {
34 }
35 
settingsChanged()36 void KBlocksView::settingsChanged()
37 {
38     SceneInterface* s = dynamic_cast<SceneInterface*>(scene());
39     if (s) {
40         s->readSettings(size());
41     }
42     fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
43 }
44 
focusInEvent(QFocusEvent *)45 void KBlocksView::focusInEvent(QFocusEvent *)
46 {
47     Q_EMIT focusEvent(false);
48 }
49 
focusOutEvent(QFocusEvent *)50 void KBlocksView::focusOutEvent(QFocusEvent *)
51 {
52     Q_EMIT focusEvent(true);
53 }
54 
resizeEvent(QResizeEvent * event)55 void KBlocksView::resizeEvent(QResizeEvent *event)
56 {
57     fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
58     event->accept();
59 }
60 
61