aboutsummaryrefslogtreecommitdiff
path: root/src/aobutton.cpp
diff options
context:
space:
mode:
authorTrickyLeifa <date.epoch@gmail.com>2024-05-16 03:09:21 +0200
committerTrickyLeifa <date.epoch@gmail.com>2024-05-16 03:09:21 +0200
commit39e4354b1dae5d8487ea5b84be9f304b1950a61a (patch)
tree734c99d3ef1a8e69007dd870a8b6763deca5ffce /src/aobutton.cpp
parenta0cee58c048772b2dcfe3992f60728d5a6f7d786 (diff)
Reimplemented favorite server widget, ...
* Reworked favorite server widget * Renamed `server_type` to `ServerInfo` * Renamed `connection_type` to `ServerConnectionType` * Refactored `AOCharButton` * Reimplemented `AOButton` * Partially reimplemented `AOEmoteButton` * Refactored `AOEvidenceButton`
Diffstat (limited to 'src/aobutton.cpp')
-rw-r--r--src/aobutton.cpp75
1 files changed, 51 insertions, 24 deletions
diff --git a/src/aobutton.cpp b/src/aobutton.cpp
index 4fc50d65..07ea649a 100644
--- a/src/aobutton.cpp
+++ b/src/aobutton.cpp
@@ -1,12 +1,10 @@
#include "aobutton.h"
-#include "debug_functions.h"
-#include "file_functions.h"
#include "options.h"
-AOButton::AOButton(AOApplication *p_ao_app, QWidget *parent)
+AOButton::AOButton(AOApplication *ao_app, QWidget *parent)
: QPushButton(parent)
- , ao_app(p_ao_app)
+ , ao_app(ao_app)
{
m_movie = new QMovie(this);
@@ -17,32 +15,61 @@ AOButton::AOButton(AOApplication *p_ao_app, QWidget *parent)
}
AOButton::~AOButton()
-{}
+{
+ deleteMovie();
+}
-void AOButton::set_image(QString p_path, QString p_misc)
+void AOButton::setImage(QString image_name)
{
- m_movie->stop();
- QString p_image;
- p_image = ao_app->get_image(p_path, Options::getInstance().theme(), Options::getInstance().subTheme(), ao_app->default_theme, p_misc, "", "", !Options::getInstance().animatedThemeEnabled());
- if (p_image.isEmpty())
+ deleteMovie();
+
+ QString file_path = ao_app->get_image(image_name, Options::getInstance().theme(), Options::getInstance().subTheme(), ao_app->default_theme, QString(), QString(), QString(), !Options::getInstance().animatedThemeEnabled());
+ if (file_path.isEmpty())
{
- this->setIcon(QIcon());
- this->setIconSize(this->size());
- this->setStyleSheet("");
- return;
+ setStyleSheet(QString());
+ setIcon(QIcon());
}
- this->setText("");
- this->setStyleSheet("QPushButton { background-color: transparent; border: 0px }");
- m_movie->setFileName(p_image);
- // We double-check if the user wants animated themes, so even if an animated image slipped through,
- // we still set it static
- if (Options::getInstance().animatedThemeEnabled() && m_movie->frameCount() > 1)
+ else
{
- m_movie->start();
+ setText(QString());
+ setStyleSheet("QPushButton { background-color: transparent; border: 0px }");
+
+ if (Options::getInstance().animatedThemeEnabled())
+ {
+ m_movie = new QMovie;
+ m_movie->setFileName(file_path);
+
+ connect(m_movie, &QMovie::frameChanged, this, &AOButton::handleNextFrame);
+
+ m_movie->start();
+ }
+ else
+ {
+ updateIcon(QPixmap(file_path));
+ }
}
- else
+}
+
+void AOButton::deleteMovie()
+{
+ if (m_movie)
{
- this->setIcon(QPixmap(p_image).scaled(this->size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
- this->setIconSize(this->size());
+ disconnect(m_movie, &QMovie::frameChanged, this, &AOButton::handleNextFrame);
+
+ m_movie->stop();
+ m_movie->deleteLater();
+ m_movie = nullptr;
}
}
+
+void AOButton::handleNextFrame()
+{
+ updateIcon(m_movie->currentPixmap());
+}
+
+void AOButton::updateIcon(QPixmap icon)
+{
+ const QSize current_size = size();
+ setIcon(icon.scaled(current_size, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
+ setIconSize(current_size);
+}