<commit_before>/*
 * Copyright (C) 2008-2010 The QXmpp developers
 *
 * Author:
 *	<NAME>
 *
 * Source:
 *	http://code.google.com/p/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */


#include "messageGraphicsItem.h"
#include <QPainter>
#include <QTextDocument>
#include <QFontMetrics>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QTime>

QLinearGradient getGradient(const QColor &col, const QRectF &rect)
{
    QLinearGradient g(rect.topLeft(), rect.bottomLeft());

    qreal hue = col.hueF();
    qreal value = col.valueF();
    qreal saturation = col.saturationF();

    QColor c = col;
    c.setHsvF(hue, 0.42 * saturation, 0.98 * value);
    g.setColorAt(0, c);
    c.setHsvF(hue, 0.58 * saturation, 0.95 * value);
    g.setColorAt(0.25, c);
    c.setHsvF(hue, 0.70 * saturation, 0.93 * value);
    g.setColorAt(0.5, c);

    c.setHsvF(hue, 0.95 * saturation, 0.9 * value);
    g.setColorAt(0.501, c);
    c.setHsvF(hue * 0.95, 0.95 * saturation, 0.95 * value);
    g.setColorAt(0.75, c);
    c.setHsvF(hue * 0.90, 0.95 * saturation, 1 * value);
    g.setColorAt(1.0, c);

    return g;
}

QLinearGradient darken(const QLinearGradient &gradient)
{
    QGradientStops stops = gradient.stops();
    for (int i = 0; i < stops.size(); ++i) {
        QColor color = stops.at(i).second;
        stops[i].second = color.darker(160);
    }

    QLinearGradient g = gradient;
    g.setStops(stops);
    return g;
}

void drawPath(QPainter *p, const QPainterPath &path,
              const QColor &col, const QString &name, int textWidth,
              bool dark = false)
{
    const QRectF pathRect = path.boundingRect();

    const QLinearGradient baseGradient = getGradient(col, pathRect);
    const QLinearGradient darkGradient = darken(baseGradient);

    p->save();

   // p->setOpacity(0.25);

    //glow
//    if (dark)
//        p->strokePath(path, QPen(darkGradient, 6));
//    else
//        p->strokePath(path, QPen(baseGradient, 6));

    p->setOpacity(1.0);

    //fill
    if (dark)
        p->fillPath(path, darkGradient);
    else
        p->fillPath(path, baseGradient);

    QLinearGradient g(pathRect.topLeft(), pathRect.topRight());
    g.setCoordinateMode(QGradient::ObjectBoundingMode);

    p->setOpacity(0.2);
    p->fillPath(path, g);

    p->setOpacity(0.5);

    // highlight
//    if (dark)
//        p->strokePath(path, QPen(col.lighter(160).darker(160), 2));
//    else
//        p->strokePath(path, QPen(col.lighter(160), 2));

    p->setOpacity(1.0);

    p->restore();
}

messageGraphicsItem::messageGraphicsItem(QGraphicsItem * parent):QGraphicsPathItem(parent),
            m_spikeWidth(9),
            m_spikeHeight(6),
            m_cornerRadius(10),
            m_textSpacing(4), m_color(Qt::yellow)
{
    setPath(createPath());
//    setFlags(QGraphicsItem::ItemIsMovable);

    QFont font;
    QFontMetrics fm(font);
    m_timeStampWidth = fm.width(getTime()) + 4;
}

void messageGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setRenderHint(QPainter::Antialiasing);
    drawPath(painter, path(), m_color, getText(), getTextWidth());

    int spike_x = m_spikeWidth;
    int spike_y = m_spikeHeight;
    int corner = m_cornerRadius;
    int length = m_width - spike_x;
    int offset = spike_x;
    QFont font;
    font.setBold(true);
    QTextDocument textDoc(getText());
    QTextOption textOp;
    textOp.setWrapMode(QTextOption::WrapAnywhere);
    textOp.setAlignment(Qt::AlignLeft);
    textDoc.setDefaultTextOption(textOp);
    textDoc.setTextWidth(getTextWidth());
    textDoc.setDefaultFont(font);
<commit_msg>suppress warnings<commit_after>/*
 * Copyright (C) 2008-2010 The QXmpp developers
 *
 * Author:
 *	<NAME>
 *
 * Source:
 *	http://code.google.com/p/qxmpp
 *
 * This file is a part of QXmpp library.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 */


#include "messageGraphicsItem.h"
#include <QPainter>
#include <QTextDocument>
#include <QFontMetrics>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QTime>

QLinearGradient getGradient(const QColor &col, const QRectF &rect)
{
    QLinearGradient g(rect.topLeft(), rect.bottomLeft());

    qreal hue = col.hueF();
    qreal value = col.valueF();
    qreal saturation = col.saturationF();

    QColor c = col;
    c.setHsvF(hue, 0.42 * saturation, 0.98 * value);
    g.setColorAt(0, c);
    c.setHsvF(hue, 0.58 * saturation, 0.95 * value);
    g.setColorAt(0.25, c);
    c.setHsvF(hue, 0.70 * saturation, 0.93 * value);
    g.setColorAt(0.5, c);

    c.setHsvF(hue, 0.95 * saturation, 0.9 * value);
    g.setColorAt(0.501, c);
    c.setHsvF(hue * 0.95, 0.95 * saturation, 0.95 * value);
    g.setColorAt(0.75, c);
    c.setHsvF(hue * 0.90, 0.95 * saturation, 1 * value);
    g.setColorAt(1.0, c);

    return g;
}

QLinearGradient darken(const QLinearGradient &gradient)
{
    QGradientStops stops = gradient.stops();
    for (int i = 0; i < stops.size(); ++i) {
        QColor color = stops.at(i).second;
        stops[i].second = color.darker(160);
    }

    QLinearGradient g = gradient;
    g.setStops(stops);
    return g;
}

void drawPath(QPainter *p, const QPainterPath &path,
              const QColor &col, const QString &name, int textWidth,
              bool dark = false)
{
    const QRectF pathRect = path.boundingRect();

    const QLinearGradient baseGradient = getGradient(col, pathRect);
    const QLinearGradient darkGradient = darken(baseGradient);

    p->save();

   // p->setOpacity(0.25);

    //glow
//    if (dark)
//        p->strokePath(path, QPen(darkGradient, 6));
//    else
//        p->strokePath(path, QPen(baseGradient, 6));

    p->setOpacity(1.0);

    //fill
    if (dark)
        p->fillPath(path, darkGradient);
    else
        p->fillPath(path, baseGradient);

    QLinearGradient g(pathRect.topLeft(), pathRect.topRight());
    g.setCoordinateMode(QGradient::ObjectBoundingMode);

    p->setOpacity(0.2);
    p->fillPath(path, g);

    p->setOpacity(0.5);

    // highlight
//    if (dark)
//        p->strokePath(path, QPen(col.lighter(160).darker(160), 2));
//    else
//        p->strokePath(path, QPen(col.lighter(160), 2));

    p->setOpacity(1.0);

    p->restore();
}

messageGraphicsItem::messageGraphicsItem(QGraphicsItem * parent):QGraphicsPathItem(parent),
            m_spikeWidth(9),
            m_spikeHeight(6),
            m_cornerRadius(10),
            m_textSpacing(4), m_color(Qt::yellow)
{
    setPath(createPath());
//    setFlags(QGraphicsItem::ItemIsMovable);

    QFont font;
    QFontMetrics fm(font);
    m_timeStampWidth = fm.width(getTime()) + 4;
}

void messageGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    painter->setRenderHint(QPainter::Antialiasing);
    drawPath(painter, path(), m_color, getText(), getTextWidth());

//    int spike_x = m_spikeWidth;
//    int spike_y = m_spikeHeight;
//    int corner = m_cornerRadius;
//    int length = m_width - spike_x;
//    int offset = spike_x;
    QFont font;
    font.setBold(true);
    QTextDocument textDoc(getText());
    QTextOption textOp;
    textOp.setWrapMode(QTextOption::WrapAnywhere);
    textOp.setAlignment(Qt::AlignLeft);
    textDoc.setDefaultTextOption(textOp);
    textDoc.setTextWidth(getTextWidth());
    textDoc.setDefaultFont(font);

{'fraction_non_alphanumeric': 0.1353491720662347, 'fraction_numerical': 0.02351811855051596, 'mean_word_length': 3.222391084093212, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 47, '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': '5000446', 'n_tokens_mistral': 3068, 'n_tokens_neox': 2834, 'n_words': 673}