X-Git-Url: http://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fwidgetscreen.cpp;h=4695f064cf7e3b2007b506e459f5386849e18696;hb=e37daa8a1873c9a9be25cf52c30044d53eeea6bc;hp=fd00a069ffd7c9ddb31b1e24c99b4049e3fa7ed8;hpb=758f7d4613278140d903394e147c4b95d8b11cd2;p=jspeed diff --git a/src/widgetscreen.cpp b/src/widgetscreen.cpp index fd00a06..4695f06 100644 --- a/src/widgetscreen.cpp +++ b/src/widgetscreen.cpp @@ -16,6 +16,134 @@ * */ +#include +#include +#include +#include +#include #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::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::iterator it = screens_.begin(); + it != screens_.end(); it++) + { + removeWidget(it.value()); + delete it.value(); + } + + screens_.clear(); + loadedScreens_.clear(); +} + +void WidgetScreen::removeUnloaded() +{ + for(QMap::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()); + } + } +}