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 bool WidgetScreen::load(QDomNode const& data, Reader* reader)
62 return load(LANDSCAPE, data, reader) && load(PORTRAIT, data, reader);
65 void WidgetScreen::setColor(Orientation orientation, QString const& color)
67 if(screens_.find(orientation) != screens_.end())
69 screens_[orientation]->setColor(color);
73 void WidgetScreen::setColor(QString const& color)
75 setColor(LANDSCAPE, color);
76 setColor(PORTRAIT, color);
79 void WidgetScreen::addScreen(ThemeScreen* screen, Orientation orientation)
81 if(screens_.find(orientation) != screens_.end())
83 removeWidget(screens_[orientation]);
84 delete screens_[orientation];
85 screens_.remove(orientation);
88 screens_[orientation] = screen;
90 connect(screen, SIGNAL(minimizePressed()), this, SIGNAL(minimizePressed()));
91 connect(screen, SIGNAL(settingsPressed()), this, SIGNAL(settingsPressed()));
92 connect(screen, SIGNAL(closePressed()), this, SIGNAL(closePressed()));
93 connect(screen, SIGNAL(clicked()), this, SIGNAL(clicked()));
96 bool WidgetScreen::orientationEnabled(Orientation orientation) const
98 return screens_.find(orientation) != screens_.end();
101 bool WidgetScreen::orientationLoaded(Orientation orientation) const
103 return loadedScreens_.find(orientation) != loadedScreens_.end();
106 void WidgetScreen::reArrange()
108 QRect rect = QApplication::desktop()->screenGeometry();
110 Orientation o = LANDSCAPE;
112 if(rect.height() > rect.width())
117 if(o != currentOrientation_)
119 if(screens_.find(o) != screens_.end())
121 setCurrentWidget(screens_[o]);
122 screens_[o]->reArrange();
123 screens_[o]->forceRepaint();
124 currentOrientation_ = o;
129 void WidgetScreen::flip()
131 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
132 it != screens_.end(); it++)
138 void WidgetScreen::clear()
140 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
141 it != screens_.end(); it++)
143 removeWidget(it.value());
148 loadedScreens_.clear();
151 void WidgetScreen::removeUnloaded()
153 for(QMap<Orientation, ThemeScreen*>::iterator it = screens_.begin();
154 it != screens_.end(); it++)
156 if(loadedScreens_.find(it.key()) == loadedScreens_.end())
158 removeWidget(it.value());
160 screens_.remove(it.key());