Beispiel #1
0
void Keyboard::mousePressEvent(QMouseEvent *e)
{
    clearHighlight(); // typing fast?

    int i2 = ((e->x() - xoffs) * 2) / defaultKeyWidth;
    int j = (e->y() - picks->height()) / keyHeight;

    int k = keycode( i2, j, (const uchar **)((useOptiKeys) ? keyboard_opti : keyboard_standard) );
    bool need_repaint = FALSE;
    unicode = -1;
    qkeycode = 0;
    if ( k >= 0x80 ) {
	if ( k == ShiftCode ) {
	    shift = !shift;
	    need_repaint = TRUE;
	} else if ( k == AltCode ){
	    alt = !alt;
	    need_repaint = TRUE;
	} else if ( k == CapsCode ) {
	    lock = !lock;
	    need_repaint = TRUE;
	} else if ( k == CtrlCode ) {
	    ctrl = !ctrl;
	    need_repaint = TRUE;
	} else if ( k == 0224 /* Expand */ ) {
	    useLargeKeys = !useLargeKeys;
	    resizeEvent(0);
	    repaint( TRUE ); // need it to clear first
	} else if ( k == 0225 /* Opti/Toggle */ ) {
	    useOptiKeys = !useOptiKeys;
	    resizeEvent(0);
	    repaint( TRUE ); // need it to clear first
	} else {
	    qkeycode = specialM[ k - 0x80 ].qcode;
	    unicode = specialM[ k - 0x80 ].unicode;
	}
    } else {
#if defined(Q_WS_QWS) || defined(_WS_QWS_)
/*
	qk = QWSServer::keyMap()[k].key_code;
	if ( qk != Key_unknown ) {
		if ( ctrl )
		    u = QWSServer::keyMap()[k].ctrl_unicode;
		else if ( shift^lock )
		    u = QWSServer::keyMap()[k].shift_unicode;
		else
		    u = QWSServer::keyMap()[k].unicode;
	}
*/
	char shifted = k;
	if ( !isalpha( k ) ) {
	    // ### Fixme, bad code, needs improving, whole thing needs to
	    // be re-coded to get rid of the way it did things with scancodes etc
	    for ( unsigned i = 0; i < sizeof(shiftMap)/sizeof(ShiftMap); i++ )
		if ( shiftMap[i].normal == k )
		    shifted = shiftMap[i].shifted;
	} else {
	    shifted = toupper( k );
	}
	QChar tempChar( shift^lock ? shifted : k );
	unicode = tempChar.unicode();
#endif
    }
    if  ( unicode != -1 ) {
	modifiers = (shift ? Qt::ShiftButton : 0) | (ctrl ? Qt::ControlButton : 0) |
		  (alt ? Qt::AltButton : 0);
#if defined(Q_WS_QWS) || defined(_WS_QWS_)
	emit key( unicode, qkeycode, modifiers, true, false );
	repeatTimer->start( 500 );
#endif
	need_repaint = shift || alt || ctrl;
	shift = alt = ctrl = FALSE;
	//qDebug( "pressed %d -> %04x ('%c')", k, u, u&0xffff < 256 ? u&0xff : 0 );

	KeyboardConfig *dc = picks->dc;

	if (dc) {
	    if (qkeycode == Qt::Key_Backspace) {
		dc->input.remove(dc->input.last()); // remove last input
		dc->decBackspaces();
	    } else if ( k == 0226 || qkeycode == Qt::Key_Return ||
		        qkeycode == Qt::Key_Space ||
			QChar(unicode).isPunct() ) {
		dc->input.clear();
		dc->resetBackspaces();
	    } else {
		dc->add(QString(QChar(unicode)));
		dc->incBackspaces();
	    }
	}

	picks->repaint();

    }
    pressedKey = k;
    if ( need_repaint ) {
	repaint( FALSE );
    } else {
	QPainter p(this);
	drawKeyboard( p, pressedKey );
    }
    pressTid = startTimer(80);
    pressed = TRUE;
}