mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
moved stuff from chatterino to appbase
This commit is contained in:
parent
41a07a43af
commit
a9ca33f431
16 changed files with 3 additions and 844 deletions
|
@ -108,7 +108,6 @@ SOURCES += \
|
|||
src/providers/twitch/TwitchMessageBuilder.cpp \
|
||||
src/providers/twitch/TwitchServer.cpp \
|
||||
src/providers/twitch/TwitchUser.cpp \
|
||||
src/common/ChatterinoSetting.cpp \
|
||||
src/singletons/helper/GifTimer.cpp \
|
||||
src/singletons/helper/LoggingChannel.cpp \
|
||||
src/controllers/moderationactions/ModerationAction.cpp \
|
||||
|
@ -141,7 +140,6 @@ SOURCES += \
|
|||
src/widgets/helper/SearchPopup.cpp \
|
||||
src/widgets/helper/SettingsDialogTab.cpp \
|
||||
src/widgets/helper/SignalLabel.cpp \
|
||||
src/widgets/helper/TitlebarButton.cpp \
|
||||
src/widgets/Notebook.cpp \
|
||||
src/widgets/Scrollbar.cpp \
|
||||
src/widgets/settingspages/AboutPage.cpp \
|
||||
|
@ -201,9 +199,7 @@ SOURCES += \
|
|||
src/controllers/notifications/NotificationModel.cpp \
|
||||
src/singletons/Toasts.cpp \
|
||||
src/common/DownloadManager.cpp \
|
||||
src/widgets/helper/Button.cpp \
|
||||
src/messages/MessageContainer.cpp \
|
||||
src/debug/Benchmark.cpp \
|
||||
src/common/UsernameSet.cpp \
|
||||
src/widgets/settingspages/AdvancedPage.cpp \
|
||||
src/util/IncognitoBrowser.cpp \
|
||||
|
@ -250,9 +246,6 @@ HEADERS += \
|
|||
src/controllers/taggedusers/TaggedUser.hpp \
|
||||
src/controllers/taggedusers/TaggedUsersController.hpp \
|
||||
src/controllers/taggedusers/TaggedUsersModel.hpp \
|
||||
src/debug/AssertInGuiThread.hpp \
|
||||
src/debug/Benchmark.hpp \
|
||||
src/debug/Log.hpp \
|
||||
src/messages/Image.hpp \
|
||||
src/messages/layouts/MessageLayout.hpp \
|
||||
src/messages/layouts/MessageLayoutContainer.hpp \
|
||||
|
@ -285,7 +278,6 @@ HEADERS += \
|
|||
src/providers/twitch/TwitchMessageBuilder.hpp \
|
||||
src/providers/twitch/TwitchServer.hpp \
|
||||
src/providers/twitch/TwitchUser.hpp \
|
||||
src/common/ChatterinoSetting.hpp \
|
||||
src/singletons/helper/GifTimer.hpp \
|
||||
src/singletons/helper/LoggingChannel.hpp \
|
||||
src/controllers/moderationactions/ModerationAction.hpp \
|
||||
|
@ -295,7 +287,6 @@ HEADERS += \
|
|||
src/util/ConcurrentMap.hpp \
|
||||
src/util/DebugCount.hpp \
|
||||
src/util/DistanceBetweenPoints.hpp \
|
||||
src/util/Helpers.hpp \
|
||||
src/util/IrcHelpers.hpp \
|
||||
src/util/LayoutCreator.hpp \
|
||||
src/util/QStringHash.hpp \
|
||||
|
@ -330,7 +321,6 @@ HEADERS += \
|
|||
src/widgets/helper/SearchPopup.hpp \
|
||||
src/widgets/helper/SettingsDialogTab.hpp \
|
||||
src/widgets/helper/SignalLabel.hpp \
|
||||
src/widgets/helper/TitlebarButton.hpp \
|
||||
src/widgets/Notebook.hpp \
|
||||
src/widgets/Scrollbar.hpp \
|
||||
src/widgets/settingspages/AboutPage.hpp \
|
||||
|
@ -367,7 +357,6 @@ HEADERS += \
|
|||
src/singletons/Theme.hpp \
|
||||
src/common/SignalVector.hpp \
|
||||
src/widgets/dialogs/LogsPopup.hpp \
|
||||
src/common/Singleton.hpp \
|
||||
src/controllers/moderationactions/ModerationActionModel.hpp \
|
||||
src/widgets/settingspages/LookPage.hpp \
|
||||
src/widgets/settingspages/FeelPage.hpp \
|
||||
|
@ -398,7 +387,6 @@ HEADERS += \
|
|||
src/singletons/Toasts.hpp \
|
||||
src/common/DownloadManager.hpp \
|
||||
src/util/LayoutHelper.hpp \
|
||||
src/widgets/helper/Button.hpp \
|
||||
src/messages/MessageContainer.hpp \
|
||||
src/common/UsernameSet.hpp \
|
||||
src/widgets/settingspages/AdvancedPage.hpp \
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 52d615d08b399eb91f890e2c775c234fcd5f678c
|
||||
Subproject commit 57d61602c375cc83418ba59a36535247060dab6a
|
|
@ -1,12 +0,0 @@
|
|||
#include "common/ChatterinoSetting.hpp"
|
||||
|
||||
#include "singletons/Settings.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void _registerSetting(std::weak_ptr<pajlada::Settings::SettingData> setting)
|
||||
{
|
||||
_actuallyRegisterSetting(setting);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,54 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <QString>
|
||||
#include <pajlada/settings.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
void _registerSetting(std::weak_ptr<pajlada::Settings::SettingData> setting);
|
||||
|
||||
template <typename Type>
|
||||
class ChatterinoSetting : public pajlada::Settings::Setting<Type>
|
||||
{
|
||||
public:
|
||||
ChatterinoSetting(const std::string &path)
|
||||
: pajlada::Settings::Setting<Type>(path)
|
||||
{
|
||||
_registerSetting(this->getData());
|
||||
}
|
||||
|
||||
ChatterinoSetting(const std::string &path, const Type &defaultValue)
|
||||
: pajlada::Settings::Setting<Type>(path, defaultValue)
|
||||
{
|
||||
_registerSetting(this->getData());
|
||||
}
|
||||
|
||||
template <typename T2>
|
||||
ChatterinoSetting &operator=(const T2 &newValue)
|
||||
{
|
||||
this->setValue(newValue);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChatterinoSetting &operator=(Type &&newValue) noexcept
|
||||
{
|
||||
pajlada::Settings::Setting<Type>::operator=(newValue);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
using pajlada::Settings::Setting<Type>::operator==;
|
||||
using pajlada::Settings::Setting<Type>::operator!=;
|
||||
|
||||
using pajlada::Settings::Setting<Type>::operator Type;
|
||||
};
|
||||
|
||||
using BoolSetting = ChatterinoSetting<bool>;
|
||||
using FloatSetting = ChatterinoSetting<float>;
|
||||
using DoubleSetting = ChatterinoSetting<double>;
|
||||
using IntSetting = ChatterinoSetting<int>;
|
||||
using StringSetting = ChatterinoSetting<std::string>;
|
||||
using QStringSetting = ChatterinoSetting<QString>;
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,26 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Settings;
|
||||
class Paths;
|
||||
|
||||
class Singleton : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
virtual ~Singleton() = default;
|
||||
|
||||
virtual void initialize(Settings &settings, Paths &paths)
|
||||
{
|
||||
(void)(settings);
|
||||
(void)(paths);
|
||||
}
|
||||
|
||||
virtual void save()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,16 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
#include <cassert>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
static void assertInGuiThread()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
assert(QCoreApplication::instance()->thread() == QThread::currentThread());
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,21 +0,0 @@
|
|||
#include "Benchmark.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
BenchmarkGuard::BenchmarkGuard(const QString &_name)
|
||||
: name_(_name)
|
||||
{
|
||||
timer_.start();
|
||||
}
|
||||
|
||||
BenchmarkGuard::~BenchmarkGuard()
|
||||
{
|
||||
log("{} {} ms", this->name_, float(timer_.nsecsElapsed()) / 1000000.0f);
|
||||
}
|
||||
|
||||
qreal BenchmarkGuard::getElapsedMs()
|
||||
{
|
||||
return qreal(timer_.nsecsElapsed()) / 1000000.0;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,22 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "debug/Log.hpp"
|
||||
|
||||
#include <QElapsedTimer>
|
||||
#include <boost/noncopyable.hpp>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class BenchmarkGuard : boost::noncopyable
|
||||
{
|
||||
public:
|
||||
BenchmarkGuard(const QString &_name);
|
||||
~BenchmarkGuard();
|
||||
qreal getElapsedMs();
|
||||
|
||||
private:
|
||||
QElapsedTimer timer_;
|
||||
QString name_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,29 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "util/Helpers.hpp"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QTime>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename... Args>
|
||||
inline void log(const std::string &formatString, Args &&... args)
|
||||
{
|
||||
qDebug().noquote() << QTime::currentTime().toString("hh:mm:ss.zzz")
|
||||
<< fS(formatString, std::forward<Args>(args)...).c_str();
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void log(const char *formatString, Args &&... args)
|
||||
{
|
||||
log(std::string(formatString), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
inline void log(const QString &formatString, Args &&... args)
|
||||
{
|
||||
log(formatString.toStdString(), std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,56 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <QUuid>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
template <typename... Args>
|
||||
auto fS(Args &&... args)
|
||||
{
|
||||
return fmt::format(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
static QString CreateUUID()
|
||||
{
|
||||
auto uuid = QUuid::createUuid();
|
||||
return uuid.toString();
|
||||
}
|
||||
|
||||
static QString createLink(const QString &url, bool file = false)
|
||||
{
|
||||
return QString("<a href=\"") + (file ? "file:///" : "") + url + "\">" +
|
||||
url + "</a>";
|
||||
}
|
||||
|
||||
static QString createNamedLink(const QString &url, const QString &name,
|
||||
bool file = false)
|
||||
{
|
||||
return QString("<a href=\"") + (file ? "file:///" : "") + url + "\">" +
|
||||
name + "</a>";
|
||||
}
|
||||
|
||||
static QString shortenString(const QString &str, unsigned maxWidth = 50)
|
||||
{
|
||||
auto shortened = QString(str);
|
||||
|
||||
if (str.size() > int(maxWidth))
|
||||
{
|
||||
shortened.resize(int(maxWidth));
|
||||
shortened += "...";
|
||||
}
|
||||
|
||||
return shortened;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
namespace fmt {
|
||||
|
||||
// format_arg for QString
|
||||
inline void format_arg(BasicFormatter<char> &f, const char *&, const QString &v)
|
||||
{
|
||||
f.writer().write("{}", v.toStdString());
|
||||
}
|
||||
|
||||
} // namespace fmt
|
|
@ -1,9 +1,9 @@
|
|||
#include "util/StreamLink.hpp"
|
||||
|
||||
#include "Application.hpp"
|
||||
#include "Helpers.hpp"
|
||||
#include "debug/Log.hpp"
|
||||
#include "singletons/Settings.hpp"
|
||||
#include "util/Helpers.hpp"
|
||||
#include "widgets/dialogs/QualityPopup.hpp"
|
||||
|
||||
#include <QErrorMessage>
|
||||
|
|
|
@ -1,338 +0,0 @@
|
|||
#include "Button.hpp"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QDesktopWidget>
|
||||
#include <QPainter>
|
||||
|
||||
#include "singletons/Theme.hpp"
|
||||
#include "util/FunctionEventFilter.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
Button::Button(BaseWidget *parent)
|
||||
: BaseWidget(parent)
|
||||
{
|
||||
connect(&effectTimer_, &QTimer::timeout, this,
|
||||
&Button::onMouseEffectTimeout);
|
||||
|
||||
this->effectTimer_.setInterval(20);
|
||||
this->effectTimer_.start();
|
||||
|
||||
this->setMouseTracking(true);
|
||||
}
|
||||
|
||||
void Button::setMouseEffectColor(boost::optional<QColor> color)
|
||||
{
|
||||
this->mouseEffectColor_ = color;
|
||||
}
|
||||
|
||||
void Button::setPixmap(const QPixmap &_pixmap)
|
||||
{
|
||||
this->pixmap_ = _pixmap;
|
||||
this->update();
|
||||
}
|
||||
|
||||
const QPixmap &Button::getPixmap() const
|
||||
{
|
||||
return this->pixmap_;
|
||||
}
|
||||
|
||||
void Button::setDim(bool value)
|
||||
{
|
||||
this->dimPixmap_ = value;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
bool Button::getDim() const
|
||||
{
|
||||
return this->dimPixmap_;
|
||||
}
|
||||
|
||||
void Button::setEnable(bool value)
|
||||
{
|
||||
this->enabled_ = value;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
bool Button::getEnable() const
|
||||
{
|
||||
return this->enabled_;
|
||||
}
|
||||
|
||||
void Button::setEnableMargin(bool value)
|
||||
{
|
||||
this->enableMargin_ = value;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
bool Button::getEnableMargin() const
|
||||
{
|
||||
return this->enableMargin_;
|
||||
}
|
||||
|
||||
qreal Button::getCurrentDimAmount() const
|
||||
{
|
||||
return this->dimPixmap_ && !this->mouseOver_ ? 0.7 : 1;
|
||||
}
|
||||
|
||||
void Button::setBorderColor(const QColor &color)
|
||||
{
|
||||
this->borderColor_ = color;
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
const QColor &Button::getBorderColor() const
|
||||
{
|
||||
return this->borderColor_;
|
||||
}
|
||||
|
||||
void Button::setMenu(std::unique_ptr<QMenu> menu)
|
||||
{
|
||||
this->menu_ = std::move(menu);
|
||||
|
||||
this->menu_->installEventFilter(
|
||||
new FunctionEventFilter(this, [this](QObject *, QEvent *event) {
|
||||
if (event->type() == QEvent::Hide)
|
||||
{
|
||||
QTimer::singleShot(20, this,
|
||||
[this] { this->menuVisible_ = false; });
|
||||
}
|
||||
return false;
|
||||
}));
|
||||
}
|
||||
|
||||
void Button::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.setRenderHint(QPainter::SmoothPixmapTransform);
|
||||
|
||||
if (!this->pixmap_.isNull())
|
||||
{
|
||||
if (!this->mouseOver_ && this->dimPixmap_ && this->enabled_)
|
||||
{
|
||||
painter.setOpacity(this->getCurrentDimAmount());
|
||||
}
|
||||
|
||||
QRect rect = this->rect();
|
||||
int s = this->enableMargin_ ? int(6 * this->scale()) : 0;
|
||||
|
||||
rect.moveLeft(s);
|
||||
rect.setRight(rect.right() - s - s);
|
||||
rect.moveTop(s);
|
||||
rect.setBottom(rect.bottom() - s - s);
|
||||
|
||||
painter.drawPixmap(rect, this->pixmap_);
|
||||
|
||||
painter.setOpacity(1);
|
||||
}
|
||||
|
||||
this->fancyPaint(painter);
|
||||
|
||||
if (this->borderColor_.isValid())
|
||||
{
|
||||
painter.setRenderHint(QPainter::Antialiasing, false);
|
||||
painter.setPen(this->borderColor_);
|
||||
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
void Button::fancyPaint(QPainter &painter)
|
||||
{
|
||||
if (!this->enabled_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
QColor c;
|
||||
|
||||
if (this->mouseEffectColor_)
|
||||
{
|
||||
c = this->mouseEffectColor_.get();
|
||||
}
|
||||
else
|
||||
{
|
||||
c = this->theme->isLightTheme() ? QColor(0, 0, 0)
|
||||
: QColor(255, 255, 255);
|
||||
}
|
||||
|
||||
if (this->hoverMultiplier_ > 0)
|
||||
{
|
||||
QRadialGradient gradient(QPointF(mousePos_), this->width() / 2);
|
||||
|
||||
gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(),
|
||||
int(50 * this->hoverMultiplier_)));
|
||||
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(),
|
||||
int(40 * this->hoverMultiplier_)));
|
||||
|
||||
painter.fillRect(this->rect(), gradient);
|
||||
}
|
||||
|
||||
for (auto effect : this->clickEffects_)
|
||||
{
|
||||
QRadialGradient gradient(effect.position.x(), effect.position.y(),
|
||||
effect.progress * qreal(width()) * 2,
|
||||
effect.position.x(), effect.position.y());
|
||||
|
||||
gradient.setColorAt(0, QColor(c.red(), c.green(), c.blue(),
|
||||
int((1 - effect.progress) * 95)));
|
||||
gradient.setColorAt(0.9999, QColor(c.red(), c.green(), c.blue(),
|
||||
int((1 - effect.progress) * 95)));
|
||||
gradient.setColorAt(1, QColor(c.red(), c.green(), c.blue(), int(0)));
|
||||
|
||||
painter.fillRect(this->rect(), gradient);
|
||||
}
|
||||
}
|
||||
|
||||
void Button::enterEvent(QEvent *)
|
||||
{
|
||||
this->mouseOver_ = true;
|
||||
}
|
||||
|
||||
void Button::leaveEvent(QEvent *)
|
||||
{
|
||||
this->mouseOver_ = false;
|
||||
}
|
||||
|
||||
void Button::mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!this->enabled_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (event->button() != Qt::LeftButton)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this->clickEffects_.push_back(ClickEffect(event->pos()));
|
||||
|
||||
this->mouseDown_ = true;
|
||||
|
||||
emit this->leftMousePress();
|
||||
|
||||
if (this->menu_ && !this->menuVisible_)
|
||||
{
|
||||
QTimer::singleShot(80, this, [this] { this->showMenu(); });
|
||||
this->mouseDown_ = false;
|
||||
this->mouseOver_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
void Button::mouseReleaseEvent(QMouseEvent *event)
|
||||
{
|
||||
if (!this->enabled_)
|
||||
return;
|
||||
|
||||
if (event->button() == Qt::LeftButton)
|
||||
{
|
||||
this->mouseDown_ = false;
|
||||
|
||||
if (this->rect().contains(event->pos()))
|
||||
emit leftClicked();
|
||||
}
|
||||
|
||||
emit clicked(event->button());
|
||||
}
|
||||
|
||||
void Button::mouseMoveEvent(QMouseEvent *event)
|
||||
{
|
||||
if (this->enabled_)
|
||||
{
|
||||
this->mousePos_ = event->pos();
|
||||
|
||||
this->update();
|
||||
}
|
||||
}
|
||||
|
||||
void Button::onMouseEffectTimeout()
|
||||
{
|
||||
bool performUpdate = false;
|
||||
|
||||
if (selected_)
|
||||
{
|
||||
if (this->hoverMultiplier_ != 0)
|
||||
{
|
||||
this->hoverMultiplier_ =
|
||||
std::max(0.0, this->hoverMultiplier_ - 0.1);
|
||||
performUpdate = true;
|
||||
}
|
||||
}
|
||||
else if (mouseOver_)
|
||||
{
|
||||
if (this->hoverMultiplier_ != 1)
|
||||
{
|
||||
this->hoverMultiplier_ =
|
||||
std::min(1.0, this->hoverMultiplier_ + 0.5);
|
||||
performUpdate = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this->hoverMultiplier_ != 0)
|
||||
{
|
||||
this->hoverMultiplier_ =
|
||||
std::max(0.0, this->hoverMultiplier_ - 0.3);
|
||||
performUpdate = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this->clickEffects_.size() != 0)
|
||||
{
|
||||
performUpdate = true;
|
||||
|
||||
for (auto it = this->clickEffects_.begin();
|
||||
it != this->clickEffects_.end();)
|
||||
{
|
||||
it->progress += mouseDown_ ? 0.02 : 0.07;
|
||||
|
||||
if (it->progress >= 1.0)
|
||||
{
|
||||
it = this->clickEffects_.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (performUpdate)
|
||||
{
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
void Button::showMenu()
|
||||
{
|
||||
if (!this->menu_)
|
||||
return;
|
||||
|
||||
auto point = [this] {
|
||||
auto bounds = QApplication::desktop()->availableGeometry(this);
|
||||
|
||||
auto point = this->mapToGlobal(
|
||||
QPoint(this->width() - this->menu_->width(), this->height()));
|
||||
|
||||
if (point.y() + this->menu_->height() > bounds.bottom())
|
||||
{
|
||||
point.setY(point.y() - this->menu_->height() - this->height());
|
||||
}
|
||||
|
||||
return point;
|
||||
};
|
||||
|
||||
this->menu_->popup(point());
|
||||
this->menu_->move(point());
|
||||
this->menuVisible_ = true;
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,89 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "widgets/BaseWidget.hpp"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
#include <QPoint>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
class Button : public BaseWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
struct ClickEffect {
|
||||
double progress = 0.0;
|
||||
QPoint position;
|
||||
|
||||
ClickEffect(QPoint _position)
|
||||
: position(_position)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
public:
|
||||
Button(BaseWidget *parent = nullptr);
|
||||
|
||||
void setMouseEffectColor(boost::optional<QColor> color);
|
||||
void setPixmap(const QPixmap &pixmap_);
|
||||
const QPixmap &getPixmap() const;
|
||||
|
||||
void setDim(bool value);
|
||||
bool getDim() const;
|
||||
qreal getCurrentDimAmount() const;
|
||||
|
||||
void setEnable(bool value);
|
||||
bool getEnable() const;
|
||||
|
||||
void setEnableMargin(bool value);
|
||||
bool getEnableMargin() const;
|
||||
|
||||
void setBorderColor(const QColor &color);
|
||||
const QColor &getBorderColor() const;
|
||||
|
||||
void setMenu(std::unique_ptr<QMenu> menu);
|
||||
|
||||
signals:
|
||||
void leftClicked();
|
||||
void clicked(Qt::MouseButton button);
|
||||
void leftMousePress();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent *) override;
|
||||
virtual void enterEvent(QEvent *) override;
|
||||
virtual void leaveEvent(QEvent *) override;
|
||||
virtual void mousePressEvent(QMouseEvent *event) override;
|
||||
virtual void mouseReleaseEvent(QMouseEvent *event) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent *event) override;
|
||||
|
||||
void fancyPaint(QPainter &painter);
|
||||
|
||||
bool enabled_{true};
|
||||
bool selected_{false};
|
||||
bool mouseOver_{false};
|
||||
bool mouseDown_{false};
|
||||
bool menuVisible_{false};
|
||||
|
||||
private:
|
||||
void onMouseEffectTimeout();
|
||||
void showMenu();
|
||||
|
||||
QColor borderColor_{};
|
||||
QPixmap pixmap_{};
|
||||
bool dimPixmap_{true};
|
||||
bool enableMargin_{true};
|
||||
QPoint mousePos_{};
|
||||
double hoverMultiplier_{0.0};
|
||||
QTimer effectTimer_{};
|
||||
std::vector<ClickEffect> clickEffects_{};
|
||||
boost::optional<QColor> mouseEffectColor_{};
|
||||
std::unique_ptr<QMenu> menu_{};
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include "Button.hpp"
|
||||
#include "widgets/helper/Button.hpp"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
|
|
|
@ -1,134 +0,0 @@
|
|||
#include "TitlebarButton.hpp"
|
||||
|
||||
#include "singletons/Theme.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
TitleBarButton::TitleBarButton()
|
||||
: Button(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
TitleBarButtonStyle TitleBarButton::getButtonStyle() const
|
||||
{
|
||||
return this->style_;
|
||||
}
|
||||
|
||||
void TitleBarButton::setButtonStyle(TitleBarButtonStyle _style)
|
||||
{
|
||||
this->style_ = _style;
|
||||
this->update();
|
||||
}
|
||||
|
||||
void TitleBarButton::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QPainter painter(this);
|
||||
|
||||
painter.setOpacity(this->getCurrentDimAmount());
|
||||
|
||||
QColor color = this->theme->window.text;
|
||||
QColor background = this->theme->window.background;
|
||||
|
||||
int xD = this->height() / 3;
|
||||
int centerX = this->width() / 2;
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing, false);
|
||||
|
||||
switch (this->style_)
|
||||
{
|
||||
case TitleBarButtonStyle::Minimize:
|
||||
{
|
||||
painter.fillRect(centerX - xD / 2, xD * 3 / 2, xD, 1, color);
|
||||
break;
|
||||
}
|
||||
case TitleBarButtonStyle::Maximize:
|
||||
{
|
||||
painter.setPen(color);
|
||||
painter.drawRect(centerX - xD / 2, xD, xD - 1, xD - 1);
|
||||
break;
|
||||
}
|
||||
case TitleBarButtonStyle::Unmaximize:
|
||||
{
|
||||
int xD2 = xD * 1 / 5;
|
||||
int xD3 = xD * 4 / 5;
|
||||
|
||||
painter.drawRect(centerX - xD / 2 + xD2, xD, xD3, xD3);
|
||||
painter.fillRect(centerX - xD / 2, xD + xD2, xD3, xD3,
|
||||
this->theme->window.background);
|
||||
painter.drawRect(centerX - xD / 2, xD + xD2, xD3, xD3);
|
||||
break;
|
||||
}
|
||||
case TitleBarButtonStyle::Close:
|
||||
{
|
||||
QRect rect(centerX - xD / 2, xD, xD - 1, xD - 1);
|
||||
painter.setPen(QPen(color, 1));
|
||||
|
||||
painter.drawLine(rect.topLeft(), rect.bottomRight());
|
||||
painter.drawLine(rect.topRight(), rect.bottomLeft());
|
||||
break;
|
||||
}
|
||||
case TitleBarButtonStyle::User:
|
||||
{
|
||||
color = "#999";
|
||||
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
|
||||
auto a = xD / 3;
|
||||
QPainterPath path;
|
||||
|
||||
painter.save();
|
||||
painter.translate(3, 3);
|
||||
|
||||
path.arcMoveTo(a, 4 * a, 6 * a, 6 * a, 0);
|
||||
path.arcTo(a, 4 * a, 6 * a, 6 * a, 0, 180);
|
||||
|
||||
painter.fillPath(path, color);
|
||||
|
||||
painter.setBrush(background);
|
||||
painter.drawEllipse(2 * a, 1 * a, 4 * a, 4 * a);
|
||||
|
||||
painter.setBrush(color);
|
||||
painter.drawEllipse(2.5 * a, 1.5 * a, 3 * a + 1, 3 * a);
|
||||
painter.restore();
|
||||
|
||||
break;
|
||||
}
|
||||
case TitleBarButtonStyle::Settings:
|
||||
{
|
||||
color = "#999";
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setRenderHint(QPainter::HighQualityAntialiasing);
|
||||
|
||||
painter.save();
|
||||
painter.translate(3, 3);
|
||||
|
||||
auto a = xD / 3;
|
||||
QPainterPath path;
|
||||
|
||||
path.arcMoveTo(a, a, 6 * a, 6 * a, 0 - (360 / 32.0));
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
path.arcTo(a, a, 6 * a, 6 * a, i * (360 / 8.0) - (360 / 32.0),
|
||||
(360 / 32.0));
|
||||
path.arcTo(2 * a, 2 * a, 4 * a, 4 * a,
|
||||
i * (360 / 8.0) + (360 / 32.0), (360 / 32.0));
|
||||
}
|
||||
|
||||
painter.strokePath(path, color);
|
||||
painter.fillPath(path, color);
|
||||
|
||||
painter.setBrush(background);
|
||||
painter.drawEllipse(3 * a, 3 * a, 2 * a, 2 * a);
|
||||
painter.restore();
|
||||
break;
|
||||
}
|
||||
default:;
|
||||
}
|
||||
|
||||
Button::paintEvent(event);
|
||||
// this->fancyPaint(painter);
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
|
@ -1,32 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "widgets/helper/Button.hpp"
|
||||
|
||||
namespace chatterino {
|
||||
|
||||
enum class TitleBarButtonStyle {
|
||||
None = 0,
|
||||
Minimize = 1,
|
||||
Maximize = 2,
|
||||
Unmaximize = 4,
|
||||
Close = 8,
|
||||
User = 16,
|
||||
Settings = 32
|
||||
};
|
||||
|
||||
class TitleBarButton : public Button
|
||||
{
|
||||
public:
|
||||
TitleBarButton();
|
||||
|
||||
TitleBarButtonStyle getButtonStyle() const;
|
||||
void setButtonStyle(TitleBarButtonStyle style_);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
private:
|
||||
TitleBarButtonStyle style_;
|
||||
};
|
||||
|
||||
} // namespace chatterino
|
Loading…
Reference in a new issue