MythTV  0.27pre
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Groups Pages
uitypes.h
Go to the documentation of this file.
1 #ifndef UIDATATYPES_H_
2 #define UIDATATYPES_H_
3 
4 #include <vector>
5 using namespace std;
6 
7 #include <QStringList>
8 #include <QKeyEvent>
9 #include <QObject>
10 #include <QPixmap>
11 #include <QVector>
12 #include <QList>
13 #include <QRect>
14 #include <QMap>
15 #include <QHash>
16 
17 #include "mythdeque.h"
18 #include "mythwidgets.h"
19 #include "mythdate.h"
20 #include "mythdialogs.h"
21 #include "mythwidgets.h"
22 #include "mythfontproperties.h"
23 
24 #ifdef USING_MINGW
25 #undef LoadImage
26 #endif
27 
28 class QFont;
29 class QPainter;
30 class UIType;
31 class MythDialog;
32 class MythThemedDialog;
33 
34 class MPUBLIC LayerSet
35 {
36  public:
37  LayerSet(const QString &name);
38  ~LayerSet();
39 
40  void Draw(QPainter *, int, int);
41  void DrawRegion(QPainter *, QRect &, int, int);
42 
43  QString GetName() { return m_name; }
44  void SetName(const QString &name) { m_name = name; }
45 
46  void SetDrawOrder(int order) { m_order = order; }
47  int GetDrawOrder() const { return m_order; }
48 
49  void SetAreaRect(QRect area) { m_area = area; }
50  QRect GetAreaRect() { return m_area; }
51 
52  void SetContext(int con) { m_context = con; }
53  int GetContext(void) { return m_context; }
54 
55  void SetDebug(bool db) { m_debug = db; }
56  void bumpUpLayers(int a_number);
57  int getLayers(){return numb_layers;}
58 
59  void AddType(UIType *);
60  UIType *GetType(const QString &name);
61  vector<UIType *> *getAllTypes(){return allTypes;}
62 
63  void SetDrawFontShadow(bool state);
64 
65 
66  private:
67  bool m_debug;
68  int m_context;
69  int m_order;
70  QString m_name;
71  QRect m_area;
73 
74  QMap<QString, UIType *> typeList;
75  vector<UIType *> *allTypes;
76 };
77 
78 class MPUBLIC UIType : public QObject
79 {
80  Q_OBJECT
81 
82  public:
83  UIType(const QString &name);
84  virtual ~UIType();
85 
86  void SetOrder(int order);
87  void SetParent(LayerSet *);
88  void SetScreen(double wmult, double hmult) { m_wmult = wmult; m_hmult = hmult; }
89  void SetContext(int con) { m_context = con;}
90  int GetContext(){return m_context;}
91  void SetDebug(bool db) { m_debug = db; }
92  void allowFocus(bool yes_or_no){takes_focus = yes_or_no;}
93  void SetDrawFontShadow(bool state) { drawFontShadow = state; }
94  QString Name();
95 
96 
97  bool canTakeFocus(){ return takes_focus;}
98  int getOrder(){return m_order;}
99  virtual void Draw(QPainter *, int, int);
100  virtual void DrawRegion(QPainter *, QRect &, int, int);
101  virtual void calculateScreenArea();
102  QRect getScreenArea(){return screen_area;}
103  QString cutDown(const QString &data, QFont *font, bool multiline = false,
104  int overload_width = -1, int overload_height = -1);
105  QString getName(){return m_name;}
106 
107  bool isShown(){return !hidden;}
108  bool isHidden(){return hidden;}
109  bool isFocused(){return has_focus;}
110 
111  public slots:
112 
113  virtual bool takeFocus();
114  virtual void looseFocus();
115  virtual void activate(){}
116  virtual void refresh();
117  virtual void show();
118  virtual void hide();
119  virtual bool toggleShow();
120 
121 
122  signals:
123 
124  //
125  // Ask my container to ask Qt to repaint
126  //
127 
128  void requestUpdate();
129  void requestUpdate(const QRect &);
130  void requestRegionUpdate(const QRect &);
131  void takingFocus();
132  void loosingFocus();
133 
134  protected:
135 
136  double m_wmult;
137  double m_hmult;
139  int m_order;
140  bool m_debug;
141  QString m_name;
143  bool has_focus;
145  QRect screen_area; // The area, in real screen coordinates
147  bool hidden; // Is this "widget" seen or hidden ?
148 };
149 
150 class MPUBLIC UIKeyType : public UIType
151 {
152  Q_OBJECT
153 
154  public:
155  UIKeyType(const QString &);
156  ~UIKeyType();
157 
158  QPoint GetPosition() { return m_pos; }
159 
160  void SetArea(QRect &area) { m_area = area; }
161  void SetPosition(QPoint pos) { m_pos = pos; }
162  void SetImages(QPixmap *normal, QPixmap *focused, QPixmap *down,
163  QPixmap *downFocused);
164  void SetDefaultImages(QPixmap *normal, QPixmap *focused, QPixmap *down,
165  QPixmap *downFocused);
166 
167  void SetFonts(fontProp *normal, fontProp *focused, fontProp *down,
168  fontProp *downFocused);
169  void SetDefaultFonts(fontProp *normal, fontProp *focused, fontProp *down,
170  fontProp *downFocused);
171 
172  void SetType(QString type) { m_type = type; }
173  QString GetType(void) const { return m_type; }
174 
175  void SetChars(QString normal, QString shift, QString alt, QString shiftAlt);
176  QString GetChar();
177 
178  void SetMoves(QString moveLeft, QString moveRight, QString moveUp,
179  QString moveDown);
180  QString GetMove(QString direction);
181 
182  void SetShiftState(bool sh, bool ag);
183  void SetOn(bool bOn) { m_bDown = bOn; refresh(); }
184  bool IsOn(void) { return m_bDown; }
185 
186  void SetToggleKey(bool bOn) { m_bToggle = bOn; }
187  bool IsToggleKey(void) { return m_bToggle; }
188 
189  virtual void Draw(QPainter *, int, int);
190  virtual void calculateScreenArea();
191 
192  public slots:
193  void push();
194  void unPush();
195  void activate(){push();}
196 
197  signals:
198  void pushed();
199 
200  private:
201  QString decodeChar(QString c);
202 
203  QRect m_area;
204  QString m_type;
205 
206  QPixmap *m_normalImg;
207  QPixmap *m_focusedImg;
208  QPixmap *m_downImg;
210 
215 
216  QPoint m_pos;
217 
218  QString m_normalChar;
219  QString m_shiftChar;
220  QString m_altChar;
221  QString m_shiftAltChar;
222 
223  QString m_moveLeft;
224  QString m_moveRight;
225  QString m_moveUp;
226  QString m_moveDown;
227 
228  bool m_bShift;
229  bool m_bAlt;
230  bool m_bDown;
231  bool m_bToggle;
232 
233  bool m_bPushed;
234  QTimer m_pushTimer;
235 };
236 
237 class MPUBLIC UIKeyboardType : public UIType
238 {
239  Q_OBJECT
240 
241  public:
242  UIKeyboardType(const QString &, int);
243  ~UIKeyboardType();
244 
245  typedef QList<UIKeyType*> KeyList;
246 
247  void SetContainer(LayerSet *container) { m_container = container; }
248  void SetArea(QRect &area) { m_area = area; }
249  void SetEdit(QWidget* edit) { m_parentEdit = edit; }
250  void SetParentDialog(MythThemedDialog * parentDialog)
251  { m_parentDialog = parentDialog; }
252 
253  KeyList GetKeys() { return m_keyList; }
254  void AddKey(UIKeyType *key);
255 
256  virtual void Draw(QPainter *, int, int);
257  virtual void calculateScreenArea();
258  virtual void keyPressEvent(QKeyEvent *e);
259 
260  private slots:
261  void charKey();
262  void lockOnOff();
263  void shiftLOnOff();
264  void shiftROnOff();
265  void shiftOff();
266  void altGrOnOff();
267  void compOnOff();
268  void updateButtons();
269  void leftCursor();
270  void rightCursor();
271  void backspaceKey();
272  void delKey();
273  void close();
274 
275  private:
276  void init();
277  void insertChar(QString c);
278  void moveUp();
279  void moveDown();
280  void moveLeft();
281  void moveRight();
282  UIKeyType *findKey(QString keyName);
283 
284  QRect m_area;
285 
287 
289  QString m_comp1;
290 
297 
298  QWidget *m_parentEdit;
300 
303 };
304 
305 #endif