run clang-format
This commit is contained in:
parent
f14afc0500
commit
9baea1fe26
|
@ -0,0 +1,58 @@
|
|||
---
|
||||
Language: Cpp
|
||||
# BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
ConstructorInitializerIndentWidth: 4
|
||||
AlignEscapedNewlinesLeft: false
|
||||
AlignTrailingComments: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AlwaysBreakTemplateDeclarations: true
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
BreakBeforeBinaryOperators: false
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BinPackParameters: true
|
||||
ColumnLimit: 80
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
DerivePointerAlignment: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
IndentCaseLabels: false
|
||||
IndentWrappedFunctionNames: false
|
||||
IndentFunctionDeclarationAfterType: false
|
||||
MaxEmptyLinesToKeep: 1
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
NamespaceIndentation: None
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PenaltyBreakBeforeFirstCallParameter: 19
|
||||
PenaltyBreakComment: 300
|
||||
PenaltyBreakString: 1000
|
||||
PenaltyBreakFirstLessLess: 120
|
||||
PenaltyExcessCharacter: 1000000
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
PointerAlignment: Right
|
||||
SpacesBeforeTrailingComments: 1
|
||||
Cpp11BracedListStyle: true
|
||||
Standard: Cpp11
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
BreakBeforeBraces: Attach
|
||||
SpacesInParentheses: false
|
||||
SpacesInAngles: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
ContinuationIndentWidth: 4
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
|
||||
SpaceBeforeParens: ControlStatements
|
||||
DisableFormat: false
|
||||
SortIncludes: true
|
||||
...
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
#!/bin/sh
|
||||
find . \( -not \( -name '*proxy.h' -o -name '*proxy.cpp' \) \) -a \( -name '*.h' -o -name '*.cpp' \) | xargs clang-format -i
|
|
@ -19,16 +19,16 @@
|
|||
|
||||
#include "fcitxqtconnection_p.h"
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusServiceWatcher>
|
||||
#include <QDBusReply>
|
||||
#include <QDBusConnectionInterface>
|
||||
#include <QDBusReply>
|
||||
#include <QDBusServiceWatcher>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
|
||||
#include <signal.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
// utils function in fcitx-utils and fcitx-config
|
||||
bool _pid_exists(pid_t pid) {
|
||||
|
@ -37,14 +37,10 @@ bool _pid_exists(pid_t pid) {
|
|||
return !(kill(pid, 0) && (errno == ESRCH));
|
||||
}
|
||||
|
||||
FcitxQtConnection::FcitxQtConnection(QObject *parent)
|
||||
: QObject(parent), d_ptr(new FcitxQtConnectionPrivate(this)) {}
|
||||
|
||||
FcitxQtConnection::FcitxQtConnection(QObject* parent): QObject(parent)
|
||||
,d_ptr(new FcitxQtConnectionPrivate(this))
|
||||
{
|
||||
}
|
||||
|
||||
void FcitxQtConnection::startConnection()
|
||||
{
|
||||
void FcitxQtConnection::startConnection() {
|
||||
Q_D(FcitxQtConnection);
|
||||
if (!d->m_initialized) {
|
||||
d->initialize();
|
||||
|
@ -52,63 +48,46 @@ void FcitxQtConnection::startConnection()
|
|||
}
|
||||
}
|
||||
|
||||
void FcitxQtConnection::endConnection()
|
||||
{
|
||||
void FcitxQtConnection::endConnection() {
|
||||
Q_D(FcitxQtConnection);
|
||||
d->cleanUp();
|
||||
d->finalize();
|
||||
d->m_connectedOnce = false;
|
||||
}
|
||||
|
||||
bool FcitxQtConnection::autoReconnect()
|
||||
{
|
||||
bool FcitxQtConnection::autoReconnect() {
|
||||
Q_D(FcitxQtConnection);
|
||||
return d->m_autoReconnect;
|
||||
}
|
||||
|
||||
void FcitxQtConnection::setAutoReconnect(bool a)
|
||||
{
|
||||
void FcitxQtConnection::setAutoReconnect(bool a) {
|
||||
Q_D(FcitxQtConnection);
|
||||
d->m_autoReconnect = a;
|
||||
}
|
||||
|
||||
QDBusConnection* FcitxQtConnection::connection()
|
||||
{
|
||||
QDBusConnection *FcitxQtConnection::connection() {
|
||||
Q_D(FcitxQtConnection);
|
||||
return d->m_connection;
|
||||
}
|
||||
|
||||
const QString& FcitxQtConnection::serviceName()
|
||||
{
|
||||
const QString &FcitxQtConnection::serviceName() {
|
||||
Q_D(FcitxQtConnection);
|
||||
return d->m_serviceName;
|
||||
}
|
||||
|
||||
bool FcitxQtConnection::isConnected()
|
||||
{
|
||||
bool FcitxQtConnection::isConnected() {
|
||||
Q_D(FcitxQtConnection);
|
||||
return d->isConnected();
|
||||
}
|
||||
|
||||
FcitxQtConnection::~FcitxQtConnection() {}
|
||||
|
||||
FcitxQtConnectionPrivate::FcitxQtConnectionPrivate(FcitxQtConnection *conn)
|
||||
: QObject(conn), q_ptr(conn), m_serviceName("org.fcitx.Fcitx5"),
|
||||
m_connection(nullptr), m_serviceWatcher(new QDBusServiceWatcher(this)),
|
||||
m_autoReconnect(true), m_connectedOnce(false), m_initialized(false) {}
|
||||
|
||||
FcitxQtConnection::~FcitxQtConnection()
|
||||
{
|
||||
}
|
||||
|
||||
FcitxQtConnectionPrivate::FcitxQtConnectionPrivate(FcitxQtConnection* conn) : QObject(conn)
|
||||
,q_ptr(conn)
|
||||
,m_serviceName("org.fcitx.Fcitx5")
|
||||
,m_connection(nullptr)
|
||||
,m_serviceWatcher(new QDBusServiceWatcher(this))
|
||||
,m_autoReconnect(true)
|
||||
,m_connectedOnce(false)
|
||||
,m_initialized(false)
|
||||
{
|
||||
}
|
||||
|
||||
FcitxQtConnectionPrivate::~FcitxQtConnectionPrivate()
|
||||
{
|
||||
FcitxQtConnectionPrivate::~FcitxQtConnectionPrivate() {
|
||||
if (m_connection)
|
||||
delete m_connection;
|
||||
}
|
||||
|
@ -129,15 +108,18 @@ void FcitxQtConnectionPrivate::createConnection() {
|
|||
return;
|
||||
}
|
||||
|
||||
disconnect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &FcitxQtConnectionPrivate::imChanged);
|
||||
disconnect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged,
|
||||
this, &FcitxQtConnectionPrivate::imChanged);
|
||||
if (!m_connection) {
|
||||
QDBusConnection* connection = new QDBusConnection(QDBusConnection::sessionBus());
|
||||
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &FcitxQtConnectionPrivate::imChanged);
|
||||
QDBusReply<bool> registered = connection->interface()->isServiceRegistered(m_serviceName);
|
||||
QDBusConnection *connection =
|
||||
new QDBusConnection(QDBusConnection::sessionBus());
|
||||
connect(m_serviceWatcher, &QDBusServiceWatcher::serviceOwnerChanged,
|
||||
this, &FcitxQtConnectionPrivate::imChanged);
|
||||
QDBusReply<bool> registered =
|
||||
connection->interface()->isServiceRegistered(m_serviceName);
|
||||
if (!registered.isValid() || !registered.value()) {
|
||||
delete connection;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
m_connection = connection;
|
||||
}
|
||||
}
|
||||
|
@ -145,27 +127,24 @@ void FcitxQtConnectionPrivate::createConnection() {
|
|||
Q_Q(FcitxQtConnection);
|
||||
if (m_connection) {
|
||||
|
||||
m_connection->connect ("org.freedesktop.DBus.Local",
|
||||
"/org/freedesktop/DBus/Local",
|
||||
"org.freedesktop.DBus.Local",
|
||||
"Disconnected",
|
||||
this,
|
||||
SLOT (dbusDisconnected ()));
|
||||
m_connection->connect("org.freedesktop.DBus.Local",
|
||||
"/org/freedesktop/DBus/Local",
|
||||
"org.freedesktop.DBus.Local", "Disconnected",
|
||||
this, SLOT(dbusDisconnected()));
|
||||
m_connectedOnce = true;
|
||||
emit q->connected();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void FcitxQtConnectionPrivate::dbusDisconnected()
|
||||
{
|
||||
void FcitxQtConnectionPrivate::dbusDisconnected() {
|
||||
cleanUp();
|
||||
|
||||
createConnection();
|
||||
}
|
||||
|
||||
void FcitxQtConnectionPrivate::imChanged(const QString& service, const QString& oldowner, const QString& newowner)
|
||||
{
|
||||
void FcitxQtConnectionPrivate::imChanged(const QString &service,
|
||||
const QString &oldowner,
|
||||
const QString &newowner) {
|
||||
if (service == m_serviceName) {
|
||||
/* old die */
|
||||
if (oldowner.length() > 0 || newowner.length() > 0)
|
||||
|
@ -173,13 +152,13 @@ void FcitxQtConnectionPrivate::imChanged(const QString& service, const QString&
|
|||
|
||||
/* new rise */
|
||||
if (newowner.length() > 0) {
|
||||
QTimer::singleShot(100, this, &FcitxQtConnectionPrivate::newServiceAppear);
|
||||
QTimer::singleShot(100, this,
|
||||
&FcitxQtConnectionPrivate::newServiceAppear);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FcitxQtConnectionPrivate::cleanUp()
|
||||
{
|
||||
void FcitxQtConnectionPrivate::cleanUp() {
|
||||
Q_Q(FcitxQtConnection);
|
||||
bool doemit = false;
|
||||
if (m_connection) {
|
||||
|
@ -199,8 +178,7 @@ void FcitxQtConnectionPrivate::cleanUp()
|
|||
emit q->disconnected();
|
||||
}
|
||||
|
||||
bool FcitxQtConnectionPrivate::isConnected()
|
||||
{
|
||||
bool FcitxQtConnectionPrivate::isConnected() {
|
||||
return m_connection && m_connection->isConnected();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ class QDBusConnection;
|
|||
|
||||
class FcitxQtConnectionPrivate;
|
||||
|
||||
|
||||
/**
|
||||
* dbus connection to fcitx
|
||||
**/
|
||||
|
@ -36,7 +35,7 @@ class FCITX5QT5DBUSADDONS_EXPORT FcitxQtConnection : public QObject {
|
|||
Q_OBJECT
|
||||
Q_PROPERTY(bool autoReconnect READ autoReconnect WRITE setAutoReconnect)
|
||||
Q_PROPERTY(bool connected READ isConnected)
|
||||
Q_PROPERTY(QDBusConnection* connection READ connection)
|
||||
Q_PROPERTY(QDBusConnection *connection READ connection)
|
||||
Q_PROPERTY(QString serviceName READ serviceName)
|
||||
public:
|
||||
/**
|
||||
|
@ -44,7 +43,7 @@ public:
|
|||
*
|
||||
* @param parent
|
||||
**/
|
||||
explicit FcitxQtConnection(QObject* parent = 0);
|
||||
explicit FcitxQtConnection(QObject *parent = 0);
|
||||
|
||||
/**
|
||||
* destroy the connection
|
||||
|
@ -79,13 +78,13 @@ public:
|
|||
*
|
||||
* @return QDBusConnection*
|
||||
**/
|
||||
QDBusConnection* connection();
|
||||
QDBusConnection *connection();
|
||||
/**
|
||||
* current fcitx dbus service name, can be used for create DBus proxy
|
||||
*
|
||||
* @return service name
|
||||
**/
|
||||
const QString& serviceName();
|
||||
const QString &serviceName();
|
||||
/**
|
||||
* check its connected or not
|
||||
**/
|
||||
|
@ -104,7 +103,7 @@ Q_SIGNALS:
|
|||
void disconnected();
|
||||
|
||||
private:
|
||||
FcitxQtConnectionPrivate * const d_ptr;
|
||||
FcitxQtConnectionPrivate *const d_ptr;
|
||||
Q_DECLARE_PRIVATE(FcitxQtConnection);
|
||||
};
|
||||
|
||||
|
|
|
@ -28,13 +28,14 @@ class QDBusServiceWatcher;
|
|||
class FcitxQtConnectionPrivate : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FcitxQtConnectionPrivate(FcitxQtConnection* conn);
|
||||
FcitxQtConnectionPrivate(FcitxQtConnection *conn);
|
||||
virtual ~FcitxQtConnectionPrivate();
|
||||
FcitxQtConnection * const q_ptr;
|
||||
FcitxQtConnection *const q_ptr;
|
||||
Q_DECLARE_PUBLIC(FcitxQtConnection);
|
||||
|
||||
private Q_SLOTS:
|
||||
void imChanged(const QString& service, const QString& oldowner, const QString& newowner);
|
||||
void imChanged(const QString &service, const QString &oldowner,
|
||||
const QString &newowner);
|
||||
void dbusDisconnected();
|
||||
void cleanUp();
|
||||
void newServiceAppear();
|
||||
|
@ -46,13 +47,12 @@ private:
|
|||
void finalize();
|
||||
|
||||
QString m_serviceName;
|
||||
QDBusConnection* m_connection;
|
||||
QDBusServiceWatcher* m_serviceWatcher;
|
||||
QDBusConnection *m_connection;
|
||||
QDBusServiceWatcher *m_serviceWatcher;
|
||||
QString m_socketFile;
|
||||
bool m_autoReconnect;
|
||||
bool m_connectedOnce;
|
||||
bool m_initialized;
|
||||
};
|
||||
|
||||
|
||||
#endif // FCITXCONNECTION_P_H
|
||||
|
|
|
@ -21,42 +21,30 @@
|
|||
|
||||
#include "fcitxqtdbustypes.h"
|
||||
|
||||
void FcitxQtFormattedPreedit::registerMetaType()
|
||||
{
|
||||
void FcitxQtFormattedPreedit::registerMetaType() {
|
||||
qRegisterMetaType<FcitxQtFormattedPreedit>("FcitxQtFormattedPreedit");
|
||||
qDBusRegisterMetaType<FcitxQtFormattedPreedit>();
|
||||
qRegisterMetaType<FcitxQtFormattedPreeditList>("FcitxQtFormattedPreeditList");
|
||||
qRegisterMetaType<FcitxQtFormattedPreeditList>(
|
||||
"FcitxQtFormattedPreeditList");
|
||||
qDBusRegisterMetaType<FcitxQtFormattedPreeditList>();
|
||||
}
|
||||
|
||||
qint32 FcitxQtFormattedPreedit::format() const
|
||||
{
|
||||
return m_format;
|
||||
}
|
||||
qint32 FcitxQtFormattedPreedit::format() const { return m_format; }
|
||||
|
||||
const QString& FcitxQtFormattedPreedit::string() const
|
||||
{
|
||||
return m_string;
|
||||
}
|
||||
const QString &FcitxQtFormattedPreedit::string() const { return m_string; }
|
||||
|
||||
void FcitxQtFormattedPreedit::setFormat(qint32 format)
|
||||
{
|
||||
m_format = format;
|
||||
}
|
||||
void FcitxQtFormattedPreedit::setFormat(qint32 format) { m_format = format; }
|
||||
|
||||
void FcitxQtFormattedPreedit::setString(const QString& str)
|
||||
{
|
||||
m_string = str;
|
||||
}
|
||||
void FcitxQtFormattedPreedit::setString(const QString &str) { m_string = str; }
|
||||
|
||||
bool FcitxQtFormattedPreedit::operator==(const FcitxQtFormattedPreedit& preedit) const
|
||||
{
|
||||
bool FcitxQtFormattedPreedit::
|
||||
operator==(const FcitxQtFormattedPreedit &preedit) const {
|
||||
return (preedit.m_format == m_format) && (preedit.m_string == m_string);
|
||||
}
|
||||
|
||||
FCITX5QT5DBUSADDONS_EXPORT
|
||||
QDBusArgument& operator<<(QDBusArgument& argument, const FcitxQtFormattedPreedit& preedit)
|
||||
{
|
||||
QDBusArgument &operator<<(QDBusArgument &argument,
|
||||
const FcitxQtFormattedPreedit &preedit) {
|
||||
argument.beginStructure();
|
||||
argument << preedit.string();
|
||||
argument << preedit.format();
|
||||
|
@ -65,8 +53,8 @@ QDBusArgument& operator<<(QDBusArgument& argument, const FcitxQtFormattedPreedit
|
|||
}
|
||||
|
||||
FCITX5QT5DBUSADDONS_EXPORT
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, FcitxQtFormattedPreedit& preedit)
|
||||
{
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument,
|
||||
FcitxQtFormattedPreedit &preedit) {
|
||||
QString str;
|
||||
qint32 format;
|
||||
argument.beginStructure();
|
||||
|
@ -78,37 +66,29 @@ const QDBusArgument& operator>>(const QDBusArgument& argument, FcitxQtFormattedP
|
|||
}
|
||||
|
||||
void FcitxQtInputContextArgument::registerMetaType() {
|
||||
qRegisterMetaType<FcitxQtInputContextArgument>("FcitxQtInputContextArgument");
|
||||
qRegisterMetaType<FcitxQtInputContextArgument>(
|
||||
"FcitxQtInputContextArgument");
|
||||
qDBusRegisterMetaType<FcitxQtInputContextArgument>();
|
||||
qRegisterMetaType<FcitxQtInputContextArgumentList>("FcitxQtInputContextArgumentList");
|
||||
qRegisterMetaType<FcitxQtInputContextArgumentList>(
|
||||
"FcitxQtInputContextArgumentList");
|
||||
qDBusRegisterMetaType<FcitxQtInputContextArgumentList>();
|
||||
}
|
||||
|
||||
const QString & FcitxQtInputContextArgument::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
const QString &FcitxQtInputContextArgument::name() const { return m_name; }
|
||||
|
||||
void FcitxQtInputContextArgument::setName(const QString& name)
|
||||
{
|
||||
void FcitxQtInputContextArgument::setName(const QString &name) {
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
const QString & FcitxQtInputContextArgument::value() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
const QString &FcitxQtInputContextArgument::value() const { return m_value; }
|
||||
|
||||
|
||||
void FcitxQtInputContextArgument::setValue(const QString& value)
|
||||
{
|
||||
void FcitxQtInputContextArgument::setValue(const QString &value) {
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
|
||||
FCITX5QT5DBUSADDONS_EXPORT
|
||||
QDBusArgument& operator<<(QDBusArgument& argument, const FcitxQtInputContextArgument& arg)
|
||||
{
|
||||
QDBusArgument &operator<<(QDBusArgument &argument,
|
||||
const FcitxQtInputContextArgument &arg) {
|
||||
argument.beginStructure();
|
||||
argument << arg.name();
|
||||
argument << arg.value();
|
||||
|
@ -117,8 +97,8 @@ QDBusArgument& operator<<(QDBusArgument& argument, const FcitxQtInputContextArgu
|
|||
}
|
||||
|
||||
FCITX5QT5DBUSADDONS_EXPORT
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, FcitxQtInputContextArgument& arg)
|
||||
{
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument,
|
||||
FcitxQtInputContextArgument &arg) {
|
||||
QString name, value;
|
||||
argument.beginStructure();
|
||||
argument >> name >> value;
|
||||
|
|
|
@ -21,20 +21,21 @@
|
|||
|
||||
#include "fcitx5qt5dbusaddons_export.h"
|
||||
|
||||
#include <QDBusArgument>
|
||||
#include <QList>
|
||||
#include <QMetaType>
|
||||
#include <QDBusArgument>
|
||||
|
||||
class FCITX5QT5DBUSADDONS_EXPORT FcitxQtFormattedPreedit {
|
||||
public:
|
||||
const QString& string() const;
|
||||
const QString &string() const;
|
||||
qint32 format() const;
|
||||
void setString(const QString& str);
|
||||
void setString(const QString &str);
|
||||
void setFormat(qint32 format);
|
||||
|
||||
static void registerMetaType();
|
||||
|
||||
bool operator ==(const FcitxQtFormattedPreedit& preedit) const;
|
||||
bool operator==(const FcitxQtFormattedPreedit &preedit) const;
|
||||
|
||||
private:
|
||||
QString m_string;
|
||||
qint32 m_format;
|
||||
|
@ -42,8 +43,10 @@ private:
|
|||
|
||||
typedef QList<FcitxQtFormattedPreedit> FcitxQtFormattedPreeditList;
|
||||
|
||||
QDBusArgument& operator<<(QDBusArgument& argument, const FcitxQtFormattedPreedit& im);
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, FcitxQtFormattedPreedit& im);
|
||||
QDBusArgument &operator<<(QDBusArgument &argument,
|
||||
const FcitxQtFormattedPreedit &im);
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument,
|
||||
FcitxQtFormattedPreedit &im);
|
||||
|
||||
Q_DECLARE_METATYPE(FcitxQtFormattedPreedit)
|
||||
Q_DECLARE_METATYPE(FcitxQtFormattedPreeditList)
|
||||
|
@ -51,14 +54,15 @@ Q_DECLARE_METATYPE(FcitxQtFormattedPreeditList)
|
|||
class FCITX5QT5DBUSADDONS_EXPORT FcitxQtInputContextArgument {
|
||||
public:
|
||||
FcitxQtInputContextArgument() {}
|
||||
FcitxQtInputContextArgument(const QString &name, const QString &value) : m_name(name), m_value(value) { }
|
||||
FcitxQtInputContextArgument(const QString &name, const QString &value)
|
||||
: m_name(name), m_value(value) {}
|
||||
|
||||
static void registerMetaType();
|
||||
|
||||
const QString& name() const;
|
||||
const QString& value() const;
|
||||
void setName(const QString&);
|
||||
void setValue(const QString& );
|
||||
const QString &name() const;
|
||||
const QString &value() const;
|
||||
void setName(const QString &);
|
||||
void setValue(const QString &);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
|
@ -67,8 +71,10 @@ private:
|
|||
|
||||
typedef QList<FcitxQtInputContextArgument> FcitxQtInputContextArgumentList;
|
||||
|
||||
QDBusArgument& operator<<(QDBusArgument& argument, const FcitxQtInputContextArgument& im);
|
||||
const QDBusArgument& operator>>(const QDBusArgument& argument, FcitxQtInputContextArgument& im);
|
||||
QDBusArgument &operator<<(QDBusArgument &argument,
|
||||
const FcitxQtInputContextArgument &im);
|
||||
const QDBusArgument &operator>>(const QDBusArgument &argument,
|
||||
FcitxQtInputContextArgument &im);
|
||||
Q_DECLARE_METATYPE(FcitxQtInputContextArgument)
|
||||
Q_DECLARE_METATYPE(FcitxQtInputContextArgumentList)
|
||||
|
||||
|
|
|
@ -19,11 +19,10 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <libintl.h>
|
||||
#include "wrapperapp.h"
|
||||
#include <libintl.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
|
||||
WrapperApp app(argc, argv);
|
||||
return app.exec();
|
||||
|
|
|
@ -19,23 +19,21 @@
|
|||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <libintl.h>
|
||||
#include <QPushButton>
|
||||
#include <QLocale>
|
||||
#include <QDebug>
|
||||
#include <QLocale>
|
||||
#include <QPushButton>
|
||||
#include <libintl.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "mainwindow.h"
|
||||
#include "fcitxqtconfiguifactory.h"
|
||||
#include "fcitxqtconnection.h"
|
||||
#include "fcitxqtinputmethodproxy.h"
|
||||
#include "fcitxqtconfiguifactory.h"
|
||||
#include "mainwindow.h"
|
||||
|
||||
MainWindow::MainWindow(FcitxQtConfigUIWidget* pluginWidget, QWidget* parent): QMainWindow(parent)
|
||||
,m_ui(new Ui::MainWindow)
|
||||
,m_connection(new FcitxQtConnection(this))
|
||||
,m_pluginWidget(pluginWidget)
|
||||
,m_proxy(0)
|
||||
{
|
||||
MainWindow::MainWindow(FcitxQtConfigUIWidget *pluginWidget, QWidget *parent)
|
||||
: QMainWindow(parent), m_ui(new Ui::MainWindow),
|
||||
m_connection(new FcitxQtConnection(this)), m_pluginWidget(pluginWidget),
|
||||
m_proxy(0) {
|
||||
m_ui->setupUi(this);
|
||||
m_ui->verticalLayout->insertWidget(0, m_pluginWidget);
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Save)->setText(_("&Save"));
|
||||
|
@ -48,24 +46,27 @@ MainWindow::MainWindow(FcitxQtConfigUIWidget* pluginWidget, QWidget* parent): QM
|
|||
|
||||
connect(m_pluginWidget, SIGNAL(changed(bool)), this, SLOT(changed(bool)));
|
||||
if (m_pluginWidget->asyncSave())
|
||||
connect(m_pluginWidget, SIGNAL(saveFinished()), this, SLOT(saveFinished()));
|
||||
connect(m_ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*)));
|
||||
connect(m_pluginWidget, SIGNAL(saveFinished()), this,
|
||||
SLOT(saveFinished()));
|
||||
connect(m_ui->buttonBox, SIGNAL(clicked(QAbstractButton *)), this,
|
||||
SLOT(clicked(QAbstractButton *)));
|
||||
connect(m_connection, SIGNAL(connected()), this, SLOT(connected()));
|
||||
|
||||
m_connection->startConnection();
|
||||
}
|
||||
|
||||
void MainWindow::connected()
|
||||
{
|
||||
void MainWindow::connected() {
|
||||
if (m_proxy) {
|
||||
delete m_proxy;
|
||||
}
|
||||
m_proxy = new FcitxQtInputMethodProxy(m_connection->serviceName(), QLatin1String("/inputmethod"), *m_connection->connection(), this);
|
||||
m_proxy = new FcitxQtInputMethodProxy(m_connection->serviceName(),
|
||||
QLatin1String("/inputmethod"),
|
||||
*m_connection->connection(), this);
|
||||
}
|
||||
|
||||
void MainWindow::clicked(QAbstractButton* button)
|
||||
{
|
||||
QDialogButtonBox::StandardButton standardButton = m_ui->buttonBox->standardButton(button);
|
||||
void MainWindow::clicked(QAbstractButton *button) {
|
||||
QDialogButtonBox::StandardButton standardButton =
|
||||
m_ui->buttonBox->standardButton(button);
|
||||
if (standardButton == QDialogButtonBox::Save) {
|
||||
if (m_pluginWidget->asyncSave())
|
||||
m_pluginWidget->setEnabled(false);
|
||||
|
@ -74,14 +75,12 @@ void MainWindow::clicked(QAbstractButton* button)
|
|||
saveFinished();
|
||||
} else if (standardButton == QDialogButtonBox::Close) {
|
||||
qApp->quit();
|
||||
}
|
||||
else if (standardButton == QDialogButtonBox::Reset) {
|
||||
} else if (standardButton == QDialogButtonBox::Reset) {
|
||||
m_pluginWidget->load();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveFinished()
|
||||
{
|
||||
void MainWindow::saveFinished() {
|
||||
if (m_pluginWidget->asyncSave())
|
||||
m_pluginWidget->setEnabled(true);
|
||||
if (m_proxy) {
|
||||
|
@ -89,13 +88,9 @@ void MainWindow::saveFinished()
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::changed(bool changed)
|
||||
{
|
||||
void MainWindow::changed(bool changed) {
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(changed);
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(changed);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
MainWindow::~MainWindow() { delete m_ui; }
|
||||
|
|
|
@ -24,27 +24,28 @@
|
|||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "ui_mainwindow.h"
|
||||
#include "fcitxqtconfiguiwidget.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
class FcitxQtInputMethodProxy;
|
||||
class FcitxQtConnection;
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(FcitxQtConfigUIWidget* pluginWidget, QWidget* parent = 0);
|
||||
explicit MainWindow(FcitxQtConfigUIWidget *pluginWidget,
|
||||
QWidget *parent = 0);
|
||||
virtual ~MainWindow();
|
||||
public slots:
|
||||
void changed(bool changed);
|
||||
void clicked(QAbstractButton* button);
|
||||
void clicked(QAbstractButton *button);
|
||||
void connected();
|
||||
void saveFinished();
|
||||
|
||||
private:
|
||||
Ui::MainWindow* m_ui;
|
||||
FcitxQtConnection* m_connection;
|
||||
FcitxQtConfigUIWidget* m_pluginWidget;
|
||||
FcitxQtInputMethodProxy* m_proxy;
|
||||
Ui::MainWindow *m_ui;
|
||||
FcitxQtConnection *m_connection;
|
||||
FcitxQtConfigUIWidget *m_pluginWidget;
|
||||
FcitxQtInputMethodProxy *m_proxy;
|
||||
};
|
||||
|
||||
#endif // FCITXQT5_GUIWRAPPER_MAINWINDOW_H
|
||||
|
|
|
@ -24,23 +24,22 @@
|
|||
|
||||
#include <QDebug>
|
||||
|
||||
#include "wrapperapp.h"
|
||||
#include "mainwindow.h"
|
||||
#include "fcitxqtconfiguifactory.h"
|
||||
#include "fcitxqtconnection.h"
|
||||
#include "mainwindow.h"
|
||||
#include "wrapperapp.h"
|
||||
#include <fcitx-utils/standardpath.h>
|
||||
|
||||
WrapperApp::WrapperApp(int& argc, char** argv): QApplication(argc, argv)
|
||||
,m_factory(new FcitxQtConfigUIFactory(this))
|
||||
,m_mainWindow(0)
|
||||
{
|
||||
WrapperApp::WrapperApp(int &argc, char **argv)
|
||||
: QApplication(argc, argv), m_factory(new FcitxQtConfigUIFactory(this)),
|
||||
m_mainWindow(0) {
|
||||
auto localedir = fcitx::StandardPath::fcitxPath("localedir");
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain("fcitx", localedir.c_str());
|
||||
bind_textdomain_codeset("fcitx", "UTF-8");
|
||||
textdomain("fcitx");
|
||||
|
||||
FcitxQtConfigUIWidget* widget = 0;
|
||||
FcitxQtConfigUIWidget *widget = 0;
|
||||
|
||||
if (argc == 3 && strcmp(argv[1], "--test") == 0) {
|
||||
if (m_factory->test(QString::fromLocal8Bit(argv[2]))) {
|
||||
|
@ -62,15 +61,10 @@ WrapperApp::WrapperApp(int& argc, char** argv): QApplication(argc, argv)
|
|||
}
|
||||
}
|
||||
|
||||
WrapperApp::~WrapperApp()
|
||||
{
|
||||
WrapperApp::~WrapperApp() {
|
||||
if (m_mainWindow) {
|
||||
delete m_mainWindow;
|
||||
}
|
||||
}
|
||||
|
||||
void WrapperApp::errorExit()
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void WrapperApp::errorExit() { exit(1); }
|
||||
|
|
|
@ -22,21 +22,22 @@
|
|||
#ifndef FCITXQT5_GUIWRAPPER_WRAPPERAPP_H
|
||||
#define FCITXQT5_GUIWRAPPER_WRAPPERAPP_H
|
||||
|
||||
#include <QApplication>
|
||||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
|
||||
class FcitxQtConfigUIFactory;
|
||||
class WrapperApp : public QApplication {
|
||||
Q_OBJECT
|
||||
public:
|
||||
WrapperApp(int& argc, char** argv);
|
||||
WrapperApp(int &argc, char **argv);
|
||||
virtual ~WrapperApp();
|
||||
|
||||
private slots:
|
||||
void errorExit();
|
||||
|
||||
private:
|
||||
FcitxQtConfigUIFactory* m_factory;
|
||||
MainWindow* m_mainWindow;
|
||||
FcitxQtConfigUIFactory *m_factory;
|
||||
MainWindow *m_mainWindow;
|
||||
};
|
||||
|
||||
#endif // FCITXQT5_GUIWRAPPER_WRAPPERAPP_H
|
||||
|
|
|
@ -31,120 +31,119 @@ struct TransKey {
|
|||
};
|
||||
|
||||
static const TransKey g_rgQtToSymX[] = {
|
||||
{ Qt::Key_Escape, XK_Escape },
|
||||
{ Qt::Key_Tab, XK_Tab },
|
||||
{ Qt::Key_Backtab, XK_ISO_Left_Tab },
|
||||
{ Qt::Key_Backspace, XK_BackSpace },
|
||||
{ Qt::Key_Return, XK_Return },
|
||||
{ Qt::Key_Enter, XK_KP_Enter },
|
||||
{ Qt::Key_Insert, XK_Insert },
|
||||
{ Qt::Key_Delete, XK_Delete },
|
||||
{ Qt::Key_Pause, XK_Pause },
|
||||
{Qt::Key_Escape, XK_Escape},
|
||||
{Qt::Key_Tab, XK_Tab},
|
||||
{Qt::Key_Backtab, XK_ISO_Left_Tab},
|
||||
{Qt::Key_Backspace, XK_BackSpace},
|
||||
{Qt::Key_Return, XK_Return},
|
||||
{Qt::Key_Enter, XK_KP_Enter},
|
||||
{Qt::Key_Insert, XK_Insert},
|
||||
{Qt::Key_Delete, XK_Delete},
|
||||
{Qt::Key_Pause, XK_Pause},
|
||||
#ifdef sun
|
||||
{ Qt::Key_Print, XK_F22 },
|
||||
{Qt::Key_Print, XK_F22},
|
||||
#else
|
||||
{ Qt::Key_Print, XK_Print },
|
||||
{Qt::Key_Print, XK_Print},
|
||||
#endif
|
||||
{ Qt::Key_SysReq, XK_Sys_Req },
|
||||
{ Qt::Key_Home, XK_Home },
|
||||
{ Qt::Key_End, XK_End },
|
||||
{ Qt::Key_Left, XK_Left },
|
||||
{ Qt::Key_Up, XK_Up },
|
||||
{ Qt::Key_Right, XK_Right },
|
||||
{ Qt::Key_Down, XK_Down },
|
||||
{Qt::Key_SysReq, XK_Sys_Req},
|
||||
{Qt::Key_Home, XK_Home},
|
||||
{Qt::Key_End, XK_End},
|
||||
{Qt::Key_Left, XK_Left},
|
||||
{Qt::Key_Up, XK_Up},
|
||||
{Qt::Key_Right, XK_Right},
|
||||
{Qt::Key_Down, XK_Down},
|
||||
//{ Qt::Key_Shift, 0 },
|
||||
//{ Qt::Key_Control, 0 },
|
||||
//{ Qt::Key_Meta, 0 },
|
||||
//{ Qt::Key_Alt, 0 },
|
||||
{ Qt::Key_CapsLock, XK_Caps_Lock },
|
||||
{ Qt::Key_NumLock, XK_Num_Lock },
|
||||
{ Qt::Key_ScrollLock, XK_Scroll_Lock },
|
||||
{ Qt::Key_F1, XK_F1 },
|
||||
{ Qt::Key_F2, XK_F2 },
|
||||
{ Qt::Key_F3, XK_F3 },
|
||||
{ Qt::Key_F4, XK_F4 },
|
||||
{ Qt::Key_F5, XK_F5 },
|
||||
{ Qt::Key_F6, XK_F6 },
|
||||
{ Qt::Key_F7, XK_F7 },
|
||||
{ Qt::Key_F8, XK_F8 },
|
||||
{ Qt::Key_F9, XK_F9 },
|
||||
{ Qt::Key_F10, XK_F10 },
|
||||
{ Qt::Key_F11, XK_F11 },
|
||||
{ Qt::Key_F12, XK_F12 },
|
||||
{ Qt::Key_F13, XK_F13 },
|
||||
{ Qt::Key_F14, XK_F14 },
|
||||
{ Qt::Key_F15, XK_F15 },
|
||||
{ Qt::Key_F16, XK_F16 },
|
||||
{ Qt::Key_F17, XK_F17 },
|
||||
{ Qt::Key_F18, XK_F18 },
|
||||
{ Qt::Key_F19, XK_F19 },
|
||||
{ Qt::Key_F20, XK_F20 },
|
||||
{ Qt::Key_F21, XK_F21 },
|
||||
{ Qt::Key_F22, XK_F22 },
|
||||
{ Qt::Key_F23, XK_F23 },
|
||||
{ Qt::Key_F24, XK_F24 },
|
||||
{ Qt::Key_F25, XK_F25 },
|
||||
{ Qt::Key_F26, XK_F26 },
|
||||
{ Qt::Key_F27, XK_F27 },
|
||||
{ Qt::Key_F28, XK_F28 },
|
||||
{ Qt::Key_F29, XK_F29 },
|
||||
{ Qt::Key_F30, XK_F30 },
|
||||
{ Qt::Key_F31, XK_F31 },
|
||||
{ Qt::Key_F32, XK_F32 },
|
||||
{ Qt::Key_F33, XK_F33 },
|
||||
{ Qt::Key_F34, XK_F34 },
|
||||
{ Qt::Key_F35, XK_F35 },
|
||||
{ Qt::Key_Super_L, XK_Super_L },
|
||||
{ Qt::Key_Super_R, XK_Super_R },
|
||||
{ Qt::Key_Menu, XK_Menu },
|
||||
{ Qt::Key_Hyper_L, XK_Hyper_L },
|
||||
{ Qt::Key_Hyper_R, XK_Hyper_R },
|
||||
{ Qt::Key_Help, XK_Help },
|
||||
{Qt::Key_CapsLock, XK_Caps_Lock},
|
||||
{Qt::Key_NumLock, XK_Num_Lock},
|
||||
{Qt::Key_ScrollLock, XK_Scroll_Lock},
|
||||
{Qt::Key_F1, XK_F1},
|
||||
{Qt::Key_F2, XK_F2},
|
||||
{Qt::Key_F3, XK_F3},
|
||||
{Qt::Key_F4, XK_F4},
|
||||
{Qt::Key_F5, XK_F5},
|
||||
{Qt::Key_F6, XK_F6},
|
||||
{Qt::Key_F7, XK_F7},
|
||||
{Qt::Key_F8, XK_F8},
|
||||
{Qt::Key_F9, XK_F9},
|
||||
{Qt::Key_F10, XK_F10},
|
||||
{Qt::Key_F11, XK_F11},
|
||||
{Qt::Key_F12, XK_F12},
|
||||
{Qt::Key_F13, XK_F13},
|
||||
{Qt::Key_F14, XK_F14},
|
||||
{Qt::Key_F15, XK_F15},
|
||||
{Qt::Key_F16, XK_F16},
|
||||
{Qt::Key_F17, XK_F17},
|
||||
{Qt::Key_F18, XK_F18},
|
||||
{Qt::Key_F19, XK_F19},
|
||||
{Qt::Key_F20, XK_F20},
|
||||
{Qt::Key_F21, XK_F21},
|
||||
{Qt::Key_F22, XK_F22},
|
||||
{Qt::Key_F23, XK_F23},
|
||||
{Qt::Key_F24, XK_F24},
|
||||
{Qt::Key_F25, XK_F25},
|
||||
{Qt::Key_F26, XK_F26},
|
||||
{Qt::Key_F27, XK_F27},
|
||||
{Qt::Key_F28, XK_F28},
|
||||
{Qt::Key_F29, XK_F29},
|
||||
{Qt::Key_F30, XK_F30},
|
||||
{Qt::Key_F31, XK_F31},
|
||||
{Qt::Key_F32, XK_F32},
|
||||
{Qt::Key_F33, XK_F33},
|
||||
{Qt::Key_F34, XK_F34},
|
||||
{Qt::Key_F35, XK_F35},
|
||||
{Qt::Key_Super_L, XK_Super_L},
|
||||
{Qt::Key_Super_R, XK_Super_R},
|
||||
{Qt::Key_Menu, XK_Menu},
|
||||
{Qt::Key_Hyper_L, XK_Hyper_L},
|
||||
{Qt::Key_Hyper_R, XK_Hyper_R},
|
||||
{Qt::Key_Help, XK_Help},
|
||||
|
||||
{ '/', XK_KP_Divide },
|
||||
{ '*', XK_KP_Multiply },
|
||||
{ '-', XK_KP_Subtract },
|
||||
{ '+', XK_KP_Add },
|
||||
{ Qt::Key_Return, XK_KP_Enter },
|
||||
{'/', XK_KP_Divide},
|
||||
{'*', XK_KP_Multiply},
|
||||
{'-', XK_KP_Subtract},
|
||||
{'+', XK_KP_Add},
|
||||
{Qt::Key_Return, XK_KP_Enter},
|
||||
{Qt::Key_Multi_key, XK_Multi_key},
|
||||
{Qt::Key_Codeinput, XK_Codeinput},
|
||||
{Qt::Key_SingleCandidate, XK_SingleCandidate},
|
||||
{Qt::Key_SingleCandidate, XK_SingleCandidate},
|
||||
{Qt::Key_MultipleCandidate, XK_MultipleCandidate},
|
||||
{Qt::Key_PreviousCandidate, XK_PreviousCandidate},
|
||||
{Qt::Key_Mode_switch, XK_Mode_switch},
|
||||
{Qt::Key_Mode_switch, XK_Mode_switch},
|
||||
{Qt::Key_Kanji, XK_Kanji},
|
||||
{Qt::Key_Muhenkan, XK_Muhenkan},
|
||||
{Qt::Key_Henkan, XK_Henkan},
|
||||
{Qt::Key_Romaji, XK_Romaji},
|
||||
{Qt::Key_Hiragana, XK_Hiragana},
|
||||
{Qt::Key_Katakana, XK_Katakana},
|
||||
{Qt::Key_Muhenkan, XK_Muhenkan},
|
||||
{Qt::Key_Henkan, XK_Henkan},
|
||||
{Qt::Key_Romaji, XK_Romaji},
|
||||
{Qt::Key_Hiragana, XK_Hiragana},
|
||||
{Qt::Key_Katakana, XK_Katakana},
|
||||
{Qt::Key_Hiragana_Katakana, XK_Hiragana_Katakana},
|
||||
{Qt::Key_Zenkaku, XK_Zenkaku},
|
||||
{Qt::Key_Hankaku, XK_Hankaku},
|
||||
{Qt::Key_Zenkaku_Hankaku, XK_Zenkaku_Hankaku},
|
||||
{Qt::Key_Touroku, XK_Touroku},
|
||||
{Qt::Key_Massyo, XK_Massyo},
|
||||
{Qt::Key_Zenkaku, XK_Zenkaku},
|
||||
{Qt::Key_Hankaku, XK_Hankaku},
|
||||
{Qt::Key_Zenkaku_Hankaku, XK_Zenkaku_Hankaku},
|
||||
{Qt::Key_Touroku, XK_Touroku},
|
||||
{Qt::Key_Massyo, XK_Massyo},
|
||||
{Qt::Key_Kana_Lock, XK_Kana_Lock},
|
||||
{Qt::Key_Kana_Shift, XK_Kana_Shift},
|
||||
{Qt::Key_Eisu_Shift, XK_Eisu_Shift},
|
||||
{Qt::Key_Eisu_toggle, XK_Eisu_toggle},
|
||||
{Qt::Key_Hangul, XK_Hangul},
|
||||
{Qt::Key_Hangul_Start, XK_Hangul_Start},
|
||||
{Qt::Key_Hangul_End, XK_Hangul_End},
|
||||
{Qt::Key_Hangul_Hanja, XK_Hangul_Hanja},
|
||||
{Qt::Key_Hangul_Jamo, XK_Hangul_Jamo},
|
||||
{Qt::Key_Kana_Shift, XK_Kana_Shift},
|
||||
{Qt::Key_Eisu_Shift, XK_Eisu_Shift},
|
||||
{Qt::Key_Eisu_toggle, XK_Eisu_toggle},
|
||||
{Qt::Key_Hangul, XK_Hangul},
|
||||
{Qt::Key_Hangul_Start, XK_Hangul_Start},
|
||||
{Qt::Key_Hangul_End, XK_Hangul_End},
|
||||
{Qt::Key_Hangul_Hanja, XK_Hangul_Hanja},
|
||||
{Qt::Key_Hangul_Jamo, XK_Hangul_Jamo},
|
||||
{Qt::Key_Hangul_Romaja, XK_Hangul_Romaja},
|
||||
{Qt::Key_Hangul_Jeonja, XK_Hangul_Jeonja},
|
||||
{Qt::Key_Hangul_Banja, XK_Hangul_Banja},
|
||||
{Qt::Key_Hangul_PreHanja, XK_Hangul_PreHanja},
|
||||
{Qt::Key_Hangul_PostHanja, XK_Hangul_PostHanja},
|
||||
{Qt::Key_Hangul_Special, XK_Hangul_Special},
|
||||
{Qt::Key_Hangul_Banja, XK_Hangul_Banja},
|
||||
{Qt::Key_Hangul_PreHanja, XK_Hangul_PreHanja},
|
||||
{Qt::Key_Hangul_PostHanja, XK_Hangul_PostHanja},
|
||||
{Qt::Key_Hangul_Special, XK_Hangul_Special},
|
||||
};
|
||||
|
||||
#include <qstring.h>
|
||||
|
||||
inline int map_sym_to_qt(uint keySym)
|
||||
{
|
||||
inline int map_sym_to_qt(uint keySym) {
|
||||
if (keySym < 0x1000) {
|
||||
if (keySym >= 'a' && keySym <= 'z')
|
||||
return QChar(keySym).toUpper().unicode();
|
||||
|
@ -164,8 +163,7 @@ inline int map_sym_to_qt(uint keySym)
|
|||
return Qt::Key_unknown;
|
||||
}
|
||||
|
||||
static bool symToKeyQt(uint keySym, int& keyQt)
|
||||
{
|
||||
static bool symToKeyQt(uint keySym, int &keyQt) {
|
||||
keyQt = map_sym_to_qt(keySym);
|
||||
return (keyQt != Qt::Key_unknown);
|
||||
}
|
||||
|
|
|
@ -19,17 +19,16 @@
|
|||
|
||||
#include "main.h"
|
||||
|
||||
|
||||
QStringList QFcitxPlatformInputContextPlugin::keys() const
|
||||
{
|
||||
QStringList QFcitxPlatformInputContextPlugin::keys() const {
|
||||
return QStringList(QStringLiteral("fcitx5"));
|
||||
|
||||
}
|
||||
|
||||
QFcitxPlatformInputContext *QFcitxPlatformInputContextPlugin::create(const QString& system, const QStringList& paramList)
|
||||
{
|
||||
QFcitxPlatformInputContext *
|
||||
QFcitxPlatformInputContextPlugin::create(const QString &system,
|
||||
const QStringList ¶mList) {
|
||||
Q_UNUSED(paramList);
|
||||
if (system.compare(system, QStringLiteral("fcitx5"), Qt::CaseInsensitive) == 0)
|
||||
if (system.compare(system, QStringLiteral("fcitx5"), Qt::CaseInsensitive) ==
|
||||
0)
|
||||
return new QFcitxPlatformInputContext;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -20,18 +20,19 @@
|
|||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
#include <qpa/qplatforminputcontextplugin_p.h>
|
||||
#include <QStringList>
|
||||
#include <qpa/qplatforminputcontextplugin_p.h>
|
||||
|
||||
#include "qfcitxplatforminputcontext.h"
|
||||
|
||||
class QFcitxPlatformInputContextPlugin : public QPlatformInputContextPlugin
|
||||
{
|
||||
class QFcitxPlatformInputContextPlugin : public QPlatformInputContextPlugin {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Q_PLUGIN_METADATA(IID QPlatformInputContextFactoryInterface_iid FILE "fcitx.json")
|
||||
Q_PLUGIN_METADATA(IID QPlatformInputContextFactoryInterface_iid FILE
|
||||
"fcitx.json")
|
||||
QStringList keys() const;
|
||||
QFcitxPlatformInputContext *create(const QString& system, const QStringList& paramList);
|
||||
QFcitxPlatformInputContext *create(const QString &system,
|
||||
const QStringList ¶mList);
|
||||
};
|
||||
|
||||
#endif // MAIN_H
|
||||
|
|
|
@ -17,35 +17,35 @@
|
|||
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
***************************************************************************/
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QDBusConnection>
|
||||
#include <QGuiApplication>
|
||||
#include <QInputMethod>
|
||||
#include <QTextCharFormat>
|
||||
#include <QKeyEvent>
|
||||
#include <QPalette>
|
||||
#include <QTextCharFormat>
|
||||
#include <QWindow>
|
||||
#include <QX11Info>
|
||||
#include <qpa/qplatformscreen.h>
|
||||
#include <qpa/qplatformcursor.h>
|
||||
#include <qpa/qplatformscreen.h>
|
||||
#include <qpa/qwindowsysteminterface.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "keyserver_x11.h"
|
||||
|
||||
#include "qfcitxplatforminputcontext.h"
|
||||
#include "fcitxqtconnection.h"
|
||||
#include "fcitxqtinputcontextproxy.h"
|
||||
#include "fcitxqtinputmethodproxy.h"
|
||||
#include "fcitxqtconnection.h"
|
||||
#include "qfcitxplatforminputcontext.h"
|
||||
|
||||
#include <fcitx-utils/utf8.h>
|
||||
#include <fcitx-utils/key.h>
|
||||
#include <fcitx-utils/textformatflags.h>
|
||||
#include <fcitx-utils/utf8.h>
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
#include <memory>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
template <typename T>
|
||||
using XCBReply = std::unique_ptr<T, decltype(&std::free)>;
|
||||
|
@ -102,36 +102,28 @@ void setFocusGroupForX11(const QByteArray &uuid) {
|
|||
ev.format = 8;
|
||||
memcpy(ev.data.data8, uuid.constData(), 16);
|
||||
|
||||
xcb_send_event(connection, false, owner,
|
||||
XCB_EVENT_MASK_NO_EVENT, reinterpret_cast<char *>(&ev));
|
||||
xcb_send_event(connection, false, owner, XCB_EVENT_MASK_NO_EVENT,
|
||||
reinterpret_cast<char *>(&ev));
|
||||
}
|
||||
|
||||
|
||||
static bool key_filtered = false;
|
||||
|
||||
static bool
|
||||
get_boolean_env(const char *name,
|
||||
bool defval)
|
||||
{
|
||||
static bool get_boolean_env(const char *name, bool defval) {
|
||||
const char *value = getenv(name);
|
||||
|
||||
if (value == nullptr)
|
||||
return defval;
|
||||
|
||||
if (strcmp(value, "") == 0 ||
|
||||
strcmp(value, "0") == 0 ||
|
||||
strcmp(value, "false") == 0 ||
|
||||
strcmp(value, "False") == 0 ||
|
||||
if (strcmp(value, "") == 0 || strcmp(value, "0") == 0 ||
|
||||
strcmp(value, "false") == 0 || strcmp(value, "False") == 0 ||
|
||||
strcmp(value, "FALSE") == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline const char*
|
||||
get_locale()
|
||||
{
|
||||
const char* locale = getenv("LC_ALL");
|
||||
static inline const char *get_locale() {
|
||||
const char *locale = getenv("LC_ALL");
|
||||
if (!locale)
|
||||
locale = getenv("LC_CTYPE");
|
||||
if (!locale)
|
||||
|
@ -142,9 +134,8 @@ get_locale()
|
|||
return locale;
|
||||
}
|
||||
|
||||
struct xkb_context* _xkb_context_new_helper()
|
||||
{
|
||||
struct xkb_context* context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
struct xkb_context *_xkb_context_new_helper() {
|
||||
struct xkb_context *context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
if (context) {
|
||||
xkb_context_set_log_level(context, XKB_LOG_LEVEL_CRITICAL);
|
||||
}
|
||||
|
@ -152,34 +143,36 @@ struct xkb_context* _xkb_context_new_helper()
|
|||
return context;
|
||||
}
|
||||
|
||||
QFcitxPlatformInputContext::QFcitxPlatformInputContext() :
|
||||
m_connection(new FcitxQtConnection(this)),
|
||||
m_improxy(nullptr),
|
||||
m_cursorPos(0),
|
||||
m_useSurroundingText(false),
|
||||
m_syncMode(get_boolean_env("FCITX_QT_USE_SYNC", false)),
|
||||
m_destroy(false),
|
||||
m_xkbContext(_xkb_context_new_helper()),
|
||||
m_xkbComposeTable(m_xkbContext ? xkb_compose_table_new_from_locale(m_xkbContext.data(), get_locale(), XKB_COMPOSE_COMPILE_NO_FLAGS) : 0),
|
||||
m_xkbComposeState(m_xkbComposeTable ? xkb_compose_state_new(m_xkbComposeTable.data(), XKB_COMPOSE_STATE_NO_FLAGS) : 0)
|
||||
{
|
||||
QFcitxPlatformInputContext::QFcitxPlatformInputContext()
|
||||
: m_connection(new FcitxQtConnection(this)), m_improxy(nullptr),
|
||||
m_cursorPos(0), m_useSurroundingText(false),
|
||||
m_syncMode(get_boolean_env("FCITX_QT_USE_SYNC", false)), m_destroy(false),
|
||||
m_xkbContext(_xkb_context_new_helper()),
|
||||
m_xkbComposeTable(m_xkbContext ? xkb_compose_table_new_from_locale(
|
||||
m_xkbContext.data(), get_locale(),
|
||||
XKB_COMPOSE_COMPILE_NO_FLAGS)
|
||||
: 0),
|
||||
m_xkbComposeState(m_xkbComposeTable
|
||||
? xkb_compose_state_new(m_xkbComposeTable.data(),
|
||||
XKB_COMPOSE_STATE_NO_FLAGS)
|
||||
: 0) {
|
||||
FcitxQtFormattedPreedit::registerMetaType();
|
||||
FcitxQtInputContextArgument::registerMetaType();
|
||||
|
||||
connect(m_connection, &FcitxQtConnection::connected, this, &QFcitxPlatformInputContext::connected);
|
||||
connect(m_connection, &FcitxQtConnection::disconnected, this, &QFcitxPlatformInputContext::cleanUp);
|
||||
connect(m_connection, &FcitxQtConnection::connected, this,
|
||||
&QFcitxPlatformInputContext::connected);
|
||||
connect(m_connection, &FcitxQtConnection::disconnected, this,
|
||||
&QFcitxPlatformInputContext::cleanUp);
|
||||
|
||||
m_connection->startConnection();
|
||||
}
|
||||
|
||||
QFcitxPlatformInputContext::~QFcitxPlatformInputContext()
|
||||
{
|
||||
QFcitxPlatformInputContext::~QFcitxPlatformInputContext() {
|
||||
m_destroy = true;
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::connected()
|
||||
{
|
||||
void QFcitxPlatformInputContext::connected() {
|
||||
if (!m_connection->isConnected())
|
||||
return;
|
||||
|
||||
|
@ -188,15 +181,16 @@ void QFcitxPlatformInputContext::connected()
|
|||
delete m_improxy;
|
||||
m_improxy = nullptr;
|
||||
}
|
||||
m_improxy = new FcitxQtInputMethodProxy(m_connection->serviceName(), QLatin1String("/inputmethod"), *m_connection->connection(), this);
|
||||
m_improxy = new FcitxQtInputMethodProxy(m_connection->serviceName(),
|
||||
QLatin1String("/inputmethod"),
|
||||
*m_connection->connection(), this);
|
||||
|
||||
QWindow* w = qApp->focusWindow();
|
||||
QWindow *w = qApp->focusWindow();
|
||||
if (w)
|
||||
createICData(w);
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::cleanUp()
|
||||
{
|
||||
void QFcitxPlatformInputContext::cleanUp() {
|
||||
m_icMap.clear();
|
||||
|
||||
if (m_improxy) {
|
||||
|
@ -209,24 +203,18 @@ void QFcitxPlatformInputContext::cleanUp()
|
|||
}
|
||||
}
|
||||
|
||||
bool QFcitxPlatformInputContext::isValid() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool QFcitxPlatformInputContext::isValid() const { return true; }
|
||||
|
||||
void QFcitxPlatformInputContext::invokeAction(QInputMethod::Action action, int cursorPosition)
|
||||
{
|
||||
if (action == QInputMethod::Click
|
||||
&& (cursorPosition <= 0 || cursorPosition >= m_preedit.length())
|
||||
)
|
||||
{
|
||||
void QFcitxPlatformInputContext::invokeAction(QInputMethod::Action action,
|
||||
int cursorPosition) {
|
||||
if (action == QInputMethod::Click &&
|
||||
(cursorPosition <= 0 || cursorPosition >= m_preedit.length())) {
|
||||
// qDebug() << action << cursorPosition;
|
||||
commitPreedit();
|
||||
}
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::commitPreedit()
|
||||
{
|
||||
void QFcitxPlatformInputContext::commitPreedit() {
|
||||
QObject *input = qApp->focusObject();
|
||||
if (!input)
|
||||
return;
|
||||
|
@ -238,11 +226,9 @@ void QFcitxPlatformInputContext::commitPreedit()
|
|||
m_commitPreedit.clear();
|
||||
}
|
||||
|
||||
|
||||
void QFcitxPlatformInputContext::reset()
|
||||
{
|
||||
void QFcitxPlatformInputContext::reset() {
|
||||
commitPreedit();
|
||||
FcitxQtInputContextProxy* proxy = validIC();
|
||||
FcitxQtInputContextProxy *proxy = validIC();
|
||||
if (proxy)
|
||||
proxy->Reset();
|
||||
if (m_xkbComposeState) {
|
||||
|
@ -251,10 +237,9 @@ void QFcitxPlatformInputContext::reset()
|
|||
QPlatformInputContext::reset();
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::update(Qt::InputMethodQueries queries )
|
||||
{
|
||||
QWindow* window = qApp->focusWindow();
|
||||
FcitxQtInputContextProxy* proxy = validICByWindow(window);
|
||||
void QFcitxPlatformInputContext::update(Qt::InputMethodQueries queries) {
|
||||
QWindow *window = qApp->focusWindow();
|
||||
FcitxQtInputContextProxy *proxy = validICByWindow(window);
|
||||
if (!proxy)
|
||||
return;
|
||||
|
||||
|
@ -272,13 +257,13 @@ void QFcitxPlatformInputContext::update(Qt::InputMethodQueries queries )
|
|||
}
|
||||
|
||||
if (queries & Qt::ImHints) {
|
||||
Qt::InputMethodHints hints = Qt::InputMethodHints(query.value(Qt::ImHints).toUInt());
|
||||
Qt::InputMethodHints hints =
|
||||
Qt::InputMethodHints(query.value(Qt::ImHints).toUInt());
|
||||
|
||||
|
||||
#define CHECK_HINTS(_HINTS, _CAPABILITY) \
|
||||
if (hints & _HINTS) \
|
||||
addCapacity(data, fcitx::CapabilityFlag::_CAPABILITY); \
|
||||
else \
|
||||
#define CHECK_HINTS(_HINTS, _CAPABILITY) \
|
||||
if (hints & _HINTS) \
|
||||
addCapacity(data, fcitx::CapabilityFlag::_CAPABILITY); \
|
||||
else \
|
||||
removeCapacity(data, fcitx::CapabilityFlag::_CAPABILITY);
|
||||
|
||||
CHECK_HINTS(Qt::ImhNoAutoUppercase, NoAutoUpperCase)
|
||||
|
@ -298,7 +283,8 @@ void QFcitxPlatformInputContext::update(Qt::InputMethodQueries queries )
|
|||
do {
|
||||
if (!m_useSurroundingText)
|
||||
break;
|
||||
if (!((queries & Qt::ImSurroundingText) && (queries & Qt::ImCursorPosition)))
|
||||
if (!((queries & Qt::ImSurroundingText) &&
|
||||
(queries & Qt::ImCursorPosition)))
|
||||
break;
|
||||
if (data.capability.test(fcitx::CapabilityFlag::Password))
|
||||
break;
|
||||
|
@ -308,7 +294,7 @@ void QFcitxPlatformInputContext::update(Qt::InputMethodQueries queries )
|
|||
if (!var.isValid() || !var1.isValid())
|
||||
break;
|
||||
QString text = var.toString();
|
||||
/* we don't want to waste too much memory here */
|
||||
/* we don't want to waste too much memory here */
|
||||
#define SURROUNDING_THRESHOLD 4096
|
||||
if (text.length() < SURROUNDING_THRESHOLD) {
|
||||
if (fcitx::utf8::validate(text.toUtf8().data())) {
|
||||
|
@ -329,8 +315,7 @@ void QFcitxPlatformInputContext::update(Qt::InputMethodQueries queries )
|
|||
if (data.surroundingText != text) {
|
||||
data.surroundingText = text;
|
||||
proxy->SetSurroundingText(text, cursor, anchor);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (data.surroundingAnchor != anchor ||
|
||||
data.surroundingCursor != cursor)
|
||||
proxy->SetSurroundingTextPosition(cursor, anchor);
|
||||
|
@ -346,18 +331,14 @@ void QFcitxPlatformInputContext::update(Qt::InputMethodQueries queries )
|
|||
data.surroundingText = QString::null;
|
||||
removeCapacity(data, fcitx::CapabilityFlag::SurroundingText);
|
||||
}
|
||||
} while(0);
|
||||
} while (0);
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::commit()
|
||||
{
|
||||
QPlatformInputContext::commit();
|
||||
}
|
||||
void QFcitxPlatformInputContext::commit() { QPlatformInputContext::commit(); }
|
||||
|
||||
void QFcitxPlatformInputContext::setFocusObject(QObject* object)
|
||||
{
|
||||
void QFcitxPlatformInputContext::setFocusObject(QObject *object) {
|
||||
Q_UNUSED(object);
|
||||
FcitxQtInputContextProxy* proxy = validICByWindow(m_lastWindow);
|
||||
FcitxQtInputContextProxy *proxy = validICByWindow(m_lastWindow);
|
||||
if (proxy) {
|
||||
proxy->FocusOut();
|
||||
}
|
||||
|
@ -375,26 +356,24 @@ void QFcitxPlatformInputContext::setFocusObject(QObject* object)
|
|||
}
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::windowDestroyed(QObject* object)
|
||||
{
|
||||
void QFcitxPlatformInputContext::windowDestroyed(QObject *object) {
|
||||
/* access QWindow is not possible here, so we use our own map to do so */
|
||||
m_icMap.erase(reinterpret_cast<QWindow*>(object));
|
||||
m_icMap.erase(reinterpret_cast<QWindow *>(object));
|
||||
// qDebug() << "Window Destroyed and we destroy IC correctly, horray!";
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::cursorRectChanged()
|
||||
{
|
||||
void QFcitxPlatformInputContext::cursorRectChanged() {
|
||||
QWindow *inputWindow = qApp->focusWindow();
|
||||
if (!inputWindow)
|
||||
return;
|
||||
FcitxQtInputContextProxy* proxy = validICByWindow(inputWindow);
|
||||
FcitxQtInputContextProxy *proxy = validICByWindow(inputWindow);
|
||||
if (!proxy)
|
||||
return;
|
||||
|
||||
auto& data = m_icMap[inputWindow];
|
||||
auto &data = m_icMap[inputWindow];
|
||||
|
||||
QRect r = qApp->inputMethod()->cursorRectangle().toRect();
|
||||
if(!r.isValid())
|
||||
if (!r.isValid())
|
||||
return;
|
||||
|
||||
r.moveTopLeft(inputWindow->mapToGlobal(r.topLeft()));
|
||||
|
@ -402,20 +381,21 @@ void QFcitxPlatformInputContext::cursorRectChanged()
|
|||
qreal scale = inputWindow->devicePixelRatio();
|
||||
if (data.rect != r) {
|
||||
data.rect = r;
|
||||
proxy->SetCursorRect(r.x() * scale, r.y() * scale,
|
||||
r.width() * scale, r.height() * scale);
|
||||
proxy->SetCursorRect(r.x() * scale, r.y() * scale, r.width() * scale,
|
||||
r.height() * scale);
|
||||
}
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::createInputContext(QWindow *w)
|
||||
{
|
||||
void QFcitxPlatformInputContext::createInputContext(QWindow *w) {
|
||||
if (!m_connection->isConnected())
|
||||
return;
|
||||
|
||||
// qDebug() << "create Input Context" << m_connection->connection()->name();
|
||||
|
||||
if (!m_improxy) {
|
||||
m_improxy = new FcitxQtInputMethodProxy(m_connection->serviceName(), QLatin1String("/inputmethod"), *m_connection->connection(), this);
|
||||
m_improxy = new FcitxQtInputMethodProxy(
|
||||
m_connection->serviceName(), QLatin1String("/inputmethod"),
|
||||
*m_connection->connection(), this);
|
||||
}
|
||||
|
||||
if (!m_improxy->isValid())
|
||||
|
@ -425,14 +405,16 @@ void QFcitxPlatformInputContext::createInputContext(QWindow *w)
|
|||
FcitxQtInputContextArgumentList args;
|
||||
args << FcitxQtInputContextArgument("program", info.fileName());
|
||||
auto result = m_improxy->CreateInputContext(args);
|
||||
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(result);
|
||||
watcher->setProperty("wid", qVariantFromValue(static_cast<void*>(w)));
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, &QFcitxPlatformInputContext::createInputContextFinished);
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(result);
|
||||
watcher->setProperty("wid", qVariantFromValue(static_cast<void *>(w)));
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, this,
|
||||
&QFcitxPlatformInputContext::createInputContextFinished);
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::createInputContextFinished(QDBusPendingCallWatcher* watcher)
|
||||
{
|
||||
auto w = reinterpret_cast<QWindow*>(watcher->property("wid").value<void*>());
|
||||
void QFcitxPlatformInputContext::createInputContextFinished(
|
||||
QDBusPendingCallWatcher *watcher) {
|
||||
auto w =
|
||||
reinterpret_cast<QWindow *>(watcher->property("wid").value<void *>());
|
||||
auto iter = m_icMap.find(w);
|
||||
if (iter == m_icMap.end()) {
|
||||
return;
|
||||
|
@ -440,7 +422,7 @@ void QFcitxPlatformInputContext::createInputContextFinished(QDBusPendingCallWatc
|
|||
|
||||
auto &data = iter->second;
|
||||
|
||||
QDBusPendingReply< QDBusObjectPath, QByteArray > result = *watcher;
|
||||
QDBusPendingReply<QDBusObjectPath, QByteArray> result = *watcher;
|
||||
|
||||
do {
|
||||
if (result.isError()) {
|
||||
|
@ -454,16 +436,24 @@ void QFcitxPlatformInputContext::createInputContextFinished(QDBusPendingCallWatc
|
|||
if (data.proxy) {
|
||||
delete data.proxy;
|
||||
}
|
||||
data.proxy = new FcitxQtInputContextProxy(m_connection->serviceName(), objectPath.path(), *m_connection->connection(), this);
|
||||
data.proxy->setProperty("icData", qVariantFromValue(static_cast<void*>(&data)));
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::CommitString, this, &QFcitxPlatformInputContext::commitString);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::ForwardKey, this, &QFcitxPlatformInputContext::forwardKey);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::UpdateFormattedPreedit, this, &QFcitxPlatformInputContext::updateFormattedPreedit);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::DeleteSurroundingText, this, &QFcitxPlatformInputContext::deleteSurroundingText);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::CurrentIM, this, &QFcitxPlatformInputContext::updateCurrentIM);
|
||||
data.proxy = new FcitxQtInputContextProxy(
|
||||
m_connection->serviceName(), objectPath.path(),
|
||||
*m_connection->connection(), this);
|
||||
data.proxy->setProperty("icData",
|
||||
qVariantFromValue(static_cast<void *>(&data)));
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::CommitString, this,
|
||||
&QFcitxPlatformInputContext::commitString);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::ForwardKey, this,
|
||||
&QFcitxPlatformInputContext::forwardKey);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::UpdateFormattedPreedit,
|
||||
this, &QFcitxPlatformInputContext::updateFormattedPreedit);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::DeleteSurroundingText,
|
||||
this, &QFcitxPlatformInputContext::deleteSurroundingText);
|
||||
connect(data.proxy, &FcitxQtInputContextProxy::CurrentIM, this,
|
||||
&QFcitxPlatformInputContext::updateCurrentIM);
|
||||
|
||||
if (data.proxy->isValid()) {
|
||||
QWindow* window = qApp->focusWindow();
|
||||
QWindow *window = qApp->focusWindow();
|
||||
if (window && window == w)
|
||||
data.proxy->FocusIn();
|
||||
}
|
||||
|
@ -475,25 +465,25 @@ void QFcitxPlatformInputContext::createInputContextFinished(QDBusPendingCallWatc
|
|||
flag |= fcitx::CapabilityFlag::FormattedPreedit;
|
||||
flag |= fcitx::CapabilityFlag::ClientUnfocusCommit;
|
||||
flag |= fcitx::CapabilityFlag::GetIMInfoOnFocus;
|
||||
m_useSurroundingText = get_boolean_env("FCITX_QT_ENABLE_SURROUNDING_TEXT", true);
|
||||
m_useSurroundingText =
|
||||
get_boolean_env("FCITX_QT_ENABLE_SURROUNDING_TEXT", true);
|
||||
if (m_useSurroundingText)
|
||||
flag |= fcitx::CapabilityFlag::SurroundingText;
|
||||
|
||||
addCapacity(data, flag, true);
|
||||
} while(0);
|
||||
} while (0);
|
||||
delete watcher;
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::updateCapacity(const FcitxQtICData &data)
|
||||
{
|
||||
void QFcitxPlatformInputContext::updateCapacity(const FcitxQtICData &data) {
|
||||
if (!data.proxy || !data.proxy->isValid())
|
||||
return;
|
||||
|
||||
QDBusPendingReply< void > result = data.proxy->SetCapability((uint) data.capability);
|
||||
QDBusPendingReply<void> result =
|
||||
data.proxy->SetCapability((uint)data.capability);
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::commitString(const QString& str)
|
||||
{
|
||||
void QFcitxPlatformInputContext::commitString(const QString &str) {
|
||||
m_cursorPos = 0;
|
||||
m_preeditList.clear();
|
||||
m_commitPreedit.clear();
|
||||
|
@ -506,8 +496,8 @@ void QFcitxPlatformInputContext::commitString(const QString& str)
|
|||
QCoreApplication::sendEvent(input, &event);
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::updateFormattedPreedit(const FcitxQtFormattedPreeditList& preeditList, int cursorPos)
|
||||
{
|
||||
void QFcitxPlatformInputContext::updateFormattedPreedit(
|
||||
const FcitxQtFormattedPreeditList &preeditList, int cursorPos) {
|
||||
QObject *input = qApp->focusObject();
|
||||
if (!input)
|
||||
return;
|
||||
|
@ -518,23 +508,29 @@ void QFcitxPlatformInputContext::updateFormattedPreedit(const FcitxQtFormattedPr
|
|||
QString str, commitStr;
|
||||
int pos = 0;
|
||||
QList<QInputMethodEvent::Attribute> attrList;
|
||||
Q_FOREACH(const FcitxQtFormattedPreedit& preedit, preeditList)
|
||||
{
|
||||
Q_FOREACH (const FcitxQtFormattedPreedit &preedit, preeditList) {
|
||||
str += preedit.string();
|
||||
if (!(fcitx::TextFormatFlags(preedit.format()) & fcitx::TextFormatFlag::DontCommit))
|
||||
if (!(fcitx::TextFormatFlags(preedit.format()) &
|
||||
fcitx::TextFormatFlag::DontCommit))
|
||||
commitStr += preedit.string();
|
||||
QTextCharFormat format;
|
||||
if (fcitx::TextFormatFlags(preedit.format()) & fcitx::TextFormatFlag::UnderLine) {
|
||||
if (fcitx::TextFormatFlags(preedit.format()) &
|
||||
fcitx::TextFormatFlag::UnderLine) {
|
||||
format.setUnderlineStyle(QTextCharFormat::DashUnderline);
|
||||
}
|
||||
if (fcitx::TextFormatFlags(preedit.format()) & fcitx::TextFormatFlag::HighLight) {
|
||||
if (fcitx::TextFormatFlags(preedit.format()) &
|
||||
fcitx::TextFormatFlag::HighLight) {
|
||||
QBrush brush;
|
||||
QPalette palette;
|
||||
palette = QGuiApplication::palette();
|
||||
format.setBackground(QBrush(QColor(palette.color(QPalette::Active, QPalette::Highlight))));
|
||||
format.setForeground(QBrush(QColor(palette.color(QPalette::Active, QPalette::HighlightedText))));
|
||||
format.setBackground(QBrush(
|
||||
QColor(palette.color(QPalette::Active, QPalette::Highlight))));
|
||||
format.setForeground(QBrush(QColor(
|
||||
palette.color(QPalette::Active, QPalette::HighlightedText))));
|
||||
}
|
||||
attrList.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, pos, preedit.string().length(), format));
|
||||
attrList.append(
|
||||
QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, pos,
|
||||
preedit.string().length(), format));
|
||||
pos += preedit.string().length();
|
||||
}
|
||||
|
||||
|
@ -542,7 +538,8 @@ void QFcitxPlatformInputContext::updateFormattedPreedit(const FcitxQtFormattedPr
|
|||
array.truncate(cursorPos);
|
||||
cursorPos = QString::fromUtf8(array).length();
|
||||
|
||||
attrList.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, cursorPos, 1, 0));
|
||||
attrList.append(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
|
||||
cursorPos, 1, 0));
|
||||
m_preedit = str;
|
||||
m_commitPreedit = commitStr;
|
||||
QInputMethodEvent event(str, attrList);
|
||||
|
@ -550,26 +547,29 @@ void QFcitxPlatformInputContext::updateFormattedPreedit(const FcitxQtFormattedPr
|
|||
update(Qt::ImCursorRectangle);
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::deleteSurroundingText(int offset, uint _nchar)
|
||||
{
|
||||
void QFcitxPlatformInputContext::deleteSurroundingText(int offset,
|
||||
uint _nchar) {
|
||||
QObject *input = qApp->focusObject();
|
||||
if (!input)
|
||||
return;
|
||||
|
||||
QInputMethodEvent event;
|
||||
|
||||
FcitxQtInputContextProxy *proxy = qobject_cast<FcitxQtInputContextProxy*>(sender());
|
||||
FcitxQtInputContextProxy *proxy =
|
||||
qobject_cast<FcitxQtInputContextProxy *>(sender());
|
||||
if (!proxy) {
|
||||
return;
|
||||
}
|
||||
|
||||
FcitxQtICData *data = static_cast<FcitxQtICData*>(proxy->property("icData").value<void *>());
|
||||
FcitxQtICData *data =
|
||||
static_cast<FcitxQtICData *>(proxy->property("icData").value<void *>());
|
||||
QVector<uint> ucsText = data->surroundingText.toUcs4();
|
||||
|
||||
int cursor = data->surroundingCursor;
|
||||
// make nchar signed so we are safer
|
||||
int nchar = _nchar;
|
||||
// Qt's reconvert semantics is different from gtk's. It doesn't count the current
|
||||
// Qt's reconvert semantics is different from gtk's. It doesn't count the
|
||||
// current
|
||||
// selection. Discard selection from nchar.
|
||||
if (data->surroundingAnchor < data->surroundingCursor) {
|
||||
nchar -= data->surroundingCursor - data->surroundingAnchor;
|
||||
|
@ -581,10 +581,12 @@ void QFcitxPlatformInputContext::deleteSurroundingText(int offset, uint _nchar)
|
|||
}
|
||||
|
||||
// validates
|
||||
if (nchar >= 0 && cursor + offset >= 0 && cursor + offset + nchar < ucsText.size()) {
|
||||
if (nchar >= 0 && cursor + offset >= 0 &&
|
||||
cursor + offset + nchar < ucsText.size()) {
|
||||
// order matters
|
||||
QVector<uint> replacedChars = ucsText.mid(cursor + offset, nchar);
|
||||
nchar = QString::fromUcs4(replacedChars.data(), replacedChars.size()).size();
|
||||
nchar = QString::fromUcs4(replacedChars.data(), replacedChars.size())
|
||||
.size();
|
||||
|
||||
int start, len;
|
||||
if (offset >= 0) {
|
||||
|
@ -596,14 +598,15 @@ void QFcitxPlatformInputContext::deleteSurroundingText(int offset, uint _nchar)
|
|||
}
|
||||
|
||||
QVector<uint> prefixedChars = ucsText.mid(start, len);
|
||||
offset = QString::fromUcs4(prefixedChars.data(), prefixedChars.size()).size() * (offset >= 0 ? 1 : -1);
|
||||
offset = QString::fromUcs4(prefixedChars.data(), prefixedChars.size())
|
||||
.size() *
|
||||
(offset >= 0 ? 1 : -1);
|
||||
event.setCommitString("", offset, nchar);
|
||||
QCoreApplication::sendEvent(input, &event);
|
||||
}
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::forwardKey(uint keyval, uint state, int type)
|
||||
{
|
||||
void QFcitxPlatformInputContext::forwardKey(uint keyval, uint state, int type) {
|
||||
QObject *input = qApp->focusObject();
|
||||
if (input != nullptr) {
|
||||
key_filtered = true;
|
||||
|
@ -614,8 +617,9 @@ void QFcitxPlatformInputContext::forwardKey(uint keyval, uint state, int type)
|
|||
}
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::updateCurrentIM(const QString& name, const QString& uniqueName, const QString& langCode)
|
||||
{
|
||||
void QFcitxPlatformInputContext::updateCurrentIM(const QString &name,
|
||||
const QString &uniqueName,
|
||||
const QString &langCode) {
|
||||
Q_UNUSED(name);
|
||||
Q_UNUSED(uniqueName);
|
||||
QLocale newLocale(langCode);
|
||||
|
@ -625,23 +629,21 @@ void QFcitxPlatformInputContext::updateCurrentIM(const QString& name, const QStr
|
|||
}
|
||||
}
|
||||
|
||||
QLocale QFcitxPlatformInputContext::locale() const
|
||||
{
|
||||
return m_locale;
|
||||
}
|
||||
QLocale QFcitxPlatformInputContext::locale() const { return m_locale; }
|
||||
|
||||
void QFcitxPlatformInputContext::createICData(QWindow* w)
|
||||
{
|
||||
void QFcitxPlatformInputContext::createICData(QWindow *w) {
|
||||
auto iter = m_icMap.find(w);
|
||||
if (iter == m_icMap.end()) {
|
||||
m_icMap.emplace(std::piecewise_construct, std::forward_as_tuple(w), std::forward_as_tuple());
|
||||
connect(w, &QObject::destroyed, this, &QFcitxPlatformInputContext::windowDestroyed);
|
||||
m_icMap.emplace(std::piecewise_construct, std::forward_as_tuple(w),
|
||||
std::forward_as_tuple());
|
||||
connect(w, &QObject::destroyed, this,
|
||||
&QFcitxPlatformInputContext::windowDestroyed);
|
||||
}
|
||||
createInputContext(w);
|
||||
}
|
||||
|
||||
QKeyEvent* QFcitxPlatformInputContext::createKeyEvent(uint keyval, uint _state, bool isRelease)
|
||||
{
|
||||
QKeyEvent *QFcitxPlatformInputContext::createKeyEvent(uint keyval, uint _state,
|
||||
bool isRelease) {
|
||||
Qt::KeyboardModifiers qstate = Qt::NoModifier;
|
||||
|
||||
fcitx::KeyStates state(_state);
|
||||
|
@ -649,42 +651,37 @@ QKeyEvent* QFcitxPlatformInputContext::createKeyEvent(uint keyval, uint _state,
|
|||
int count = 1;
|
||||
if (state & fcitx::KeyState::Alt) {
|
||||
qstate |= Qt::AltModifier;
|
||||
count ++;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (state & fcitx::KeyState::Shift) {
|
||||
qstate |= Qt::ShiftModifier;
|
||||
count ++;
|
||||
count++;
|
||||
}
|
||||
|
||||
if (state & fcitx::KeyState::Ctrl) {
|
||||
qstate |= Qt::ControlModifier;
|
||||
count ++;
|
||||
count++;
|
||||
}
|
||||
|
||||
int key;
|
||||
symToKeyQt(keyval, key);
|
||||
|
||||
QKeyEvent* keyevent = new QKeyEvent(
|
||||
isRelease ? (QEvent::KeyRelease) : (QEvent::KeyPress),
|
||||
key,
|
||||
qstate,
|
||||
QString(),
|
||||
false,
|
||||
count
|
||||
);
|
||||
QKeyEvent *keyevent =
|
||||
new QKeyEvent(isRelease ? (QEvent::KeyRelease) : (QEvent::KeyPress),
|
||||
key, qstate, QString(), false, count);
|
||||
|
||||
return keyevent;
|
||||
}
|
||||
|
||||
bool QFcitxPlatformInputContext::filterEvent(const QEvent* event)
|
||||
{
|
||||
bool QFcitxPlatformInputContext::filterEvent(const QEvent *event) {
|
||||
do {
|
||||
if (event->type() != QEvent::KeyPress && event->type() != QEvent::KeyRelease) {
|
||||
if (event->type() != QEvent::KeyPress &&
|
||||
event->type() != QEvent::KeyRelease) {
|
||||
break;
|
||||
}
|
||||
|
||||
const QKeyEvent* keyEvent = static_cast<const QKeyEvent*>(event);
|
||||
const QKeyEvent *keyEvent = static_cast<const QKeyEvent *>(event);
|
||||
quint32 keyval = keyEvent->nativeVirtualKey();
|
||||
quint32 keycode = keyEvent->nativeScanCode();
|
||||
quint32 state = keyEvent->nativeModifiers();
|
||||
|
@ -703,7 +700,7 @@ bool QFcitxPlatformInputContext::filterEvent(const QEvent* event)
|
|||
break;
|
||||
}
|
||||
|
||||
FcitxQtInputContextProxy* proxy = validICByWindow(qApp->focusWindow());
|
||||
FcitxQtInputContextProxy *proxy = validICByWindow(qApp->focusWindow());
|
||||
|
||||
if (!proxy) {
|
||||
if (filterEventFallback(keyval, keycode, state, isRelease)) {
|
||||
|
@ -715,17 +712,15 @@ bool QFcitxPlatformInputContext::filterEvent(const QEvent* event)
|
|||
|
||||
proxy->FocusIn();
|
||||
|
||||
auto reply = proxy->ProcessKeyEvent(keyval,
|
||||
keycode,
|
||||
state,
|
||||
isRelease,
|
||||
QDateTime::currentDateTime().toTime_t());
|
||||
|
||||
auto reply =
|
||||
proxy->ProcessKeyEvent(keyval, keycode, state, isRelease,
|
||||
QDateTime::currentDateTime().toTime_t());
|
||||
|
||||
if (Q_UNLIKELY(m_syncMode)) {
|
||||
reply.waitForFinished();
|
||||
|
||||
if (!m_connection->isConnected() || !reply.isFinished() || reply.isError() || !reply.value()) {
|
||||
if (!m_connection->isConnected() || !reply.isFinished() ||
|
||||
reply.isError() || !reply.value()) {
|
||||
if (filterEventFallback(keyval, keycode, state, isRelease)) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -735,30 +730,30 @@ bool QFcitxPlatformInputContext::filterEvent(const QEvent* event)
|
|||
update(Qt::ImCursorRectangle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
ProcessKeyWatcher* watcher = new ProcessKeyWatcher(*keyEvent, qApp->focusWindow(), reply, this);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished,
|
||||
this, &QFcitxPlatformInputContext::processKeyEventFinished);
|
||||
} else {
|
||||
ProcessKeyWatcher *watcher = new ProcessKeyWatcher(
|
||||
*keyEvent, qApp->focusWindow(), reply, this);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, this,
|
||||
&QFcitxPlatformInputContext::processKeyEventFinished);
|
||||
return true;
|
||||
}
|
||||
} while(0);
|
||||
} while (0);
|
||||
return QPlatformInputContext::filterEvent(event);
|
||||
}
|
||||
|
||||
void QFcitxPlatformInputContext::processKeyEventFinished(QDBusPendingCallWatcher* w)
|
||||
{
|
||||
ProcessKeyWatcher* watcher = static_cast<ProcessKeyWatcher*>(w);
|
||||
QDBusPendingReply< bool > result(*watcher);
|
||||
void QFcitxPlatformInputContext::processKeyEventFinished(
|
||||
QDBusPendingCallWatcher *w) {
|
||||
ProcessKeyWatcher *watcher = static_cast<ProcessKeyWatcher *>(w);
|
||||
QDBusPendingReply<bool> result(*watcher);
|
||||
bool filtered = false;
|
||||
|
||||
QWindow* window = watcher->window();
|
||||
QWindow *window = watcher->window();
|
||||
// if window is already destroyed, we can only throw this event away.
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
const QKeyEvent& keyEvent = watcher->keyEvent();
|
||||
const QKeyEvent &keyEvent = watcher->keyEvent();
|
||||
|
||||
// use same variable name as in QXcbKeyboard::handleKeyEvent
|
||||
QEvent::Type type = keyEvent.type();
|
||||
|
@ -772,7 +767,8 @@ void QFcitxPlatformInputContext::processKeyEventFinished(QDBusPendingCallWatcher
|
|||
ulong time = keyEvent.timestamp();
|
||||
|
||||
if (result.isError() || !result.value()) {
|
||||
filtered = filterEventFallback(sym, code, state, type == QEvent::KeyPress);
|
||||
filtered =
|
||||
filterEventFallback(sym, code, state, type == QEvent::KeyPress);
|
||||
} else {
|
||||
filtered = true;
|
||||
}
|
||||
|
@ -789,18 +785,20 @@ void QFcitxPlatformInputContext::processKeyEventFinished(QDBusPendingCallWatcher
|
|||
globalPos = window->screen()->handle()->cursor()->pos();
|
||||
pos = window->mapFromGlobal(globalPos);
|
||||
}
|
||||
QWindowSystemInterface::handleContextMenuEvent(window, false, pos, globalPos, modifiers);
|
||||
QWindowSystemInterface::handleContextMenuEvent(
|
||||
window, false, pos, globalPos, modifiers);
|
||||
}
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(window, time, type, qtcode, modifiers,
|
||||
code, sym, state, string, isAutoRepeat);
|
||||
QWindowSystemInterface::handleExtendedKeyEvent(
|
||||
window, time, type, qtcode, modifiers, code, sym, state, string,
|
||||
isAutoRepeat);
|
||||
}
|
||||
|
||||
delete watcher;
|
||||
}
|
||||
|
||||
|
||||
bool QFcitxPlatformInputContext::filterEventFallback(uint keyval, uint keycode, uint state, bool isRelease)
|
||||
{
|
||||
bool QFcitxPlatformInputContext::filterEventFallback(uint keyval, uint keycode,
|
||||
uint state,
|
||||
bool isRelease) {
|
||||
Q_UNUSED(keycode);
|
||||
if (processCompose(keyval, state, isRelease)) {
|
||||
return true;
|
||||
|
@ -808,17 +806,16 @@ bool QFcitxPlatformInputContext::filterEventFallback(uint keyval, uint keycode,
|
|||
return false;
|
||||
}
|
||||
|
||||
FcitxQtInputContextProxy* QFcitxPlatformInputContext::validIC()
|
||||
{
|
||||
FcitxQtInputContextProxy *QFcitxPlatformInputContext::validIC() {
|
||||
if (m_icMap.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
QWindow* window = qApp->focusWindow();
|
||||
QWindow *window = qApp->focusWindow();
|
||||
return validICByWindow(window);
|
||||
}
|
||||
|
||||
FcitxQtInputContextProxy* QFcitxPlatformInputContext::validICByWindow(QWindow* w)
|
||||
{
|
||||
FcitxQtInputContextProxy *
|
||||
QFcitxPlatformInputContext::validICByWindow(QWindow *w) {
|
||||
if (!w) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -836,27 +833,29 @@ FcitxQtInputContextProxy* QFcitxPlatformInputContext::validICByWindow(QWindow* w
|
|||
return data.proxy;
|
||||
}
|
||||
|
||||
|
||||
bool QFcitxPlatformInputContext::processCompose(uint keyval, uint state, bool isRelease)
|
||||
{
|
||||
bool QFcitxPlatformInputContext::processCompose(uint keyval, uint state,
|
||||
bool isRelease) {
|
||||
Q_UNUSED(state);
|
||||
|
||||
if (!m_xkbComposeTable || isRelease)
|
||||
return false;
|
||||
|
||||
struct xkb_compose_state* xkbComposeState = m_xkbComposeState.data();
|
||||
struct xkb_compose_state *xkbComposeState = m_xkbComposeState.data();
|
||||
|
||||
enum xkb_compose_feed_result result = xkb_compose_state_feed(xkbComposeState, keyval);
|
||||
enum xkb_compose_feed_result result =
|
||||
xkb_compose_state_feed(xkbComposeState, keyval);
|
||||
if (result == XKB_COMPOSE_FEED_IGNORED) {
|
||||
return false;
|
||||
}
|
||||
|
||||
enum xkb_compose_status status = xkb_compose_state_get_status(xkbComposeState);
|
||||
enum xkb_compose_status status =
|
||||
xkb_compose_state_get_status(xkbComposeState);
|
||||
if (status == XKB_COMPOSE_NOTHING) {
|
||||
return 0;
|
||||
} else if (status == XKB_COMPOSE_COMPOSED) {
|
||||
char buffer[] = {'\0', '\0', '\0', '\0', '\0', '\0', '\0'};
|
||||
int length = xkb_compose_state_get_utf8(xkbComposeState, buffer, sizeof(buffer));
|
||||
int length =
|
||||
xkb_compose_state_get_utf8(xkbComposeState, buffer, sizeof(buffer));
|
||||
xkb_compose_state_reset(xkbComposeState);
|
||||
if (length != 0) {
|
||||
commitString(QString::fromUtf8(buffer));
|
||||
|
@ -869,5 +868,4 @@ bool QFcitxPlatformInputContext::processCompose(uint keyval, uint state, bool is
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
// kate: indent-mode cstyle; space-indent on; indent-width 0;
|
||||
|
|
|
@ -20,25 +20,26 @@
|
|||
#ifndef QFCITXPLATFORMINPUTCONTEXT_H
|
||||
#define QFCITXPLATFORMINPUTCONTEXT_H
|
||||
|
||||
#include <qpa/qplatforminputcontext.h>
|
||||
#include <QWindow>
|
||||
#include <QKeyEvent>
|
||||
#include "fcitxqtinputcontextproxy.h"
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusServiceWatcher>
|
||||
#include <QPointer>
|
||||
#include <QFileSystemWatcher>
|
||||
#include <QKeyEvent>
|
||||
#include <QPointer>
|
||||
#include <QRect>
|
||||
#include <QWindow>
|
||||
#include <fcitx-utils/capabilityflags.h>
|
||||
#include <qpa/qplatforminputcontext.h>
|
||||
#include <unordered_map>
|
||||
#include <xkbcommon/xkbcommon-compose.h>
|
||||
#include "fcitxqtinputcontextproxy.h"
|
||||
#include <fcitx-utils/capabilityflags.h>
|
||||
|
||||
class FcitxQtConnection;
|
||||
class QFileSystemWatcher;
|
||||
|
||||
struct FcitxQtICData {
|
||||
FcitxQtICData() : proxy(nullptr), surroundingAnchor(-1), surroundingCursor(-1) {}
|
||||
FcitxQtICData(const FcitxQtICData& that) = delete;
|
||||
FcitxQtICData()
|
||||
: proxy(nullptr), surroundingAnchor(-1), surroundingCursor(-1) {}
|
||||
FcitxQtICData(const FcitxQtICData &that) = delete;
|
||||
~FcitxQtICData() {
|
||||
if (proxy) {
|
||||
if (proxy->isValid()) {
|
||||
|
@ -55,98 +56,89 @@ struct FcitxQtICData {
|
|||
int surroundingCursor;
|
||||
};
|
||||
|
||||
|
||||
class ProcessKeyWatcher : public QDBusPendingCallWatcher
|
||||
{
|
||||
class ProcessKeyWatcher : public QDBusPendingCallWatcher {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProcessKeyWatcher(const QKeyEvent& event, QWindow* window, const QDBusPendingCall &call, QObject *parent = 0) :
|
||||
QDBusPendingCallWatcher(call, parent)
|
||||
,m_event(event.type(), event.key(), event.modifiers(),
|
||||
event.nativeScanCode(), event.nativeVirtualKey(), event.nativeModifiers(),
|
||||
event.text(), event.isAutoRepeat(), event.count())
|
||||
,m_window(window)
|
||||
{
|
||||
}
|
||||
ProcessKeyWatcher(const QKeyEvent &event, QWindow *window,
|
||||
const QDBusPendingCall &call, QObject *parent = 0)
|
||||
: QDBusPendingCallWatcher(call, parent),
|
||||
m_event(event.type(), event.key(), event.modifiers(),
|
||||
event.nativeScanCode(), event.nativeVirtualKey(),
|
||||
event.nativeModifiers(), event.text(), event.isAutoRepeat(),
|
||||
event.count()),
|
||||
m_window(window) {}
|
||||
|
||||
virtual ~ProcessKeyWatcher() {
|
||||
}
|
||||
virtual ~ProcessKeyWatcher() {}
|
||||
|
||||
const QKeyEvent& keyEvent() {
|
||||
return m_event;
|
||||
}
|
||||
const QKeyEvent &keyEvent() { return m_event; }
|
||||
|
||||
QWindow* window() {
|
||||
return m_window.data();
|
||||
}
|
||||
QWindow *window() { return m_window.data(); }
|
||||
|
||||
private:
|
||||
QKeyEvent m_event;
|
||||
QPointer<QWindow> m_window;
|
||||
};
|
||||
|
||||
struct XkbContextDeleter
|
||||
{
|
||||
static inline void cleanup(struct xkb_context* pointer)
|
||||
{
|
||||
if (pointer) xkb_context_unref(pointer);
|
||||
struct XkbContextDeleter {
|
||||
static inline void cleanup(struct xkb_context *pointer) {
|
||||
if (pointer)
|
||||
xkb_context_unref(pointer);
|
||||
}
|
||||
};
|
||||
|
||||
struct XkbComposeTableDeleter
|
||||
{
|
||||
static inline void cleanup(struct xkb_compose_table* pointer)
|
||||
{
|
||||
if (pointer) xkb_compose_table_unref(pointer);
|
||||
struct XkbComposeTableDeleter {
|
||||
static inline void cleanup(struct xkb_compose_table *pointer) {
|
||||
if (pointer)
|
||||
xkb_compose_table_unref(pointer);
|
||||
}
|
||||
};
|
||||
|
||||
struct XkbComposeStateDeleter
|
||||
{
|
||||
static inline void cleanup(struct xkb_compose_state* pointer)
|
||||
{
|
||||
if (pointer) xkb_compose_state_unref(pointer);
|
||||
struct XkbComposeStateDeleter {
|
||||
static inline void cleanup(struct xkb_compose_state *pointer) {
|
||||
if (pointer)
|
||||
xkb_compose_state_unref(pointer);
|
||||
}
|
||||
};
|
||||
|
||||
class FcitxQtInputMethodProxy;
|
||||
|
||||
class QFcitxPlatformInputContext : public QPlatformInputContext
|
||||
{
|
||||
class QFcitxPlatformInputContext : public QPlatformInputContext {
|
||||
Q_OBJECT
|
||||
public:
|
||||
QFcitxPlatformInputContext();
|
||||
virtual ~QFcitxPlatformInputContext();
|
||||
|
||||
virtual bool filterEvent(const QEvent* event) Q_DECL_OVERRIDE;
|
||||
virtual bool filterEvent(const QEvent *event) Q_DECL_OVERRIDE;
|
||||
virtual bool isValid() const Q_DECL_OVERRIDE;
|
||||
virtual void invokeAction(QInputMethod::Action , int cursorPosition) Q_DECL_OVERRIDE;
|
||||
virtual void invokeAction(QInputMethod::Action,
|
||||
int cursorPosition) Q_DECL_OVERRIDE;
|
||||
virtual void reset() Q_DECL_OVERRIDE;
|
||||
virtual void commit() Q_DECL_OVERRIDE;
|
||||
virtual void update(Qt::InputMethodQueries quries ) Q_DECL_OVERRIDE;
|
||||
virtual void setFocusObject(QObject* object) Q_DECL_OVERRIDE;
|
||||
virtual void update(Qt::InputMethodQueries quries) Q_DECL_OVERRIDE;
|
||||
virtual void setFocusObject(QObject *object) Q_DECL_OVERRIDE;
|
||||
virtual QLocale locale() const Q_DECL_OVERRIDE;
|
||||
|
||||
public Q_SLOTS:
|
||||
void cursorRectChanged();
|
||||
void commitString(const QString& str);
|
||||
void updateFormattedPreedit(const FcitxQtFormattedPreeditList& preeditList, int cursorPos);
|
||||
void commitString(const QString &str);
|
||||
void updateFormattedPreedit(const FcitxQtFormattedPreeditList &preeditList,
|
||||
int cursorPos);
|
||||
void deleteSurroundingText(int offset, uint nchar);
|
||||
void forwardKey(uint keyval, uint state, int type);
|
||||
void createInputContextFinished(QDBusPendingCallWatcher* watcher);
|
||||
void createInputContextFinished(QDBusPendingCallWatcher *watcher);
|
||||
void connected();
|
||||
void cleanUp();
|
||||
void windowDestroyed(QObject* object);
|
||||
void updateCurrentIM(const QString &name, const QString &uniqueName, const QString &langCode);
|
||||
|
||||
void windowDestroyed(QObject *object);
|
||||
void updateCurrentIM(const QString &name, const QString &uniqueName,
|
||||
const QString &langCode);
|
||||
|
||||
private:
|
||||
void createInputContext(QWindow *w);
|
||||
bool processCompose(uint keyval, uint state, bool isRelaese);
|
||||
QKeyEvent* createKeyEvent(uint keyval, uint state, bool isRelaese);
|
||||
QKeyEvent *createKeyEvent(uint keyval, uint state, bool isRelaese);
|
||||
|
||||
void addCapacity(FcitxQtICData &data, fcitx::CapabilityFlags capability, bool forceUpdate = false)
|
||||
{
|
||||
void addCapacity(FcitxQtICData &data, fcitx::CapabilityFlags capability,
|
||||
bool forceUpdate = false) {
|
||||
auto newcaps = data.capability | capability;
|
||||
if (data.capability != newcaps || forceUpdate) {
|
||||
data.capability = newcaps;
|
||||
|
@ -154,8 +146,8 @@ private:
|
|||
}
|
||||
}
|
||||
|
||||
void removeCapacity(FcitxQtICData &data, fcitx::CapabilityFlags capability, bool forceUpdate = false)
|
||||
{
|
||||
void removeCapacity(FcitxQtICData &data, fcitx::CapabilityFlags capability,
|
||||
bool forceUpdate = false) {
|
||||
auto newcaps = data.capability & (~capability);
|
||||
if (data.capability != newcaps || forceUpdate) {
|
||||
data.capability = newcaps;
|
||||
|
@ -165,13 +157,14 @@ private:
|
|||
|
||||
void updateCapacity(const FcitxQtICData &data);
|
||||
void commitPreedit();
|
||||
void createICData(QWindow* w);
|
||||
FcitxQtInputContextProxy* validIC();
|
||||
FcitxQtInputContextProxy* validICByWindow(QWindow* window);
|
||||
bool filterEventFallback(uint keyval, uint keycode, uint state, bool isRelaese);
|
||||
void createICData(QWindow *w);
|
||||
FcitxQtInputContextProxy *validIC();
|
||||
FcitxQtInputContextProxy *validICByWindow(QWindow *window);
|
||||
bool filterEventFallback(uint keyval, uint keycode, uint state,
|
||||
bool isRelaese);
|
||||
|
||||
FcitxQtConnection* m_connection;
|
||||
FcitxQtInputMethodProxy* m_improxy;
|
||||
FcitxQtConnection *m_connection;
|
||||
FcitxQtInputMethodProxy *m_improxy;
|
||||
QString m_preedit;
|
||||
QString m_commitPreedit;
|
||||
FcitxQtFormattedPreeditList m_preeditList;
|
||||
|
@ -181,15 +174,17 @@ private:
|
|||
QString m_lastSurroundingText;
|
||||
int m_lastSurroundingAnchor;
|
||||
int m_lastSurroundingCursor;
|
||||
std::unordered_map<QWindow*, FcitxQtICData> m_icMap;
|
||||
std::unordered_map<QWindow *, FcitxQtICData> m_icMap;
|
||||
QPointer<QWindow> m_lastWindow;
|
||||
bool m_destroy;
|
||||
QScopedPointer<struct xkb_context, XkbContextDeleter> m_xkbContext;
|
||||
QScopedPointer<struct xkb_compose_table, XkbComposeTableDeleter> m_xkbComposeTable;
|
||||
QScopedPointer<struct xkb_compose_state, XkbComposeStateDeleter> m_xkbComposeState;
|
||||
QScopedPointer<struct xkb_compose_table, XkbComposeTableDeleter>
|
||||
m_xkbComposeTable;
|
||||
QScopedPointer<struct xkb_compose_state, XkbComposeStateDeleter>
|
||||
m_xkbComposeState;
|
||||
QLocale m_locale;
|
||||
private slots:
|
||||
void processKeyEventFinished(QDBusPendingCallWatcher*);
|
||||
void processKeyEventFinished(QDBusPendingCallWatcher *);
|
||||
};
|
||||
|
||||
#endif // QFCITXPLATFORMINPUTCONTEXT_H
|
||||
|
|
|
@ -18,40 +18,32 @@
|
|||
***************************************************************************/
|
||||
|
||||
#include "fcitxqtconfiguifactory.h"
|
||||
#include "fcitxqtconfiguiplugin.h"
|
||||
#include "fcitxqtconfiguifactory_p.h"
|
||||
#include "fcitxqtconfiguiplugin.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QLibrary>
|
||||
#include <QPluginLoader>
|
||||
#include <QStandardPaths>
|
||||
#include <libintl.h>
|
||||
#include <fcitx-utils/standardpath.h>
|
||||
#include <libintl.h>
|
||||
|
||||
FcitxQtConfigUIFactoryPrivate::FcitxQtConfigUIFactoryPrivate(FcitxQtConfigUIFactory* factory) : QObject(factory)
|
||||
,q_ptr(factory)
|
||||
{
|
||||
}
|
||||
FcitxQtConfigUIFactoryPrivate::FcitxQtConfigUIFactoryPrivate(
|
||||
FcitxQtConfigUIFactory *factory)
|
||||
: QObject(factory), q_ptr(factory) {}
|
||||
|
||||
FcitxQtConfigUIFactoryPrivate::~FcitxQtConfigUIFactoryPrivate()
|
||||
{
|
||||
}
|
||||
FcitxQtConfigUIFactoryPrivate::~FcitxQtConfigUIFactoryPrivate() {}
|
||||
|
||||
FcitxQtConfigUIFactory::FcitxQtConfigUIFactory(QObject* parent): QObject(parent)
|
||||
,d_ptr(new FcitxQtConfigUIFactoryPrivate(this))
|
||||
{
|
||||
FcitxQtConfigUIFactory::FcitxQtConfigUIFactory(QObject *parent)
|
||||
: QObject(parent), d_ptr(new FcitxQtConfigUIFactoryPrivate(this)) {
|
||||
Q_D(FcitxQtConfigUIFactory);
|
||||
d->scan();
|
||||
}
|
||||
|
||||
FcitxQtConfigUIFactory::~FcitxQtConfigUIFactory()
|
||||
{
|
||||
FcitxQtConfigUIFactory::~FcitxQtConfigUIFactory() {}
|
||||
|
||||
}
|
||||
|
||||
FcitxQtConfigUIWidget* FcitxQtConfigUIFactory::create(const QString& file)
|
||||
{
|
||||
FcitxQtConfigUIWidget *FcitxQtConfigUIFactory::create(const QString &file) {
|
||||
Q_D(FcitxQtConfigUIFactory);
|
||||
|
||||
if (!d->plugins.contains(file))
|
||||
|
@ -60,41 +52,43 @@ FcitxQtConfigUIWidget* FcitxQtConfigUIFactory::create(const QString& file)
|
|||
return d->plugins[file]->create(file);
|
||||
}
|
||||
|
||||
bool FcitxQtConfigUIFactory::test(const QString& file) {
|
||||
bool FcitxQtConfigUIFactory::test(const QString &file) {
|
||||
Q_D(FcitxQtConfigUIFactory);
|
||||
|
||||
return d->plugins.contains(file);
|
||||
}
|
||||
|
||||
void FcitxQtConfigUIFactoryPrivate::scan()
|
||||
{
|
||||
fcitx::StandardPath::global().scanFiles(fcitx::StandardPath::Type::Addon, "qt5", [this] (const std::string &path, const std::string &dirPath, bool user) {
|
||||
do {
|
||||
if (user) {
|
||||
break;
|
||||
}
|
||||
|
||||
QDir dir(QString::fromLocal8Bit(dirPath.c_str()));
|
||||
QFileInfo fi (dir.filePath (QString::fromLocal8Bit(path.c_str())));
|
||||
|
||||
QString filePath = fi.filePath(); // file name with path
|
||||
QString fileName = fi.fileName(); // just file name
|
||||
|
||||
if (!QLibrary::isLibrary (filePath)) {
|
||||
break;
|
||||
}
|
||||
|
||||
QPluginLoader* loader = new QPluginLoader (filePath, this);
|
||||
// qDebug() << loader->load();
|
||||
// qDebug() << loader->errorString();
|
||||
FcitxQtConfigUIFactoryInterface* plugin = qobject_cast< FcitxQtConfigUIFactoryInterface* > (loader->instance());
|
||||
if (plugin) {
|
||||
QStringList list = plugin->files();
|
||||
Q_FOREACH(const QString& s, list) {
|
||||
plugins[s] = plugin;
|
||||
void FcitxQtConfigUIFactoryPrivate::scan() {
|
||||
fcitx::StandardPath::global().scanFiles(
|
||||
fcitx::StandardPath::Type::Addon, "qt5",
|
||||
[this](const std::string &path, const std::string &dirPath, bool user) {
|
||||
do {
|
||||
if (user) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while(0);
|
||||
return true;
|
||||
});
|
||||
|
||||
QDir dir(QString::fromLocal8Bit(dirPath.c_str()));
|
||||
QFileInfo fi(
|
||||
dir.filePath(QString::fromLocal8Bit(path.c_str())));
|
||||
|
||||
QString filePath = fi.filePath(); // file name with path
|
||||
QString fileName = fi.fileName(); // just file name
|
||||
|
||||
if (!QLibrary::isLibrary(filePath)) {
|
||||
break;
|
||||
}
|
||||
|
||||
QPluginLoader *loader = new QPluginLoader(filePath, this);
|
||||
// qDebug() << loader->load();
|
||||
// qDebug() << loader->errorString();
|
||||
FcitxQtConfigUIFactoryInterface *plugin =
|
||||
qobject_cast<FcitxQtConfigUIFactoryInterface *>(
|
||||
loader->instance());
|
||||
if (plugin) {
|
||||
QStringList list = plugin->files();
|
||||
Q_FOREACH (const QString &s, list) { plugins[s] = plugin; }
|
||||
}
|
||||
} while (0);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,20 +20,19 @@
|
|||
#ifndef FCITX_QT_CONFIG_UI_FACTORY_H
|
||||
#define FCITX_QT_CONFIG_UI_FACTORY_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
#include "fcitx5qt5widgetsaddons_export.h"
|
||||
#include "fcitxqtconfiguiwidget.h"
|
||||
#include "fcitxqtconfiguiplugin.h"
|
||||
#include "fcitxqtconfiguiwidget.h"
|
||||
|
||||
class FcitxQtConfigUIFactoryPrivate;
|
||||
/**
|
||||
* ui plugin factory.
|
||||
**/
|
||||
class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactory : public QObject
|
||||
{
|
||||
class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactory : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
/**
|
||||
|
@ -41,7 +40,7 @@ public:
|
|||
*
|
||||
* @param parent object parent
|
||||
**/
|
||||
explicit FcitxQtConfigUIFactory(QObject* parent = 0);
|
||||
explicit FcitxQtConfigUIFactory(QObject *parent = 0);
|
||||
virtual ~FcitxQtConfigUIFactory();
|
||||
/**
|
||||
* create widget based on file name, it might return 0 if there is no match
|
||||
|
@ -49,16 +48,18 @@ public:
|
|||
* @param file file name need to be configured
|
||||
* @return FcitxQtConfigUIWidget*
|
||||
**/
|
||||
FcitxQtConfigUIWidget* create(const QString& file);
|
||||
FcitxQtConfigUIWidget *create(const QString &file);
|
||||
/**
|
||||
* a simplified version of create, but it just test if there is a valid entry or not
|
||||
* a simplified version of create, but it just test if there is a valid
|
||||
*entry or not
|
||||
*
|
||||
* @param file file name
|
||||
* @return bool
|
||||
**/
|
||||
bool test(const QString& file);
|
||||
bool test(const QString &file);
|
||||
|
||||
private:
|
||||
FcitxQtConfigUIFactoryPrivate* d_ptr;
|
||||
FcitxQtConfigUIFactoryPrivate *d_ptr;
|
||||
Q_DECLARE_PRIVATE(FcitxQtConfigUIFactory);
|
||||
};
|
||||
|
||||
|
|
|
@ -20,20 +20,20 @@
|
|||
#ifndef FCITXQTCONFIGUIFACTORY_P_H
|
||||
#define FCITXQTCONFIGUIFACTORY_P_H
|
||||
|
||||
#include <QObject>
|
||||
#include "fcitxqtconfiguifactory.h"
|
||||
#include <QObject>
|
||||
|
||||
class FcitxQtConfigUIFactoryPrivate : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
FcitxQtConfigUIFactoryPrivate(FcitxQtConfigUIFactory* conn);
|
||||
FcitxQtConfigUIFactoryPrivate(FcitxQtConfigUIFactory *conn);
|
||||
virtual ~FcitxQtConfigUIFactoryPrivate();
|
||||
FcitxQtConfigUIFactory * const q_ptr;
|
||||
FcitxQtConfigUIFactory *const q_ptr;
|
||||
Q_DECLARE_PUBLIC(FcitxQtConfigUIFactory);
|
||||
|
||||
private:
|
||||
void scan();
|
||||
QMap<QString, FcitxQtConfigUIFactoryInterface*> plugins;
|
||||
QMap<QString, FcitxQtConfigUIFactoryInterface *> plugins;
|
||||
};
|
||||
|
||||
#endif // FCITXQTCONFIGUIFACTORY_P_H
|
|
@ -19,12 +19,7 @@
|
|||
|
||||
#include "fcitxqtconfiguiplugin.h"
|
||||
|
||||
FcitxQtConfigUIPlugin::FcitxQtConfigUIPlugin(QObject* parent): QObject(parent)
|
||||
{
|
||||
FcitxQtConfigUIPlugin::FcitxQtConfigUIPlugin(QObject *parent)
|
||||
: QObject(parent) {}
|
||||
|
||||
}
|
||||
|
||||
FcitxQtConfigUIPlugin::~FcitxQtConfigUIPlugin()
|
||||
{
|
||||
|
||||
}
|
||||
FcitxQtConfigUIPlugin::~FcitxQtConfigUIPlugin() {}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
#define FCITXQTCONFIGPLUGIN_H
|
||||
|
||||
#include "fcitx5qt5widgetsaddons_export.h"
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
class FcitxQtConfigUIWidget;
|
||||
|
@ -30,8 +30,7 @@ class FcitxQtConfigUIWidget;
|
|||
/**
|
||||
* interface for qt config ui
|
||||
*/
|
||||
struct FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactoryInterface
|
||||
{
|
||||
struct FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactoryInterface {
|
||||
/**
|
||||
* return the name for plugin
|
||||
*/
|
||||
|
@ -44,7 +43,7 @@ struct FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactoryInterface
|
|||
*
|
||||
* @return plugin name
|
||||
*/
|
||||
virtual FcitxQtConfigUIWidget *create( const QString &key ) = 0;
|
||||
virtual FcitxQtConfigUIWidget *create(const QString &key) = 0;
|
||||
|
||||
/**
|
||||
* return a list that this plugin will handle, need to be consist with
|
||||
|
@ -55,19 +54,22 @@ struct FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIFactoryInterface
|
|||
virtual QStringList files() = 0;
|
||||
};
|
||||
|
||||
#define FcitxQtConfigUIFactoryInterface_iid "org.fcitx.Fcitx.FcitxQtConfigUIFactoryInterface"
|
||||
Q_DECLARE_INTERFACE(FcitxQtConfigUIFactoryInterface, FcitxQtConfigUIFactoryInterface_iid)
|
||||
#define FcitxQtConfigUIFactoryInterface_iid \
|
||||
"org.fcitx.Fcitx.FcitxQtConfigUIFactoryInterface"
|
||||
Q_DECLARE_INTERFACE(FcitxQtConfigUIFactoryInterface,
|
||||
FcitxQtConfigUIFactoryInterface_iid)
|
||||
|
||||
/**
|
||||
* base class for qt config ui
|
||||
*/
|
||||
class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIPlugin : public QObject, public FcitxQtConfigUIFactoryInterface {
|
||||
class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIPlugin
|
||||
: public QObject,
|
||||
public FcitxQtConfigUIFactoryInterface {
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(FcitxQtConfigUIFactoryInterface)
|
||||
public:
|
||||
explicit FcitxQtConfigUIPlugin(QObject* parent = 0);
|
||||
explicit FcitxQtConfigUIPlugin(QObject *parent = 0);
|
||||
virtual ~FcitxQtConfigUIPlugin();
|
||||
};
|
||||
|
||||
|
||||
#endif // FCITXCONFIGPLUGIN_H
|
||||
|
|
|
@ -19,17 +19,9 @@
|
|||
|
||||
#include "fcitxqtconfiguiwidget.h"
|
||||
|
||||
FcitxQtConfigUIWidget::FcitxQtConfigUIWidget(QWidget* parent): QWidget(parent)
|
||||
{
|
||||
FcitxQtConfigUIWidget::FcitxQtConfigUIWidget(QWidget *parent)
|
||||
: QWidget(parent) {}
|
||||
|
||||
}
|
||||
QString FcitxQtConfigUIWidget::icon() { return QLatin1String("fcitx"); }
|
||||
|
||||
QString FcitxQtConfigUIWidget::icon()
|
||||
{
|
||||
return QLatin1String("fcitx");
|
||||
}
|
||||
|
||||
bool FcitxQtConfigUIWidget::asyncSave()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool FcitxQtConfigUIWidget::asyncSave() { return false; }
|
||||
|
|
|
@ -28,11 +28,13 @@
|
|||
class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtConfigUIWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FcitxQtConfigUIWidget(QWidget* parent = 0);
|
||||
explicit FcitxQtConfigUIWidget(QWidget *parent = 0);
|
||||
|
||||
/**
|
||||
* load the configuration, usually, this is being called upon a "reset" button clicked
|
||||
* the outer gui will not call it for you for the first time, your initialization might
|
||||
* load the configuration, usually, this is being called upon a "reset"
|
||||
*button clicked
|
||||
* the outer gui will not call it for you for the first time, your
|
||||
*initialization might
|
||||
* want to call it by yourself.
|
||||
*
|
||||
* @return void
|
||||
|
|
|
@ -44,36 +44,34 @@
|
|||
#include "fcitxqtkeysequencewidget.h"
|
||||
#include "fcitxqtkeysequencewidget_p.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QTimer>
|
||||
#include <QHash>
|
||||
#include <QHBoxLayout>
|
||||
#include <QToolButton>
|
||||
#include <QApplication>
|
||||
#include <QMessageBox>
|
||||
#include <QDebug>
|
||||
#include <libintl.h>
|
||||
#include <QHBoxLayout>
|
||||
#include <QHash>
|
||||
#include <QKeyEvent>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include <QToolButton>
|
||||
#include <fcitx-utils/key.h>
|
||||
#include <libintl.h>
|
||||
|
||||
#include "qtkeytrans.h"
|
||||
|
||||
#define _(x) QString::fromUtf8(dgettext("fcitx", x))
|
||||
|
||||
class FcitxQtKeySequenceWidgetPrivate
|
||||
{
|
||||
class FcitxQtKeySequenceWidgetPrivate {
|
||||
public:
|
||||
FcitxQtKeySequenceWidgetPrivate(FcitxQtKeySequenceWidget *q);
|
||||
|
||||
void init();
|
||||
|
||||
static QKeySequence appendToSequence(const QKeySequence& seq, int keyQt);
|
||||
static QKeySequence appendToSequence(const QKeySequence &seq, int keyQt);
|
||||
static bool isOkWhenModifierless(int keyQt);
|
||||
|
||||
void updateShortcutDisplay();
|
||||
void startRecording();
|
||||
|
||||
void controlModifierlessTimout()
|
||||
{
|
||||
void controlModifierlessTimout() {
|
||||
if (nKey != 0 && !modifierKeys) {
|
||||
// No modifier key pressed currently. Start the timout
|
||||
modifierlessTimeout.start(600);
|
||||
|
@ -81,21 +79,18 @@ public:
|
|||
// A modifier is pressed. Stop the timeout
|
||||
modifierlessTimeout.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void cancelRecording()
|
||||
{
|
||||
void cancelRecording() {
|
||||
keySequence = oldKeySequence;
|
||||
side = oldSide;
|
||||
doneRecording();
|
||||
}
|
||||
|
||||
//private slot
|
||||
// private slot
|
||||
void doneRecording(bool validate = true);
|
||||
|
||||
//members
|
||||
// members
|
||||
FcitxQtKeySequenceWidget *const q;
|
||||
QHBoxLayout *layout;
|
||||
FcitxQtKeySequenceButton *keyButton;
|
||||
|
@ -114,41 +109,31 @@ public:
|
|||
FcitxQtModifierSide oldSide;
|
||||
};
|
||||
|
||||
FcitxQtKeySequenceWidgetPrivate::FcitxQtKeySequenceWidgetPrivate(FcitxQtKeySequenceWidget *q)
|
||||
: q(q)
|
||||
,layout(nullptr)
|
||||
,keyButton(nullptr)
|
||||
,clearButton(nullptr)
|
||||
,allowModifierless(false)
|
||||
,nKey(0)
|
||||
,modifierKeys(0)
|
||||
,isRecording(false)
|
||||
,multiKeyShortcutsAllowed(true)
|
||||
,allowModifierOnly(false)
|
||||
,side(MS_Unknown)
|
||||
{}
|
||||
FcitxQtKeySequenceWidgetPrivate::FcitxQtKeySequenceWidgetPrivate(
|
||||
FcitxQtKeySequenceWidget *q)
|
||||
: q(q), layout(nullptr), keyButton(nullptr), clearButton(nullptr),
|
||||
allowModifierless(false), nKey(0), modifierKeys(0), isRecording(false),
|
||||
multiKeyShortcutsAllowed(true), allowModifierOnly(false),
|
||||
side(MS_Unknown) {}
|
||||
|
||||
FcitxQtKeySequenceWidget::FcitxQtKeySequenceWidget(QWidget *parent)
|
||||
: QWidget(parent),
|
||||
d(new FcitxQtKeySequenceWidgetPrivate(this))
|
||||
{
|
||||
: QWidget(parent), d(new FcitxQtKeySequenceWidgetPrivate(this)) {
|
||||
d->init();
|
||||
setFocusProxy( d->keyButton );
|
||||
connect(d->keyButton, &QPushButton::clicked, this, &FcitxQtKeySequenceWidget::captureKeySequence);
|
||||
connect(d->clearButton, &QPushButton::clicked, this, &FcitxQtKeySequenceWidget::clearKeySequence);
|
||||
connect(&d->modifierlessTimeout, &QTimer::timeout, this, [this] () {
|
||||
d->doneRecording();
|
||||
});
|
||||
//TODO: how to adopt style changes at runtime?
|
||||
setFocusProxy(d->keyButton);
|
||||
connect(d->keyButton, &QPushButton::clicked, this,
|
||||
&FcitxQtKeySequenceWidget::captureKeySequence);
|
||||
connect(d->clearButton, &QPushButton::clicked, this,
|
||||
&FcitxQtKeySequenceWidget::clearKeySequence);
|
||||
connect(&d->modifierlessTimeout, &QTimer::timeout, this,
|
||||
[this]() { d->doneRecording(); });
|
||||
// TODO: how to adopt style changes at runtime?
|
||||
/*QFont modFont = d->clearButton->font();
|
||||
modFont.setStyleHint(QFont::TypeWriter);
|
||||
d->clearButton->setFont(modFont);*/
|
||||
d->updateShortcutDisplay();
|
||||
}
|
||||
|
||||
|
||||
void FcitxQtKeySequenceWidgetPrivate::init()
|
||||
{
|
||||
void FcitxQtKeySequenceWidgetPrivate::init() {
|
||||
layout = new QHBoxLayout(q);
|
||||
layout->setMargin(0);
|
||||
|
||||
|
@ -170,72 +155,55 @@ void FcitxQtKeySequenceWidgetPrivate::init()
|
|||
#endif
|
||||
}
|
||||
|
||||
FcitxQtKeySequenceWidget::~FcitxQtKeySequenceWidget() { delete d; }
|
||||
|
||||
FcitxQtKeySequenceWidget::~FcitxQtKeySequenceWidget ()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool FcitxQtKeySequenceWidget::multiKeyShortcutsAllowed() const
|
||||
{
|
||||
bool FcitxQtKeySequenceWidget::multiKeyShortcutsAllowed() const {
|
||||
return d->multiKeyShortcutsAllowed;
|
||||
}
|
||||
|
||||
|
||||
void FcitxQtKeySequenceWidget::setMultiKeyShortcutsAllowed(bool allowed)
|
||||
{
|
||||
void FcitxQtKeySequenceWidget::setMultiKeyShortcutsAllowed(bool allowed) {
|
||||
d->multiKeyShortcutsAllowed = allowed;
|
||||
}
|
||||
|
||||
void FcitxQtKeySequenceWidget::setModifierlessAllowed(bool allow)
|
||||
{
|
||||
void FcitxQtKeySequenceWidget::setModifierlessAllowed(bool allow) {
|
||||
d->allowModifierless = allow;
|
||||
}
|
||||
|
||||
bool FcitxQtKeySequenceWidget::isModifierlessAllowed()
|
||||
{
|
||||
bool FcitxQtKeySequenceWidget::isModifierlessAllowed() {
|
||||
return d->allowModifierless;
|
||||
}
|
||||
|
||||
bool FcitxQtKeySequenceWidget::isModifierOnlyAllowed()
|
||||
{
|
||||
bool FcitxQtKeySequenceWidget::isModifierOnlyAllowed() {
|
||||
return d->allowModifierOnly;
|
||||
}
|
||||
|
||||
void FcitxQtKeySequenceWidget::setModifierOnlyAllowed(bool allow)
|
||||
{
|
||||
void FcitxQtKeySequenceWidget::setModifierOnlyAllowed(bool allow) {
|
||||
d->allowModifierOnly = allow;
|
||||
}
|
||||
|
||||
FcitxQtModifierSide FcitxQtKeySequenceWidget::modifierSide()
|
||||
{
|
||||
return d->side;
|
||||
}
|
||||
FcitxQtModifierSide FcitxQtKeySequenceWidget::modifierSide() { return d->side; }
|
||||
|
||||
void FcitxQtKeySequenceWidget::setClearButtonShown(bool show)
|
||||
{
|
||||
void FcitxQtKeySequenceWidget::setClearButtonShown(bool show) {
|
||||
d->clearButton->setVisible(show);
|
||||
}
|
||||
|
||||
//slot
|
||||
void FcitxQtKeySequenceWidget::captureKeySequence()
|
||||
{
|
||||
d->startRecording();
|
||||
}
|
||||
// slot
|
||||
void FcitxQtKeySequenceWidget::captureKeySequence() { d->startRecording(); }
|
||||
|
||||
|
||||
QKeySequence FcitxQtKeySequenceWidget::keySequence() const
|
||||
{
|
||||
QKeySequence FcitxQtKeySequenceWidget::keySequence() const {
|
||||
return d->keySequence;
|
||||
}
|
||||
|
||||
|
||||
//slot
|
||||
void FcitxQtKeySequenceWidget::setKeySequence(const QKeySequence& seq, FcitxQtModifierSide side, FcitxQtKeySequenceWidget::Validation validate)
|
||||
{
|
||||
// oldKeySequence holds the key sequence before recording started, if setKeySequence()
|
||||
// is called while not recording then set oldKeySequence to the existing sequence so
|
||||
// that the keySequenceChanged() signal is emitted if the new and previous key
|
||||
// slot
|
||||
void FcitxQtKeySequenceWidget::setKeySequence(
|
||||
const QKeySequence &seq, FcitxQtModifierSide side,
|
||||
FcitxQtKeySequenceWidget::Validation validate) {
|
||||
// oldKeySequence holds the key sequence before recording started, if
|
||||
// setKeySequence()
|
||||
// is called while not recording then set oldKeySequence to the existing
|
||||
// sequence so
|
||||
// that the keySequenceChanged() signal is emitted if the new and previous
|
||||
// key
|
||||
// sequences are different
|
||||
if (!d->isRecording) {
|
||||
d->oldKeySequence = d->keySequence;
|
||||
|
@ -247,16 +215,13 @@ void FcitxQtKeySequenceWidget::setKeySequence(const QKeySequence& seq, FcitxQtMo
|
|||
d->doneRecording(validate == Validate);
|
||||
}
|
||||
|
||||
|
||||
//slot
|
||||
void FcitxQtKeySequenceWidget::clearKeySequence()
|
||||
{
|
||||
// slot
|
||||
void FcitxQtKeySequenceWidget::clearKeySequence() {
|
||||
setKeySequence(QKeySequence());
|
||||
d->side = MS_Unknown;
|
||||
}
|
||||
|
||||
void FcitxQtKeySequenceWidgetPrivate::startRecording()
|
||||
{
|
||||
void FcitxQtKeySequenceWidgetPrivate::startRecording() {
|
||||
nKey = 0;
|
||||
modifierKeys = 0;
|
||||
oldKeySequence = keySequence;
|
||||
|
@ -267,22 +232,22 @@ void FcitxQtKeySequenceWidgetPrivate::startRecording()
|
|||
keyButton->grabKeyboard();
|
||||
|
||||
if (!QWidget::keyboardGrabber()) {
|
||||
qWarning() << "Failed to grab the keyboard! Most likely qt's nograb option is active";
|
||||
qWarning() << "Failed to grab the keyboard! Most likely qt's nograb "
|
||||
"option is active";
|
||||
}
|
||||
|
||||
keyButton->setDown(true);
|
||||
updateShortcutDisplay();
|
||||
}
|
||||
|
||||
|
||||
void FcitxQtKeySequenceWidgetPrivate::doneRecording(bool validate)
|
||||
{
|
||||
void FcitxQtKeySequenceWidgetPrivate::doneRecording(bool validate) {
|
||||
modifierlessTimeout.stop();
|
||||
isRecording = false;
|
||||
keyButton->releaseKeyboard();
|
||||
keyButton->setDown(false);
|
||||
|
||||
if (keySequence==oldKeySequence && (oldSide == side || !allowModifierOnly)) {
|
||||
if (keySequence == oldKeySequence &&
|
||||
(oldSide == side || !allowModifierOnly)) {
|
||||
// The sequence hasn't changed
|
||||
updateShortcutDisplay();
|
||||
return;
|
||||
|
@ -293,24 +258,24 @@ void FcitxQtKeySequenceWidgetPrivate::doneRecording(bool validate)
|
|||
updateShortcutDisplay();
|
||||
}
|
||||
|
||||
|
||||
void FcitxQtKeySequenceWidgetPrivate::updateShortcutDisplay()
|
||||
{
|
||||
void FcitxQtKeySequenceWidgetPrivate::updateShortcutDisplay() {
|
||||
do {
|
||||
if (keySequence.count() != 1) {
|
||||
break;
|
||||
}
|
||||
int key = keySequence[0] & (~Qt::KeyboardModifierMask);
|
||||
if (key == Qt::Key_Shift
|
||||
|| key == Qt::Key_Control
|
||||
|| key == Qt::Key_Meta
|
||||
|| key == Qt::Key_Alt) {
|
||||
if (key == Qt::Key_Shift || key == Qt::Key_Control ||
|
||||
key == Qt::Key_Meta || key == Qt::Key_Alt) {
|
||||
QString s;
|
||||
int mod = keySequence[0] & (Qt::KeyboardModifierMask);
|
||||
if (mod & Qt::META && key != Qt::Key_Meta) s += "Meta+";
|
||||
if (mod & Qt::CTRL && key != Qt::Key_Control) s += "Ctrl+";
|
||||
if (mod & Qt::ALT && key != Qt::Key_Alt) s += "Alt+";
|
||||
if (mod & Qt::SHIFT && key != Qt::Key_Shift) s += "Shift+";
|
||||
if (mod & Qt::META && key != Qt::Key_Meta)
|
||||
s += "Meta+";
|
||||
if (mod & Qt::CTRL && key != Qt::Key_Control)
|
||||
s += "Ctrl+";
|
||||
if (mod & Qt::ALT && key != Qt::Key_Alt)
|
||||
s += "Alt+";
|
||||
if (mod & Qt::SHIFT && key != Qt::Key_Shift)
|
||||
s += "Shift+";
|
||||
|
||||
if (side == MS_Left) {
|
||||
s += _("Left") + " ";
|
||||
|
@ -318,41 +283,46 @@ void FcitxQtKeySequenceWidgetPrivate::updateShortcutDisplay()
|
|||
s += _("Right") + " ";
|
||||
}
|
||||
|
||||
switch(key) {
|
||||
case Qt::Key_Shift:
|
||||
s += "Shift";
|
||||
break;
|
||||
case Qt::Key_Control:
|
||||
s += "Ctrl";
|
||||
break;
|
||||
case Qt::Key_Meta:
|
||||
s += "Meta";
|
||||
break;
|
||||
case Qt::Key_Alt:
|
||||
s += "Alt";
|
||||
break;
|
||||
switch (key) {
|
||||
case Qt::Key_Shift:
|
||||
s += "Shift";
|
||||
break;
|
||||
case Qt::Key_Control:
|
||||
s += "Ctrl";
|
||||
break;
|
||||
case Qt::Key_Meta:
|
||||
s += "Meta";
|
||||
break;
|
||||
case Qt::Key_Alt:
|
||||
s += "Alt";
|
||||
break;
|
||||
}
|
||||
keyButton->setText(s);
|
||||
return;
|
||||
}
|
||||
} while(0);
|
||||
} while (0);
|
||||
|
||||
//empty string if no non-modifier was pressed
|
||||
// empty string if no non-modifier was pressed
|
||||
QString s = keySequence.toString(QKeySequence::NativeText);
|
||||
s.replace('&', QLatin1String("&&"));
|
||||
|
||||
if (isRecording) {
|
||||
if (modifierKeys) {
|
||||
if (!s.isEmpty()) s.append(",");
|
||||
if (modifierKeys & Qt::META) s += "Meta+";
|
||||
if (modifierKeys & Qt::CTRL) s += "Ctrl+";
|
||||
if (modifierKeys & Qt::ALT) s += "Alt+";
|
||||
if (modifierKeys & Qt::SHIFT) s += "Shift+";
|
||||
if (!s.isEmpty())
|
||||
s.append(",");
|
||||
if (modifierKeys & Qt::META)
|
||||
s += "Meta+";
|
||||
if (modifierKeys & Qt::CTRL)
|
||||
s += "Ctrl+";
|
||||
if (modifierKeys & Qt::ALT)
|
||||
s += "Alt+";
|
||||
if (modifierKeys & Qt::SHIFT)
|
||||
s += "Shift+";
|
||||
|
||||
} else if (nKey == 0) {
|
||||
s = "...";
|
||||
}
|
||||
//make it clear that input is still going on
|
||||
// make it clear that input is still going on
|
||||
s.append(" ...");
|
||||
}
|
||||
|
||||
|
@ -365,15 +335,10 @@ void FcitxQtKeySequenceWidgetPrivate::updateShortcutDisplay()
|
|||
keyButton->setText(s);
|
||||
}
|
||||
|
||||
FcitxQtKeySequenceButton::~FcitxQtKeySequenceButton() {}
|
||||
|
||||
FcitxQtKeySequenceButton::~FcitxQtKeySequenceButton()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//prevent Qt from special casing Tab and Backtab
|
||||
bool FcitxQtKeySequenceButton::event (QEvent* e)
|
||||
{
|
||||
// prevent Qt from special casing Tab and Backtab
|
||||
bool FcitxQtKeySequenceButton::event(QEvent *e) {
|
||||
if (d->isRecording && e->type() == QEvent::KeyPress) {
|
||||
keyPressEvent(static_cast<QKeyEvent *>(e));
|
||||
return true;
|
||||
|
@ -391,25 +356,28 @@ bool FcitxQtKeySequenceButton::event (QEvent* e)
|
|||
return QPushButton::event(e);
|
||||
}
|
||||
|
||||
|
||||
void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e)
|
||||
{
|
||||
void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e) {
|
||||
int keyQt = e->key();
|
||||
if (keyQt == -1) {
|
||||
// Qt sometimes returns garbage keycodes, I observed -1, if it doesn't know a key.
|
||||
// We cannot do anything useful with those (several keys have -1, indistinguishable)
|
||||
// Qt sometimes returns garbage keycodes, I observed -1, if it doesn't
|
||||
// know a key.
|
||||
// We cannot do anything useful with those (several keys have -1,
|
||||
// indistinguishable)
|
||||
// and QKeySequence.toString() will also yield a garbage string.
|
||||
QMessageBox::warning(this,
|
||||
_("The key you just pressed is not supported by Qt."),
|
||||
_("Unsupported Key"));
|
||||
QMessageBox::warning(
|
||||
this, _("The key you just pressed is not supported by Qt."),
|
||||
_("Unsupported Key"));
|
||||
return d->cancelRecording();
|
||||
}
|
||||
|
||||
uint newModifiers = e->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
|
||||
uint newModifiers =
|
||||
e->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
|
||||
|
||||
//don't have the return or space key appear as first key of the sequence when they
|
||||
//were pressed to start editing - catch and them and imitate their effect
|
||||
if (!d->isRecording && ((keyQt == Qt::Key_Return || keyQt == Qt::Key_Space))) {
|
||||
// don't have the return or space key appear as first key of the sequence
|
||||
// when they
|
||||
// were pressed to start editing - catch and them and imitate their effect
|
||||
if (!d->isRecording &&
|
||||
((keyQt == Qt::Key_Return || keyQt == Qt::Key_Space))) {
|
||||
d->startRecording();
|
||||
d->modifierKeys = newModifiers;
|
||||
d->updateShortcutDisplay();
|
||||
|
@ -423,15 +391,14 @@ void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e)
|
|||
e->accept();
|
||||
d->modifierKeys = newModifiers;
|
||||
|
||||
|
||||
switch(keyQt) {
|
||||
case Qt::Key_AltGr: //or else we get unicode salad
|
||||
switch (keyQt) {
|
||||
case Qt::Key_AltGr: // or else we get unicode salad
|
||||
return;
|
||||
case Qt::Key_Shift:
|
||||
case Qt::Key_Control:
|
||||
case Qt::Key_Alt:
|
||||
case Qt::Key_Meta:
|
||||
case Qt::Key_Menu: //unused (yes, but why?)
|
||||
case Qt::Key_Menu: // unused (yes, but why?)
|
||||
d->controlModifierlessTimout();
|
||||
d->updateShortcutDisplay();
|
||||
break;
|
||||
|
@ -440,8 +407,9 @@ void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e)
|
|||
if (d->nKey == 0 && !(d->modifierKeys & ~Qt::SHIFT)) {
|
||||
// It's the first key and no modifier pressed. Check if this is
|
||||
// allowed
|
||||
if (!(FcitxQtKeySequenceWidgetPrivate::isOkWhenModifierless(keyQt)
|
||||
|| d->allowModifierless)) {
|
||||
if (!(FcitxQtKeySequenceWidgetPrivate::isOkWhenModifierless(
|
||||
keyQt) ||
|
||||
d->allowModifierless)) {
|
||||
// No it's not
|
||||
return;
|
||||
}
|
||||
|
@ -451,8 +419,7 @@ void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e)
|
|||
if (keyQt) {
|
||||
if ((keyQt == Qt::Key_Backtab) && (d->modifierKeys & Qt::SHIFT)) {
|
||||
keyQt = Qt::Key_Tab | d->modifierKeys;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
keyQt |= d->modifierKeys;
|
||||
}
|
||||
|
||||
|
@ -460,7 +427,8 @@ void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e)
|
|||
d->keySequence = QKeySequence(keyQt);
|
||||
} else {
|
||||
d->keySequence =
|
||||
FcitxQtKeySequenceWidgetPrivate::appendToSequence(d->keySequence, keyQt);
|
||||
FcitxQtKeySequenceWidgetPrivate::appendToSequence(
|
||||
d->keySequence, keyQt);
|
||||
}
|
||||
|
||||
d->nKey++;
|
||||
|
@ -474,9 +442,7 @@ void FcitxQtKeySequenceButton::keyPressEvent(QKeyEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void FcitxQtKeySequenceButton::keyReleaseEvent(QKeyEvent *e)
|
||||
{
|
||||
void FcitxQtKeySequenceButton::keyReleaseEvent(QKeyEvent *e) {
|
||||
if (e->key() == -1) {
|
||||
// ignore garbage, see keyPressEvent()
|
||||
return;
|
||||
|
@ -487,26 +453,23 @@ void FcitxQtKeySequenceButton::keyReleaseEvent(QKeyEvent *e)
|
|||
|
||||
e->accept();
|
||||
|
||||
if (!d->multiKeyShortcutsAllowed
|
||||
&& d->allowModifierOnly
|
||||
&& (e->key() == Qt::Key_Shift
|
||||
|| e->key() == Qt::Key_Control
|
||||
|| e->key() == Qt::Key_Meta
|
||||
|| e->key() == Qt::Key_Alt)) {
|
||||
if (!d->multiKeyShortcutsAllowed && d->allowModifierOnly &&
|
||||
(e->key() == Qt::Key_Shift || e->key() == Qt::Key_Control ||
|
||||
e->key() == Qt::Key_Meta || e->key() == Qt::Key_Alt)) {
|
||||
d->side = MS_Unknown;
|
||||
|
||||
if (qApp->platformName() == "xcb") {
|
||||
|
||||
if (e->nativeVirtualKey() == FcitxKey_Control_L
|
||||
|| e->nativeVirtualKey() == FcitxKey_Alt_L
|
||||
|| e->nativeVirtualKey() == FcitxKey_Shift_L
|
||||
|| e->nativeVirtualKey() == FcitxKey_Super_L) {
|
||||
if (e->nativeVirtualKey() == FcitxKey_Control_L ||
|
||||
e->nativeVirtualKey() == FcitxKey_Alt_L ||
|
||||
e->nativeVirtualKey() == FcitxKey_Shift_L ||
|
||||
e->nativeVirtualKey() == FcitxKey_Super_L) {
|
||||
d->side = MS_Left;
|
||||
}
|
||||
if (e->nativeVirtualKey() == FcitxKey_Control_R
|
||||
|| e->nativeVirtualKey() == FcitxKey_Alt_R
|
||||
|| e->nativeVirtualKey() == FcitxKey_Shift_R
|
||||
|| e->nativeVirtualKey() == FcitxKey_Super_R) {
|
||||
if (e->nativeVirtualKey() == FcitxKey_Control_R ||
|
||||
e->nativeVirtualKey() == FcitxKey_Alt_R ||
|
||||
e->nativeVirtualKey() == FcitxKey_Shift_R ||
|
||||
e->nativeVirtualKey() == FcitxKey_Super_R) {
|
||||
d->side = MS_Right;
|
||||
}
|
||||
}
|
||||
|
@ -516,10 +479,10 @@ void FcitxQtKeySequenceButton::keyReleaseEvent(QKeyEvent *e)
|
|||
return;
|
||||
}
|
||||
|
||||
uint newModifiers =
|
||||
e->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
|
||||
|
||||
uint newModifiers = e->modifiers() & (Qt::SHIFT | Qt::CTRL | Qt::ALT | Qt::META);
|
||||
|
||||
//if a modifier that belongs to the shortcut was released...
|
||||
// if a modifier that belongs to the shortcut was released...
|
||||
if ((newModifiers & d->modifierKeys) < d->modifierKeys) {
|
||||
d->modifierKeys = newModifiers;
|
||||
d->controlModifierlessTimout();
|
||||
|
@ -527,10 +490,10 @@ void FcitxQtKeySequenceButton::keyReleaseEvent(QKeyEvent *e)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
QKeySequence FcitxQtKeySequenceWidgetPrivate::appendToSequence(const QKeySequence& seq, int keyQt)
|
||||
{
|
||||
// static
|
||||
QKeySequence
|
||||
FcitxQtKeySequenceWidgetPrivate::appendToSequence(const QKeySequence &seq,
|
||||
int keyQt) {
|
||||
switch (seq.count()) {
|
||||
case 0:
|
||||
return QKeySequence(keyQt);
|
||||
|
@ -545,11 +508,9 @@ QKeySequence FcitxQtKeySequenceWidgetPrivate::appendToSequence(const QKeySequenc
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
//static
|
||||
bool FcitxQtKeySequenceWidgetPrivate::isOkWhenModifierless(int keyQt)
|
||||
{
|
||||
//this whole function is a hack, but especially the first line of code
|
||||
// static
|
||||
bool FcitxQtKeySequenceWidgetPrivate::isOkWhenModifierless(int keyQt) {
|
||||
// this whole function is a hack, but especially the first line of code
|
||||
if (QKeySequence(keyQt).toString().length() == 1)
|
||||
return false;
|
||||
|
||||
|
@ -557,7 +518,7 @@ bool FcitxQtKeySequenceWidgetPrivate::isOkWhenModifierless(int keyQt)
|
|||
case Qt::Key_Return:
|
||||
case Qt::Key_Space:
|
||||
case Qt::Key_Tab:
|
||||
case Qt::Key_Backtab: //does this ever happen?
|
||||
case Qt::Key_Backtab: // does this ever happen?
|
||||
case Qt::Key_Backspace:
|
||||
case Qt::Key_Delete:
|
||||
return false;
|
||||
|
@ -566,41 +527,39 @@ bool FcitxQtKeySequenceWidgetPrivate::isOkWhenModifierless(int keyQt)
|
|||
}
|
||||
}
|
||||
|
||||
void FcitxQtKeySequenceWidget::keyQtToFcitx(int keyQt, FcitxQtModifierSide side, int& outsym, uint& outstate)
|
||||
{
|
||||
void FcitxQtKeySequenceWidget::keyQtToFcitx(int keyQt, FcitxQtModifierSide side,
|
||||
int &outsym, uint &outstate) {
|
||||
int key = keyQt & (~Qt::KeyboardModifierMask);
|
||||
int state = keyQt & Qt::KeyboardModifierMask;
|
||||
int sym = 0;
|
||||
keyQtToSym(key, Qt::KeyboardModifiers(state), sym, outstate);
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
outsym = sym;
|
||||
}
|
||||
|
||||
int FcitxQtKeySequenceWidget::keyFcitxToQt(int sym, uint state)
|
||||
{
|
||||
int FcitxQtKeySequenceWidget::keyFcitxToQt(int sym, uint state) {
|
||||
Qt::KeyboardModifiers qstate = Qt::NoModifier;
|
||||
|
||||
int key;
|
||||
symToKeyQt((int) sym, state, key, qstate);
|
||||
symToKeyQt((int)sym, state, key, qstate);
|
||||
|
||||
return key | qstate;
|
||||
}
|
||||
|
||||
|
||||
#include "moc_fcitxqtkeysequencewidget.cpp"
|
||||
|
|
|
@ -49,38 +49,24 @@
|
|||
|
||||
#include "fcitx5qt5widgetsaddons_export.h"
|
||||
|
||||
enum FcitxQtModifierSide {
|
||||
MS_Unknown = 0,
|
||||
MS_Left = 1,
|
||||
MS_Right = 2
|
||||
};
|
||||
enum FcitxQtModifierSide { MS_Unknown = 0, MS_Left = 1, MS_Right = 2 };
|
||||
|
||||
class FcitxQtKeySequenceWidgetPrivate;
|
||||
|
||||
class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtKeySequenceWidget: public QWidget
|
||||
{
|
||||
class FCITX5QT5WIDGETSADDONS_EXPORT FcitxQtKeySequenceWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(
|
||||
bool multiKeyShortcutsAllowed
|
||||
READ multiKeyShortcutsAllowed
|
||||
WRITE setMultiKeyShortcutsAllowed )
|
||||
Q_PROPERTY(bool multiKeyShortcutsAllowed READ multiKeyShortcutsAllowed WRITE
|
||||
setMultiKeyShortcutsAllowed)
|
||||
|
||||
Q_PROPERTY(
|
||||
bool modifierlessAllowed
|
||||
READ isModifierlessAllowed
|
||||
WRITE setModifierlessAllowed )
|
||||
Q_PROPERTY(bool modifierlessAllowed READ isModifierlessAllowed WRITE
|
||||
setModifierlessAllowed)
|
||||
|
||||
Q_PROPERTY(
|
||||
bool modifierOnlyAllowed
|
||||
READ isModifierOnlyAllowed
|
||||
WRITE setModifierOnlyAllowed )
|
||||
Q_PROPERTY(bool modifierOnlyAllowed READ isModifierOnlyAllowed WRITE
|
||||
setModifierOnlyAllowed)
|
||||
|
||||
public:
|
||||
enum Validation {
|
||||
Validate = 0,
|
||||
NoValidate = 1
|
||||
};
|
||||
enum Validation { Validate = 0, NoValidate = 1 };
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
|
@ -111,7 +97,8 @@ public:
|
|||
|
||||
QKeySequence keySequence() const;
|
||||
|
||||
static void keyQtToFcitx(int keyQt, FcitxQtModifierSide side, int& outsym, uint& outstate);
|
||||
static void keyQtToFcitx(int keyQt, FcitxQtModifierSide side, int &outsym,
|
||||
uint &outstate);
|
||||
static int keyFcitxToQt(int sym, uint state);
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -119,7 +106,9 @@ Q_SIGNALS:
|
|||
|
||||
public Q_SLOTS:
|
||||
void captureKeySequence();
|
||||
void setKeySequence(const QKeySequence &seq, FcitxQtModifierSide side = MS_Unknown, Validation val = NoValidate);
|
||||
void setKeySequence(const QKeySequence &seq,
|
||||
FcitxQtModifierSide side = MS_Unknown,
|
||||
Validation val = NoValidate);
|
||||
void clearKeySequence();
|
||||
|
||||
private:
|
||||
|
@ -129,4 +118,4 @@ private:
|
|||
Q_DISABLE_COPY(FcitxQtKeySequenceWidget)
|
||||
};
|
||||
|
||||
#endif //KKEYSEQUENCEWIDGET_H
|
||||
#endif // KKEYSEQUENCEWIDGET_H
|
||||
|
|
|
@ -42,19 +42,18 @@
|
|||
#ifndef FCITXQT_KEYSEQUENCEWIDGET_P_H
|
||||
#define FCITXQT_KEYSEQUENCEWIDGET_P_H
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QHBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QToolButton>
|
||||
|
||||
class FcitxQtKeySequenceWidgetPrivate;
|
||||
class FcitxQtKeySequenceButton: public QPushButton
|
||||
{
|
||||
class FcitxQtKeySequenceButton : public QPushButton {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FcitxQtKeySequenceButton(FcitxQtKeySequenceWidgetPrivate *d, QWidget *parent)
|
||||
: QPushButton(parent),
|
||||
d(d) {}
|
||||
explicit FcitxQtKeySequenceButton(FcitxQtKeySequenceWidgetPrivate *d,
|
||||
QWidget *parent)
|
||||
: QPushButton(parent), d(d) {}
|
||||
|
||||
virtual ~FcitxQtKeySequenceButton();
|
||||
|
||||
|
@ -62,7 +61,7 @@ protected:
|
|||
/**
|
||||
* Reimplemented for internal reasons.
|
||||
*/
|
||||
virtual bool event (QEvent *event);
|
||||
virtual bool event(QEvent *event);
|
||||
virtual void keyPressEvent(QKeyEvent *event);
|
||||
virtual void keyReleaseEvent(QKeyEvent *event);
|
||||
|
||||
|
@ -70,4 +69,4 @@ private:
|
|||
FcitxQtKeySequenceWidgetPrivate *const d;
|
||||
};
|
||||
|
||||
#endif //FCITXQT_KEYSEQUENCEWIDGET_P_H
|
||||
#endif // FCITXQT_KEYSEQUENCEWIDGET_P_H
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -21,8 +21,10 @@
|
|||
#define QTKEYTRANS_H
|
||||
#include <qnamespace.h>
|
||||
|
||||
bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, int& sym, unsigned int& state);
|
||||
bool keyQtToSym(int qtcode, Qt::KeyboardModifiers mod, int &sym,
|
||||
unsigned int &state);
|
||||
|
||||
bool symToKeyQt(int sym, unsigned int state, int& qtcode, Qt::KeyboardModifiers& mod);
|
||||
bool symToKeyQt(int sym, unsigned int state, int &qtcode,
|
||||
Qt::KeyboardModifiers &mod);
|
||||
|
||||
#endif
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue