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