summaryrefslogtreecommitdiff
path: root/src/common/fqterm_shortcuthelper.h
blob: 6364d4ecf89494241cb609f3cce7549d9d56c7bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// SPDX-License-Identifier: GPL-2.0-or-later

#ifndef __FQTERM_SHORTCUTHELPER__
#define __FQTERM_SHORTCUTHELPER__

#include "fqterm.h"
#include <QObject>
#include <QString>
#include <QMap>

class QWidget;
class QAction;
namespace FQTerm
{
class FQTermConfig;


#define FQTERM_ADDACTION(WIDGET, NAME, RECEIVER, FUNCTION) \
  do{ \
  QAction *action = getAction((FQTermShortcutHelper::NAME));\
  QObject::disconnect(action, SIGNAL(triggered()), (RECEIVER), SLOT(FUNCTION())); \
  FQ_VERIFY(connect(action, SIGNAL(triggered()), (RECEIVER), SLOT(FUNCTION()))); \
  (WIDGET)->addAction(action);\
  } while(0)



class FQTermShortcutHelper : public QObject
{
  Q_OBJECT;
public:
  enum FQTERM_SHORTCUT
  {
    FQTERM_APPLICATION_SHORTCUT_START = 0,
    CONNECT,
    DISCONNECT,
    CONN_INFO,
    ADDRESSBOOK,  //F2
    QUICKLOGIN,   //F3
    COPY,         //Ctrl+Ins under lin & win, Ctrl+C under mac
    PASTE,        //Shift+Insert under lin & win, Ctrl+V under mac
    COPYWITHCOLOR, 
    RECTANGLESELECTION,
    AUTOCOPYSELECTION,
    PASTEWORDWRAP,
    ENGLISHFONT,
    OTHERFONT,
    COLORSETTING,
    ANSICOLOR,
    REFRESHSCREEN,  //F5
    UIFONT,
    FULLSCREEN,   //F6
    BOSSCOLOR,    //F12
    SWITCHBAR,
    SEARCHIT,       //Ctrl+Alt+G
    WEIBOSHARE,
    EXTERNALEDITOR,   //Ctrl+Alt+E
    FASTPOST,   //Ctrl+Alt+F
    CURRENTSETTING,
    DEFAULTSETTING,
    SAVESETTING,
    PREFERENCE,
    SHORTCUTSETTING,
    EDITSCHEMA,
    COPYARTICLE,  //F9
    LOGRAW,
    ANTIIDLE, 
    AUTOREPLY,
    VIEWMESSAGE,  //F10
    IPLOOKUP,
    BEEP,
    MOUSESUPPORT,
    IMAGEVIEWER,
    RUNSCRIPT,    //F7
    STOPSCRIPT,   //F8
    RUNPYTHONSCRIPT, //Ctrl+F1
    ABOUT,        //F1
    HOMEPAGE,
    CASCADEWINDOWS,
    TILEWINDOWS,
    EXIT,
    COLORCTL_NO,
    COLORCTL_SMTH,
    COLORCTL_PTT,
    COLORCTL_OLD_CUSTOM,
    COLORCTL_CUSTOM,
    AUTORECONNECT,
    SCROLLBAR_LEFT,
    SCROLLBAR_RIGHT,
    SCROLLBAR_HIDDEN,
    SEARCH_GOOGLE,
    SEARCH_BAIDU,
    SEARCH_BING,
    SEARCH_YAHOO,
    SEARCH_CUSTOM,
    LANGUAGE_ENGLISH,
    NEXTWINDOW,
    PREVWINDOW,
    GLOBAL_SHOW_FQTERM,
    FQTERM_APPLICATION_SHORTCUT_END,
  };


public:
  FQTermShortcutHelper(FQTermConfig* config, QWidget* actionParent);
  ~FQTermShortcutHelper();
  
private:
  struct ShortcutDescriptionEntry
  {
    ShortcutDescriptionEntry(const QString& key = QString(""), const QString& defaultshortcuttext = QString(""), const QString& description = QString(""));
    ~ShortcutDescriptionEntry();
    QString key_;
    QString defaultshortcuttext_;
    QString description_;
    QAction* action_;
  };
  void initShortcutDescriptionTable();
  FQTermConfig* config_;
  QWidget* actionParent_;
  QMap<int, ShortcutDescriptionEntry> shortcutDescriptionTable_;
  void initShortcutDescriptionTableEntry(int index, const QString& key, const QString& defaultshortcuttext, const QString& description, const QString& actionSkin = QString::null);
  
public:

  QString getShortcutText(int shortcut) ;
  QString getShortcutDescription(int shortcut) {
    return shortcutDescriptionTable_[shortcut].description_;
  }
  QString getShortcutDefaultText(int shortcut) {
    return shortcutDescriptionTable_[shortcut].defaultshortcuttext_;
  }
  void setShortcutText(int shortcut, const QString& text);
  void resetShortcutText(int shortcut);
  void resetAllShortcutText();

  QAction* getAction(int shortcut) {
    return shortcutDescriptionTable_[shortcut].action_;
  }
  void retranslateActions();
private:
  //These functions are used to save shortcut
  QString getShortcutSection() {
    return QString("shortcutsettings");
  }
  QString getShortcutKey(int shortcut) {
    return shortcutDescriptionTable_[shortcut].key_;
  }
  
  QString getShortcutConfig(int shortcut);
  void setShortcutConfig(int shortcut, const QString& text);
  void retranslateAction(int shortcut, const QString& text);
};
  
  
}//namespace FQTerm


#endif