mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
small fixes in Image
This commit is contained in:
parent
038fdd5446
commit
da4714944d
4 changed files with 38 additions and 34 deletions
|
@ -1,16 +1,15 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/Aliases.hpp"
|
|
||||||
#include "common/Outcome.hpp"
|
|
||||||
#include "common/ProviderId.hpp"
|
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
#include <boost/preprocessor.hpp>
|
#include <boost/preprocessor.hpp>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "common/Aliases.hpp"
|
||||||
|
#include "common/Outcome.hpp"
|
||||||
|
#include "common/ProviderId.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
enum class HighlightState {
|
enum class HighlightState {
|
||||||
|
@ -46,4 +45,14 @@ enum class CopyMode {
|
||||||
OnlyTextAndEmotes,
|
OnlyTextAndEmotes,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct DeleteLater {
|
||||||
|
void operator()(QObject *obj)
|
||||||
|
{
|
||||||
|
obj->deleteLater();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
using QObjectPtr = std::unique_ptr<T, DeleteLater>;
|
||||||
|
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
#include "messages/Image.hpp"
|
#include "messages/Image.hpp"
|
||||||
|
|
||||||
|
#include <QBuffer>
|
||||||
|
#include <QImageReader>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <functional>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include "Application.hpp"
|
#include "Application.hpp"
|
||||||
#include "common/Common.hpp"
|
#include "common/Common.hpp"
|
||||||
#include "common/NetworkRequest.hpp"
|
#include "common/NetworkRequest.hpp"
|
||||||
|
@ -11,15 +20,6 @@
|
||||||
#include "util/DebugCount.hpp"
|
#include "util/DebugCount.hpp"
|
||||||
#include "util/PostToThread.hpp"
|
#include "util/PostToThread.hpp"
|
||||||
|
|
||||||
#include <QBuffer>
|
|
||||||
#include <QImageReader>
|
|
||||||
#include <QNetworkAccessManager>
|
|
||||||
#include <QNetworkReply>
|
|
||||||
#include <QNetworkRequest>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <functional>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
// Frames
|
// Frames
|
||||||
|
@ -324,7 +324,7 @@ int Image::width() const
|
||||||
assertInGuiThread();
|
assertInGuiThread();
|
||||||
|
|
||||||
if (auto pixmap = this->frames_->first())
|
if (auto pixmap = this->frames_->first())
|
||||||
return pixmap->width() * this->scale_;
|
return int(pixmap->width() * this->scale_);
|
||||||
else
|
else
|
||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
@ -369,6 +369,7 @@ void Image::actuallyLoad()
|
||||||
if (!shared)
|
if (!shared)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// fourtf: is this the right thing to do?
|
||||||
shared->empty_ = true;
|
shared->empty_ = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include <pajlada/signals/signal.hpp>
|
#include <pajlada/signals/signal.hpp>
|
||||||
|
|
||||||
#include "common/Aliases.hpp"
|
#include "common/Aliases.hpp"
|
||||||
#include "common/NullablePtr.hpp"
|
#include "common/Common.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
@ -45,6 +45,7 @@ namespace detail {
|
||||||
class Image;
|
class Image;
|
||||||
using ImagePtr = std::shared_ptr<Image>;
|
using ImagePtr = std::shared_ptr<Image>;
|
||||||
|
|
||||||
|
/// This class is thread safe.
|
||||||
class Image : public std::enable_shared_from_this<Image>, boost::noncopyable
|
class Image : public std::enable_shared_from_this<Image>, boost::noncopyable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -72,14 +73,14 @@ private:
|
||||||
Image(qreal scale);
|
Image(qreal scale);
|
||||||
|
|
||||||
void setPixmap(const QPixmap &pixmap);
|
void setPixmap(const QPixmap &pixmap);
|
||||||
|
|
||||||
void actuallyLoad();
|
void actuallyLoad();
|
||||||
|
|
||||||
Url url_{};
|
const Url url_{};
|
||||||
qreal scale_{1};
|
const qreal scale_{1};
|
||||||
bool empty_{false};
|
std::atomic_bool empty_{false};
|
||||||
|
|
||||||
|
// gui thread only
|
||||||
bool shouldLoad_{false};
|
bool shouldLoad_{false};
|
||||||
std::unique_ptr<detail::Frames> frames_{};
|
std::unique_ptr<detail::Frames> frames_{};
|
||||||
QObject object_{};
|
|
||||||
};
|
};
|
||||||
} // namespace chatterino
|
} // namespace chatterino
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "providers/irc/IrcConnection2.hpp"
|
|
||||||
|
|
||||||
#include <IrcMessage>
|
#include <IrcMessage>
|
||||||
|
#include <functional>
|
||||||
|
#include <mutex>
|
||||||
#include <pajlada/signals/signal.hpp>
|
#include <pajlada/signals/signal.hpp>
|
||||||
#include <pajlada/signals/signalholder.hpp>
|
#include <pajlada/signals/signalholder.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include "common/Common.hpp"
|
||||||
#include <mutex>
|
#include "providers/irc/IrcConnection2.hpp"
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
@ -73,15 +73,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
void initConnection();
|
void initConnection();
|
||||||
|
|
||||||
struct Deleter {
|
QObjectPtr<IrcConnection> writeConnection_ = nullptr;
|
||||||
void operator()(IrcConnection *conn)
|
QObjectPtr<IrcConnection> readConnection_ = nullptr;
|
||||||
{
|
|
||||||
conn->deleteLater();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
std::unique_ptr<IrcConnection, Deleter> writeConnection_ = nullptr;
|
|
||||||
std::unique_ptr<IrcConnection, Deleter> readConnection_ = nullptr;
|
|
||||||
|
|
||||||
QTimer reconnectTimer_;
|
QTimer reconnectTimer_;
|
||||||
int falloffCounter_ = 1;
|
int falloffCounter_ = 1;
|
||||||
|
|
Loading…
Reference in a new issue