<commit_before>#include "monitorbox.h"



MonitorBox::MonitorBox(QRect widgetDims, QSize monitorResolution, QWidget *parent)
    : QWidget(parent)
    , _monitorWidgetSize(widgetDims)
{
    mapMonitorResolutionToWidgetCoordinates(monitorResolution);
}

MonitorBox::~MonitorBox()
{
    while (_windowRendering.size() > 0) {
        delete _windowRendering.back();
        _windowRendering.pop_back();
    }
}

void MonitorBox::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    QPen pen = painter.pen();
    painter.setPen(pen);
    //Draw border
    painter.setPen(QPen(Qt::gray, 4));
    painter.drawRoundedRect(0, 0, width() - 1, height() - 1, 10, 10);
    //Draw monitor outline
    painter.setPen(QPen(Qt::black, 2));
    painter.drawRect(_monitorDimensionsScaled);
    //Draw window(s)
    painter.setPen(Qt::blue);
    for (unsigned int i = 0; i < _nWindows; ++i) {
        if (i <= _windowRendering.size()) {
            painter.drawRect(*_windowRendering[i]);
        }
    }
}

void MonitorBox::windowDimensionsChanged(unsigned int index, const QRectF newDimensions) {
    mapWindowResolutionToWidgetCoordinates(index, newDimensions);
}

void MonitorBox::mapMonitorResolutionToWidgetCoordinates(QSize r) {
    float aspectRatio = static_cast<float>(r.width()) /
        static_cast<float>(r.height());
    _marginWidget = _monitorWidgetSize.width() * _marginFractionOfWidgetSize;
    if (aspectRatio >= 1.0) {
        float newWidth = _monitorWidgetSize.width()
            * (1.0 - _marginFractionOfWidgetSize * 2.0);
        _monitorScaleFactor = newWidth / static_cast<float>(r.width());
        float newHeight = newWidth / aspectRatio;
        _monitorDimensionsScaled = {<commit_msg>Added window ID number to monitorbox rendering<commit_after>#include "monitorbox.h"



MonitorBox::MonitorBox(QRect widgetDims, QSize monitorResolution, QWidget *parent)
    : QWidget(parent)
    , _monitorWidgetSize(widgetDims)
{
    mapMonitorResolutionToWidgetCoordinates(monitorResolution);
}

MonitorBox::~MonitorBox()
{
    while (_windowRendering.size() > 0) {
        delete _windowRendering.back();
        _windowRendering.pop_back();
    }
}

void MonitorBox::paintEvent(QPaintEvent *event)
{
    Q_UNUSED(event);
    QPainter painter(this);
    QPen pen = painter.pen();
    painter.setPen(pen);
    //Draw border
    painter.setPen(QPen(Qt::gray, 4));
    painter.drawRoundedRect(0, 0, width() - 1, height() - 1, 10, 10);
    //Draw monitor outline
    painter.setPen(QPen(Qt::black, 2));
    painter.drawRect(_monitorDimensionsScaled);
    //Draw window(s)
    painter.setPen(Qt::blue);
    painter.setFont(QFont("Arial", 16));
    for (unsigned int i = 0; i < _nWindows; ++i) {
        if (i <= _windowRendering.size()) {
            painter.drawRect(*_windowRendering[i]);
            QPointF t = QPointF(_windowRendering[i]->left() + 5,
                _windowRendering[i]->bottom() - 5);
            painter.drawText(t, QString::fromStdString(std::to_string(i + 1)));
        }
    }
}

void MonitorBox::windowDimensionsChanged(unsigned int index, const QRectF newDimensions) {
    mapWindowResolutionToWidgetCoordinates(index, newDimensions);
}

void MonitorBox::mapMonitorResolutionToWidgetCoordinates(QSize r) {
    float aspectRatio = static_cast<float>(r.width()) /
        static_cast<float>(r.height());
    _marginWidget = _monitorWidgetSize.width() * _marginFractionOfWidgetSize;
    if (aspectRatio >= 1.0) {
        float newWidth = _monitorWidgetSize.width()
            * (1.0 - _marginFractionOfWidgetSize * 2.0);
        _monitorScaleFactor = newWidth / static_cast<float>(r.width());
        float newHeight = newWidth / aspectRatio;
        _monitorDimensionsScaled = {
{'fraction_non_alphanumeric': 0.12844527696012845, 'fraction_numerical': 0.010971367407010971, 'mean_word_length': 3.6783479349186483, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, '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': '3830381', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1191, 'n_words': 211}