~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to tools/qvfb/skin.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the virtual framebuffer of the Qt Toolkit.
 
6
**
 
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.
 
10
**
 
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.
 
15
**
 
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.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
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.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "skin.h"
 
30
#include "qvfb.h"
 
31
#include "qvfbview.h"
 
32
 
 
33
#include <qbitmap.h>
 
34
#include <qpixmap.h>
 
35
#include <qtextstream.h>
 
36
#include <qfile.h>
 
37
#include <qpainter.h>
 
38
#include <qevent.h>
 
39
 
 
40
Skin::Skin( QVFb *p, const QString &skinFile, int &viewW, int &viewH ) : QWidget(p)
 
41
{
 
42
    QFile f( skinFile );
 
43
    f.open( IO_ReadOnly );
 
44
    QTextStream ts( &f );
 
45
    ts >> skinImageUpFileName;
 
46
    ts >> skinImageDownFileName;
 
47
    ts >> viewX1;
 
48
    ts >> viewY1;
 
49
    ts >> viewW;
 
50
    ts >> viewH;
 
51
    ts >> transparancy;
 
52
    ts >> numberOfAreas;
 
53
//  Debug the skin file parsing
 
54
//  printf("read: -%s- -%i- -%i- -%i-\n", skinImage.latin1(), viewX1, viewY1, numberOfAreas );
 
55
    areas = new ButtonAreas[numberOfAreas];
 
56
 
 
57
    for (int i = 0; i < numberOfAreas; i++) {
 
58
        ts >> areas[i].name;
 
59
        ts >> areas[i].keyCode;
 
60
        ts >> areas[i].x1;
 
61
        ts >> areas[i].y1;
 
62
        ts >> areas[i].x2;
 
63
        ts >> areas[i].y2;
 
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 );
 
67
    }
 
68
 
 
69
    parent = p;
 
70
    skinImageUp = new QPixmap( skinImageUpFileName );
 
71
    skinImageDown = new QPixmap( skinImageDownFileName );
 
72
//  setPixmap( ipaq );
 
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);
 
77
    parent->show();
 
78
    parent->setMask( mask );
 
79
    parent->setFixedSize( skinImageUp->size() );
 
80
    buttonPressed = false;
 
81
    buttonIndex = 0;
 
82
}
 
83
 
 
84
 
 
85
Skin::~Skin( )
 
86
{
 
87
}
 
88
 
 
89
 
 
90
void Skin::setView( QVFbView *v )
 
91
{
 
92
    view = v;
 
93
    view->move( viewX1, viewY1 );
 
94
    view->setWindowOpacity(transparancy);
 
95
}
 
96
 
 
97
 
 
98
void Skin::paintEvent( QPaintEvent * )
 
99
{
 
100
    QPainter p( this );
 
101
//  printf("read: -%s-\n", skinImageUp.latin1());
 
102
    if (skinImageUp)
 
103
        p.drawPixmap( 0, 0, *skinImageUp );
 
104
    if (buttonPressed == true) {
 
105
        ButtonAreas *ba = &areas[buttonIndex];
 
106
        if (skinImageDown)
 
107
            p.drawPixmap( ba->x1, ba->y1, *skinImageDown, ba->x1, ba->y1, ba->x2 - ba->x1, ba->y2 - ba->y1 );
 
108
    }
 
109
}
 
110
 
 
111
 
 
112
void Skin::mousePressEvent( QMouseEvent *e )
 
113
{
 
114
    if (e->button() == Qt::RightButton) {
 
115
        parent->createPopupMenu();
 
116
    } else {
 
117
        buttonPressed = false;
 
118
 
 
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 );
 
122
            QRect r( p1, p2 );
 
123
            if ( r.contains( e->pos() ) ) {
 
124
                buttonPressed = true;
 
125
                buttonIndex = i;
 
126
                buttonCode = areas[buttonIndex].keyCode;
 
127
                QKeyEvent keyEvent( QEvent::KeyPress, buttonCode, 0, 0 );
 
128
                if (view)
 
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 );
 
134
                continue;
 
135
            }
 
136
        }
 
137
 
 
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());
 
140
        clickPos = e->pos();
 
141
    }
 
142
}
 
143
 
 
144
 
 
145
void Skin::mouseMoveEvent( QMouseEvent *e )
 
146
{
 
147
    if ( buttonPressed == false ) {
 
148
        QPoint newpos =  e->globalPos() - clickPos;
 
149
        parent->move( newpos );
 
150
    }
 
151
}
 
152
 
 
153
 
 
154
void Skin::mouseReleaseEvent( QMouseEvent * )
 
155
{
 
156
    if ( buttonPressed ) {
 
157
        QKeyEvent keyEvent( QEvent::KeyRelease, buttonCode, 0, 0 );
 
158
        if (view)
 
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 );
 
163
    }
 
164
}