예제 #1
0
파일: hotkey.c 프로젝트: Axure/fcitx
/*
 * Do some custom process
 */
FCITX_EXPORT_API
void FcitxHotkeyGetKey(FcitxKeySym keysym, unsigned int iKeyState, FcitxKeySym* outk, unsigned int* outs)
{
    /* key state != 0 */
    if (iKeyState) {
        if (iKeyState != FcitxKeyState_Shift && FcitxHotkeyIsHotKeyLAZ(keysym, 0))
            keysym = keysym + FcitxKey_A - FcitxKey_a;
        /*
         * alt shift 1 shoud be alt + !
         * shift+s should be S
         */

        if (FcitxHotkeyIsHotKeyLAZ(keysym, 0) || FcitxHotkeyIsHotKeyUAZ(keysym, 0)) {
            if (iKeyState == FcitxKeyState_Shift)
                iKeyState &= ~FcitxKeyState_Shift;
        }
        else {
            if ((iKeyState & FcitxKeyState_Shift)
                && (((FcitxHotkeyIsHotKeySimple(keysym, 0) || FcitxKeySymToUnicode(keysym) != 0)
                    && keysym != FcitxKey_space && keysym != FcitxKey_Return)
                    || (keysym >= FcitxKey_KP_0 && keysym <= FcitxKey_KP_9)))
                iKeyState &= ~FcitxKeyState_Shift;
        }
    }

    if (keysym == FcitxKey_ISO_Left_Tab)
        keysym = FcitxKey_Tab;

    *outk = keysym;

    *outs = iKeyState;
}
예제 #2
0
void KeyboardLayoutWidget::drawKeyLabelHelper(QPainter* painter, int keysym, int angle, int glp, int x, int y, int width, int height, int padding, bool is_pressed)
{
    if (keysym == 0)
        return;

    if (keysym == XK_VoidSymbol)
        return;

    if (padding >= height / 2)
        padding = 0;
    if (padding >= width / 2)
        padding = 0;

    Qt::Alignment align;

    QRectF rect(padding, padding, (width - 2 * padding), (height - 2 * padding));
    switch (glp) {
    case KEYBOARD_DRAWING_POS_TOPLEFT:
        align = Qt::AlignTop | Qt::AlignLeft;
        break;
    case KEYBOARD_DRAWING_POS_BOTTOMLEFT:
        align = Qt::AlignBottom | Qt::AlignLeft;
        break;
    case KEYBOARD_DRAWING_POS_TOPRIGHT:
        align = Qt::AlignTop | Qt::AlignRight;
        break;
    case KEYBOARD_DRAWING_POS_BOTTOMRIGHT:
        align = Qt::AlignBottom | Qt::AlignRight;
        break;
    default:
        return;
    }

    if (keysym == XK_ISO_Left_Tab)
        keysym = XK_Tab;

    keysym = (int) FcitxHotkeyPadToMain((FcitxKeySym) keysym);
    uint32_t unicode = FcitxKeySymToUnicode((FcitxKeySym) keysym);

    if (deadMap.contains(keysym)) {
        unicode = deadMap[keysym];
    }
    QString text;
    if (unicode
        && QChar(unicode).category() != QChar::Other_Control
        && !QChar(unicode).isSpace())
        text.append(QChar(unicode));
    else {
        if (keysym == XK_Prior) {
            text = "PgUp";
        }
        else if (keysym == XK_Next) {
            text = "PgDn";
        }
        else {
            text = QString(XKeysymToString(keysym));
        }
    }
    if (text != "_") {
        if (text.endsWith("_L") || text.endsWith("_R"))
            text = text.replace('_', ' ');
        else
            text = text.replace('_', '\n');
    }
    painter->save();
    QTransform trans;
    trans.translate(x + padding / 2, y + padding / 2);
    trans.rotate(angle / 10);
    painter->setTransform(trans);
    //painter->fillRect(QRectF(0, 0, width - padding, height - padding), QBrush(Qt::blue));
    // painter->setClipRect(QRect(x + padding / 2, y + padding / 2, width - padding, height - padding));

    trans.reset();
    trans.translate(x, y);
    trans.rotate(angle / 10);
    QFont font = painter->font();
    font.setPixelSize(TEXT_SIZE * (height / 2 - padding));
    QFontMetricsF fm(font);
    QStringList lines = text.split('\n');
    foreach(const QString& line, lines) {
        qreal w = fm.width(line);
        if (w > (width - padding * 2)  * TEXT_SIZE) {
            double sz = font.pixelSize() / w * (width - padding * 2) * TEXT_SIZE;
            if (sz < 1)
                sz = 1;
            font.setPixelSize(font.pixelSize() / w * (width - padding * 2) * TEXT_SIZE);
        }
    }