UBKeyboardPalette.h 5.98 KB
Newer Older
Claudio Valerio's avatar
Claudio Valerio committed
1 2 3
#ifndef UBKEYBOARDPALETTE_H
#define UBKEYBOARDPALETTE_H

4
#include "UBActionPalette.h"
Claudio Valerio's avatar
Claudio Valerio committed
5 6 7 8 9 10 11 12 13 14 15

#include <QLayout>
#include <QPainter>
#include <QMenu>
#include <QIcon>

#include "frameworks/UBPlatformUtils.h"

class UBKeyButton;
class UBKeyboardButton;

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
class UBApplication;
class UBMainWindow;

class BTNImages
{
public:

    BTNImages(QString _strHeight, int _width, int _height);

    QString m_strHeight;
    int m_width;
    int m_height;

    QImage m_btnLeftPassive;
    QImage m_btnCenterPassive;
    QImage m_btnRightPassive;
    QImage m_btnLeftActive;
    QImage m_btnCenterActive;
    QImage m_btnRightActive;

private:
    QString m_strLeftPassive;
    QString m_strCenterPassive;
    QString m_strRightPassive;
    QString m_strLeftActive;
    QString m_strCenterActive;
    QString m_strRightActive;

};

class ContentImage
{
public:

    ContentImage(QString strHeight, int m_height, QString strContentPath);

    QString m_strHeight;
    int m_height;

    QImage m_btnContent;

private:
    QString m_strContent;
};

class UBKeyboardPalette : public UBActionPalette
Claudio Valerio's avatar
Claudio Valerio committed
62 63 64 65 66
{
    Q_OBJECT

friend class UBKeyboardButton;
friend class UBCapsLockButton;
67
friend class UBShiftButton;
Claudio Valerio's avatar
Claudio Valerio committed
68
friend class UBLocaleButton;
69
friend class UBKeyButton;
Claudio Valerio's avatar
Claudio Valerio committed
70 71

public:
72
    UBKeyboardPalette(QWidget *parent);
Claudio Valerio's avatar
Claudio Valerio committed
73 74
    ~UBKeyboardPalette();

75 76
    BTNImages *currBtnImages;

Claudio Valerio's avatar
Claudio Valerio committed
77 78 79 80 81
    bool isEnabled(){return locales!= NULL;}
    virtual QSize  sizeHint () const;
    virtual void adjustSizeAndPosition(bool pUp = true);
    QString getKeyButtonSize() const {QString res; res.sprintf("%dx%d", btnWidth, btnHeight); return res;}
    void setKeyButtonSize(const QString& strSize);
Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
82 83 84

    bool m_isVisible;
    QPoint m_pos;
Claudio Valerio's avatar
Claudio Valerio committed
85 86 87 88 89 90 91 92 93 94 95

signals:
    void moved(const QPoint&);
    void localeChanged(int);
    void keyboardActivated(bool);

private slots:
    void syncPosition(const QPoint & pos);
    void syncLocale(int nLocale);
    void keyboardPaletteButtonSizeChanged(QVariant size);
    void onActivated(bool b);
96
    void onDeactivated();
Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
97
    void showKeyboard(bool show);
98
    void hideKeyboard();
Claudio Valerio's avatar
Claudio Valerio committed
99 100 101

protected:
    bool capsLock;
102
    bool shift;
Claudio Valerio's avatar
Claudio Valerio committed
103 104 105 106
    int nCurrentLocale;
    int nLocalesCount;
    UBKeyboardLocale** locales;

107 108 109
    int nSpecialModifierIndex;
    KEYCODE specialModifier;

110
    QString strSize;
Claudio Valerio's avatar
Claudio Valerio committed
111 112
    int btnWidth;
    int btnHeight;
113
// 
Claudio Valerio's avatar
Claudio Valerio committed
114 115
    bool languagePopupActive;
    bool keyboardActive;
116
// 
Claudio Valerio's avatar
Claudio Valerio committed
117 118
    virtual void  enterEvent ( QEvent * event );
    virtual void  leaveEvent ( QEvent * event );
119
    virtual void  paintEvent(QPaintEvent *event);
Claudio Valerio's avatar
Claudio Valerio committed
120 121
    virtual void  moveEvent ( QMoveEvent * event );

122
    void sendKeyEvent(KEYCODE keyCode);
Claudio Valerio's avatar
Claudio Valerio committed
123 124 125 126 127

    void setLocale(int nLocale);

    const QString* getLocaleName();

128 129
    void init();

Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
130

131
private:
Claudio Valerio's avatar
Claudio Valerio committed
132 133 134 135 136 137

    QRect originalRect;

    UBKeyButton** buttons;
    UBKeyboardButton** ctrlButtons;

Anatoly Mihalchenko's avatar
Anatoly Mihalchenko committed
138 139 140 141 142
    /*
      For MacOS: synchronization with system locale.
    */
    void checkLayout();

Claudio Valerio's avatar
Claudio Valerio committed
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
    void createCtrlButtons();

    void setInput(const UBKeyboardLocale* locale);

    // Can be redefined under each platform
    void onLocaleChanged(UBKeyboardLocale* locale);

    // Storage for platform-dependent objects (linux)
    void* storage;
    // Linux-related parameters
    int min_keycodes, max_keycodes, byte_per_code;
};

class UBKeyboardButton : public QWidget
{
    Q_OBJECT

public:
161
    UBKeyboardButton(UBKeyboardPalette* parent, QString contentImagePath);
Claudio Valerio's avatar
Claudio Valerio committed
162 163 164
    ~UBKeyboardButton();

protected:
165 166 167 168 169

    UBKeyboardPalette* m_parent;
    ContentImage *imgContent;
    QString m_contentImagePath;

Claudio Valerio's avatar
Claudio Valerio committed
170
    void paintEvent(QPaintEvent *event);
171

Claudio Valerio's avatar
Claudio Valerio committed
172 173 174 175 176 177 178 179 180
    virtual void  enterEvent ( QEvent * event );
    virtual void  leaveEvent ( QEvent * event );
    virtual void  mousePressEvent ( QMouseEvent * event );
    virtual void  mouseReleaseEvent ( QMouseEvent * event );

    virtual void onPress() = 0;
    virtual void onRelease() = 0;
    virtual void paintContent(QPainter& painter) = 0;

181
    virtual bool isPressed();
Claudio Valerio's avatar
Claudio Valerio committed
182 183 184

    UBKeyboardPalette* keyboard;

185
    void sendUnicodeSymbol(KEYCODE keycode);
Claudio Valerio's avatar
Claudio Valerio committed
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
    void sendControlSymbol(int nSymbol);

private:
    bool bFocused;
    bool bPressed;
};

class UBKeyButton : public UBKeyboardButton
{
    Q_OBJECT

public:
    UBKeyButton(UBKeyboardPalette* parent);
    ~UBKeyButton();

    void setKeyBt(const KEYBT* keybt){this->keybt = keybt;}

    virtual void onPress();
    virtual void onRelease();
    virtual void paintContent(QPainter& painter);

private:
208
    bool shifted();
Claudio Valerio's avatar
Claudio Valerio committed
209 210 211 212 213 214 215 216
    const KEYBT* keybt;
};

class UBCntrlButton : public UBKeyboardButton
{
    Q_OBJECT

public:
217
    UBCntrlButton(UBKeyboardPalette* parent, int _code, const QString& _contentImagePath );
Claudio Valerio's avatar
Claudio Valerio committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    UBCntrlButton(UBKeyboardPalette* parent, const QString& _label, int _code );
    ~UBCntrlButton();

    virtual void onPress();
    virtual void onRelease();
    virtual void paintContent(QPainter& painter);

private:
    QString label;
    int code;
};

class UBCapsLockButton : public UBKeyboardButton
{
    Q_OBJECT

public:
235
    UBCapsLockButton(UBKeyboardPalette* parent, const QString _contentImagePath);
Claudio Valerio's avatar
Claudio Valerio committed
236 237 238 239 240
    ~UBCapsLockButton();

    virtual void onPress();
    virtual void onRelease();
    virtual void paintContent(QPainter& painter);
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259

protected:
    virtual bool isPressed();
};

class UBShiftButton : public UBKeyboardButton
{
    Q_OBJECT

public:
    UBShiftButton(UBKeyboardPalette* parent, const QString _contentImagePath);
    ~UBShiftButton();

    virtual void onPress();
    virtual void onRelease();
    virtual void paintContent(QPainter& painter);

protected:
    virtual bool isPressed();
Claudio Valerio's avatar
Claudio Valerio committed
260 261
};

262

Claudio Valerio's avatar
Claudio Valerio committed
263 264 265 266 267 268 269 270 271 272 273 274 275
class UBLocaleButton : public UBKeyboardButton
{
    Q_OBJECT

public:
    UBLocaleButton(UBKeyboardPalette* parent);
    ~UBLocaleButton();

    virtual void onPress();
    virtual void onRelease();
    virtual void paintContent(QPainter& painter);

protected:
276
    QMenu* localeMenu;
Claudio Valerio's avatar
Claudio Valerio committed
277 278 279
};

#endif // UBKEYBOARDPALETTE_H