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);
49 loadedScreens_.insert(orientation);
51 if(loadedScreens_.size() == 1)
53 currentOrientation_ = orientation;
54 setCurrentWidget(screens_[orientation]);
61 bool WidgetScreen::load(QDomNode const& data, Reader* reader)
63 return load(LANDSCAPE, data, reader) && load(PORTRAIT, data, reader);
66 void WidgetScreen::setColor(Orientation orientation, QString const& color)
68 if(screens_.find(orientation) != screens_.end())
70 screens_[orientation]->setColor(color);
74 void WidgetScreen::setColor(QString const& color)
76 setColor(LANDSCAPE, color);
77 setColor(PORTRAIT, color);
80 void WidgetScreen::addScreen(ThemeScreen* screen, Orientation orientation)
82 if(screens_.find(orientation) != screens_.end())
84 removeWidget(screens_[orientation]);
85 delete screens_[orientation];
86 screens_.remove(orientation);
89 screens_[orientation] = screen;
91 connect(screen, SIGNAL(minimizePressed()), this, SIGNAL(minimizePressed()));
92 connect(screen, SIGNAL(settingsPressed()), this, SIGNAL(settingsPressed()));
93 connect(screen, SIGNAL(closePressed()), this, SIGNAL(closePressed()));
94 connect(screen, SIGNAL(clicked()), this, SIGNAL(clicked()));
97 bool WidgetScreen::orientationEnabled(Orientation orientation) const
99 return screens_.find(orientation) != screens_.end();
102 bool WidgetScreen::orientationLoaded(Orientation orientation) const
104 return loadedScreens_.find(orientation) != loadedScreens_.end();
107 void WidgetScreen::reArrange()
109 QRect rect = QApplication::desktop()->screenGeometry();
111 Orientation o = LANDSCAPE;
113 if(rect.height() > rect.width())
118 if(o != currentOrientation_)
120 if(screens_.find(o) != screens_.end())
122 currentOrientation_ = o;
123 setCurrentWidget(screens_[o]);
124 screens_[o]->reArrange();
125 screens_[o]->forceRepaint();
130 void WidgetScreen::flip()
132 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
133 it != screens_.end(); it++)
139 void WidgetScreen::clear()
141 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
142 it != screens_.end(); it++)
144 removeWidget(it.value());
149 loadedScreens_.clear();
152 void WidgetScreen::removeUnloaded()
154 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
155 it != screens_.end(); it++)
157 if(loadedScreens_.find(it.key()) == loadedScreens_.end())
159 removeWidget(it.value());
161 screens_.remove(it.key());