00001 #ifndef MYTHMAINWINDOW_H_
00002 #define MYTHMAINWINDOW_H_
00003
00004 #include <qwidget.h>
00005 #include <qdialog.h>
00006 #include <qevent.h>
00007 #include <qfont.h>
00008 #ifdef USE_OPENGL_PAINTER
00009 #include <qgl.h>
00010 #endif
00011
00012 #include "mythuitype.h"
00013 #include "mythscreenstack.h"
00014
00015 class MythMediaDevice;
00016
00017 const int kExternalKeycodeEventType = 33213;
00018 const int kExitToMainMenuEventType = 33214;
00019
00020 class ExternalKeycodeEvent : public QCustomEvent
00021 {
00022 public:
00023 ExternalKeycodeEvent(const int key)
00024 : QCustomEvent(kExternalKeycodeEventType), keycode(key) {}
00025
00026 int getKeycode() { return keycode; }
00027
00028 private:
00029 int keycode;
00030 };
00031
00032 class ExitToMainMenuEvent : public QCustomEvent
00033 {
00034 public:
00035 ExitToMainMenuEvent(void) : QCustomEvent(kExitToMainMenuEventType) {}
00036 };
00037
00038 #define REG_KEY(a, b, c, d) GetMythMainWindow()->RegisterKey(a, b, c, d)
00039 #define GET_KEY(a, b) GetMythMainWindow()->GetKey(a, b)
00040 #define REG_JUMP(a, b, c, d) GetMythMainWindow()->RegisterJump(a, b, c, d)
00041 #define REG_JUMPLOC(a, b, c, d, e) GetMythMainWindow()->RegisterJump(a, b, c, d, true, e)
00042 #define REG_JUMPEX(a, b, c, d, e) GetMythMainWindow()->RegisterJump(a, b, c, d, e)
00043 #define REG_MEDIA_HANDLER(a, b, c, d, e, f) GetMythMainWindow()->RegisterMediaHandler(a, b, c, d, e, f)
00044 #define REG_MEDIAPLAYER(a,b,c) GetMythMainWindow()->RegisterMediaPlugin(a, b, c)
00045
00046 typedef int (*MediaPlayCallback)(const QString &, const QString &, const QString &, const QString &, int, const QString &);
00047
00048 class MythMainWindowPrivate;
00049
00050
00051 #ifdef USE_OPENGL_PAINTER
00052 #define QWidget QGLWidget
00053 #endif
00054
00055 class MythMainWindow : public QWidget
00056 {
00057 Q_OBJECT
00058 #undef QWidget
00059 public:
00060 void Init(void);
00061 void Show(void);
00062
00063 void AddScreenStack(MythScreenStack *stack, bool main = false);
00064 MythScreenStack *GetMainStack();
00065
00066 bool TranslateKeyPress(const QString &context, QKeyEvent *e,
00067 QStringList &actions, bool allowJumps = true);
00068
00069 void ClearKey(const QString &context, const QString &action);
00070 void BindKey(const QString &context, const QString &action,
00071 const QString &key);
00072 void RegisterKey(const QString &context, const QString &action,
00073 const QString &description, const QString &key);
00074 QString GetKey(const QString &context, const QString &action) const;
00075
00076 void ClearJump(const QString &destination);
00077 void BindJump(const QString &destination, const QString &key);
00078 void RegisterJump(const QString &destination, const QString &description,
00079 const QString &key, void (*callback)(void),
00080 bool exittomain = true, QString localAction = "");
00081 void RegisterMediaHandler(const QString &destination,
00082 const QString &description, const QString &key,
00083 void (*callback)(MythMediaDevice* mediadevice),
00084 int mediaType, const QString &extensions);
00085
00086 void RegisterMediaPlugin(const QString &name, const QString &desc,
00087 MediaPlayCallback fn);
00088
00089 bool HandleMedia(QString& handler, const QString& mrl,
00090 const QString& plot="", const QString& title="",
00091 const QString& director="", int lenMins=120,
00092 const QString& year="1895");
00093
00094 void JumpTo(const QString &destination, bool pop = true);
00095 bool DestinationExists(const QString &destination) const;
00096
00097 bool IsExitingToMain(void) const;
00098
00099 static MythMainWindow *getMainWindow(const bool useDB = true);
00100 static void destroyMainWindow();
00101
00102 MythPainter *GetCurrentPainter();
00103
00104 void AllowInput(bool allow);
00105
00106 QRect GetUIScreenRect();
00107
00108 int NormalizeFontSize(int pointSize);
00109 QFont CreateQFont(const QString &face, int pointSize = 12,
00110 int weight = QFont::Normal, bool italic = FALSE);
00111 QRect NormRect(const QRect &rect);
00112 QPoint NormPoint(const QPoint &point);
00113 QSize NormSize(const QSize &size);
00114 int NormX(const int x);
00115 int NormY(const int y);
00116 int fonTweak;
00117
00118
00119 void attach(QWidget *child);
00120 void detach(QWidget *child);
00121
00122 QWidget *currentWidget(void);
00123
00124 public slots:
00125 void drawTimeout();
00126 void mouseTimeout();
00127
00128 protected:
00129 MythMainWindow(const bool useDB = true);
00130 virtual ~MythMainWindow();
00131
00132 bool eventFilter(QObject *o, QEvent *e);
00133 void customEvent(QCustomEvent *ce);
00134 void closeEvent(QCloseEvent *e);
00135 void paintEvent(QPaintEvent *e);
00136 #ifdef USING_APPLEREMOTE
00137 bool event(QEvent* e);
00138 #endif
00139
00140 void ExitToMainMenu();
00141
00142 QObject *getTarget(QKeyEvent &key);
00143
00144 MythMainWindowPrivate *d;
00145 };
00146
00147 MythMainWindow *GetMythMainWindow();
00148 void DestroyMythMainWindow();
00149
00150 MythPainter *GetMythPainter();
00151
00152 #endif
00153