2022-06-25 23:15:16 +00:00
|
|
|
#include "NewsDialog.h"
|
|
|
|
#include "ui_NewsDialog.h"
|
|
|
|
|
|
|
|
NewsDialog::NewsDialog(QList<NewsEntryPtr> entries, QWidget* parent) : QDialog(parent), ui(new Ui::NewsDialog())
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
for (auto entry : entries) {
|
|
|
|
ui->articleListWidget->addItem(entry->title);
|
|
|
|
m_entries.insert(entry->title, entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
connect(ui->articleListWidget, &QListWidget::currentTextChanged, this, &NewsDialog::selectedArticleChanged);
|
|
|
|
connect(ui->toggleListButton, &QPushButton::clicked, this, &NewsDialog::toggleArticleList);
|
|
|
|
|
|
|
|
m_article_list_hidden = ui->articleListWidget->isHidden();
|
|
|
|
|
|
|
|
auto first_item = ui->articleListWidget->item(0);
|
2022-05-02 19:34:55 +00:00
|
|
|
first_item->setSelected(true);
|
2022-06-25 23:15:16 +00:00
|
|
|
|
|
|
|
auto article_entry = m_entries.constFind(first_item->text()).value();
|
|
|
|
ui->articleTitleLabel->setText(QString("<a href='%1'>%2</a>").arg(article_entry->link, first_item->text()));
|
|
|
|
ui->currentArticleContentBrowser->setText(article_entry->content);
|
|
|
|
}
|
|
|
|
|
|
|
|
NewsDialog::~NewsDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewsDialog::selectedArticleChanged(const QString& new_title)
|
|
|
|
{
|
2023-05-08 13:50:47 +00:00
|
|
|
auto const& article_entry_ptr = m_entries.constFind(new_title);
|
|
|
|
auto const& article_entry = article_entry_ptr.value();
|
2022-06-25 23:15:16 +00:00
|
|
|
|
|
|
|
ui->articleTitleLabel->setText(QString("<a href='%1'>%2</a>").arg(article_entry->link, new_title));
|
|
|
|
ui->currentArticleContentBrowser->setText(article_entry->content);
|
|
|
|
}
|
|
|
|
|
|
|
|
void NewsDialog::toggleArticleList()
|
|
|
|
{
|
|
|
|
m_article_list_hidden = !m_article_list_hidden;
|
|
|
|
|
|
|
|
ui->articleListWidget->setHidden(m_article_list_hidden);
|
|
|
|
|
|
|
|
if (m_article_list_hidden)
|
|
|
|
ui->toggleListButton->setText(tr("Show article list"));
|
|
|
|
else
|
|
|
|
ui->toggleListButton->setText(tr("Hide article list"));
|
|
|
|
}
|