Get rid of unused functions and add variant that support text arg.
This commit is contained in:
parent
123301896a
commit
72acd72cf2
|
@ -1,7 +1,7 @@
|
|||
ecm_setup_version(PROJECT VARIABLE_PREFIX FCITX5QT5WIDGETSADDONS
|
||||
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/fcitx5qt5widgetsaddons_version.h"
|
||||
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/Fcitx5Qt5WidgetsAddonsConfigVersion.cmake"
|
||||
SOVERSION 1)
|
||||
SOVERSION 2)
|
||||
|
||||
# create a Config.cmake and a ConfigVersion.cmake file and install them
|
||||
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Fcitx5Qt5WidgetsAddons")
|
||||
|
@ -51,9 +51,9 @@ target_include_directories(Fcitx5Qt5WidgetsAddons PUBLIC "$<BUILD_INTERFACE:${fc
|
|||
target_include_directories(Fcitx5Qt5WidgetsAddons INTERFACE "$<INSTALL_INTERFACE:${Fcitx5Qt5_INCLUDE_INSTALL_DIR}/Fcitx5QtWidgetsAddons>")
|
||||
|
||||
set_target_properties(Fcitx5Qt5WidgetsAddons
|
||||
PROPERTIES VERSION 1.0
|
||||
PROPERTIES VERSION 1.1
|
||||
AUTOMOC TRUE
|
||||
SOVERSION 1
|
||||
SOVERSION 2
|
||||
COMPILE_FLAGS "-fvisibility=hidden"
|
||||
EXPORT_NAME WidgetsAddons
|
||||
)
|
||||
|
|
|
@ -60,10 +60,44 @@ Q_LOGGING_CATEGORY(fcitx5qtKeysequenceWidget, "fcitx5.qt.keysequencewidget")
|
|||
|
||||
namespace fcitx {
|
||||
|
||||
namespace {
|
||||
|
||||
bool isX11LikePlatform() {
|
||||
return qApp->platformName() == "xcb" || qApp->platformName() == "wayland";
|
||||
}
|
||||
|
||||
bool keyQtToFcitx(int keyQt, const QString &text, FcitxQtModifierSide side,
|
||||
Key &outkey) {
|
||||
int key = keyQt & (~Qt::KeyboardModifierMask);
|
||||
int state = keyQt & Qt::KeyboardModifierMask;
|
||||
int sym;
|
||||
unsigned int states;
|
||||
if (!keyQtToSym(key, Qt::KeyboardModifiers(state), text, sym, states)) {
|
||||
return false;
|
||||
}
|
||||
if (side == MS_Right) {
|
||||
switch (sym) {
|
||||
case FcitxKey_Control_L:
|
||||
sym = FcitxKey_Control_R;
|
||||
break;
|
||||
case FcitxKey_Alt_L:
|
||||
sym = FcitxKey_Alt_R;
|
||||
break;
|
||||
case FcitxKey_Shift_L:
|
||||
sym = FcitxKey_Shift_R;
|
||||
break;
|
||||
case FcitxKey_Super_L:
|
||||
sym = FcitxKey_Super_R;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outkey = Key(static_cast<KeySym>(sym), KeyStates(states));
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
class FcitxQtKeySequenceWidgetPrivate {
|
||||
public:
|
||||
FcitxQtKeySequenceWidgetPrivate(FcitxQtKeySequenceWidget *q);
|
||||
|
@ -375,8 +409,7 @@ void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e) {
|
|||
}
|
||||
|
||||
Key key;
|
||||
if (FcitxQtKeySequenceWidget::keyQtToFcitx(keyQt, MS_Unknown,
|
||||
key)) {
|
||||
if (keyQtToFcitx(keyQt, e->text(), MS_Unknown, key)) {
|
||||
if (d->keyCodeModeAction_->isChecked()) {
|
||||
key = Key::fromKeyCode(e->nativeScanCode(), key.states());
|
||||
}
|
||||
|
@ -432,7 +465,7 @@ void FcitxQtKeySequenceButton::keyReleaseEvent(QKeyEvent *e) {
|
|||
}
|
||||
int keyQt = e->key() | d->modifierKeys_;
|
||||
Key key;
|
||||
if (FcitxQtKeySequenceWidget::keyQtToFcitx(keyQt, side, key)) {
|
||||
if (keyQtToFcitx(keyQt, e->text(), side, key)) {
|
||||
if (d->keyCodeModeAction_->isChecked()) {
|
||||
key = Key::fromKeyCode(e->nativeScanCode(), key.states());
|
||||
}
|
||||
|
@ -471,46 +504,6 @@ bool FcitxQtKeySequenceWidgetPrivate::isOkWhenModifierless(int keyQt) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool FcitxQtKeySequenceWidget::keyQtToFcitx(int keyQt, FcitxQtModifierSide side,
|
||||
Key &outkey) {
|
||||
int key = keyQt & (~Qt::KeyboardModifierMask);
|
||||
int state = keyQt & Qt::KeyboardModifierMask;
|
||||
int sym;
|
||||
unsigned int states;
|
||||
if (!keyQtToSym(key, Qt::KeyboardModifiers(state), sym, states)) {
|
||||
return false;
|
||||
}
|
||||
if (side == MS_Right) {
|
||||
switch (sym) {
|
||||
case FcitxKey_Control_L:
|
||||
sym = FcitxKey_Control_R;
|
||||
break;
|
||||
case FcitxKey_Alt_L:
|
||||
sym = FcitxKey_Alt_R;
|
||||
break;
|
||||
case FcitxKey_Shift_L:
|
||||
sym = FcitxKey_Shift_R;
|
||||
break;
|
||||
case FcitxKey_Super_L:
|
||||
sym = FcitxKey_Super_R;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
outkey = Key(static_cast<KeySym>(sym), KeyStates(states));
|
||||
return true;
|
||||
}
|
||||
|
||||
int FcitxQtKeySequenceWidget::keyFcitxToQt(Key key) {
|
||||
Qt::KeyboardModifiers qstate = Qt::NoModifier;
|
||||
|
||||
int qtkey = 0;
|
||||
symToKeyQt(static_cast<int>(key.sym()),
|
||||
static_cast<unsigned int>(key.states()), qtkey, qstate);
|
||||
|
||||
return qtkey | qstate;
|
||||
}
|
||||
} // namespace fcitx
|
||||
|
||||
#include "moc_fcitxqtkeysequencewidget.cpp"
|
||||
|
|
|
@ -90,9 +90,6 @@ public:
|
|||
|
||||
const QList<Key> &keySequence() const;
|
||||
|
||||
static bool keyQtToFcitx(int keyQt, FcitxQtModifierSide side, Key &outkey);
|
||||
static int keyFcitxToQt(Key key);
|
||||
|
||||
Q_SIGNALS:
|
||||
void keySequenceChanged(const QList<Key> &seq);
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
namespace fcitx {
|
||||
|
||||
void qEventToSym(int key, const QString &text, Qt::KeyboardModifiers mod,
|
||||
void qEventToSym(int key, Qt::KeyboardModifiers mod, const QString &text,
|
||||
int &outsym, unsigned int &outstate) {
|
||||
int sym = 0;
|
||||
fcitx::KeyStates state;
|
||||
|
@ -760,7 +760,12 @@ bool symToKeyQt(int sym, unsigned int state, int &qtcode,
|
|||
|
||||
bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, int &sym,
|
||||
unsigned int &state) {
|
||||
qEventToSym(qtcode, QString(), mod, sym, state);
|
||||
return keyQtToSym(qtcode, mod, QString(), sym, state);
|
||||
}
|
||||
|
||||
bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, const QString &text,
|
||||
int &sym, unsigned int &state) {
|
||||
qEventToSym(qtcode, mod, text, sym, state);
|
||||
|
||||
return sym >= 0;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#ifndef _WIDGETSADDONS_QTKEYTRANS_H_
|
||||
#define _WIDGETSADDONS_QTKEYTRANS_H_
|
||||
|
||||
#include <QString>
|
||||
#include <qnamespace.h>
|
||||
|
||||
namespace fcitx {
|
||||
|
@ -13,6 +14,9 @@ namespace fcitx {
|
|||
bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, int &sym,
|
||||
unsigned int &state);
|
||||
|
||||
bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, const QString &text,
|
||||
int &sym, unsigned int &state);
|
||||
|
||||
bool symToKeyQt(int sym, unsigned int state, int &qtcode,
|
||||
Qt::KeyboardModifiers &mod);
|
||||
} // namespace fcitx
|
||||
|
|
Loading…
Reference in New Issue