void MaximizeState::relayout(const QRectF& r, bool animate)
{
	Q_UNUSED(r);
	m_wm->maximizeActiveWindow(animate);
	QRectF boundingRect;

	CardWindow* activeWin = m_wm->activeWindow();
	if(activeWin) {
		if(WindowType::Type_ModalChildWindowCard != activeWin->type()) {
			boundingRect = m_wm->normalOrScreenBounds(activeWin);
			activeWin->setBoundingRect(boundingRect.width(), boundingRect.height());
		}
		else {
			// forward the call to the child.
			activeWin->setBoundingRect(Settings::LunaSettings()->modalWindowWidth, activeWin->boundingRect().height());

			// Notify the parent as well.
			CardWindow* parent = m_wm->modalParent();
			if(parent) {
				boundingRect = m_wm->normalOrScreenBounds(parent);
				parent->setBoundingRect(boundingRect.width(), boundingRect.height());
			}
		}
	}
}
void MaximizeState::onEntry(QEvent* event)
{
	CardWindowManagerState::onEntry(event);
	CardWindow* activeWin = m_wm->activeWindow();
	Q_ASSERT(activeWin != 0);

	SystemUiController::instance()->setCardWindowMaximized(true);
	SystemUiController::instance()->setMaximizedCardWindow(activeWin);

	m_wm->queueFocusAction(activeWin, true);
	activeWin->setAttachedToGroup(false);

	if(WindowType::Type_ModalChildWindowCard != activeWin->type()) {
		QRectF boundingRect = m_wm->normalOrScreenBounds(activeWin);
		activeWin->setBoundingRect(boundingRect.width(), boundingRect.height());
	}
	else {
		activeWin->setBoundingRect(Settings::LunaSettings()->modalWindowWidth, Settings::LunaSettings()->modalWindowHeight);
		//activeWin->setMaximized(true);
	}
}
// --------------------------------------------------------------------------------------------------
void PreparingState::onEntry(QEvent* event)
{
	CardWindowManagerState::onEntry(event);

	// unpack the window which we need to prepare
	CardWindow* win = 0;
	if (event->type() == QEvent::StateMachineSignal) {
		QStateMachine::SignalEvent* se = static_cast<QStateMachine::SignalEvent*>(event);
		win = se->arguments().at(0).value<CardWindow*>();

		if (win) {
			QRectF boundingRect = m_wm->normalOrScreenBounds(0);
			if(WindowType::Type_ModalChildWindowCard != win->type())
				win->setBoundingRect(boundingRect.width(), boundingRect.height());
			else {
				win->setBoundingRect(Settings::LunaSettings()->modalWindowWidth, Settings::LunaSettings()->modalWindowHeight);
			}
		}
	}

	m_wm->prepareAddWindowSibling(win);
}
void MaximizeState::animationsFinished()
{
	finishMaximizingActiveWindow();
	QRectF boundingRect;

	CardWindow* activeWin = m_wm->activeWindow();
	if (activeWin) {
		if(WindowType::Type_ModalChildWindowCard != activeWin->type()) {
			boundingRect = m_wm->normalOrScreenBounds(activeWin);
			activeWin->setBoundingRect(boundingRect.width(), boundingRect.height());
		}
		else {
			activeWin->setBoundingRect(Settings::LunaSettings()->modalWindowWidth, Settings::LunaSettings()->modalWindowHeight);

			// Notify the parent.
			CardWindow* parent = m_wm->modalParent();
			if(parent) {
				boundingRect = m_wm->normalOrScreenBounds(parent);
				parent->setBoundingRect(boundingRect.width(), boundingRect.height());
			}
		}
	}
}
void MinimizeState::onEntry(QEvent* event)
{
	CardWindowManagerState::onEntry(event);

	CardWindow* activeWin = m_wm->activeWindow();
	if (activeWin) {
		m_wm->queueFocusAction(activeWin, false);
		QRectF boundingRect = m_wm->normalOrScreenBounds(0);
		activeWin->setBoundingRect(boundingRect.width(), boundingRect.height());
		m_wm->firstCardAlert();
	}
	SystemUiController::instance()->setCardWindowMaximized(false);
	SystemUiController::instance()->setMaximizedCardWindow(0);
}