~ubuntu-branches/debian/sid/smplayer/sid

« back to all changes in this revision

Viewing changes to src/keychooser.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Breuil Cyril
  • Date: 2007-06-24 16:35:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070624163529-hhckbmd24uicada7
Tags: 0.5.20-0ubuntu1
* New upstream release
* Change Maintainer Email

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  smplayer, GUI front-end for mplayer.
 
2
    Copyright (C) 2007 Ricardo Villalba <rvm@escomposlinux.org>
 
3
 
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
*/
 
18
 
 
19
/* 
 
20
    Note: most of the code in this class has been taken from the source 
 
21
    code of Qt-3 Designer (propertyeditor.h and propertyeditor.cpp).
 
22
        Copyright (C) 2000 Trolltech AS.
 
23
*/
 
24
 
 
25
 
 
26
#include "keychooser.h"
 
27
#include <qkeysequence.h>
 
28
 
 
29
 
 
30
KeyChooser::KeyChooser( QWidget * parent, const char * name ) 
 
31
        : QLineEdit(parent, name)
 
32
{
 
33
        num=0;
 
34
        k1=0; k2=0; k3=0; k4=0;
 
35
        mouseEnter = false;
 
36
}
 
37
 
 
38
KeyChooser::~KeyChooser() {
 
39
}
 
40
 
 
41
void KeyChooser::clear() {
 
42
        num=0;
 
43
        k1=0; k2=0; k3=0; k4=0;
 
44
        QLineEdit::clear();
 
45
}
 
46
 
 
47
void KeyChooser::keyPressEvent( QKeyEvent * e ) {
 
48
        num = 0;
 
49
        int nextKey = e->key();
 
50
 
 
51
    if ( num > 3 ||
 
52
         nextKey == Qt::Key_Control ||
 
53
         nextKey == Qt::Key_Shift ||
 
54
         nextKey == Qt::Key_Meta ||
 
55
         nextKey == Qt::Key_Alt )
 
56
        {
 
57
                e->ignore();
 
58
         return;
 
59
        }
 
60
 
 
61
    nextKey |= translateModifiers( e->state() );
 
62
    switch( num ) {
 
63
        case 0:
 
64
            k1 = nextKey;
 
65
            break;
 
66
        case 1:
 
67
            k2 = nextKey;
 
68
            break;
 
69
        case 2:
 
70
            k3 = nextKey;
 
71
            break;
 
72
        case 3:
 
73
            k4 = nextKey;
 
74
            break;
 
75
        default:
 
76
            break;
 
77
    }
 
78
    //num++;
 
79
    QKeySequence ks( k1, k2, k3, k4 );
 
80
    setText( ks );
 
81
 
 
82
        e->accept();
 
83
        qDebug("KeyChooser::keyPressEvent: num = %d", num);
 
84
}
 
85
 
 
86
bool KeyChooser::event( QEvent * e ) {
 
87
        if ( e->type() == QEvent::KeyPress ) {
 
88
                QKeyEvent *k = (QKeyEvent *)e;
 
89
                if ( !mouseEnter &&
 
90
            (k->key() == Qt::Key_Up ||
 
91
             k->key() == Qt::Key_Down) )
 
92
            return QLineEdit::event(e); //FALSE;
 
93
                keyPressEvent(k);
 
94
        return TRUE;
 
95
    } else if ( (e->type() == QEvent::FocusIn) ||
 
96
                (e->type() == QEvent::MouseButtonPress) ) {
 
97
        mouseEnter = (e->type() == QEvent::MouseButtonPress);
 
98
        return TRUE;
 
99
    }
 
100
 
 
101
    // Lets eat accelerators now..
 
102
    if ( e->type() == QEvent::Accel ||
 
103
         e->type() == QEvent::AccelOverride  ||
 
104
         e->type() == QEvent::KeyRelease )
 
105
        return TRUE;
 
106
 
 
107
        //return FALSE;
 
108
        return QLineEdit::event(e);
 
109
}
 
110
 
 
111
int KeyChooser::translateModifiers( int state ) {
 
112
    int result = 0;
 
113
    if ( state & Qt::ShiftButton )
 
114
        result |= Qt::SHIFT;
 
115
    if ( state & Qt::ControlButton )
 
116
        result |= Qt::CTRL;
 
117
    if ( state & Qt::MetaButton )
 
118
        result |= Qt::META;
 
119
    if ( state & Qt::AltButton )
 
120
        result |= Qt::ALT;
 
121
    return result;
 
122
}