1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*
* SPDX-FileCopyrightText: 2011~2011 CSSlayer <wengxt@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
/* this file is based on from libgnomekbd/libgnomekbd/gkbd-keyboard-drawing.c */
#ifndef KEYBOARDLAYOUTWIDGET_H
#define KEYBOARDLAYOUTWIDGET_H
#include <QMap>
#include <QWidget>
#include <vector>
class QPainter;
struct Doodad;
struct _XkbDesc;
struct _XkbShapeDoodad;
union _XkbDoodad;
typedef enum {
KEYBOARD_DRAWING_ITEM_TYPE_INVALID = 0,
KEYBOARD_DRAWING_ITEM_TYPE_KEY,
KEYBOARD_DRAWING_ITEM_TYPE_KEY_EXTRA,
KEYBOARD_DRAWING_ITEM_TYPE_DOODAD
} KeyboardDrawingItemType;
typedef enum {
KEYBOARD_DRAWING_POS_TOPLEFT,
KEYBOARD_DRAWING_POS_TOPRIGHT,
KEYBOARD_DRAWING_POS_BOTTOMLEFT,
KEYBOARD_DRAWING_POS_BOTTOMRIGHT,
KEYBOARD_DRAWING_POS_TOTAL,
KEYBOARD_DRAWING_POS_FIRST = KEYBOARD_DRAWING_POS_TOPLEFT,
KEYBOARD_DRAWING_POS_LAST = KEYBOARD_DRAWING_POS_BOTTOMRIGHT
} KeyboardDrawingGroupLevelPosition;
namespace fcitx {
namespace kcm {
struct DrawingItem {
DrawingItem()
: type(KEYBOARD_DRAWING_ITEM_TYPE_INVALID), originX(0), originY(0),
angle(0), priority(0) {}
virtual ~DrawingItem() {}
KeyboardDrawingItemType type;
int originX;
int originY;
int angle;
unsigned int priority;
};
struct Doodad : public DrawingItem {
Doodad() : doodad(0), on(0) {}
union _XkbDoodad *doodad;
int on;
};
struct DrawingKey : public DrawingItem {
DrawingKey() : xkbkey(0), pressed(false), keycode(0) {}
struct _XkbKey *xkbkey;
bool pressed;
unsigned int keycode;
};
struct KeyboardDrawingGroupLevel {
int group;
int level;
};
class KeyboardLayoutWidget : public QWidget {
Q_OBJECT
public:
explicit KeyboardLayoutWidget(QWidget *parent = 0);
virtual ~KeyboardLayoutWidget();
void setGroup(int group);
void setKeyboardLayout(const QString &layout, const QString &variant);
void generatePixmap(bool force = false);
protected:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void paintEvent(QPaintEvent *event) override;
void init();
void alloc();
void release();
void initInicatorDoodad(union _XkbDoodad *xkbdoodad, Doodad &doodad);
unsigned int findKeycode(const char *keyName);
void rotateRectangle(int origin_x, int origin_y, int x, int y, int angle,
int &rotated_x, int &rotated_y);
bool parseXkbColorSpec(char *colorspec, QColor &color);
void initColors();
void focusOutEvent(QFocusEvent *event) override;
void drawKey(QPainter *painter, DrawingKey *item);
void drawDoodad(QPainter *painter, Doodad *doodad);
void drawKeyLabel(QPainter *painter, unsigned int keycode, int angle,
int arg4, int originY, int x2, int y2, bool pressed);
void drawKeyLabelHelper(QPainter *painter, const QString &text, int angle,
int glp, int end_glp, int x, int y, int width,
int height, int padding, bool is_pressed);
void drawShapeDoodad(QPainter *painter, Doodad *doodad,
struct _XkbShapeDoodad *shapeDoodad);
void drawTextDoodad(QPainter *painter, Doodad *doodad,
struct _XkbTextDoodad *textDoodad);
void drawIndicatorDoodad(QPainter *painter, Doodad *doodad,
struct _XkbIndicatorDoodad *indicatorDoodad);
int calcShapeOriginOffsetX(struct _XkbOutline *outline);
void drawOutline(QPainter *painter, struct _XkbOutline *outline,
QColor color, int angle, int originX, int originY);
void drawRectangle(QPainter *painter, QColor color, int angle, int xkb_x,
int xkb_y, int xkb_width, int xkb_height,
unsigned int radius);
void drawPolygon(QPainter *painter, QColor color, int originX, int originY,
struct _XkbPoint *points, unsigned int num_points,
unsigned int radius);
void rotateCoordinate(int originX, int originY, int x, int y, int angle,
int *rotated_x, int *rotated_y);
int xkbToPixmapCoord(int n);
double xkbToPixmapDouble(double d);
void roundedPolygon(QPainter *painter, bool filled, double radius,
const std::vector<QPointF> &points);
void drawCurveRectangle(QPainter *painter, bool filled, QColor color, int x,
int y, int width, int height, double radius);
void roundedCorner(QPainterPath &path, QPointF b, QPointF c, double radius);
void resizeEvent(QResizeEvent *event) override;
void setKeyboard(struct _XkbComponentNames *xkbDesc);
private:
void keyEvent(QKeyEvent *keyEvent);
QString keySymToString(unsigned long keysym);
QList<DrawingItem *> keyboardItems;
std::vector<DrawingKey> keys;
QList<Doodad *> physicalIndicators;
struct _XkbDesc *xkb = nullptr;
unsigned int l3mod = 0;
std::vector<QColor> colors;
QPixmap image;
double ratio = 1.0;
KeyboardDrawingGroupLevel **groupLevels;
bool trackModifiers = false;
int mods;
QMap<unsigned int, unsigned int> deadMap;
};
} // namespace kcm
} // namespace fcitx
#endif
|