00001 #include <qapplication.h>
00002
00003 #include "mythdialogbox.h"
00004 #include "mythlistbutton.h"
00005 #include "mythmainwindow.h"
00006 #include "mythfontproperties.h"
00007 #include "mythcontext.h"
00008 #include "mythmediamonitor.h"
00009
00010 MythDialogBox::MythDialogBox(const QString &text,
00011 MythScreenStack *parent, const char *name)
00012 : MythScreenType(parent, name, false)
00013 {
00014 m_id = "";
00015 m_retScreen = NULL;
00016 m_text = text;
00017 buttonList = NULL;
00018 }
00019
00020 bool MythDialogBox::Create(void)
00021 {
00022 if (!CopyWindowFromBase("MythDialogBox", this))
00023 return false;
00024
00025 SetFullscreen(false);
00026
00027 MythUIText *textarea = dynamic_cast<MythUIText *>(GetChild("messagearea"));
00028 buttonList = dynamic_cast<MythListButton *>(GetChild("list"));
00029
00030 if (!textarea || !buttonList)
00031 return false;
00032
00033 textarea->SetText(m_text);
00034 buttonList->SetActive(true);
00035
00036 connect(buttonList, SIGNAL(itemClicked(MythListButtonItem*)),
00037 this, SLOT(Select(MythListButtonItem*)));
00038
00039 return true;
00040 }
00041
00042 void MythDialogBox::Select(MythListButtonItem* item)
00043 {
00044 SendEvent(buttonList->GetItemPos(item));
00045 m_ScreenStack->PopScreen();
00046 }
00047
00048 void MythDialogBox::SetReturnEvent(MythScreenType *retscreen,
00049 const QString &resultid)
00050 {
00051 m_retScreen = retscreen;
00052 m_id = resultid;
00053 }
00054
00055 void MythDialogBox::AddButton(const QString &title)
00056 {
00057 new MythListButtonItem(buttonList, title);
00058 }
00059
00060 bool MythDialogBox::keyPressEvent(QKeyEvent *event)
00061 {
00062 if (GetFocusWidget()->keyPressEvent(event))
00063 return true;
00064
00065 bool handled = false;
00066 QStringList actions;
00067 if (GetMythMainWindow()->TranslateKeyPress("qt", event, actions))
00068 {
00069 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00070 {
00071 QString action = actions[i];
00072 handled = true;
00073
00074 if (action == "ESCAPE" || action == "LEFT" || action == "MENU")
00075 {
00076 SendEvent(-1);
00077 m_ScreenStack->PopScreen();
00078 }
00079 else if (action == "RIGHT")
00080 {
00081 MythListButtonItem *item = buttonList->GetItemCurrent();
00082 Select(item);
00083 }
00084 else
00085 handled = false;
00086 }
00087 }
00088
00089 return handled;
00090 }
00091
00092 void MythDialogBox::SendEvent(int res)
00093 {
00094 if (!m_retScreen)
00095 return;
00096
00097 DialogCompletionEvent *dce = new DialogCompletionEvent(m_id, res);
00098 QApplication::postEvent(m_retScreen, dce);
00099 }