/***************************************************************************
 *   Copyright (C) 2003-2005 by liuspider                                  *
 *   liuspider@users.sourceforge.net                                       *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 **************************************************************************/
#ifndef SKIMKEYGRABBER_H
#define SKIMKEYGRABBER_H

#include <kdialogbase.h>

class KLineEdit;

#include <qtoolbutton.h>

class SkimShortcutEditor : public QWidget
{
Q_OBJECT
public:
    SkimShortcutEditor(QWidget *parent = 0, const char *name = 0);
    KLineEdit * lineEditor;
private slots:
    void invokeGrabber();
private:
    QToolButton * button;
};

class KEditListBox;
class SkimShortcutListEditor : public KDialogBase
{
Q_OBJECT
public:
    SkimShortcutListEditor(QWidget *parent = 0, const char *name = 0);
    void setStringList(QStringList &);
    QString getCombinedString();
private slots:
    void verifyShortcut(const QString &);
private:
    SkimShortcutEditor* editor;
    KEditListBox* listBox;
};

class SkimEditShortcutButton : public QToolButton
{
Q_OBJECT
public:
    SkimEditShortcutButton(QWidget *parent = 0, const char *name = 0);
public slots:
    void setShortcuts(const QString &);
//     void setEditor(KLineEdit *k);
signals:
    void setEditorText(const QString &);
private slots:
    void invokeShortcutListEditor();
private:
    KLineEdit * lineEditor;
    QString shortcuts;
};

//uncomment the following line to test none-X11 platform
// #undef Q_WS_X11

class QCheckBox;

class SkimKeyGrabber : public KDialogBase
{
Q_OBJECT
public:
    SkimKeyGrabber(QWidget *parent = 0, const char *name = 0);
    QString getShortcut() {return finalKeys;};
    ~SkimKeyGrabber();

public slots:
    int exec();
protected:
#ifdef Q_WS_X11
    bool x11Event ( XEvent * );
    void addCheckModifier(QCheckBox *, UINT16);
#else
    void keyPressEvent ( QKeyEvent * e );
    void keyReleaseEvent ( QKeyEvent * e );
    QString keys;
#endif
private:
    class SkimKeyGrabberPrivate;
    SkimKeyGrabberPrivate* d;
    void checkKeys(int key, QValueList<int> & oldkeys, QValueList<int> & newkeys, QCheckBox * cb);
    QString finalKeys;
    QCheckBox * ctrl;
    QCheckBox * alt;
    QCheckBox * shift;
    QCheckBox * release;
#ifdef Q_WS_X11
    QCheckBox * capslock;
    QCheckBox * meta;
    QCheckBox * hyper;
    QCheckBox * super;
#endif
//     QCheckBox * leftRight;
};

#endif
