/**
 * Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 *
 * For the applicable distribution terms see the license.txt -file, included in
 * the distribution.
 */

#include "screensizeprovider.h"

#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>

// Constants
const int DesktopFixedWidth(800);
const int DesktopFixedHeight(640);


/*!
  \class ScreenSizeProvider
  \brief Provides the screen size attributes.
*/


/*!
  Constructor.
*/
ScreenSizeProvider::ScreenSizeProvider(QObject *parent)
    : QObject(parent)
{
    update();
}


/*!
  Copy constructor.
  Not for explicit use.
*/
ScreenSizeProvider::ScreenSizeProvider(const ScreenSizeProvider &instance)
    : QObject(0),
      m_screenRect(instance.m_screenRect)
{
}


/*!
  Destructor.
*/
ScreenSizeProvider::~ScreenSizeProvider()
{
}


/*!
  Returns the width of the screen.
*/
int ScreenSizeProvider::width() const
{
    return m_screenRect.width();
}


/*!
  Returns the height of the screen.
*/
int ScreenSizeProvider::height() const
{
    return m_screenRect.height();
}


/*!
  Returns the screen size rectangle.
*/
QRect ScreenSizeProvider::size() const
{
    return m_screenRect;
}


/*!
  Resolves the width and the height of the screen.
*/
void ScreenSizeProvider::update()
{
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined (Q_WS_MAEMO_6)
    QRect screenRect = QApplication::desktop()->screenGeometry();

    qDebug() << "ScreenSizeProvider::update():" << screenRect.width()
             << "x" << screenRect.height();

    if (screenRect.width() != m_screenRect.width() ||
            screenRect.height() != m_screenRect.height()) {
        m_screenRect = screenRect;
        emit widthChanged(m_screenRect.width());
        emit heightChanged(m_screenRect.height());
    }
#else
    if (m_screenRect.width() != DesktopFixedWidth ||
            m_screenRect.height() != DesktopFixedHeight) {
        m_screenRect.setWidth(DesktopFixedWidth);
        m_screenRect.setHeight(DesktopFixedHeight);
        emit widthChanged(m_screenRect.width());
        emit heightChanged(m_screenRect.height());
    }
#endif
}


// End of file.
