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/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 =

View file

@ -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 {

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
#define SETTING_H
#include <QSettings>
#include <QString>
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

View file

@ -1,12 +1,63 @@
#include "settings/settings.h"
#include <QDir>
#include <QStandardPaths>
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<Setting *> 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

View file

@ -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 <QSettings>
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<Setting *> settingsItems;
template <class T>
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;
};
}
}

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);
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

View file

@ -1,7 +1,7 @@
#ifndef CHATWIDGETHEADERBUTTON_H
#define CHATWIDGETHEADERBUTTON_H
#include "widgets/chatwidgetheaderbuttonlabel.h"
#include "widgets/signallabel.h"
#include <QHBoxLayout>
#include <QLabel>
@ -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;

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 {
ChatWidgetInput::ChatWidgetInput()
: edit(this)
{
setFixedHeight(38);
}

View file

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

View file

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

View file

@ -3,21 +3,48 @@
#include <QFlags>
#include <QLabel>
#include <QMouseEvent>
#include <QWidget>
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