newspiece.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "newspiece.h"
  2. #include "ui_newspiece.h"
  3. #include <QDebug>
  4. NewsPiece::NewsPiece(QWidget *parent) :
  5. QWidget(parent),
  6. ui(new Ui::NewsPiece)
  7. {
  8. ui->setupUi(this);
  9. }
  10. void NewsPiece::setTitle(const QString &title, const QString &url)
  11. {
  12. _title = title;
  13. _url = url;
  14. ui->news_head_small->setText("<a style=\"color: #cfa644; text-decoration:none;\" href = '" + QString(url).remove("\n") + "'>" + QString(title).remove("\n") + "</a>");
  15. resize(sizeHint());
  16. }
  17. void NewsPiece::setDate(const QString &date)
  18. {
  19. ui->news_date_small->setText(QString(date).remove("\n"));
  20. resize(sizeHint());
  21. }
  22. void NewsPiece::setContents(const QString &contents)
  23. {
  24. ui->news_content_common->setText(QString(contents).remove("\n"));
  25. resize(sizeHint());
  26. }
  27. void NewsPiece::setIcon(const QPixmap &pixmap)
  28. {
  29. ui->news_icon->setPixmap(pixmap.scaled(ui->news_icon->sizeHint()));
  30. }
  31. QString NewsPiece::getTitle()
  32. {
  33. return _title;
  34. }
  35. QString NewsPiece::getUrl()
  36. {
  37. return _url;
  38. }
  39. QString NewsPiece::getDate()
  40. {
  41. return ui->news_date_small->text();
  42. }
  43. QString NewsPiece::getContents()
  44. {
  45. return ui->news_content_common->text();
  46. }
  47. QPixmap NewsPiece::getIcon()
  48. {
  49. return *ui->news_icon->pixmap();
  50. }
  51. NewsPiece::~NewsPiece()
  52. {
  53. delete ui;
  54. }