added settings

This commit is contained in:
fourtf 2017-01-20 06:10:28 +01:00
parent 21e938c3b6
commit d215bd58b0
18 changed files with 540 additions and 125 deletions

View file

@ -55,7 +55,6 @@ SOURCES += main.cpp\
widgets/chatwidget.cpp \ widgets/chatwidget.cpp \
widgets/chatwidgetheader.cpp \ widgets/chatwidgetheader.cpp \
widgets/chatwidgetheaderbutton.cpp \ widgets/chatwidgetheaderbutton.cpp \
widgets/chatwidgetheaderbuttonlabel.cpp \
widgets/chatwidgetinput.cpp \ widgets/chatwidgetinput.cpp \
widgets/chatwidgetview.cpp \ widgets/chatwidgetview.cpp \
widgets/mainwindow.cpp \ widgets/mainwindow.cpp \
@ -88,14 +87,12 @@ HEADERS += account.h \
messages/word.h \ messages/word.h \
messages/wordpart.h \ messages/wordpart.h \
resources.h \ resources.h \
settings/realsetting.h \
settings/setting.h \ settings/setting.h \
settings/settings.h \ settings/settings.h \
twitchemotevalue.h \ twitchemotevalue.h \
widgets/chatwidget.h \ widgets/chatwidget.h \
widgets/chatwidgetheader.h \ widgets/chatwidgetheader.h \
widgets/chatwidgetheaderbutton.h \ widgets/chatwidgetheaderbutton.h \
widgets/chatwidgetheaderbuttonlabel.h \
widgets/chatwidgetinput.h \ widgets/chatwidgetinput.h \
widgets/chatwidgetview.h \ widgets/chatwidgetview.h \
widgets/mainwindow.h \ widgets/mainwindow.h \
@ -110,7 +107,11 @@ HEADERS += account.h \
widgets/settingsdialogtab.h \ widgets/settingsdialogtab.h \
widgets/signallabel.h \ widgets/signallabel.h \
widgets/textinputdialog.h \ widgets/textinputdialog.h \
windows.h windows.h \
settings/boolsetting.h \
settings/stringsetting.h \
settings/intsetting.h \
settings/floatsetting.h
PRECOMPILED_HEADER = PRECOMPILED_HEADER =

View file

@ -415,6 +415,10 @@ Message::layout(int width, bool enableEmoteMargins)
bool recalculateImages = this->emoteGeneration != Emotes::getGeneration(); bool recalculateImages = this->emoteGeneration != Emotes::getGeneration();
bool recalculateText = this->fontGeneration != Fonts::getGeneration(); bool recalculateText = this->fontGeneration != Fonts::getGeneration();
qreal emoteScale = settings::Settings::getEmoteScale().get();
bool scaleEmotesByLineHeight =
settings::Settings::getScaleEmotesByLineHeight().get();
if (recalculateImages || recalculateText) { if (recalculateImages || recalculateText) {
this->emoteGeneration = Emotes::getGeneration(); this->emoteGeneration = Emotes::getGeneration();
this->fontGeneration = Fonts::getGeneration(); this->fontGeneration = Fonts::getGeneration();
@ -429,16 +433,12 @@ Message::layout(int width, bool enableEmoteMargins)
qreal w = image.getWidth(); qreal w = image.getWidth();
qreal h = image.getHeight(); qreal h = image.getHeight();
if (settings::Settings::getScaleEmotesByLineHeight()) { if (scaleEmotesByLineHeight) {
word.setSize(w * mediumTextLineHeight / h * word.setSize(w * mediumTextLineHeight / h * emoteScale,
settings::Settings::getEmoteScale(), mediumTextLineHeight * emoteScale);
mediumTextLineHeight *
settings::Settings::getEmoteScale());
} else { } else {
word.setSize(w * image.getScale() * word.setSize(w * image.getScale() * emoteScale,
settings::Settings::getEmoteScale(), h * image.getScale() * emoteScale);
h * image.getScale() *
settings::Settings::getEmoteScale());
} }
} }
} else { } else {

49
settings/boolsetting.h Normal file
View file

@ -0,0 +1,49 @@
#ifndef BOOLSETTING_H
#define BOOLSETTING_H
#include "settings/setting.h"
#include <QString>
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

56
settings/floatsetting.h Normal file
View file

@ -0,0 +1,56 @@
#ifndef REALSETTING_H
#define REALSETTING_H
#include "settings/setting.h"
#include <QString>
namespace chatterino {
namespace settings {
class FloatSetting : public Setting
{
public:
FloatSetting(const QString &name, qreal defaultValue,
qreal minValue = std::numeric_limits<qreal>::min(),
qreal maxValue = std::numeric_limits<qreal>::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

49
settings/intsetting.h Normal file
View file

@ -0,0 +1,49 @@
#ifndef INTSETTING_H
#define INTSETTING_H
#include "settings/setting.h"
#include <QString>
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

View file

@ -1,32 +0,0 @@
#ifndef REALSETTING_H
#define REALSETTING_H
#include <QString>
namespace chatterino {
namespace settings {
class RealSetting : public Setting
{
public:
RealSetting(const QString &name, qreal defaultValue,
qreal minValue = std::numeric_limits<qreal>::min(),
qreal maxValue = std::numeric_limits<qreal>::max())
: Setting(name)
, value(defaultValue)
, defaultValue(defaultValue)
, minValue(minValue)
, maxValue(maxValue)
{
}
private:
qreal value;
qreal defaultValue;
qreal minValue;
qreal maxValue;
};
}
}
#endif // REALSETTING_H

View file

@ -1,6 +1,7 @@
#ifndef SETTING_H #ifndef SETTING_H
#define SETTING_H #define SETTING_H
#include <QSettings>
#include <QString> #include <QString>
namespace chatterino { namespace chatterino {
@ -14,17 +15,20 @@ public:
{ {
} }
virtual void save(const QSettings &settings) = 0;
virtual void load(const QSettings &settings) = 0;
protected:
const QString & const QString &
getName() const getName() const
{ {
return name; return name;
} }
virtual QString toString() = 0;
private: private:
QString name; QString name;
}; };
} }
}
#endif // SETTING_H #endif // SETTING_H

View file

@ -1,12 +1,63 @@
#include "settings/settings.h" #include "settings/settings.h"
#include <QDir>
#include <QStandardPaths>
namespace chatterino { namespace chatterino {
namespace settings { 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<Setting *> Settings::settingsItems;
bool Settings::portable(false);
messages::Word::Type Settings::wordTypeMask = messages::Word::Default; 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 bool

View file

@ -2,6 +2,12 @@
#define APPSETTINGS_H #define APPSETTINGS_H
#include "messages/word.h" #include "messages/word.h"
#include "settings/boolsetting.h"
#include "settings/floatsetting.h"
#include "settings/setting.h"
#include "settings/stringsetting.h"
#include <QSettings>
namespace chatterino { namespace chatterino {
namespace settings { namespace settings {
@ -17,27 +23,225 @@ public:
static bool isIgnoredEmote(const QString &emote); static bool isIgnoredEmote(const QString &emote);
static qreal static void load();
getEmoteScale() static void save();
{
return 1;
}
static qreal
getBadgeScale()
{
return 1;
}
static bool static bool
getScaleEmotesByLineHeight() getPortable()
{ {
return false; return portable;
}
static void
setPortable(bool value)
{
portable = value;
} }
private: private:
Settings(); 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<Setting *> settingsItems;
template <class T>
static T
addSetting(T setting)
{
settingsItems.push_back(setting);
return setting;
}
static bool portable;
static messages::Word::Type wordTypeMask; 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;
}; };
} }
} }

50
settings/stringsetting.h Normal file
View file

@ -0,0 +1,50 @@
#ifndef STRINGSETTING_H
#define STRINGSETTING_H
#include "settings/setting.h"
#include <QString>
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

View file

@ -16,15 +16,17 @@ ChatWidgetHeaderButton::ChatWidgetHeaderButton()
{ {
setLayout(&hbox); setLayout(&hbox);
label.setAlignment(Qt::AlignCenter);
hbox.setMargin(0); hbox.setMargin(0);
hbox.addSpacing(6); hbox.addSpacing(6);
hbox.addWidget(&this->label); hbox.addWidget(&this->label);
hbox.addSpacing(6); hbox.addSpacing(6);
QObject::connect(&this->label, &ChatWidgetHeaderButtonLabel::mouseUp, this, QObject::connect(&this->label, &SignalLabel::mouseUp, this,
&ChatWidgetHeaderButton::labelMouseUp); &ChatWidgetHeaderButton::labelMouseUp);
QObject::connect(&this->label, &ChatWidgetHeaderButtonLabel::mouseDown, QObject::connect(&this->label, &SignalLabel::mouseDown, this,
this, &ChatWidgetHeaderButton::labelMouseDown); &ChatWidgetHeaderButton::labelMouseDown);
} }
void void

View file

@ -1,7 +1,7 @@
#ifndef CHATWIDGETHEADERBUTTON_H #ifndef CHATWIDGETHEADERBUTTON_H
#define CHATWIDGETHEADERBUTTON_H #define CHATWIDGETHEADERBUTTON_H
#include "widgets/chatwidgetheaderbuttonlabel.h" #include "widgets/signallabel.h"
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
@ -18,7 +18,7 @@ class ChatWidgetHeaderButton : public QWidget
public: public:
ChatWidgetHeaderButton(); ChatWidgetHeaderButton();
ChatWidgetHeaderButtonLabel & SignalLabel &
getLabel() getLabel()
{ {
return label; return label;
@ -38,7 +38,7 @@ protected:
private: private:
QHBoxLayout hbox; QHBoxLayout hbox;
ChatWidgetHeaderButtonLabel label; SignalLabel label;
bool mouseOver; bool mouseOver;
bool mouseDown; bool mouseDown;

View file

@ -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();
}
}
}
}

View file

@ -1,28 +0,0 @@
#ifndef CHATWIDGETHEADERBUTTONLABEL_H
#define CHATWIDGETHEADERBUTTONLABEL_H
#include <QLabel>
#include <QMouseEvent>
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

View file

@ -7,6 +7,7 @@ namespace chatterino {
namespace widgets { namespace widgets {
ChatWidgetInput::ChatWidgetInput() ChatWidgetInput::ChatWidgetInput()
: edit(this)
{ {
setFixedHeight(38); setFixedHeight(38);
} }

View file

@ -2,6 +2,7 @@
#define CHATWIDGETINPUT_H #define CHATWIDGETINPUT_H
#include <QPaintEvent> #include <QPaintEvent>
#include <QTextEdit>
#include <QWidget> #include <QWidget>
namespace chatterino { namespace chatterino {
@ -16,6 +17,9 @@ public:
protected: protected:
void paintEvent(QPaintEvent *); void paintEvent(QPaintEvent *);
private:
QTextEdit edit;
}; };
} }
} }

View file

@ -147,6 +147,10 @@ ChatWidgetView::paintEvent(QPaintEvent *)
} }
y += message->getHeight(); y += message->getHeight();
if (y > height()) {
break;
}
} }
} }
} }

View file

@ -3,21 +3,48 @@
#include <QFlags> #include <QFlags>
#include <QLabel> #include <QLabel>
#include <QMouseEvent>
#include <QWidget> #include <QWidget>
class SignalLabel : public QLabel class SignalLabel : public QLabel
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SignalLabel(QWidget *parent = 0, Qt::WindowFlags f = 0) explicit SignalLabel(QWidget *parent = 0, Qt::WindowFlags f = 0)
: QLabel(parent, f) {} : QLabel(parent, f)
{
}
virtual ~SignalLabel() = default; virtual ~SignalLabel() = default;
signals: signals:
void mouseDoubleClick(QMouseEvent *ev); void mouseDoubleClick(QMouseEvent *ev);
void mouseDown();
void mouseUp();
protected: protected:
virtual void mouseDoubleClickEvent(QMouseEvent *ev) override { virtual void
mouseDoubleClickEvent(QMouseEvent *ev) override
{
emit this->mouseDoubleClick(ev); 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