1 | /* |
2 | * Copyright (C) 1995 Paul Olav Tvete <paul@troll.no> |
3 | * Copyright (C) 2000-2008 Stephan Kulow <coolo@kde.org> |
4 | * Copyright (C) 2009-2010 Parker Coates <coates@kde.org> |
5 | * |
6 | * License of original code: |
7 | * ------------------------------------------------------------------------- |
8 | * Permission to use, copy, modify, and distribute this software and its |
9 | * documentation for any purpose and without fee is hereby granted, |
10 | * provided that the above copyright notice appear in all copies and that |
11 | * both that copyright notice and this permission notice appear in |
12 | * supporting documentation. |
13 | * |
14 | * This file is provided AS IS with no warranties of any kind. The author |
15 | * shall have no liability with respect to the infringement of copyrights, |
16 | * trade secrets or any patents by this file or any part thereof. In no |
17 | * event will the author be liable for any lost revenue or profits or |
18 | * other special, indirect and consequential damages. |
19 | * ------------------------------------------------------------------------- |
20 | * |
21 | * License of modifications/additions made after 2009-01-01: |
22 | * ------------------------------------------------------------------------- |
23 | * This program is free software; you can redistribute it and/or |
24 | * modify it under the terms of the GNU General Public License as |
25 | * published by the Free Software Foundation; either version 2 of |
26 | * the License, or (at your option) any later version. |
27 | * |
28 | * This program is distributed in the hope that it will be useful, |
29 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
30 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
31 | * GNU General Public License for more details. |
32 | * |
33 | * You should have received a copy of the GNU General Public License |
34 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
35 | * ------------------------------------------------------------------------- |
36 | */ |
37 | |
38 | #include "view.h" |
39 | |
40 | #include "gameselectionscene.h" |
41 | #include "renderer.h" |
42 | |
43 | #include "KCardScene" |
44 | |
45 | #include <QtGui/QResizeEvent> |
46 | |
47 | |
48 | // ================================================================ |
49 | // class PatienceView |
50 | |
51 | |
52 | PatienceView::PatienceView( QWidget * parent ) |
53 | : QGraphicsView( parent ), |
54 | KGameRendererClient( Renderer::self(), "background" ) |
55 | { |
56 | setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
57 | setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff ); |
58 | setFrameStyle( QFrame::NoFrame ); |
59 | |
60 | // This makes the background of the widget transparent so that Oxygen's |
61 | // (or any other style's) window gradient is visible in unpainted areas of |
62 | // the scene. |
63 | QPalette p = palette(); |
64 | QColor c = p.color( QPalette::Base ); |
65 | c.setAlpha( 0 ); |
66 | p.setColor( QPalette::Base, c ); |
67 | setPalette( p ); |
68 | setBackgroundRole( QPalette::Base ); |
69 | |
70 | setAlignment( Qt::AlignLeft | Qt::AlignTop ); |
71 | setCacheMode( QGraphicsView::CacheBackground ); |
72 | } |
73 | |
74 | |
75 | PatienceView::~PatienceView() |
76 | { |
77 | } |
78 | |
79 | |
80 | void PatienceView::setScene( QGraphicsScene * scene ) |
81 | { |
82 | QGraphicsView::setScene( scene ); |
83 | updateSceneSize(); |
84 | } |
85 | |
86 | |
87 | void PatienceView::resizeEvent( QResizeEvent * e ) |
88 | { |
89 | QGraphicsView::resizeEvent( e ); |
90 | setRenderSize( e->size() ); |
91 | resetCachedContent(); |
92 | updateSceneSize(); |
93 | } |
94 | |
95 | |
96 | void PatienceView::drawBackground( QPainter * painter, const QRectF & rect ) |
97 | { |
98 | QRectF source = rect.translated( -sceneRect().topLeft() ); |
99 | if ( m_background.size() != size() ) |
100 | { |
101 | qreal xScale = m_background.width() / width(); |
102 | qreal yScale = m_background.height() / height(); |
103 | source = QRectF( source.x() * xScale, |
104 | source.y() * yScale, |
105 | source.width() * xScale, |
106 | source.height() * yScale ); |
107 | } |
108 | |
109 | painter->drawPixmap( rect, m_background, source ); |
110 | } |
111 | |
112 | |
113 | void PatienceView::receivePixmap( const QPixmap & pixmap ) |
114 | { |
115 | m_background = pixmap; |
116 | resetCachedContent(); |
117 | } |
118 | |
119 | |
120 | void PatienceView::updateSceneSize() |
121 | { |
122 | KCardScene * cs = dynamic_cast<KCardScene*>( scene() ); |
123 | if ( cs ) |
124 | { |
125 | cs->resizeScene( size() ); |
126 | } |
127 | else |
128 | { |
129 | GameSelectionScene * gss = dynamic_cast<GameSelectionScene*>( scene() ); |
130 | if ( gss ) |
131 | gss->resizeScene( size() ); |
132 | } |
133 | } |
134 | |