1 /*
2     SPDX-FileCopyrightText: 2008-2010 Stefan Majewsky <majewsky@gmx.net>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "view.h"
8 
9 #include <QWheelEvent>
10 #include <KLocalizedString>
11 
View(QWidget * parent)12 KDiamond::View::View(QWidget *parent)
13     : QGraphicsView(parent)
14 {
15     setFrameStyle(QFrame::NoFrame);
16     setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
17     setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
18     //optimize rendering
19     setOptimizationFlags(QGraphicsView::DontSavePainterState | QGraphicsView::DontAdjustForAntialiasing);
20     //"What's this?" context help
21     setWhatsThis(i18n("<h3>Rules of Game</h3><p>Your goal is to assemble lines of at least three similar diamonds. Click on two adjacent diamonds to swap them.</p><p>Earn extra points by building cascades, and extra seconds by assembling big lines or multiple lines at one time.</p>"));
22 }
23 
setScene(QGraphicsScene * scene)24 void KDiamond::View::setScene(QGraphicsScene *scene)
25 {
26     QGraphicsView::setScene(scene);
27     resizeEvent(nullptr);
28 }
29 
resizeEvent(QResizeEvent * event)30 void KDiamond::View::resizeEvent(QResizeEvent *event)
31 {
32     Q_UNUSED(event)
33     //make widget coordinates equal scene coordinates
34     scene()->setSceneRect(rect());
35     setTransform(QTransform());
36 }
37 
wheelEvent(QWheelEvent * event)38 void KDiamond::View::wheelEvent(QWheelEvent *event)
39 {
40     //do not allow wheel events
41     event->ignore();
42 }
43