diff --git a/chatterino.pro b/chatterino.pro index 80f06c8e7..a2b3b50d8 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -55,7 +55,6 @@ SOURCES += main.cpp\ widgets/chatwidget.cpp \ widgets/chatwidgetheader.cpp \ widgets/chatwidgetheaderbutton.cpp \ - widgets/chatwidgetheaderbuttonlabel.cpp \ widgets/chatwidgetinput.cpp \ widgets/chatwidgetview.cpp \ widgets/mainwindow.cpp \ @@ -88,14 +87,12 @@ HEADERS += account.h \ messages/word.h \ messages/wordpart.h \ resources.h \ - settings/realsetting.h \ settings/setting.h \ settings/settings.h \ twitchemotevalue.h \ widgets/chatwidget.h \ widgets/chatwidgetheader.h \ widgets/chatwidgetheaderbutton.h \ - widgets/chatwidgetheaderbuttonlabel.h \ widgets/chatwidgetinput.h \ widgets/chatwidgetview.h \ widgets/mainwindow.h \ @@ -110,7 +107,11 @@ HEADERS += account.h \ widgets/settingsdialogtab.h \ widgets/signallabel.h \ widgets/textinputdialog.h \ - windows.h + windows.h \ + settings/boolsetting.h \ + settings/stringsetting.h \ + settings/intsetting.h \ + settings/floatsetting.h PRECOMPILED_HEADER = diff --git a/messages/message.cpp b/messages/message.cpp index 2e7dc54ff..76bfd8ba7 100644 --- a/messages/message.cpp +++ b/messages/message.cpp @@ -415,6 +415,10 @@ Message::layout(int width, bool enableEmoteMargins) bool recalculateImages = this->emoteGeneration != Emotes::getGeneration(); bool recalculateText = this->fontGeneration != Fonts::getGeneration(); + qreal emoteScale = settings::Settings::getEmoteScale().get(); + bool scaleEmotesByLineHeight = + settings::Settings::getScaleEmotesByLineHeight().get(); + if (recalculateImages || recalculateText) { this->emoteGeneration = Emotes::getGeneration(); this->fontGeneration = Fonts::getGeneration(); @@ -429,16 +433,12 @@ Message::layout(int width, bool enableEmoteMargins) qreal w = image.getWidth(); qreal h = image.getHeight(); - if (settings::Settings::getScaleEmotesByLineHeight()) { - word.setSize(w * mediumTextLineHeight / h * - settings::Settings::getEmoteScale(), - mediumTextLineHeight * - settings::Settings::getEmoteScale()); + if (scaleEmotesByLineHeight) { + word.setSize(w * mediumTextLineHeight / h * emoteScale, + mediumTextLineHeight * emoteScale); } else { - word.setSize(w * image.getScale() * - settings::Settings::getEmoteScale(), - h * image.getScale() * - settings::Settings::getEmoteScale()); + word.setSize(w * image.getScale() * emoteScale, + h * image.getScale() * emoteScale); } } } else { diff --git a/settings/boolsetting.h b/settings/boolsetting.h new file mode 100644 index 000000000..4639d3b1e --- /dev/null +++ b/settings/boolsetting.h @@ -0,0 +1,49 @@ +#ifndef BOOLSETTING_H +#define BOOLSETTING_H + +#include "settings/setting.h" + +#include + +namespace chatterino { +namespace settings { +class BoolSetting : public Setting +{ +public: + BoolSetting(const QString &name, bool defaultValue) + : Setting(name) + , value(defaultValue) + , defaultValue(defaultValue) + { + } + + bool + get() const + { + return this->value; + } + + void + set(bool value) + { + this->value = value; + } + + void + save(const QSettings &settings) override + { + } + + void + load(const QSettings &settings) override + { + } + +private: + bool value; + bool defaultValue; +}; +} +} + +#endif // BOOLSETTING_H diff --git a/settings/floatsetting.h b/settings/floatsetting.h new file mode 100644 index 000000000..39909d114 --- /dev/null +++ b/settings/floatsetting.h @@ -0,0 +1,56 @@ +#ifndef REALSETTING_H +#define REALSETTING_H + +#include "settings/setting.h" + +#include + +namespace chatterino { +namespace settings { + +class FloatSetting : public Setting +{ +public: + FloatSetting(const QString &name, qreal defaultValue, + qreal minValue = std::numeric_limits::min(), + qreal maxValue = std::numeric_limits::max()) + : Setting(name) + , value(defaultValue) + , defaultValue(defaultValue) + , minValue(minValue) + , maxValue(maxValue) + { + } + + qreal + get() const + { + return this->value; + } + + qreal + set(qreal value) + { + return (this->value = std::max(std::min(value, maxValue), minValue)); + } + + void + save(const QSettings &settings) override + { + } + + void + load(const QSettings &settings) override + { + } + +private: + qreal value; + qreal defaultValue; + qreal minValue; + qreal maxValue; +}; +} +} + +#endif // REALSETTING_H diff --git a/settings/intsetting.h b/settings/intsetting.h new file mode 100644 index 000000000..8a4e1c369 --- /dev/null +++ b/settings/intsetting.h @@ -0,0 +1,49 @@ +#ifndef INTSETTING_H +#define INTSETTING_H + +#include "settings/setting.h" + +#include + +namespace chatterino { +namespace settings { +class BoolSetting : public Setting +{ +public: + BoolSetting(const QString &name, int defaultValue) + : Setting(name) + , value(defaultValue) + , defaultValue(defaultValue) + { + } + + int + get() const + { + return this->value; + } + + int + set(int value) + { + return (this->value = value); + } + + void + save(const QSettings &settings) override + { + } + + void + load(const QSettings &settings) override + { + } + +private: + int value; + int defaultValue; +}; +} +} + +#endif // INTSETTING_H diff --git a/settings/realsetting.h b/settings/realsetting.h deleted file mode 100644 index 7750abdee..000000000 --- a/settings/realsetting.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef REALSETTING_H -#define REALSETTING_H - -#include - -namespace chatterino { -namespace settings { - -class RealSetting : public Setting -{ -public: - RealSetting(const QString &name, qreal defaultValue, - qreal minValue = std::numeric_limits::min(), - qreal maxValue = std::numeric_limits::max()) - : Setting(name) - , value(defaultValue) - , defaultValue(defaultValue) - , minValue(minValue) - , maxValue(maxValue) - { - } - -private: - qreal value; - qreal defaultValue; - qreal minValue; - qreal maxValue; -}; -} -} - -#endif // REALSETTING_H diff --git a/settings/setting.h b/settings/setting.h index 44e1c84aa..ef76dd3a0 100644 --- a/settings/setting.h +++ b/settings/setting.h @@ -1,6 +1,7 @@ #ifndef SETTING_H #define SETTING_H +#include #include namespace chatterino { @@ -14,17 +15,20 @@ public: { } + virtual void save(const QSettings &settings) = 0; + virtual void load(const QSettings &settings) = 0; + +protected: const QString & getName() const { return name; } - virtual QString toString() = 0; - private: QString name; }; } +} #endif // SETTING_H diff --git a/settings/settings.cpp b/settings/settings.cpp index 79404e4e6..3d38a71b7 100644 --- a/settings/settings.cpp +++ b/settings/settings.cpp @@ -1,12 +1,63 @@ #include "settings/settings.h" +#include +#include + namespace chatterino { namespace settings { +StringSetting Settings::theme("", "dark"); +StringSetting Settings::user("", ""); +FloatSetting Settings::emoteScale("", 1.0); +BoolSetting Settings::scaleEmotesByLineHeight("", false); +BoolSetting Settings::showTimestamps("", true); +BoolSetting Settings::showTimestampSeconds("", false); +BoolSetting Settings::allowDouplicateMessages("", true); +BoolSetting Settings::linksDoubleClickOnly("", false); +BoolSetting Settings::hideEmptyInput("", false); +BoolSetting Settings::showMessageLength("", false); +BoolSetting Settings::seperateMessages("", false); +BoolSetting Settings::mentionUsersWithAt("", false); +BoolSetting Settings::allowCommandsAtEnd("", false); +BoolSetting Settings::enableHighlights("", true); +BoolSetting Settings::enableHighlightSound("", true); +BoolSetting Settings::enableHighlightTaskbar("", true); +BoolSetting Settings::customHighlightSound("", false); +BoolSetting Settings::enableTwitchEmotes("", true); +BoolSetting Settings::enableBttvEmotes("", true); +BoolSetting Settings::enableFFzEmotes("", true); +BoolSetting Settings::enableEmojis("", true); +BoolSetting Settings::enableGifAnimations("", true); +BoolSetting Settings::enableGifs("", true); +BoolSetting Settings::inlineWhispers("", true); +BoolSetting Settings::windowTopMost("", true); + +QSettings Settings::settings( + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), + QSettings::IniFormat); + +std::vector Settings::settingsItems; + +bool Settings::portable(false); + messages::Word::Type Settings::wordTypeMask = messages::Word::Default; -Settings::Settings() +int Settings::_ = Settings::_init(); + +void +Settings::save() { + for (Setting *item : settingsItems) { + item->save(settings); + } +} + +void +Settings::load() +{ + for (Setting *item : settingsItems) { + item->load(settings); + } } bool diff --git a/settings/settings.h b/settings/settings.h index 2d9f8da08..41e1bb014 100644 --- a/settings/settings.h +++ b/settings/settings.h @@ -2,6 +2,12 @@ #define APPSETTINGS_H #include "messages/word.h" +#include "settings/boolsetting.h" +#include "settings/floatsetting.h" +#include "settings/setting.h" +#include "settings/stringsetting.h" + +#include namespace chatterino { namespace settings { @@ -17,27 +23,225 @@ public: static bool isIgnoredEmote(const QString &emote); - static qreal - getEmoteScale() - { - return 1; - } - - static qreal - getBadgeScale() - { - return 1; - } + static void load(); + static void save(); static bool - getScaleEmotesByLineHeight() + getPortable() { - return false; + return portable; + } + + static void + setPortable(bool value) + { + portable = value; } private: Settings(); + + static int _; + static int + _init() + { + settingsItems.reserve(25); + settingsItems.push_back(&theme); + settingsItems.push_back(&user); + settingsItems.push_back(&emoteScale); + settingsItems.push_back(&scaleEmotesByLineHeight); + settingsItems.push_back(&showTimestamps); + settingsItems.push_back(&showTimestampSeconds); + settingsItems.push_back(&allowDouplicateMessages); + settingsItems.push_back(&linksDoubleClickOnly); + settingsItems.push_back(&hideEmptyInput); + settingsItems.push_back(&showMessageLength); + settingsItems.push_back(&seperateMessages); + settingsItems.push_back(&mentionUsersWithAt); + settingsItems.push_back(&allowCommandsAtEnd); + settingsItems.push_back(&enableHighlights); + settingsItems.push_back(&enableHighlightSound); + settingsItems.push_back(&enableHighlightTaskbar); + settingsItems.push_back(&customHighlightSound); + settingsItems.push_back(&enableTwitchEmotes); + settingsItems.push_back(&enableBttvEmotes); + settingsItems.push_back(&enableFFzEmotes); + settingsItems.push_back(&enableEmojis); + settingsItems.push_back(&enableGifAnimations); + settingsItems.push_back(&enableGifs); + settingsItems.push_back(&inlineWhispers); + settingsItems.push_back(&windowTopMost); + } + + static QSettings settings; + static std::vector settingsItems; + + template + static T + addSetting(T setting) + { + settingsItems.push_back(setting); + return setting; + } + + static bool portable; + static messages::Word::Type wordTypeMask; + + // settings +public: + static StringSetting + getTheme() + { + return Settings::theme; + } + static StringSetting + getUser() + { + return Settings::user; + } + static FloatSetting + getEmoteScale() + { + return Settings::emoteScale; + } + static BoolSetting + getScaleEmotesByLineHeight() + { + return Settings::scaleEmotesByLineHeight; + } + static BoolSetting + getShowTimestamps() + { + return Settings::showTimestamps; + } + static BoolSetting + getShowTimestampSeconds() + { + return Settings::showTimestampSeconds; + } + static BoolSetting + getAllowDouplicateMessages() + { + return Settings::allowDouplicateMessages; + } + static BoolSetting + getLinksDoubleClickOnly() + { + return Settings::linksDoubleClickOnly; + } + static BoolSetting + getHideEmptyInput() + { + return Settings::hideEmptyInput; + } + static BoolSetting + getShowMessageLength() + { + return Settings::showMessageLength; + } + static BoolSetting + getSeperateMessages() + { + return Settings::seperateMessages; + } + static BoolSetting + getMentionUsersWithAt() + { + return Settings::mentionUsersWithAt; + } + static BoolSetting + getAllowCommandsAtEnd() + { + return Settings::allowCommandsAtEnd; + } + static BoolSetting + getEnableHighlights() + { + return Settings::enableHighlights; + } + static BoolSetting + getEnableHighlightSound() + { + return Settings::enableHighlightSound; + } + static BoolSetting + getEnableHighlightTaskbar() + { + return Settings::enableHighlightTaskbar; + } + static BoolSetting + getCustomHighlightSound() + { + return Settings::customHighlightSound; + } + static BoolSetting + getEnableTwitchEmotes() + { + return Settings::enableTwitchEmotes; + } + static BoolSetting + getEnableBttvEmotes() + { + return Settings::enableBttvEmotes; + } + static BoolSetting + getEnableFFzEmotes() + { + return Settings::enableFFzEmotes; + } + static BoolSetting + getEnableEmojis() + { + return Settings::enableEmojis; + } + static BoolSetting + getEnableGifAnimations() + { + return Settings::enableGifAnimations; + } + static BoolSetting + getEnableGifs() + { + return Settings::enableGifs; + } + static BoolSetting + getInlineWhispers() + { + return Settings::inlineWhispers; + } + static BoolSetting + getWindowTopMost() + { + return Settings::windowTopMost; + } + +private: + static StringSetting theme; + static StringSetting user; + static FloatSetting emoteScale; + static BoolSetting scaleEmotesByLineHeight; + static BoolSetting showTimestamps; + static BoolSetting showTimestampSeconds; + static BoolSetting allowDouplicateMessages; + static BoolSetting linksDoubleClickOnly; + static BoolSetting hideEmptyInput; + static BoolSetting showMessageLength; + static BoolSetting seperateMessages; + static BoolSetting mentionUsersWithAt; + static BoolSetting allowCommandsAtEnd; + static BoolSetting enableHighlights; + static BoolSetting enableHighlightSound; + static BoolSetting enableHighlightTaskbar; + static BoolSetting customHighlightSound; + static BoolSetting enableTwitchEmotes; + static BoolSetting enableBttvEmotes; + static BoolSetting enableFFzEmotes; + static BoolSetting enableEmojis; + static BoolSetting enableGifAnimations; + static BoolSetting enableGifs; + static BoolSetting inlineWhispers; + static BoolSetting windowTopMost; }; } } diff --git a/settings/stringsetting.h b/settings/stringsetting.h new file mode 100644 index 000000000..121697f7d --- /dev/null +++ b/settings/stringsetting.h @@ -0,0 +1,50 @@ +#ifndef STRINGSETTING_H +#define STRINGSETTING_H + +#include "settings/setting.h" + +#include + +namespace chatterino { +namespace settings { + +class StringSetting : public Setting +{ +public: + StringSetting(const QString &name, const QString &defaultValue) + : Setting(name) + , value(defaultValue) + , defaultValue(defaultValue) + { + } + + const QString & + get() const + { + return this->value; + } + + const QString & + set(const QString &value) + { + return (this->value = value); + } + + void + save(const QSettings &settings) override + { + } + + void + load(const QSettings &settings) override + { + } + +private: + QString value; + QString defaultValue; +}; +} +} + +#endif // STRINGSETTING_H diff --git a/widgets/chatwidgetheaderbutton.cpp b/widgets/chatwidgetheaderbutton.cpp index 14ebf41f8..974eb2f48 100644 --- a/widgets/chatwidgetheaderbutton.cpp +++ b/widgets/chatwidgetheaderbutton.cpp @@ -16,15 +16,17 @@ ChatWidgetHeaderButton::ChatWidgetHeaderButton() { setLayout(&hbox); + label.setAlignment(Qt::AlignCenter); + hbox.setMargin(0); hbox.addSpacing(6); hbox.addWidget(&this->label); hbox.addSpacing(6); - QObject::connect(&this->label, &ChatWidgetHeaderButtonLabel::mouseUp, this, + QObject::connect(&this->label, &SignalLabel::mouseUp, this, &ChatWidgetHeaderButton::labelMouseUp); - QObject::connect(&this->label, &ChatWidgetHeaderButtonLabel::mouseDown, - this, &ChatWidgetHeaderButton::labelMouseDown); + QObject::connect(&this->label, &SignalLabel::mouseDown, this, + &ChatWidgetHeaderButton::labelMouseDown); } void diff --git a/widgets/chatwidgetheaderbutton.h b/widgets/chatwidgetheaderbutton.h index f8cd91ddd..d70cce1bd 100644 --- a/widgets/chatwidgetheaderbutton.h +++ b/widgets/chatwidgetheaderbutton.h @@ -1,7 +1,7 @@ #ifndef CHATWIDGETHEADERBUTTON_H #define CHATWIDGETHEADERBUTTON_H -#include "widgets/chatwidgetheaderbuttonlabel.h" +#include "widgets/signallabel.h" #include #include @@ -18,7 +18,7 @@ class ChatWidgetHeaderButton : public QWidget public: ChatWidgetHeaderButton(); - ChatWidgetHeaderButtonLabel & + SignalLabel & getLabel() { return label; @@ -38,7 +38,7 @@ protected: private: QHBoxLayout hbox; - ChatWidgetHeaderButtonLabel label; + SignalLabel label; bool mouseOver; bool mouseDown; diff --git a/widgets/chatwidgetheaderbuttonlabel.cpp b/widgets/chatwidgetheaderbuttonlabel.cpp deleted file mode 100644 index 0ccef3719..000000000 --- a/widgets/chatwidgetheaderbuttonlabel.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "widgets/chatwidgetheaderbuttonlabel.h" - -namespace chatterino { -namespace widgets { - -ChatWidgetHeaderButtonLabel::ChatWidgetHeaderButtonLabel() -{ - setAlignment(Qt::AlignCenter); -} - -void -ChatWidgetHeaderButtonLabel::mousePressEvent(QMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) { - emit mouseDown(); - } -} - -void -ChatWidgetHeaderButtonLabel::mouseReleaseEvent(QMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) { - emit mouseUp(); - } -} -} -} diff --git a/widgets/chatwidgetheaderbuttonlabel.h b/widgets/chatwidgetheaderbuttonlabel.h deleted file mode 100644 index 37f7420a6..000000000 --- a/widgets/chatwidgetheaderbuttonlabel.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef CHATWIDGETHEADERBUTTONLABEL_H -#define CHATWIDGETHEADERBUTTONLABEL_H - -#include -#include - -namespace chatterino { -namespace widgets { - -class ChatWidgetHeaderButtonLabel : public QLabel -{ - Q_OBJECT - -public: - ChatWidgetHeaderButtonLabel(); - -signals: - void mouseDown(); - void mouseUp(); - -protected: - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); -}; -} -} - -#endif // CHATWIDGETHEADERBUTTONLABEL_H diff --git a/widgets/chatwidgetinput.cpp b/widgets/chatwidgetinput.cpp index fcf9f3282..8d3b64326 100644 --- a/widgets/chatwidgetinput.cpp +++ b/widgets/chatwidgetinput.cpp @@ -7,6 +7,7 @@ namespace chatterino { namespace widgets { ChatWidgetInput::ChatWidgetInput() + : edit(this) { setFixedHeight(38); } diff --git a/widgets/chatwidgetinput.h b/widgets/chatwidgetinput.h index 2bd744b9d..d469878e3 100644 --- a/widgets/chatwidgetinput.h +++ b/widgets/chatwidgetinput.h @@ -2,6 +2,7 @@ #define CHATWIDGETINPUT_H #include +#include #include namespace chatterino { @@ -16,6 +17,9 @@ public: protected: void paintEvent(QPaintEvent *); + +private: + QTextEdit edit; }; } } diff --git a/widgets/chatwidgetview.cpp b/widgets/chatwidgetview.cpp index 388538965..0d49708f4 100644 --- a/widgets/chatwidgetview.cpp +++ b/widgets/chatwidgetview.cpp @@ -147,6 +147,10 @@ ChatWidgetView::paintEvent(QPaintEvent *) } y += message->getHeight(); + + if (y > height()) { + break; + } } } } diff --git a/widgets/signallabel.h b/widgets/signallabel.h index 5c8d43421..4053de56b 100644 --- a/widgets/signallabel.h +++ b/widgets/signallabel.h @@ -3,21 +3,48 @@ #include #include +#include #include class SignalLabel : public QLabel { Q_OBJECT + public: explicit SignalLabel(QWidget *parent = 0, Qt::WindowFlags f = 0) - : QLabel(parent, f) {} + : QLabel(parent, f) + { + } virtual ~SignalLabel() = default; + signals: void mouseDoubleClick(QMouseEvent *ev); + + void mouseDown(); + void mouseUp(); + protected: - virtual void mouseDoubleClickEvent(QMouseEvent *ev) override { + virtual void + mouseDoubleClickEvent(QMouseEvent *ev) override + { emit this->mouseDoubleClick(ev); } + + virtual void + mousePressEvent(QMouseEvent *event) override + { + if (event->button() == Qt::LeftButton) { + emit mouseDown(); + } + } + + void + mouseReleaseEvent(QMouseEvent *event) override + { + if (event->button() == Qt::LeftButton) { + emit mouseUp(); + } + } }; -#endif // SIGNALLABEL_H +#endif // SIGNALLABEL_H