*
*/
+#include <QtCore/QString>
+#include <QtCore/QDebug>
+#include <QtGui/QApplication>
+#include <QtGui/QDesktopWidget>
+#include <QtXml/QDomNode>
#include "widgetscreen.h"
+#include "themescreen.h"
-WidgetScreen::WidgetScreen(QWidget* parent): QStackedWidget(parent), AbstractScreen(){}
+WidgetScreen::WidgetScreen(QWidget* parent): QStackedWidget(parent), AbstractScreen(),
+currentOrientation_(LANDSCAPE)
+{
+}
+
+WidgetScreen::~WidgetScreen()
+{
+ clear();
+}
+
+bool WidgetScreen::load(Orientation orientation, QDomNode const& data, Reader* reader)
+{
+ if(screens_.find(orientation) == screens_.end())
+ {
+ qDebug() << "Orientation " << orientation << " not set";
+ return false;
+ }
+
+ bool ret = screens_[orientation]->load(data, reader);
+
+ if(ret && screens_.size() == 1)
+ {
+ currentOrientation_ = orientation;
+ }
+
+ if(ret)
+ {
+ loadedScreens_.insert(orientation);
+ }
+
+ return ret;
+}
+
+void WidgetScreen::addScreen(ThemeScreen* screen, Orientation orientation)
+{
+ if(screens_.find(orientation) != screens_.end())
+ {
+ removeWidget(screens_[orientation]);
+ delete screens_[orientation];
+ screens_.remove(orientation);
+ }
+
+ screens_[orientation] = screen;
+ addWidget(screen);
+ connect(screen, SIGNAL(minimizePressed()), this, SIGNAL(minimizePressed()));
+ connect(screen, SIGNAL(settingsPressed()), this, SIGNAL(settingsPressed()));
+ connect(screen, SIGNAL(closePressed()), this, SIGNAL(closePressed()));
+ connect(screen, SIGNAL(clicked()), this, SIGNAL(clicked()));
+}
+
+bool WidgetScreen::orientationEnabled(Orientation orientation) const
+{
+ return screens_.find(orientation) != screens_.end();
+}
+
+bool WidgetScreen::orientationLoaded(Orientation orientation) const
+{
+ return loadedScreens_.find(orientation) != loadedScreens_.end();
+}
+
+void WidgetScreen::reArrange()
+{
+ QRect rect = QApplication::desktop()->screenGeometry();
+
+ Orientation o = LANDSCAPE;
+
+ if(rect.height() > rect.width())
+ {
+ o = PORTRAIT;
+ }
+
+ if(o != currentOrientation_)
+ {
+ if(screens_.find(o) != screens_.end())
+ {
+ setCurrentWidget(screens_[o]);
+ screens_[o]->reArrange();
+ screens_[o]->forceRepaint();
+ currentOrientation_ = o;
+ }
+ }
+}
+
+void WidgetScreen::flip()
+{
+ for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
+ it != screens_.end(); it++)
+ {
+ it.value()->flip();
+ }
+}
+
+void WidgetScreen::setColor(QString const& color)
+{
+ Q_UNUSED(color);
+}
+
+void WidgetScreen::clear()
+{
+ for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
+ it != screens_.end(); it++)
+ {
+ removeWidget(it.value());
+ delete it.value();
+ }
+
+ screens_.clear();
+ loadedScreens_.clear();
+}
+
+void WidgetScreen::removeUnloaded()
+{
+ for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
+ it != screens_.end(); it++)
+ {
+ if(loadedScreens_.find(it.key()) == loadedScreens_.end())
+ {
+ removeWidget(it.value());
+ delete it.value();
+ screens_.remove(it.key());
+ }
+ }
+}