00001 #include <cassert> 00002 #include <iostream> 00003 using namespace std; 00004 00005 #include "mythcontext.h" 00006 #include "mythscreentype.h" 00007 #include "mythscreenstack.h" 00008 #include "mythmainwindow.h" 00009 00010 MythScreenType::MythScreenType(MythScreenStack *parent, const char *name, 00011 bool fullscreen) 00012 : MythUIType(parent, name) 00013 { 00014 assert(parent); 00015 00016 m_FullScreen = fullscreen; 00017 m_CurrentFocusWidget = NULL; 00018 00019 m_ScreenStack = parent; 00020 m_IsDeleting = false; 00021 00022 // Can be overridden, of course, but default to full sized. 00023 m_Area = GetMythMainWindow()->GetUIScreenRect(); 00024 } 00025 00026 MythScreenType::MythScreenType(MythUIType *parent, const char *name, 00027 bool fullscreen) 00028 : MythUIType(parent, name) 00029 { 00030 m_FullScreen = fullscreen; 00031 m_CurrentFocusWidget = NULL; 00032 00033 m_ScreenStack = NULL; 00034 m_IsDeleting = false; 00035 00036 m_Area = GetMythMainWindow()->GetUIScreenRect(); 00037 } 00038 00039 MythScreenType::~MythScreenType() 00040 { 00041 } 00042 00043 bool MythScreenType::IsFullscreen(void) 00044 { 00045 return m_FullScreen; 00046 } 00047 00048 void MythScreenType::SetFullscreen(bool full) 00049 { 00050 m_FullScreen = full; 00051 } 00052 00053 MythUIType *MythScreenType::GetFocusWidget(void) 00054 { 00055 return m_CurrentFocusWidget; 00056 } 00057 00058 bool MythScreenType::SetFocusWidget(MythUIType *widget) 00059 { 00060 if (!widget) 00061 { 00062 QPtrListIterator<MythUIType> it(m_FocusWidgetList); 00063 MythUIType *current; 00064 00065 while ((current = it.current())) 00066 { 00067 if (current->CanTakeFocus()) 00068 { 00069 widget = current; 00070 break; 00071 } 00072 ++it; 00073 } 00074 } 00075 00076 if (!widget) 00077 return false; 00078 00079 if (m_CurrentFocusWidget) 00080 m_CurrentFocusWidget->LoseFocus(); 00081 m_CurrentFocusWidget = widget; 00082 m_CurrentFocusWidget->TakeFocus(); 00083 00084 return true; 00085 } 00086 00087 bool MythScreenType::NextPrevWidgetFocus(bool up) 00088 { 00089 if (!m_CurrentFocusWidget || m_FocusWidgetList.isEmpty()) 00090 return SetFocusWidget(NULL); 00091 00092 bool reachedCurrent = false; 00093 // QPtrListIterator will always start at the beginning of the list 00094 // in this function. It is not a traditional list iterator 00095 QPtrListIterator<MythUIType> it(m_FocusWidgetList); 00096 MythUIType *current; 00097 00098 // There is probably a more efficient way to do this, but the list 00099 // is never going to be that big so it will do for now 00100 if (up) 00101 { 00102 while ((current = it.current())) 00103 { 00104 if (reachedCurrent) 00105 return SetFocusWidget(current); 00106 00107 if (current == m_CurrentFocusWidget) 00108 reachedCurrent = true; 00109 00110 ++it; 00111 } 00112 } 00113 else 00114 { 00115 it.toLast(); 00116 while ((current = it.current())) 00117 { 00118 if (reachedCurrent) 00119 return SetFocusWidget(current); 00120 00121 if (current == m_CurrentFocusWidget) 00122 reachedCurrent = true; 00123 00124 --it; 00125 } 00126 } 00127 00128 // fall back to first/last possible widget 00129 if (up) 00130 return SetFocusWidget(it.toFirst()); 00131 else 00132 return SetFocusWidget(it.toLast()); 00133 00134 return false; 00135 } 00136 00137 bool MythScreenType::BuildFocusList(void) 00138 { 00139 m_FocusWidgetList.clear(); 00140 00141 AddFocusableChildrenToList(m_FocusWidgetList); 00142 00143 if (m_FocusWidgetList.count() > 0) 00144 return true; 00145 00146 return false; 00147 } 00148 00149 MythScreenStack *MythScreenType::GetScreenStack(void) 00150 { 00151 return m_ScreenStack; 00152 } 00153 00154 void MythScreenType::aboutToHide(void) 00155 { 00156 } 00157 00158 void MythScreenType::aboutToShow(void) 00159 { 00160 } 00161 00162 bool MythScreenType::IsDeleting(void) 00163 { 00164 return m_IsDeleting; 00165 } 00166 00167 void MythScreenType::SetDeleting(bool deleting) 00168 { 00169 m_IsDeleting = deleting; 00170 } 00171 00172 bool MythScreenType::Create(void) 00173 { 00174 return true; 00175 } 00176 00177 bool MythScreenType::ParseElement(QDomElement &element) 00178 { 00179 if (element.tagName() == "area") 00180 m_Area = parseRect(element); 00181 else 00182 return false; 00183 00184 return true; 00185 } 00186 00187 void MythScreenType::CopyFrom(MythUIType *base) 00188 { 00189 MythScreenType *st = dynamic_cast<MythScreenType *>(base); 00190 if (!st) 00191 { 00192 VERBOSE(VB_IMPORTANT, "ERROR, bad parsing"); 00193 return; 00194 } 00195 00196 m_FullScreen = st->m_FullScreen; 00197 m_IsDeleting = false; 00198 00199 MythUIType::CopyFrom(base); 00200 00201 BuildFocusList(); 00202 SetFocusWidget(NULL); 00203 }; 00204 00205 void MythScreenType::CreateCopy(MythUIType *) 00206 { 00207 VERBOSE(VB_IMPORTANT, "CreateCopy called on screentype - bad."); 00208 } 00209
1.5.5