#include "newspiece.h"
#include "ui_newspiece.h"
#include <QDebug>

NewsPiece::NewsPiece(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::NewsPiece)
{
    ui->setupUi(this);
}

void NewsPiece::setTitle(const QString &title, const QString &url)
{
    _title = title;
    _url = url;
    ui->news_head_small->setText("<a style=\"color: #cfa644; text-decoration:none;\" href = '" + QString(url).remove("\n") + "'>" + QString(title).remove("\n") + "</a>");
    resize(sizeHint());
}

void NewsPiece::setDate(const QString &date)
{
    ui->news_date_small->setText(QString(date).remove("\n"));
    resize(sizeHint());
}

void NewsPiece::setContents(const QString &contents)
{
    ui->news_content_small->setText(QString(contents).remove("\n"));
    resize(sizeHint());
}

void NewsPiece::setIcon(const QPixmap &pixmap)
{
    ui->news_icon->setPixmap(pixmap.scaled(ui->news_icon->sizeHint()));
}

QString NewsPiece::getTitle()
{
    return _title;
}

QString NewsPiece::getUrl()
{
    return _url;
}

QString NewsPiece::getDate()
{
    return ui->news_date_small->text();
}

QString NewsPiece::getContents()
{
    return ui->news_content_small->text();
}

QPixmap NewsPiece::getIcon()
{
    return *ui->news_icon->pixmap();
}

NewsPiece::~NewsPiece()
{
    delete ui;
}
