* move message_log_widget to game

* move files

* update headers

* fix cmakelists

* oracle fixes

* split implementation out to cpp

* fix recursive import

* fix main file

* format
This commit is contained in:
ebbit1q 2025-09-20 14:35:52 +02:00 committed by GitHub
parent f484c98152
commit 17dcaf9afa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
337 changed files with 728 additions and 721 deletions

View file

@ -1,8 +1,8 @@
#include "dlg_create_game.h"
#include "../client/tabs/tab_room.h"
#include "../server/pending_command.h"
#include "../settings/cache_settings.h"
#include "../tabs/tab_room.h"
#include "pb/serverinfo_game.pb.h"
#include "trice_limits.h"

View file

@ -1,264 +0,0 @@
#include "dlg_create_token.h"
#include "../client/ui/widgets/cards/card_info_picture_widget.h"
#include "../database/card_database_manager.h"
#include "../database/card_database_model.h"
#include "../main.h"
#include "../settings/cache_settings.h"
#include "deck_list.h"
#include "trice_limits.h"
#include <QCheckBox>
#include <QCloseEvent>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QLabel>
#include <QLineEdit>
#include <QRadioButton>
#include <QTreeView>
#include <QVBoxLayout>
DlgCreateToken::DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent)
: QDialog(parent), predefinedTokens(_predefinedTokens)
{
pic = new CardInfoPictureWidget();
pic->setObjectName("pic");
nameLabel = new QLabel(tr("&Name:"));
nameEdit = new QLineEdit(tr("Token"));
nameEdit->setMaxLength(MAX_NAME_LENGTH);
QTimer::singleShot(100, this, [=, this]() {
nameEdit->selectAll();
nameEdit->setFocus();
});
connect(nameEdit, &QLineEdit::textChanged, this, &DlgCreateToken::updateSearch);
nameLabel->setBuddy(nameEdit);
colorLabel = new QLabel(tr("C&olor:"));
colorEdit = new QComboBox;
colorEdit->addItem(tr("white"), QChar('w'));
colorEdit->addItem(tr("blue"), QChar('u'));
colorEdit->addItem(tr("black"), QChar('b'));
colorEdit->addItem(tr("red"), QChar('r'));
colorEdit->addItem(tr("green"), QChar('g'));
colorEdit->addItem(tr("multicolor"), QChar('m'));
colorEdit->addItem(tr("colorless"), QChar());
colorLabel->setBuddy(colorEdit);
ptLabel = new QLabel(tr("&P/T:"));
ptEdit = new QLineEdit;
ptEdit->setMaxLength(MAX_NAME_LENGTH);
ptLabel->setBuddy(ptEdit);
annotationLabel = new QLabel(tr("&Annotation:"));
annotationEdit = new QLineEdit;
annotationEdit->setMaxLength(MAX_NAME_LENGTH);
annotationLabel->setBuddy(annotationEdit);
destroyCheckBox = new QCheckBox(tr("&Destroy token when it leaves the table"));
destroyCheckBox->setChecked(true);
faceDownCheckBox = new QCheckBox(tr("Create face-down (Only hides name)"));
connect(faceDownCheckBox, &QCheckBox::toggled, this, &DlgCreateToken::faceDownCheckBoxToggled);
QGridLayout *grid = new QGridLayout;
grid->addWidget(nameLabel, 0, 0);
grid->addWidget(nameEdit, 0, 1);
grid->addWidget(colorLabel, 1, 0);
grid->addWidget(colorEdit, 1, 1);
grid->addWidget(ptLabel, 2, 0);
grid->addWidget(ptEdit, 2, 1);
grid->addWidget(annotationLabel, 3, 0);
grid->addWidget(annotationEdit, 3, 1);
grid->addWidget(destroyCheckBox, 4, 0, 1, 2);
grid->addWidget(faceDownCheckBox, 5, 0, 1, 2);
QGroupBox *tokenDataGroupBox = new QGroupBox(tr("Token data"));
tokenDataGroupBox->setLayout(grid);
cardDatabaseModel = new CardDatabaseModel(CardDatabaseManager::getInstance(), false, this);
cardDatabaseDisplayModel = new TokenDisplayModel(this);
cardDatabaseDisplayModel->setSourceModel(cardDatabaseModel);
chooseTokenFromAllRadioButton = new QRadioButton(tr("Show &all tokens"));
connect(chooseTokenFromAllRadioButton, &QRadioButton::toggled, this, &DlgCreateToken::actChooseTokenFromAll);
chooseTokenFromDeckRadioButton = new QRadioButton(tr("Show tokens from this &deck"));
connect(chooseTokenFromDeckRadioButton, &QRadioButton::toggled, this, &DlgCreateToken::actChooseTokenFromDeck);
QByteArray deckHeaderState = SettingsCache::instance().layouts().getDeckEditorDbHeaderState();
chooseTokenView = new QTreeView;
chooseTokenView->setModel(cardDatabaseDisplayModel);
chooseTokenView->setUniformRowHeights(true);
chooseTokenView->setRootIsDecorated(false);
chooseTokenView->setAlternatingRowColors(true);
chooseTokenView->setSortingEnabled(true);
chooseTokenView->sortByColumn(0, Qt::AscendingOrder);
chooseTokenView->resizeColumnToContents(0);
chooseTokenView->setWordWrap(true);
if (!deckHeaderState.isNull())
chooseTokenView->header()->restoreState(deckHeaderState);
chooseTokenView->header()->setStretchLastSection(false);
chooseTokenView->header()->hideSection(1); // Sets
chooseTokenView->header()->hideSection(2); // Mana Cost
chooseTokenView->header()->setSectionResizeMode(5, QHeaderView::ResizeToContents); // Color(s)
connect(chooseTokenView->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
&DlgCreateToken::tokenSelectionChanged);
connect(chooseTokenView, &QTreeView::doubleClicked, this, &DlgCreateToken::actOk);
if (predefinedTokens.isEmpty()) {
chooseTokenFromAllRadioButton->setChecked(true);
chooseTokenFromDeckRadioButton->setDisabled(true); // No tokens in deck = no need for option
} else {
chooseTokenFromDeckRadioButton->setChecked(true);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>(predefinedTokens.begin(), predefinedTokens.end()));
#else
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
#endif
}
QVBoxLayout *tokenChooseLayout = new QVBoxLayout;
tokenChooseLayout->addWidget(chooseTokenFromAllRadioButton);
tokenChooseLayout->addWidget(chooseTokenFromDeckRadioButton);
tokenChooseLayout->addWidget(chooseTokenView);
QGroupBox *tokenChooseGroupBox = new QGroupBox(tr("Choose token from list"));
tokenChooseGroupBox->setLayout(tokenChooseLayout);
QGridLayout *hbox = new QGridLayout;
hbox->addWidget(pic, 0, 0, 1, 1);
hbox->addWidget(tokenDataGroupBox, 1, 0, 1, 1);
hbox->addWidget(tokenChooseGroupBox, 0, 1, 2, 1);
hbox->setColumnStretch(1, 1);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgCreateToken::actOk);
connect(buttonBox, &QDialogButtonBox::rejected, this, &DlgCreateToken::actReject);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(hbox);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Create token"));
resize(600, 500);
restoreGeometry(SettingsCache::instance().getTokenDialogGeometry());
}
void DlgCreateToken::closeEvent(QCloseEvent *event)
{
event->accept();
SettingsCache::instance().setTokenDialogGeometry(saveGeometry());
}
void DlgCreateToken::faceDownCheckBoxToggled(bool checked)
{
if (checked) {
colorEdit->setCurrentIndex(6);
colorEdit->setEnabled(false);
ptEdit->clear();
ptEdit->clearFocus();
ptEdit->setEnabled(false);
} else {
colorEdit->setEnabled(true);
ptEdit->setEnabled(true);
annotationEdit->setEnabled(true);
}
}
void DlgCreateToken::tokenSelectionChanged(const QModelIndex &current, const QModelIndex & /*previous*/)
{
const QModelIndex realIndex = cardDatabaseDisplayModel->mapToSource(current);
CardInfoPtr cardInfo;
if (current.row() >= 0) {
cardInfo = cardDatabaseModel->getCard(realIndex.row());
}
if (cardInfo) {
updateSearchFieldWithoutUpdatingFilter(cardInfo->getName());
const QChar cardColor = cardInfo->getColorChar();
colorEdit->setCurrentIndex(colorEdit->findData(cardColor, Qt::UserRole, Qt::MatchFixedString));
ptEdit->setText(cardInfo->getPowTough());
if (SettingsCache::instance().getAnnotateTokens())
annotationEdit->setText(cardInfo->getText());
} else {
nameEdit->setText("");
colorEdit->setCurrentIndex(colorEdit->findData(QString(), Qt::UserRole, Qt::MatchFixedString));
ptEdit->setText("");
annotationEdit->setText("");
}
const auto &cardProviderId =
SettingsCache::instance().cardOverrides().getCardPreferenceOverride(cardInfo->getName());
if (!cardProviderId.isEmpty()) {
CardRef ref;
ref.name = cardInfo->getName();
ref.providerId = cardProviderId;
pic->setCard(CardDatabaseManager::getInstance()->getCard(ref));
} else {
pic->setCard(CardDatabaseManager::getInstance()->getPreferredCard(cardInfo));
}
}
void DlgCreateToken::updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const
{
nameEdit->blockSignals(true);
nameEdit->setText(newValue);
nameEdit->blockSignals(false);
}
void DlgCreateToken::updateSearch(const QString &search)
{
cardDatabaseDisplayModel->setCardName(search);
}
void DlgCreateToken::actChooseTokenFromAll(bool checked)
{
if (checked) {
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>());
}
}
void DlgCreateToken::actChooseTokenFromDeck(bool checked)
{
if (checked) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>(predefinedTokens.begin(), predefinedTokens.end()));
#else
cardDatabaseDisplayModel->setCardNameSet(QSet<QString>::fromList(predefinedTokens));
#endif
}
}
void DlgCreateToken::actOk()
{
SettingsCache::instance().setTokenDialogGeometry(saveGeometry());
accept();
}
void DlgCreateToken::actReject()
{
SettingsCache::instance().setTokenDialogGeometry(saveGeometry());
reject();
}
TokenInfo DlgCreateToken::getTokenInfo() const
{
return {.name = nameEdit->text(),
.color = colorEdit->itemData(colorEdit->currentIndex()).toString(),
.pt = ptEdit->text(),
.annotation = annotationEdit->text(),
.destroy = destroyCheckBox->isChecked(),
.faceDown = faceDownCheckBox->isChecked(),
.providerId = SettingsCache::instance().cardOverrides().getCardPreferenceOverride(nameEdit->text())};
}

View file

@ -1,65 +0,0 @@
#ifndef DLG_CREATETOKEN_H
#define DLG_CREATETOKEN_H
#include <QDialog>
#include <QModelIndex>
class QLabel;
class QLineEdit;
class QComboBox;
class QCheckBox;
class QPushButton;
class QRadioButton;
class QCloseEvent;
class QTreeView;
class DeckList;
class CardDatabaseModel;
class TokenDisplayModel;
class CardInfoPictureWidget;
struct TokenInfo
{
QString name;
QString color;
QString pt;
QString annotation;
bool destroy = true;
bool faceDown = false;
QString providerId;
};
class DlgCreateToken : public QDialog
{
Q_OBJECT
public:
explicit DlgCreateToken(const QStringList &_predefinedTokens, QWidget *parent = nullptr);
TokenInfo getTokenInfo() const;
protected:
void closeEvent(QCloseEvent *event) override;
private slots:
void faceDownCheckBoxToggled(bool checked);
void tokenSelectionChanged(const QModelIndex &current, const QModelIndex &previous);
void updateSearch(const QString &search);
void actChooseTokenFromAll(bool checked);
void actChooseTokenFromDeck(bool checked);
void actOk();
void actReject();
private:
CardDatabaseModel *cardDatabaseModel;
TokenDisplayModel *cardDatabaseDisplayModel;
QStringList predefinedTokens;
QLabel *nameLabel, *colorLabel, *ptLabel, *annotationLabel;
QComboBox *colorEdit;
QLineEdit *nameEdit, *ptEdit, *annotationEdit;
QCheckBox *destroyCheckBox;
QCheckBox *faceDownCheckBox;
QRadioButton *chooseTokenFromAllRadioButton, *chooseTokenFromDeckRadioButton;
CardInfoPictureWidget *pic;
QTreeView *chooseTokenView;
void updateSearchFieldWithoutUpdatingFilter(const QString &newValue) const;
};
#endif

View file

@ -1,7 +1,7 @@
#ifndef DLG_FILTER_GAMES_H
#define DLG_FILTER_GAMES_H
#include "../game/games_model.h"
#include "../server/games_model.h"
#include <QCheckBox>
#include <QComboBox>

View file

@ -1,10 +1,10 @@
#include "dlg_manage_sets.h"
#include "../client/network/sets_model.h"
#include "../client/ui/picture_loader/picture_loader.h"
#include "../database/card_database_manager.h"
#include "../deck/custom_line_edit.h"
#include "../main.h"
#include "../picture_loader/picture_loader.h"
#include "../settings/cache_settings.h"
#include <QAction>

View file

@ -1,139 +0,0 @@
#include "dlg_move_top_cards_until.h"
#include "../database/card_database.h"
#include "../database/card_database_manager.h"
#include "../filters/filter_string.h"
#include <QDialogButtonBox>
#include <QLabel>
#include <QLineEdit>
#include <QMessageBox>
#include <QSpinBox>
#include <QString>
#include <QVBoxLayout>
#include <QWidget>
DlgMoveTopCardsUntil::DlgMoveTopCardsUntil(QWidget *parent, QStringList exprs, uint _numberOfHits, bool autoPlay)
: QDialog(parent)
{
exprLabel = new QLabel(tr("Card name (or search expressions):"));
exprComboBox = new QComboBox(this);
exprComboBox->setFocus();
exprComboBox->setEditable(true);
exprComboBox->setInsertPolicy(QComboBox::InsertAtTop);
exprComboBox->insertItems(0, exprs);
exprLabel->setBuddy(exprComboBox);
numberOfHitsLabel = new QLabel(tr("Number of hits:"));
numberOfHitsEdit = new QSpinBox(this);
numberOfHitsEdit->setRange(1, 99);
numberOfHitsEdit->setValue(_numberOfHits);
numberOfHitsLabel->setBuddy(numberOfHitsEdit);
auto *grid = new QGridLayout;
grid->addWidget(numberOfHitsLabel, 0, 0);
grid->addWidget(numberOfHitsEdit, 0, 1);
autoPlayCheckBox = new QCheckBox(tr("Auto play hits"));
autoPlayCheckBox->setChecked(autoPlay);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &DlgMoveTopCardsUntil::validateAndAccept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
auto *mainLayout = new QVBoxLayout;
mainLayout->addWidget(exprLabel);
mainLayout->addWidget(exprComboBox);
mainLayout->addItem(grid);
mainLayout->addWidget(autoPlayCheckBox);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Put top cards on stack until..."));
}
/**
* @brief Checks if a card matching the expr exists in the card database.
*
* @returns true if a card matching the expression exists.
*/
static bool matchExistsInDb(const FilterString &filterString)
{
const auto *cardDatabase = CardDatabaseManager::getInstance();
const auto &allCards = cardDatabase->getCardList();
const auto it = std::find_if(allCards.begin(), allCards.end(),
[&filterString](const CardInfoPtr &card) { return filterString.check(card); });
return it != allCards.end();
}
/**
* @brief Validates that a card matching the expr exists in the card database.
* If no match is found, then pop up a window to warn the user, giving them a chance to back out.
*
* @returns whether to proceed with the action
*/
bool DlgMoveTopCardsUntil::validateMatchExists(const FilterString &filterString)
{
if (matchExistsInDb(filterString)) {
return true;
}
const auto msg = tr("No cards matching the search expression exists in the card database. Proceed anyways?");
const auto res =
QMessageBox::warning(this, tr("Cockatrice"), msg, QMessageBox::Yes | QMessageBox::No, QMessageBox::No);
if (res == QMessageBox::No) {
return false;
}
return true;
}
void DlgMoveTopCardsUntil::validateAndAccept()
{
auto movingCardsUntilFilter = FilterString(exprComboBox->currentText());
if (!movingCardsUntilFilter.valid()) {
QMessageBox::warning(this, tr("Invalid filter"), movingCardsUntilFilter.error(), QMessageBox::Ok);
return;
}
if (!validateMatchExists(movingCardsUntilFilter)) {
return;
}
// move currently selected text to top of history list
if (exprComboBox->currentIndex() != 0) {
QString currentExpr = exprComboBox->currentText();
exprComboBox->removeItem(exprComboBox->currentIndex());
exprComboBox->insertItem(0, currentExpr);
exprComboBox->setCurrentIndex(0);
}
accept();
}
QString DlgMoveTopCardsUntil::getExpr() const
{
return exprComboBox->currentText();
}
QStringList DlgMoveTopCardsUntil::getExprs() const
{
QStringList exprs;
for (int i = 0; i < exprComboBox->count(); ++i) {
exprs.append(exprComboBox->itemText(i));
}
return exprs;
}
uint DlgMoveTopCardsUntil::getNumberOfHits() const
{
return numberOfHitsEdit->text().toUInt();
}
bool DlgMoveTopCardsUntil::isAutoPlay() const
{
return autoPlayCheckBox->isChecked();
}

View file

@ -1,37 +0,0 @@
#ifndef DLG_MOVE_TOP_CARDS_UNTIL_H
#define DLG_MOVE_TOP_CARDS_UNTIL_H
#include <QCheckBox>
#include <QComboBox>
#include <QDialog>
#include <QDialogButtonBox>
#include <QLabel>
#include <QSpinBox>
class FilterString;
class DlgMoveTopCardsUntil : public QDialog
{
Q_OBJECT
QLabel *exprLabel, *numberOfHitsLabel;
QComboBox *exprComboBox;
QSpinBox *numberOfHitsEdit;
QDialogButtonBox *buttonBox;
QCheckBox *autoPlayCheckBox;
void validateAndAccept();
bool validateMatchExists(const FilterString &filterString);
public:
explicit DlgMoveTopCardsUntil(QWidget *parent = nullptr,
QStringList exprs = QStringList(),
uint numberOfHits = 1,
bool autoPlay = false);
QString getExpr() const;
QStringList getExprs() const;
uint getNumberOfHits() const;
bool isAutoPlay() const;
};
#endif // DLG_MOVE_TOP_CARDS_UNTIL_H

View file

@ -1,52 +0,0 @@
#include "dlg_roll_dice.h"
#include "trice_limits.h"
#include <QDialogButtonBox>
#include <QLabel>
#include <QSpinBox>
#include <QVBoxLayout>
#include <QWidget>
DlgRollDice::DlgRollDice(QWidget *parent) : QDialog(parent)
{
numberOfSidesLabel = new QLabel(tr("Number of sides:"));
numberOfSidesEdit = new QSpinBox(this);
numberOfSidesEdit->setValue(DEFAULT_NUMBER_SIDES_DIE);
numberOfSidesEdit->setRange(MINIMUM_DIE_SIDES, MAXIMUM_DIE_SIDES);
numberOfSidesEdit->setFocus();
numberOfSidesLabel->setBuddy(numberOfSidesEdit);
numberOfDiceLabel = new QLabel(tr("Number of dice:"));
numberOfDiceEdit = new QSpinBox(this);
numberOfDiceEdit->setValue(DEFAULT_NUMBER_DICE_TO_ROLL);
numberOfDiceEdit->setRange(MINIMUM_DICE_TO_ROLL, MAXIMUM_DICE_TO_ROLL);
numberOfDiceLabel->setBuddy(numberOfDiceEdit);
auto *grid = new QGridLayout;
grid->addWidget(numberOfSidesLabel, 0, 0);
grid->addWidget(numberOfSidesEdit, 0, 1);
grid->addWidget(numberOfDiceLabel, 1, 0);
grid->addWidget(numberOfDiceEdit, 1, 1);
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
auto *mainLayout = new QVBoxLayout;
mainLayout->addItem(grid);
mainLayout->addWidget(buttonBox);
setLayout(mainLayout);
setWindowTitle(tr("Roll Dice"));
}
uint DlgRollDice::getDieSideCount() const
{
return numberOfSidesEdit->text().toUInt();
}
uint DlgRollDice::getDiceToRollCount() const
{
return numberOfDiceEdit->text().toUInt();
}

View file

@ -1,26 +0,0 @@
#ifndef DLG_ROLL_DICE_H
#define DLG_ROLL_DICE_H
#include <QDialog>
#include <QDialogButtonBox>
#include <QLabel>
#include <QSpinBox>
class DlgRollDice : public QDialog
{
Q_OBJECT
static constexpr uint DEFAULT_NUMBER_SIDES_DIE = 20;
static constexpr uint DEFAULT_NUMBER_DICE_TO_ROLL = 1;
QLabel *numberOfSidesLabel, *numberOfDiceLabel;
QSpinBox *numberOfSidesEdit, *numberOfDiceEdit;
QDialogButtonBox *buttonBox;
public:
explicit DlgRollDice(QWidget *parent = nullptr);
[[nodiscard]] uint getDieSideCount() const;
[[nodiscard]] uint getDiceToRollCount() const;
};
#endif // DLG_ROLL_DICE_H

View file

@ -1,9 +1,9 @@
#include "dlg_select_set_for_cards.h"
#include "../client/ui/widgets/cards/card_info_picture_widget.h"
#include "../client/ui/widgets/general/layout_containers/flow_widget.h"
#include "../database/card_database_manager.h"
#include "../deck/deck_loader.h"
#include "../interface/widgets/cards/card_info_picture_widget.h"
#include "../interface/widgets/general/layout_containers/flow_widget.h"
#include "dlg_select_set_for_cards.h"
#include <QCheckBox>

View file

@ -1,8 +1,8 @@
#ifndef DLG_SELECT_SET_FOR_CARDS_H
#define DLG_SELECT_SET_FOR_CARDS_H
#include "../client/ui/widgets/general/layout_containers/flow_widget.h"
#include "../deck/deck_list_model.h"
#include "../interface/widgets/general/layout_containers/flow_widget.h"
#include <QCheckBox>
#include <QDialog>

View file

@ -4,17 +4,17 @@
#include "../client/network/release_channel.h"
#include "../client/network/spoiler_background_updater.h"
#include "../client/sound_engine.h"
#include "../client/tabs/tab_supervisor.h"
#include "../client/ui/picture_loader/picture_loader.h"
#include "../client/ui/theme_manager.h"
#include "../client/ui/widgets/general/background_sources.h"
#include "../database/card_database.h"
#include "../database/card_database_manager.h"
#include "../deck/custom_line_edit.h"
#include "../interface/theme_manager.h"
#include "../interface/widgets/general/background_sources.h"
#include "../main.h"
#include "../picture_loader/picture_loader.h"
#include "../settings/cache_settings.h"
#include "../settings/card_counter_settings.h"
#include "../settings/shortcut_treeview.h"
#include "../tabs/tab_supervisor.h"
#include "../utility/sequence_edit.h"
#include <QAbstractButton>

View file

@ -1,7 +1,7 @@
#include "dlg_tip_of_the_day.h"
#include "../client/ui/tip_of_the_day.h"
#include "../settings/cache_settings.h"
#include "tip_of_the_day.h"
#include <QCheckBox>
#include <QDate>

View file

@ -2,7 +2,7 @@
#include "../client/network/client_update_checker.h"
#include "../client/network/release_channel.h"
#include "../client/ui/window_main.h"
#include "../interface/window_main.h"
#include "../settings/cache_settings.h"
#include <QApplication>

View file

@ -0,0 +1,103 @@
#include "tip_of_the_day.h"
#include <QDate>
#include <QFile>
#include <QMessageBox>
#include <QTextStream>
#include <QXmlStreamReader>
#include <utility>
#define TIPDDBMODEL_COLUMNS 3
TipOfTheDay::TipOfTheDay(QString _title, QString _content, QString _imagePath, QDate _date)
: title(std::move(_title)), content(std::move(_content)), imagePath(std::move(_imagePath)), date(_date)
{
}
TipsOfTheDay::TipsOfTheDay(QString xmlPath, QObject *parent) : QAbstractListModel(parent)
{
tipList = new QList<TipOfTheDay>;
QFile xmlFile(xmlPath);
QTextStream errorStream(stderr);
if (!QFile::exists(xmlPath)) {
errorStream << tr("File does not exist.\n");
return;
} else if (!xmlFile.open(QIODevice::ReadOnly)) {
errorStream << tr("Failed to open file.\n");
return;
}
QXmlStreamReader reader(&xmlFile);
while (!reader.atEnd()) {
if (reader.readNext() == QXmlStreamReader::EndElement) {
break;
}
auto readerName = reader.name().toString();
if (readerName == "tip") {
QString title, content, imagePath;
QDate date;
reader.readNext();
while (!reader.atEnd()) {
if (reader.readNext() == QXmlStreamReader::EndElement) {
break;
}
readerName = reader.name().toString();
if (readerName == "title") {
title = reader.readElementText();
} else if (readerName == "text") {
content = reader.readElementText();
} else if (readerName == "image") {
imagePath = "theme:tips/images/" + reader.readElementText();
} else if (readerName == "date") {
date = QDate::fromString(reader.readElementText(), Qt::ISODate);
} else {
// unknown element, do nothing
}
}
tipList->append(TipOfTheDay(title, content, imagePath, date));
}
}
}
TipsOfTheDay::~TipsOfTheDay()
{
delete tipList;
}
QVariant TipsOfTheDay::data(const QModelIndex &index, int /*role*/) const
{
if (!index.isValid() || index.row() >= tipList->size() || index.column() >= TIPDDBMODEL_COLUMNS)
return QVariant();
TipOfTheDay tip = tipList->at(index.row());
switch (index.column()) {
case TitleColumn:
return tip.getTitle();
case ContentColumn:
return tip.getContent();
case ImagePathColumn:
return tip.getImagePath();
case DateColumn:
return tip.getDate();
default:
return QVariant();
}
}
TipOfTheDay TipsOfTheDay::getTip(int tipId)
{
return tipList->at(tipId);
}
int TipsOfTheDay::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return tipList->size();
}

View file

@ -0,0 +1,55 @@
#ifndef TIP_OF_DAY_H
#define TIP_OF_DAY_H
#include <QAbstractListModel>
#include <QDate>
class TipOfTheDay
{
public:
explicit TipOfTheDay(QString _title, QString _content, QString _imagePath, QDate _date);
QString getTitle() const
{
return title;
}
QString getContent() const
{
return content;
}
QString getImagePath() const
{
return imagePath;
}
QDate getDate() const
{
return date;
}
private:
QString title, content, imagePath;
QDate date;
};
class TipsOfTheDay : public QAbstractListModel
{
Q_OBJECT
public:
enum Columns
{
TitleColumn,
ContentColumn,
ImagePathColumn,
DateColumn,
};
explicit TipsOfTheDay(QString xmlPath, QObject *parent = nullptr);
~TipsOfTheDay() override;
TipOfTheDay getTip(int tipId);
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
private:
QList<TipOfTheDay> *tipList;
};
#endif