00001 #define MYTHAPPEARANCE_CPP
00002
00003
00004 #include <qnamespace.h>
00005 #include <qstringlist.h>
00006 #include <qapplication.h>
00007 #include <qdom.h>
00008 #include <qbuttongroup.h>
00009 #include <qimage.h>
00010 #include <qevent.h>
00011 #include <qdir.h>
00012 #include <qstring.h>
00013
00014
00015 #include "mythcontext.h"
00016 #include "mythmainwindow.h"
00017 #include "myththemebase.h"
00018
00019 using namespace std;
00020
00021 #include "mythappearance.h"
00022
00023
00024 MythAppearance::MythAppearance(MythScreenStack *parent, const char *name)
00025 : MythScreenType(parent, name)
00026 {
00027 gContext->addCurrentLocation("AppearanceWizard");
00028
00029
00030
00031 m_coarsefine = false;
00032 m_fine = 1;
00033 m_coarse = 10;
00034 m_change = m_fine;
00035 m_screenheight = 0, m_screenwidth = 0;
00036 m_arrowsize_x = 30;
00037 m_arrowsize_y = 30;
00038 m_topleftarrow_x = 0;
00039 m_topleftarrow_y = 0;
00040
00041 m_menuPopup = NULL;
00042 m_changed = false;
00043
00044 getSettings();
00045 getScreenInfo();
00046 m_whicharrow = true;
00047
00048 m_xsize = GetMythMainWindow()->GetUIScreenRect().width();
00049 m_ysize = GetMythMainWindow()->GetUIScreenRect().height();
00050
00051 }
00052
00053 MythAppearance::~MythAppearance() {}
00054
00055
00056 bool MythAppearance::Create()
00057 {
00058 bool foundtheme = false;
00059
00060
00061 foundtheme = LoadWindowFromXML("appear-ui.xml", "appearance", this);
00062
00063 if (!foundtheme)
00064 {
00065 VERBOSE(VB_IMPORTANT, "Unable to load window appearance from "
00066 "appear-ui.xml");
00067 return false;
00068 }
00069
00070 m_topleftarrow = dynamic_cast<MythUIImage *>
00071 (GetChild("topleft"));
00072
00073 m_bottomrightarrow = dynamic_cast<MythUIImage *>
00074 (GetChild("bottomright"));
00075
00076 m_size = dynamic_cast<MythUIText *>
00077 (GetChild("size"));
00078
00079 m_offsets = dynamic_cast<MythUIText *>
00080 (GetChild("offsets"));
00081
00082 m_changeamount = dynamic_cast<MythUIText *>
00083 (GetChild("changeamount"));
00084
00085 m_offsets = dynamic_cast<MythUIText *>
00086 (GetChild("offsets"));
00087
00088 m_changeamount = dynamic_cast<MythUIText *>
00089 (GetChild("changeamount"));
00090
00091
00092 m_arrowsize_x = m_topleftarrow->GetArea().width();
00093 m_arrowsize_y = m_topleftarrow->GetArea().height();
00094
00095
00096 m_topleftarrow_x = m_xoffset;
00097 m_topleftarrow_y = m_yoffset;
00098 m_bottomrightarrow_x = m_screenwidth - m_xoffset - m_arrowsize_x;
00099 m_bottomrightarrow_y = m_screenheight - m_yoffset - m_arrowsize_y;
00100
00101 setContext(1);
00102 updateScreen();
00103
00104 return true;
00105 }
00106
00107 void MythAppearance::setContext(int context)
00108 {
00109
00110 if (context == 1)
00111 {
00112 m_topleftarrow->SetVisible(true);
00113 m_bottomrightarrow->SetVisible(false);
00114 }
00115 else if (context == 2)
00116 {
00117 m_bottomrightarrow->SetVisible(true);
00118 m_topleftarrow->SetVisible(false);
00119 }
00120
00121 }
00122
00123 void MythAppearance::getSettings()
00124 {
00125 float m_wmult = 0, m_hmult = 0;
00126 gContext->GetScreenSettings(m_screenwidth, m_wmult, m_screenheight, m_hmult);
00127 }
00128
00129 void MythAppearance::getScreenInfo()
00130 {
00131 m_xoffset_old = gContext->GetNumSetting("GuiOffsetX", 0);
00132 m_yoffset_old = gContext->GetNumSetting("GuiOffsetY", 0);
00133 m_xoffset = m_xoffset_old;
00134 m_yoffset = m_yoffset_old;
00135 }
00136
00137
00138 bool MythAppearance::keyPressEvent(QKeyEvent *event)
00139 {
00140 QStringList actions;
00141 bool handled = false;
00142
00143 gContext->GetMainWindow()->TranslateKeyPress("Global", event, actions);
00144
00145 for (unsigned int i = 0; i < actions.size() && !handled; i++)
00146 {
00147 QString action = actions[i];
00148 handled = true;
00149
00150 if (action == "SELECT")
00151 swapArrows();
00152 else if (action == "UP")
00153 moveUp();
00154 else if (action == "DOWN")
00155 moveDown();
00156 else if (action == "LEFT")
00157 moveLeft();
00158 else if (action == "RIGHT")
00159 moveRight();
00160 else if (action == "MENU")
00161 doMenu();
00162 else if (action == "ESCAPE")
00163 {
00164 gContext->removeCurrentLocation();
00165 GetMythMainWindow()->GetMainStack()->PopScreen();
00166 }
00167 else
00168 handled = false;
00169 }
00170
00171 return handled;
00172 }
00173
00174 void MythAppearance::swapArrows()
00175 {
00176 if (m_whicharrow)
00177 {
00178 setContext(2);
00179 m_whicharrow = false;
00180 }
00181
00182 else
00183 {
00184 setContext(1);
00185 m_whicharrow = true;
00186 }
00187
00188
00189 updateScreen();
00190
00191 }
00192
00193 void MythAppearance::moveUp()
00194 {
00195 if (m_whicharrow)
00196 {
00197 m_topleftarrow_y -= m_change;
00198 if (m_topleftarrow_y < 0)
00199 m_topleftarrow_y = 0;
00200 }
00201 else
00202 {
00203 m_bottomrightarrow_y -= m_change;
00204 if (m_bottomrightarrow_y < int(m_screenheight * 0.75))
00205 m_bottomrightarrow_y = int(m_screenheight * 0.75);
00206 }
00207
00208 updateScreen();
00209 anythingChanged();
00210 }
00211
00212 void MythAppearance::moveLeft()
00213 {
00214 if (m_whicharrow)
00215 {
00216 m_topleftarrow_x -= m_change;
00217 if (m_topleftarrow_x < 0)
00218 m_topleftarrow_x = 0;
00219 }
00220 else
00221 {
00222 m_bottomrightarrow_x -= m_change;
00223 if (m_bottomrightarrow_x < int(m_screenwidth * 0.75))
00224 m_bottomrightarrow_x = int(m_screenwidth * 0.75);
00225 }
00226
00227 updateScreen();
00228 anythingChanged();
00229 }
00230
00231 void MythAppearance::moveDown()
00232 {
00233 if (m_whicharrow)
00234 {
00235 {
00236 m_topleftarrow_y += m_change;
00237 if (m_topleftarrow_y > int(m_screenheight * 0.25))
00238 m_topleftarrow_y = int(m_screenheight * 0.25);
00239 }
00240 }
00241 else
00242 {
00243 m_bottomrightarrow_y += m_change;
00244 if (m_bottomrightarrow_y > m_screenheight - m_arrowsize_y)
00245 m_bottomrightarrow_y = m_screenheight - m_arrowsize_y;
00246 }
00247
00248 updateScreen();
00249 anythingChanged();
00250 }
00251
00252 void MythAppearance::moveRight()
00253 {
00254 if (m_whicharrow)
00255 {
00256 m_topleftarrow_x += m_change;
00257 if (m_topleftarrow_x > int (m_screenwidth * 0.25))
00258 m_topleftarrow_x = int (m_screenwidth * 0.25);
00259 }
00260 else
00261 {
00262 m_bottomrightarrow_x += m_change;
00263 if (m_bottomrightarrow_x > m_screenwidth - m_arrowsize_x)
00264 m_bottomrightarrow_x = m_screenwidth - m_arrowsize_x;
00265 }
00266
00267 updateScreen();
00268 anythingChanged();
00269 }
00270
00271 void MythAppearance::updateScreen()
00272 {
00273 m_xsize = (m_bottomrightarrow_x - m_topleftarrow_x + m_arrowsize_x);
00274 m_ysize = (m_bottomrightarrow_y - m_topleftarrow_y + m_arrowsize_y);
00275 m_xoffset = m_topleftarrow_x;
00276 m_yoffset = m_topleftarrow_y;
00277 m_topleftarrow->SetPosition(QPoint(m_topleftarrow_x, m_topleftarrow_y));
00278 m_bottomrightarrow->SetPosition(QPoint(m_bottomrightarrow_x, m_bottomrightarrow_y));
00279 m_size->SetText(QString("Size: %1 x %2").arg(m_xsize).arg(m_ysize));
00280 m_offsets->SetText(QString("Offset: %1 x %2").arg(m_xoffset).arg(m_yoffset));
00281 m_changeamount->SetText(QString("Change amount: %1 pixel(s)").arg(m_change));
00282
00283 }
00284
00285 void MythAppearance::doMenu()
00286 {
00287 if (m_menuPopup)
00288 return;
00289
00290 QString label = "MythAppearance Menu";
00291
00292 MythScreenStack *mainStack = GetMythMainWindow()->GetMainStack();
00293
00294 m_menuPopup = new MythDialogBox(label, mainStack, "menuPopup");
00295
00296 if (m_menuPopup->Create())
00297 mainStack->AddScreen(m_menuPopup);
00298
00299 if (m_changed)
00300 {
00301 m_menuPopup->SetReturnEvent(this, "save");
00302 m_menuPopup->AddButton("Save and Quit");
00303 }
00304 else
00305 m_menuPopup->SetReturnEvent(this, "nosave");
00306
00307 m_menuPopup->AddButton("Reset Screen Size Settings and Quit");
00308 m_menuPopup->AddButton("Coarse/Fine adjustment");
00309 m_menuPopup->AddButton("Close Menu");
00310
00311 updateScreen();
00312 }
00313
00314 void MythAppearance::slotSaveSettings()
00315 {
00316 VERBOSE(VB_IMPORTANT, "Updating screen size settings");
00317 updateSettings();
00318 }
00319
00320 void MythAppearance::slotChangeCoarseFine()
00321 {
00322 if (m_coarsefine)
00323 {
00324 m_coarsefine = false;
00325 m_change = m_fine;
00326 }
00327 else
00328 {
00329 m_coarsefine = true;
00330 m_change = m_coarse;
00331 }
00332
00333 updateScreen();
00334 }
00335
00336 void MythAppearance::updateSettings()
00337 {
00338 gContext->SaveSetting("GuiOffsetX", m_xoffset);
00339 gContext->SaveSetting("GuiOffsetY", m_yoffset);
00340 gContext->SaveSetting("GuiWidth", m_xsize);
00341 gContext->SaveSetting("GuiHeight", m_ysize);
00342 VERBOSE(VB_IMPORTANT, "Updated screen size settings");
00343 GetMythMainWindow()->JumpTo("Reload Theme");
00344 }
00345
00346 void MythAppearance::slotResetSettings()
00347 {
00348 gContext->SaveSetting("GuiOffsetX", 0);
00349 gContext->SaveSetting("GuiOffsetY", 0);
00350 gContext->SaveSetting("GuiWidth", 0);
00351 gContext->SaveSetting("GuiHeight", 0);
00352 m_changed = false;
00353 GetMythMainWindow()->JumpTo("Reload Theme");
00354 }
00355
00356 void MythAppearance::anythingChanged()
00357 {
00358 if (m_xsize != m_screenwidth)
00359 m_changed = true;
00360 else if (m_xoffset != m_xoffset_old)
00361 m_changed = true;
00362 else if (m_ysize != m_screenheight)
00363 m_changed = true;
00364 else if (m_yoffset != m_yoffset_old)
00365 m_changed = true;
00366 else m_changed = false;
00367 }
00368
00369 void MythAppearance::customEvent(QCustomEvent *event)
00370 {
00371
00372 if (event->type() == kMythDialogBoxCompletionEventType)
00373 {
00374 DialogCompletionEvent *dce =
00375 dynamic_cast<DialogCompletionEvent*>(event);
00376
00377 QString resultid= dce->GetId();
00378 int buttonnum = dce->GetResult();
00379
00380 if (resultid == "save")
00381 {
00382 if (buttonnum == 0)
00383 slotSaveSettings();
00384 else if (buttonnum == 1)
00385 slotResetSettings();
00386 else if (buttonnum == 2)
00387 slotChangeCoarseFine();
00388 }
00389 else if (resultid == "nosave")
00390 {
00391 if (buttonnum == 0)
00392 slotResetSettings();
00393 if (buttonnum == 1)
00394 slotChangeCoarseFine();
00395 }
00396
00397 m_menuPopup = NULL;
00398 }
00399
00400 }