1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the virtual framebuffer of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
35
#include <qtextstream.h>
40
Skin::Skin( QVFb *p, const QString &skinFile, int &viewW, int &viewH ) : QWidget(p)
43
f.open( IO_ReadOnly );
45
ts >> skinImageUpFileName;
46
ts >> skinImageDownFileName;
53
// Debug the skin file parsing
54
// printf("read: -%s- -%i- -%i- -%i-\n", skinImage.latin1(), viewX1, viewY1, numberOfAreas );
55
areas = new ButtonAreas[numberOfAreas];
57
for (int i = 0; i < numberOfAreas; i++) {
59
ts >> areas[i].keyCode;
64
// Debug the skin file parsing
65
// printf("read: -%s- -%i- -%i- -%i- -%i- -%i-\n", areas[i].name.latin1(),
66
// areas[i].keyCode, areas[i].x1, areas[i].y1, areas[i].x2, areas[i].y2 );
70
skinImageUp = new QPixmap( skinImageUpFileName );
71
skinImageDown = new QPixmap( skinImageDownFileName );
73
setFixedSize( skinImageUp->size() );
74
QBitmap mask = skinImageUp->createHeuristicMask();
75
Qt::WFlags wf = Qt::WStyle_Customize | Qt::WType_TopLevel | Qt::WStyle_NoBorder;
76
parent->setParent(0, wf);
78
parent->setMask( mask );
79
parent->setFixedSize( skinImageUp->size() );
80
buttonPressed = false;
90
void Skin::setView( QVFbView *v )
93
view->move( viewX1, viewY1 );
94
view->setWindowOpacity(transparancy);
98
void Skin::paintEvent( QPaintEvent * )
101
// printf("read: -%s-\n", skinImageUp.latin1());
103
p.drawPixmap( 0, 0, *skinImageUp );
104
if (buttonPressed == true) {
105
ButtonAreas *ba = &areas[buttonIndex];
107
p.drawPixmap( ba->x1, ba->y1, *skinImageDown, ba->x1, ba->y1, ba->x2 - ba->x1, ba->y2 - ba->y1 );
112
void Skin::mousePressEvent( QMouseEvent *e )
114
if (e->button() == Qt::RightButton) {
115
parent->createPopupMenu();
117
buttonPressed = false;
119
for (int i = 0; i < numberOfAreas; i++) {
120
QPoint p1( areas[i].x1, areas[i].y1 );
121
QPoint p2( areas[i].x2, areas[i].y2 );
123
if ( r.contains( e->pos() ) ) {
124
buttonPressed = true;
126
buttonCode = areas[buttonIndex].keyCode;
127
QKeyEvent keyEvent( QEvent::KeyPress, buttonCode, 0, 0 );
129
view->skinKeyPressEvent( &keyEvent );
130
// Debug message to be sure we are clicking the right areas
131
// printf("%s clicked\n", areas[i].name);
132
ButtonAreas *ba = &areas[buttonIndex];
133
repaint( ba->x1, ba->y1, ba->x2 - ba->x1, ba->y2 - ba->y1); //#####, false );
138
// This is handy for finding the areas to define rectangles for new skins
139
// printf("Clicked in %i,%i\n", e->pos().x(), e->pos().y());
145
void Skin::mouseMoveEvent( QMouseEvent *e )
147
if ( buttonPressed == false ) {
148
QPoint newpos = e->globalPos() - clickPos;
149
parent->move( newpos );
154
void Skin::mouseReleaseEvent( QMouseEvent * )
156
if ( buttonPressed ) {
157
QKeyEvent keyEvent( QEvent::KeyRelease, buttonCode, 0, 0 );
159
view->skinKeyReleaseEvent( &keyEvent );
160
buttonPressed = false;
161
ButtonAreas *ba = &areas[buttonIndex];
162
repaint( ba->x1, ba->y1, ba->x2 - ba->x1, ba->y2 - ba->y1); //######, false );