<commit_before>//===========================================
//  Lumina-DE source code
//  Copyright (c) 2016, <NAME>
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "LDesktopBackground.h"

#include <QPainter>

void LDesktopBackground::paintEvent(QPaintEvent *) {
    if (bgPixmap != NULL) {
        QPainter painter(this);
        painter.setBrush(*bgPixmap);
        painter.drawRect(0, 0, width(), height());
    }
}

void LDesktopBackground::setBackground(const QString& bgFile, const QString& format) {
    if (bgPixmap != NULL) delete bgPixmap;
    bgPixmap = new QPixmap(size());

    if (bgFile.startsWith("rgb(")) {
        QStringList colors = bgFile.section(")",0,0).section("(",1,1).split(",");
        QColor color = QColor(colors[0].toInt(), colors[1].toInt(), colors[2].toInt());
        bgPixmap->fill(color);
    } else {
        bgPixmap->fill(Qt::black);

        // Load the background file and scale
        QPixmap bgImage(bgFile);
        if (format == "stretch" || format == "full" || format == "fit") {
            Qt::AspectRatioMode mode;
            if (format == "stretch") {
                mode = Qt::IgnoreAspectRatio;
            } else if (format == "full") {
                mode = Qt::KeepAspectRatioByExpanding;
            } else {
                mode = Qt::KeepAspectRatio;
            }
            bgImage = bgImage.scaled(size(), mode);
        }

        // Calculate the offset
        int dx = 0, dy = 0;
        int drawWidth = bgImage.width(), drawHeight = bgImage.height();
        if (format == "fit" || format == "center" || format == "full") {
            dx = (width() - bgImage.width()) / 2;
            dy = (height() - bgImage.height()) / 2;
        } else if (format == "tile") {
            drawWidth = width();
            drawHeight = height();
        } else {
            if (format.endsWith("right")) {
                dx = width() - bgImage.width();
            }
            if (format.startsWith("bottom")) {
                dy = height() - bgImage.height();
            }
        }

        // Draw the background image
        QPainter painter(bgPixmap);
        painter.setBrush(bgImage);
        painter.setBrushOrigin(dx, dy);
        painter.drawRect(dx, dy, drawWidth, drawHeight);
    }
    update();
    show();
}

LDesktopBackground::LDesktopBackground() : QWidget() {
    bgPixmap = NULL;
}

LDesktopBackground::~LDesktopBackground() {
    if (bgPixmap != NULL) delete bgPixmap;
}
<commit_msg>Try to fix a scaling issue with desktop backgrounds on 4K systems.<commit_after>//===========================================
//  Lumina-DE source code
//  Copyright (c) 2016, <NAME>
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#include "LDesktopBackground.h"

#include <QPainter>

void LDesktopBackground::paintEvent(QPaintEvent *) {
    if (bgPixmap != NULL) {
        QPainter painter(this);
        painter.setBrush(*bgPixmap);
        painter.drawRect(0, 0, width(), height());
    }
}

void LDesktopBackground::setBackground(const QString& bgFile, const QString& format) {
    if (bgPixmap != NULL) delete bgPixmap;
    bgPixmap = new QPixmap(size());

    if (bgFile.startsWith("rgb(")) {
        QStringList colors = bgFile.section(")",0,0).section("(",1,1).split(",");
        QColor color = QColor(colors[0].toInt(), colors[1].toInt(), colors[2].toInt());
        bgPixmap->fill(color);
    } else {
        bgPixmap->fill(Qt::black);

        // Load the background file and scale
        QPixmap bgImage(bgFile);
        if (format == "stretch" || format == "full" || format == "fit") {
            Qt::AspectRatioMode mode;
            if (format == "stretch") {
                mode = Qt::IgnoreAspectRatio;
            } else if (format == "full") {
                mode = Qt::KeepAspectRatioByExpanding;
            } else {
                mode = Qt::KeepAspectRatio;
            }
            if(bgImage.height() != this->height() && bgImage.width() != this->width() ){ bgImage = bgImage.scaled(size(), mode);  }
            //bgImage = bgImage.scaled(size(), mode);
        }

        // Calculate the offset
        int dx = 0, dy = 0;
        int drawWidth = bgImage.width(), drawHeight = bgImage.height();
        if (format == "fit" || format == "center" || format == "full") {
            dx = (width() - bgImage.width()) / 2;
            dy = (height() - bgImage.height()) / 2;
        } else if (format == "tile") {
            drawWidth = width();
            drawHeight = height();
        } else {
            if (format.endsWith("right")) {
                dx = width() - bgImage.width();
            }
            if (format.startsWith("bottom")) {
                dy = height() - bgImage.height();
            }
        }

        // Draw the background image
        QPainter painter(bgPixmap);
        painter.setBrush(bgImage);
        painter.setBrushOrigin(dx, dy);
        painter.drawRect(dx, dy, drawWidth, drawHeight);
    }
    update();
    show();
}

LDesktopBackground::LDesktopBackground() : QWidget() {
    bgPixmap = NULL;
}

LDesktopBackground::~LDesktopBackground() {
    if (bgPixmap != NULL) delete bgPixmap;
}

{'fraction_non_alphanumeric': 0.18043273753527753, 'fraction_numerical': 0.00696142991533396, 'mean_word_length': 2.2613496932515336, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '670272', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1538, 'n_words': 360}