feat: add Cat support

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2022-10-01 20:11:07 +02:00
parent 5c02265325
commit 3009356c8a
No known key found for this signature in database
GPG Key ID: C10411294912A422
4 changed files with 36 additions and 47 deletions

View File

@ -882,7 +882,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
ui->actionCAT->setChecked(cat_enable);
// NOTE: calling the operator like that is an ugly hack to appease ancient gcc...
connect(ui->actionCAT.operator->(), SIGNAL(toggled(bool)), SLOT(onCatToggled(bool)));
setCatBackground(cat_enable);
view->setCatDisplayed(cat_enable);
}
// start instance when double-clicked
connect(view, &InstanceView::instanceActivated, this, &MainWindow::instanceActivated);
@ -1469,54 +1469,10 @@ void MainWindow::downloadUpdates(GoUpdate::Status status)
void MainWindow::onCatToggled(bool state)
{
setCatBackground(state);
view->setCatDisplayed(state);
APPLICATION->settings()->set("TheCat", state);
}
namespace {
template <typename T>
T non_stupid_abs(T in)
{
if (in < 0)
return -in;
return in;
}
}
void MainWindow::setCatBackground(bool enabled)
{
if (enabled)
{
QDateTime now = QDateTime::currentDateTime();
QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
QString cat;
if(non_stupid_abs(now.daysTo(xmas)) <= 4) {
cat = "catmas";
}
else if (non_stupid_abs(now.daysTo(birthday)) <= 12) {
cat = "cattiversary";
}
else {
cat = "kitteh";
}
view->setStyleSheet(QString(R"(
InstanceView
{
background-image: url(:/backgrounds/%1);
background-attachment: fixed;
background-clip: padding;
background-position: top right;
background-repeat: none;
background-color:palette(base);
})").arg(cat));
}
else
{
view->setStyleSheet(QString());
}
}
void MainWindow::runModalTask(Task *task)
{
connect(task, &Task::failed, [this](QString reason)

View File

@ -212,7 +212,6 @@ private:
void addInstance(QString url = QString());
void activateInstance(InstancePtr instance);
void setCatBackground(bool enabled);
void updateInstanceToolIcon(QString new_icon);
void setSelectedInstanceById(const QString &id);
void updateStatusCenter();

View File

@ -161,3 +161,35 @@ QModelIndex InstanceView::mappedIndex(const QModelIndex& index) const
{
return m_proxy->mapToSource(index);
}
void InstanceView::setCatDisplayed(bool enabled)
{
if (enabled) {
QDateTime now = QDateTime::currentDateTime();
QDateTime birthday(QDate(now.date().year(), 11, 30), QTime(0, 0));
QDateTime xmas(QDate(now.date().year(), 12, 25), QTime(0, 0));
QString cat;
if (std::abs(now.daysTo(xmas)) <= 4) {
cat = "catmas";
} else if (std::abs(now.daysTo(birthday)) <= 12) {
cat = "cattiversary";
} else {
cat = "kitteh";
}
setStyleSheet(QString(R"(
*
{
background-image: url(:/backgrounds/%1);
background-attachment: fixed;
background-clip: padding;
background-position: bottom right;
background-repeat: none;
background-color:palette(base);
})")
.arg(cat));
m_table->setAlternatingRowColors(false);
} else {
setStyleSheet(QString());
m_table->setAlternatingRowColors(true);
}
}

View File

@ -39,6 +39,8 @@ class InstanceView : public QStackedWidget {
// save state of current view
void storeState();
void setCatDisplayed(bool enabled);
signals:
void instanceActivated(InstancePtr inst);
void currentInstanceChanged(InstancePtr current, InstancePtr previous);