#ifndef SHORTCUTLINE_H
#define SHORTCUTLINE_H

#include <QLineEdit>
#include <QKeyEvent>
#include <KActionCollection>
#include <KGlobalAccel>
#include <QObject>
#include <QDBusInterface>
#include <QDBusConnection>
#include "../shell/type.h"
#include "ukcccommon.h"

using namespace ukcc;

class ShortcutLine : public QLineEdit
{
    Q_OBJECT
public:
    ShortcutLine(QList<KeyEntry> *generalEntries,
                 QList<KeyEntry> *windowEntries,
                 QList<KeyEntry> *customEntries,
                 QWidget *parent = nullptr);
    ~ShortcutLine();
protected:
    void keyPressEvent(QKeyEvent *event);   //键盘按下事件
    void keyReleaseEvent(QKeyEvent *event); //键盘松开事件
    void focusInEvent(QFocusEvent *e);      //焦点进入事件
    void focusOutEvent(QFocusEvent *e);     //焦点退出事件

public:
    QString m_conflictValue = "";
    QString m_conflictKey   = "";

private:
    QString firstKey, secondKey, thirdKey, forthKey;
    bool shortCutObtainedFlag;
    QList<KeyEntry> *systemEntry;
    QList<KeyEntry>* m_windowEntry;
    QList<KeyEntry> *customEntry;
    QKeySequence seq;
    bool isShortCutObtained = false;
    QDBusInterface *mKglobalIfc;

public:
    void initInputKeyAndText(const bool &clearText);
    bool lastKeyIsAvailable(const int &key, const int &keyCode);
    bool conflictWithGlobalShortcuts(const QKeySequence &keySequence);
    bool conflictWithStandardShortcuts(const QKeySequence &seq);
    bool conflictWithSystemShortcuts(const QKeySequence &seq);
    bool conflictWithWindowShortcuts(const QKeySequence &seq);
    bool conflictWithCustomShortcuts(const QKeySequence &seq);
    QString keyToLib(QString key);
    void shortCutObtained(const bool &flag, const int &keyNum = 0); //true:success but may be conflicted, false: invalid
    QString keyToString(int keyValue);
    QKeySequence keySequence();
    void setKeySequence(QKeySequence setSeq);
    void initInterface();

Q_SIGNALS:
    void shortCutAvailable(const int &flag); //0:success, -1:shortcut invalid, -2:shortcut conflict
};


#endif // SHORTCUTLINE_H
