2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtCore/QString>
20 #include <QtCore/QDebug>
21 #include <QtGui/QApplication>
22 #include <QtGui/QDesktopWidget>
23 #include <QtXml/QDomNode>
24 #include "widgetscreen.h"
25 #include "themescreen.h"
27 WidgetScreen::WidgetScreen(QWidget* parent): QStackedWidget(parent), AbstractScreen(),
28 currentOrientation_(LANDSCAPE)
32 WidgetScreen::~WidgetScreen()
37 bool WidgetScreen::load(Orientation orientation, QDomNode const& data, Reader* reader)
39 if(screens_.find(orientation) == screens_.end())
41 qDebug() << "Orientation " << orientation << " not set";
45 bool ret = screens_[orientation]->load(data, reader);
47 if(ret && screens_.size() == 1)
49 currentOrientation_ = orientation;
54 loadedScreens_.insert(orientation);
60 void WidgetScreen::addScreen(ThemeScreen* screen, Orientation orientation)
62 if(screens_.find(orientation) != screens_.end())
64 removeWidget(screens_[orientation]);
65 delete screens_[orientation];
66 screens_.remove(orientation);
69 screens_[orientation] = screen;
71 connect(screen, SIGNAL(minimizePressed()), this, SIGNAL(minimizePressed()));
72 connect(screen, SIGNAL(settingsPressed()), this, SIGNAL(settingsPressed()));
73 connect(screen, SIGNAL(closePressed()), this, SIGNAL(closePressed()));
74 connect(screen, SIGNAL(clicked()), this, SIGNAL(clicked()));
77 bool WidgetScreen::orientationEnabled(Orientation orientation) const
79 return screens_.find(orientation) != screens_.end();
82 bool WidgetScreen::orientationLoaded(Orientation orientation) const
84 return loadedScreens_.find(orientation) != loadedScreens_.end();
87 void WidgetScreen::reArrange()
89 QRect rect = QApplication::desktop()->screenGeometry();
91 Orientation o = LANDSCAPE;
93 if(rect.height() > rect.width())
98 if(o != currentOrientation_)
100 if(screens_.find(o) != screens_.end())
102 setCurrentWidget(screens_[o]);
103 screens_[o]->reArrange();
104 screens_[o]->forceRepaint();
105 currentOrientation_ = o;
110 void WidgetScreen::flip()
112 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
113 it != screens_.end(); it++)
119 void WidgetScreen::setColor(QString const& color)
124 void WidgetScreen::clear()
126 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
127 it != screens_.end(); it++)
129 removeWidget(it.value());
134 loadedScreens_.clear();
137 void WidgetScreen::removeUnloaded()
139 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
140 it != screens_.end(); it++)
142 if(loadedScreens_.find(it.key()) == loadedScreens_.end())
144 removeWidget(it.value());
146 screens_.remove(it.key());