#include "getscreenshot.h"
#include <QGuiApplication>

GetScreenShot::GetScreenShot()
{
    if (QGSettings::isSchemaInstalled("org.mate.background")) {
        m_backgroundGSettings = new QGSettings("org.mate.background");
        setBackground(m_backgroundGSettings->get("pictureFilename").toString());
        connect(m_backgroundGSettings, &QGSettings::changed, [this](const QString &key) {
            if (key == "pictureFilename") {
                setBackground(m_backgroundGSettings->get("pictureFilename").toString());
            }
        });
    }
}
void GetScreenShot::paint(QPainter *painter)
{
    painter->setRenderHint(QPainter::Antialiasing,true);
    m_screen = QGuiApplication::primaryScreen();
    if(m_flag) {
        painter->drawPixmap(0,0,width(),height(),m_screen->grabWindow(0));
    }
}
void GetScreenShot::getScreen()
{
    m_screen = QGuiApplication::primaryScreen();
    m_flag = true;
    update();
}

QString GetScreenShot::background() const
{
    return m_background;
}

void GetScreenShot::setBackground(const QString &background)
{
    if (m_background != background) {
        m_background = background;
        Q_EMIT backgroundChanged();
    }
}
