MythTV  0.26-pre
uitypes.h
Go to the documentation of this file.
00001 #ifndef UIDATATYPES_H_
00002 #define UIDATATYPES_H_
00003 
00004 #include <vector>
00005 using namespace std;
00006 
00007 #include <QStringList>
00008 #include <QKeyEvent>
00009 #include <QObject>
00010 #include <QPixmap>
00011 #include <QVector>
00012 #include <QList>
00013 #include <QRect>
00014 #include <QMap>
00015 #include <QHash>
00016 
00017 #include "mythdeque.h"
00018 #include "mythwidgets.h"
00019 #include "mythmiscutil.h"
00020 #include "mythdialogs.h"
00021 #include "mythwidgets.h"
00022 #include "mythfontproperties.h"
00023 
00024 #ifdef USING_MINGW
00025 #undef LoadImage
00026 #endif
00027 
00028 class QFont;
00029 class QPainter;
00030 class UIType;
00031 class MythDialog;
00032 class MythThemedDialog;
00033 
00034 class MPUBLIC LayerSet
00035 {
00036   public:
00037     LayerSet(const QString &name);
00038    ~LayerSet();
00039 
00040     void    Draw(QPainter *, int, int);
00041     void    DrawRegion(QPainter *, QRect &, int, int);
00042 
00043     QString GetName() { return m_name; }
00044     void    SetName(const QString &name) { m_name = name; }
00045 
00046     void    SetDrawOrder(int order) { m_order = order; }
00047     int     GetDrawOrder() const { return m_order; }
00048 
00049     void    SetAreaRect(QRect area) { m_area = area; }
00050     QRect   GetAreaRect() { return m_area; }
00051 
00052     void    SetContext(int con) { m_context = con; }
00053     int     GetContext(void) { return m_context; }
00054 
00055     void    SetDebug(bool db) { m_debug = db; }
00056     void    bumpUpLayers(int a_number);
00057     int     getLayers(){return numb_layers;}
00058 
00059     void    AddType(UIType *);
00060     UIType  *GetType(const QString &name);
00061     vector<UIType *> *getAllTypes(){return allTypes;}
00062 
00063     void    SetDrawFontShadow(bool state);
00064 
00065 
00066   private:
00067     bool    m_debug;
00068     int     m_context;
00069     int     m_order;
00070     QString m_name;
00071     QRect   m_area;
00072     int     numb_layers;
00073 
00074     QMap<QString, UIType *> typeList;
00075     vector<UIType *> *allTypes;
00076 };
00077 
00078 class MPUBLIC UIType : public QObject
00079 {
00080   Q_OBJECT
00081 
00082   public:
00083     UIType(const QString &name);
00084     virtual ~UIType();
00085 
00086     void SetOrder(int order);
00087     void SetParent(LayerSet *);
00088     void SetScreen(double wmult, double hmult) { m_wmult = wmult; m_hmult = hmult; }
00089     void SetContext(int con) { m_context = con;}
00090     int  GetContext(){return m_context;}
00091     void SetDebug(bool db) { m_debug = db; }
00092     void allowFocus(bool yes_or_no){takes_focus = yes_or_no;}
00093     void SetDrawFontShadow(bool state) { drawFontShadow = state; }
00094     QString Name();
00095 
00096 
00097     bool    canTakeFocus(){ return takes_focus;}
00098     int     getOrder(){return m_order;}
00099     virtual void Draw(QPainter *, int, int);
00100     virtual void DrawRegion(QPainter *, QRect &, int, int);
00101     virtual void calculateScreenArea();
00102     QRect   getScreenArea(){return screen_area;}
00103     QString cutDown(const QString &data, QFont *font, bool multiline = false,
00104                     int overload_width = -1, int overload_height = -1);
00105     QString getName(){return m_name;}
00106 
00107     bool    isShown(){return !hidden;}
00108     bool    isHidden(){return hidden;}
00109     bool    isFocused(){return has_focus;}
00110 
00111   public slots:
00112 
00113     virtual bool takeFocus();
00114     virtual void looseFocus();
00115     virtual void activate(){}
00116     virtual void refresh();
00117     virtual void show();
00118     virtual void hide();
00119     virtual bool toggleShow();
00120 
00121 
00122   signals:
00123 
00124     //
00125     //  Ask my container to ask Qt to repaint
00126     //
00127 
00128     void requestUpdate();
00129     void requestUpdate(const QRect &);
00130     void requestRegionUpdate(const QRect &);
00131     void takingFocus();
00132     void loosingFocus();
00133 
00134   protected:
00135 
00136     double   m_wmult;
00137     double   m_hmult;
00138     int      m_context;
00139     int      m_order;
00140     bool     m_debug;
00141     QString  m_name;
00142     LayerSet *m_parent;
00143     bool     has_focus;
00144     bool     takes_focus;
00145     QRect    screen_area;   // The area, in real screen coordinates
00146     bool     drawFontShadow;
00147     bool     hidden;        // Is this "widget" seen or hidden ?
00148 };
00149 
00150 class MPUBLIC UIKeyType : public UIType
00151 {
00152     Q_OBJECT
00153 
00154   public:
00155     UIKeyType(const QString &);
00156     ~UIKeyType();
00157 
00158     QPoint GetPosition() { return m_pos; }
00159 
00160     void SetArea(QRect &area) { m_area = area; }
00161     void SetPosition(QPoint pos) { m_pos = pos; }
00162     void SetImages(QPixmap *normal, QPixmap *focused, QPixmap *down,
00163                    QPixmap *downFocused);
00164     void SetDefaultImages(QPixmap *normal, QPixmap *focused, QPixmap *down,
00165                           QPixmap *downFocused);
00166 
00167     void SetFonts(fontProp *normal, fontProp *focused, fontProp *down,
00168                   fontProp *downFocused);
00169     void SetDefaultFonts(fontProp *normal, fontProp *focused, fontProp *down,
00170                          fontProp *downFocused);
00171 
00172     void    SetType(QString type) { m_type = type; }
00173     QString GetType(void) const { return m_type; }
00174 
00175     void    SetChars(QString normal, QString shift, QString alt, QString shiftAlt);
00176     QString GetChar();
00177 
00178     void    SetMoves(QString moveLeft, QString moveRight, QString moveUp,
00179                   QString moveDown);
00180     QString GetMove(QString direction);
00181 
00182     void SetShiftState(bool sh, bool ag);
00183     void SetOn(bool bOn) { m_bDown = bOn; refresh(); }
00184     bool IsOn(void) { return m_bDown; }
00185 
00186     void SetToggleKey(bool bOn) { m_bToggle = bOn; }
00187     bool IsToggleKey(void) { return m_bToggle; }
00188 
00189    virtual void Draw(QPainter *, int, int);
00190     virtual void calculateScreenArea();
00191 
00192   public slots:
00193     void    push();
00194     void    unPush();
00195     void    activate(){push();}
00196 
00197   signals:
00198     void    pushed();
00199 
00200   private:
00201     QString decodeChar(QString c);
00202 
00203     QRect   m_area;
00204     QString m_type;
00205 
00206     QPixmap *m_normalImg;
00207     QPixmap *m_focusedImg;
00208     QPixmap *m_downImg;
00209     QPixmap *m_downFocusedImg;
00210 
00211     fontProp *m_normalFont;
00212     fontProp *m_focusedFont;
00213     fontProp *m_downFont;
00214     fontProp *m_downFocusedFont;
00215 
00216     QPoint m_pos;
00217 
00218     QString m_normalChar;
00219     QString m_shiftChar;
00220     QString m_altChar;
00221     QString m_shiftAltChar;
00222 
00223     QString m_moveLeft;
00224     QString m_moveRight;
00225     QString m_moveUp;
00226     QString m_moveDown;
00227 
00228     bool    m_bShift;
00229     bool    m_bAlt;
00230     bool    m_bDown;
00231     bool    m_bToggle;
00232 
00233     bool    m_bPushed;
00234     QTimer  m_pushTimer;
00235 };
00236 
00237 class MPUBLIC UIKeyboardType : public UIType
00238 {
00239     Q_OBJECT
00240 
00241   public:
00242     UIKeyboardType(const QString &, int);
00243     ~UIKeyboardType();
00244 
00245     typedef QList<UIKeyType*> KeyList;
00246 
00247     void SetContainer(LayerSet *container) { m_container = container; }
00248     void SetArea(QRect &area) { m_area = area; }
00249     void SetEdit(QWidget* edit) { m_parentEdit = edit; }
00250     void SetParentDialog(MythThemedDialog * parentDialog)
00251             { m_parentDialog = parentDialog; }
00252 
00253     KeyList GetKeys() { return m_keyList; }
00254     void AddKey(UIKeyType *key);
00255 
00256     virtual void Draw(QPainter *, int, int);
00257     virtual void calculateScreenArea();
00258     virtual void keyPressEvent(QKeyEvent *e);
00259 
00260   private slots:
00261     void charKey();
00262     void lockOnOff();
00263     void shiftLOnOff();
00264     void shiftROnOff();
00265     void shiftOff();
00266     void altGrOnOff();
00267     void compOnOff();
00268     void updateButtons();
00269     void leftCursor();
00270     void rightCursor();
00271     void backspaceKey();
00272     void delKey();
00273     void close();
00274 
00275   private:
00276     void init();
00277     void insertChar(QString c);
00278     void moveUp();
00279     void moveDown();
00280     void moveLeft();
00281     void moveRight();
00282     UIKeyType *findKey(QString keyName);
00283 
00284     QRect     m_area;
00285 
00286     bool m_bInitalized;
00287 
00288     bool      m_bCompTrap;
00289     QString   m_comp1;
00290 
00291     UIKeyType *m_altKey;
00292     UIKeyType *m_lockKey;
00293     UIKeyType *m_shiftLKey;
00294     UIKeyType *m_shiftRKey;
00295     UIKeyType *m_focusedKey;
00296     UIKeyType *m_doneKey;
00297 
00298     QWidget          *m_parentEdit;
00299     MythThemedDialog *m_parentDialog;
00300 
00301     LayerSet  *m_container;
00302     KeyList   m_keyList;
00303 };
00304 
00305 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends