updated settingsdialog

This commit is contained in:
fourtf 2017-01-22 12:46:35 +01:00
parent 8d85f91c4d
commit be92a82891
21 changed files with 487 additions and 232 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

BIN
images/UserProfile_22x.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 286 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 480 B

View file

@ -337,7 +337,7 @@ Message::Message(const IrcPrivateMessage &ircMessage, const Channel &channel,
"introducing-cheering-celebrate-"
"together-da62af41fac6"))));
words.push_back(
Word(image, Word::Bits, QString("cheer"),
Word(image, Word::BitsStatic, QString("cheer"),
QString("Twitch Cheer"),
Link(Link::Url,
QString("https://blog.twitch.tv/"
@ -405,6 +405,8 @@ Message::Message(const IrcPrivateMessage &ircMessage, const Channel &channel,
bool
Message::layout(int width, bool enableEmoteMargins)
{
auto &settings = settings::Settings::getInstance();
width = width - (width % 2);
int mediumTextLineHeight = Fonts::getFontMetrics(Fonts::Medium).height();
@ -415,9 +417,8 @@ 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();
qreal emoteScale = settings.getEmoteScale().get();
bool scaleEmotesByLineHeight = settings.getScaleEmotesByLineHeight().get();
if (recalculateImages || recalculateText) {
this->emoteGeneration = Emotes::getGeneration();
@ -474,7 +475,7 @@ Message::layout(int width, bool enableEmoteMargins)
}
};
int flags = settings::Settings::getWordTypeMask();
uint32_t flags = settings::Settings::getInstance().getWordTypeMask();
for (auto it = this->words.begin(); it != this->words.end(); ++it) {
Word &word = *it;

View file

@ -34,7 +34,7 @@ public:
EmoteImages = TwitchEmoteImage | BttvEmoteImage | BttvGifEmoteImage |
FfzEmoteImage,
Bits = (1 << 12),
BitsStatic = (1 << 12),
BitsAnimated = (1 << 13),
BadgeStaff = (1 << 14),
@ -59,7 +59,7 @@ public:
EmojiImage = (1 << 27),
EmojiText = (1 << 28),
Default = TimestampNoSeconds | Badges | Username | Bits |
Default = TimestampNoSeconds | Badges | Username | BitsStatic |
FfzEmoteImage | BttvEmoteImage | BttvGifEmoteImage |
TwitchEmoteImage | BitsAmount | Text | ButtonBan |
ButtonTimeout

View file

@ -27,5 +27,8 @@
<file>emojidata.txt</file>
<file>images/button_ban.png</file>
<file>images/button_timeout.png</file>
<file>images/StatusAnnotations_Blocked_16xLG_color.png</file>
<file>images/UserProfile_22x.png</file>
<file>images/VSO_Link_blue_16x.png</file>
</qresource>
</RCC>

View file

@ -6,44 +6,85 @@
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);
BoolSetting Settings::hideTabX("", false);
Settings Settings::_;
QSettings Settings::settings(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
QSettings::IniFormat);
Settings::Settings()
: settings(
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
QSettings::IniFormat)
, settingsItems()
, portable(false)
, wordTypeMask(messages::Word::Default)
, theme("", "dark")
, user("", "")
, emoteScale("", 1.0)
, scaleEmotesByLineHeight("", false)
, showTimestamps("", true)
, showTimestampSeconds("", false)
, showLastMessageIndicator("", false)
, allowDouplicateMessages("", true)
, linksDoubleClickOnly("", false)
, hideEmptyInput("", false)
, showMessageLength("", false)
, seperateMessages("", false)
, mentionUsersWithAt("", false)
, allowCommandsAtEnd("", false)
, enableHighlights("", true)
, enableHighlightSound("", true)
, enableHighlightTaskbar("", true)
, customHighlightSound("", false)
, enableTwitchEmotes("", true)
, enableBttvEmotes("", true)
, enableFfzEmotes("", true)
, enableEmojis("", true)
, enableGifAnimations("", true)
, enableGifs("", true)
, inlineWhispers("", true)
, windowTopMost("", true)
, hideTabX("", false)
{
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(&showLastMessageIndicator);
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);
settingsItems.push_back(&hideTabX);
std::vector<Setting *> Settings::settingsItems;
bool Settings::portable(false);
messages::Word::Type Settings::wordTypeMask = messages::Word::Default;
int Settings::_ = Settings::_init();
QObject::connect(&showTimestamps, &BoolSetting::valueChanged, this,
&Settings::updateWordTypeMask);
QObject::connect(&showTimestampSeconds, &BoolSetting::valueChanged, this,
&Settings::updateWordTypeMask);
QObject::connect(&enableBttvEmotes, &BoolSetting::valueChanged, this,
&Settings::updateWordTypeMask);
QObject::connect(&enableEmojis, &BoolSetting::valueChanged, this,
&Settings::updateWordTypeMask);
QObject::connect(&enableFfzEmotes, &BoolSetting::valueChanged, this,
&Settings::updateWordTypeMask);
QObject::connect(&enableTwitchEmotes, &BoolSetting::valueChanged, this,
&Settings::updateWordTypeMask);
}
void
Settings::save()
@ -62,9 +103,45 @@ Settings::load()
}
bool
Settings::isIgnoredEmote(const QString &emote)
Settings::isIgnoredEmote(const QString &)
{
return false;
}
void
Settings::updateWordTypeMask(bool)
{
using namespace messages;
uint32_t mask = Word::Text;
if (showTimestamps.get()) {
mask |= showTimestampSeconds.get() ? Word::TimestampWithSeconds
: Word::TimestampNoSeconds;
}
mask |= enableTwitchEmotes.get() ? Word::TwitchEmoteImage
: Word::TwitchEmoteText;
mask |= enableFfzEmotes.get() ? Word::FfzEmoteImage : Word::FfzEmoteText;
mask |= enableBttvEmotes.get() ? Word::BttvEmoteImage : Word::BttvEmoteText;
mask |= (enableBttvEmotes.get() && enableGifs.get()) ? Word::BttvEmoteImage
: Word::BttvEmoteText;
mask |= enableEmojis.get() ? Word::EmojiImage : Word::EmojiText;
mask |= Word::BitsAmount;
mask |= enableGifs.get() ? Word::BitsAnimated : Word::BitsStatic;
mask |= Word::Badges;
mask |= Word::Username;
Word::Type _mask = (Word::Type)mask;
// if (mask != _mask) {
wordTypeMask = _mask;
emit wordTypeMaskChanged();
// }
}
}
}

View file

@ -12,243 +12,231 @@
namespace chatterino {
namespace settings {
class Settings
class Settings : public QObject
{
Q_OBJECT
public:
static messages::Word::Type
static Settings &
getInstance()
{
return _;
}
void load();
void save();
messages::Word::Type
getWordTypeMask()
{
return wordTypeMask;
}
static bool isIgnoredEmote(const QString &emote);
bool isIgnoredEmote(const QString &emote);
static void load();
static void save();
static bool
bool
getPortable()
{
return portable;
}
static void
void
setPortable(bool value)
{
portable = value;
}
signals:
void wordTypeMaskChanged();
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);
settingsItems.push_back(&hideTabX);
}
static Settings _;
static QSettings settings;
static std::vector<Setting *> settingsItems;
void updateWordTypeMask(bool);
template <class T>
static T
addSetting(T setting)
{
settingsItems.push_back(setting);
return setting;
}
QSettings settings;
std::vector<Setting *> settingsItems;
static bool portable;
// template <class T>
// T
// addSetting(T setting)
// {
// settingsItems.push_back(setting);
// return setting;
// }
static messages::Word::Type wordTypeMask;
bool portable;
messages::Word::Type wordTypeMask;
private:
StringSetting theme;
StringSetting user;
FloatSetting emoteScale;
BoolSetting scaleEmotesByLineHeight;
BoolSetting showTimestamps;
BoolSetting showTimestampSeconds;
BoolSetting showLastMessageIndicator;
BoolSetting allowDouplicateMessages;
BoolSetting linksDoubleClickOnly;
BoolSetting hideEmptyInput;
BoolSetting showMessageLength;
BoolSetting seperateMessages;
BoolSetting mentionUsersWithAt;
BoolSetting allowCommandsAtEnd;
BoolSetting enableHighlights;
BoolSetting enableHighlightSound;
BoolSetting enableHighlightTaskbar;
BoolSetting customHighlightSound;
BoolSetting enableTwitchEmotes;
BoolSetting enableBttvEmotes;
BoolSetting enableFfzEmotes;
BoolSetting enableEmojis;
BoolSetting enableGifAnimations;
BoolSetting enableGifs;
BoolSetting inlineWhispers;
BoolSetting windowTopMost;
BoolSetting hideTabX;
// settings
public:
static StringSetting &
StringSetting &
getTheme()
{
return Settings::theme;
return this->theme;
}
static StringSetting &
StringSetting &
getUser()
{
return Settings::user;
return this->user;
}
static FloatSetting &
FloatSetting &
getEmoteScale()
{
return Settings::emoteScale;
return this->emoteScale;
}
static BoolSetting &
BoolSetting &
getScaleEmotesByLineHeight()
{
return Settings::scaleEmotesByLineHeight;
return this->scaleEmotesByLineHeight;
}
static BoolSetting &
BoolSetting &
getShowTimestamps()
{
return Settings::showTimestamps;
return this->showTimestamps;
}
static BoolSetting &
BoolSetting &
getShowTimestampSeconds()
{
return Settings::showTimestampSeconds;
return this->showTimestampSeconds;
}
static BoolSetting &
BoolSetting &
getShowLastMessageIndicator()
{
return this->showLastMessageIndicator;
}
BoolSetting &
getAllowDouplicateMessages()
{
return Settings::allowDouplicateMessages;
return this->allowDouplicateMessages;
}
static BoolSetting &
BoolSetting &
getLinksDoubleClickOnly()
{
return Settings::linksDoubleClickOnly;
return this->linksDoubleClickOnly;
}
static BoolSetting &
BoolSetting &
getHideEmptyInput()
{
return Settings::hideEmptyInput;
return this->hideEmptyInput;
}
static BoolSetting &
BoolSetting &
getShowMessageLength()
{
return Settings::showMessageLength;
return this->showMessageLength;
}
static BoolSetting &
BoolSetting &
getSeperateMessages()
{
return Settings::seperateMessages;
return this->seperateMessages;
}
static BoolSetting &
BoolSetting &
getMentionUsersWithAt()
{
return Settings::mentionUsersWithAt;
return this->mentionUsersWithAt;
}
static BoolSetting &
BoolSetting &
getAllowCommandsAtEnd()
{
return Settings::allowCommandsAtEnd;
return this->allowCommandsAtEnd;
}
static BoolSetting &
BoolSetting &
getEnableHighlights()
{
return Settings::enableHighlights;
return this->enableHighlights;
}
static BoolSetting &
BoolSetting &
getEnableHighlightSound()
{
return Settings::enableHighlightSound;
return this->enableHighlightSound;
}
static BoolSetting &
BoolSetting &
getEnableHighlightTaskbar()
{
return Settings::enableHighlightTaskbar;
return this->enableHighlightTaskbar;
}
static BoolSetting &
BoolSetting &
getCustomHighlightSound()
{
return Settings::customHighlightSound;
return this->customHighlightSound;
}
static BoolSetting &
BoolSetting &
getEnableTwitchEmotes()
{
return Settings::enableTwitchEmotes;
return this->enableTwitchEmotes;
}
static BoolSetting &
BoolSetting &
getEnableBttvEmotes()
{
return Settings::enableBttvEmotes;
return this->enableBttvEmotes;
}
static BoolSetting &
getEnableFFzEmotes()
BoolSetting &
getEnableFfzEmotes()
{
return Settings::enableFFzEmotes;
return this->enableFfzEmotes;
}
static BoolSetting &
BoolSetting &
getEnableEmojis()
{
return Settings::enableEmojis;
return this->enableEmojis;
}
static BoolSetting &
BoolSetting &
getEnableGifAnimations()
{
return Settings::enableGifAnimations;
return this->enableGifAnimations;
}
static BoolSetting &
BoolSetting &
getEnableGifs()
{
return Settings::enableGifs;
return this->enableGifs;
}
static BoolSetting &
BoolSetting &
getInlineWhispers()
{
return Settings::inlineWhispers;
return this->inlineWhispers;
}
static BoolSetting &
BoolSetting &
getWindowTopMost()
{
return Settings::windowTopMost;
return this->windowTopMost;
}
static BoolSetting &
BoolSetting &
getHideTabX()
{
return Settings::hideTabX;
return this->hideTabX;
}
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;
static BoolSetting hideTabX;
};
}
}

View file

@ -1,6 +1,7 @@
#include "widgets/chatwidget.h"
#include "channels.h"
#include "colorscheme.h"
#include "settings/settings.h"
#include "widgets/textinputdialog.h"
#include <QFont>
@ -23,10 +24,6 @@ ChatWidget::ChatWidget(QWidget *parent)
this->vbox.setSpacing(0);
this->vbox.setMargin(1);
// header.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// view.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// input.setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
this->vbox.addWidget(&header);
this->vbox.addWidget(&view, 1);
this->vbox.addWidget(&input);

View file

@ -2,6 +2,7 @@
#define CHATWIDGET_H
#include "channel.h"
#include "messages/word.h"
#include "widgets/chatwidgetheader.h"
#include "widgets/chatwidgetinput.h"
#include "widgets/chatwidgetview.h"

View file

@ -1,5 +1,6 @@
#include "widgets/chatwidgetinput.h"
#include "colorscheme.h"
#include "settings/settings.h"
#include <QPainter>
@ -38,6 +39,20 @@ ChatWidgetInput::ChatWidgetInput()
// this->emotesLabel.setMaximumSize(12, 12);
this->refreshTheme();
this->setMessageLengthVisisble(
settings::Settings::getInstance().getShowMessageLength().get());
QObject::connect(&settings::Settings::getInstance().getShowMessageLength(),
&settings::BoolSetting::valueChanged, this,
&setMessageLengthVisisble);
}
ChatWidgetInput::~ChatWidgetInput()
{
QObject::disconnect(
&settings::Settings::getInstance().getShowMessageLength(),
&settings::BoolSetting::valueChanged, this, &setMessageLengthVisisble);
}
void

View file

@ -21,6 +21,7 @@ class ChatWidgetInput : public QWidget
public:
ChatWidgetInput();
~ChatWidgetInput();
protected:
void paintEvent(QPaintEvent *);
@ -37,6 +38,11 @@ private:
private slots:
void refreshTheme();
void
setMessageLengthVisisble(bool value)
{
this->textLengthLabel.setHidden(!value);
}
};
}
}

View file

@ -2,8 +2,8 @@
#include "channels.h"
#include "colorscheme.h"
#include "messages/message.h"
#include "messages/word.h"
#include "messages/wordpart.h"
#include "settings/settings.h"
#include "widgets/chatwidget.h"
#include <math.h>
@ -22,6 +22,17 @@ ChatWidgetView::ChatWidgetView(ChatWidget *parent)
auto scroll = QScroller::scroller(this);
scroll->scrollTo(QPointF(0, 100));
QObject::connect(&settings::Settings::getInstance(),
&settings::Settings::wordTypeMaskChanged, this,
&wordTypeMaskChanged);
}
ChatWidgetView::~ChatWidgetView()
{
QObject::disconnect(&settings::Settings::getInstance(),
&settings::Settings::wordTypeMaskChanged, this,
&wordTypeMaskChanged);
}
bool

View file

@ -2,6 +2,7 @@
#define CHATVIEW_H
#include "channel.h"
#include "messages/word.h"
#include "widgets/scrollbar.h"
#include <QPaintEvent>
@ -17,6 +18,7 @@ class ChatWidgetView : public QWidget
public:
explicit ChatWidgetView(ChatWidget *parent);
~ChatWidgetView();
bool layoutMessages();
@ -29,6 +31,15 @@ private:
ChatWidget *chatWidget;
ScrollBar scrollbar;
private slots:
void
wordTypeMaskChanged()
{
if (layoutMessages()) {
repaint();
}
}
};
}
}

View file

@ -14,10 +14,6 @@ MainWindow::MainWindow(QWidget *parent)
{
setCentralWidget(&this->notebook);
this->notebook.addPage();
this->notebook.addPage();
this->notebook.addPage();
QPalette palette;
palette.setColor(QPalette::Background,
ColorScheme::instance().TabPanelBackground);

View file

@ -18,6 +18,7 @@ Notebook::Notebook(QWidget *parent)
, addButton(this)
, settingsButton(this)
, userButton(this)
, selectedPage(nullptr)
{
connect(&this->settingsButton, SIGNAL(clicked()), this,
SLOT(settingsButtonClicked()));
@ -34,6 +35,8 @@ Notebook::Notebook(QWidget *parent)
this->userButton.icon = NotebookButton::IconUser;
this->addButton.resize(24, 24);
this->addPage();
}
NotebookPage *
@ -42,13 +45,15 @@ Notebook::addPage(bool select)
auto tab = new NotebookTab(this);
auto page = new NotebookPage(this, tab);
tab->show();
if (select || this->pages.count() == 0) {
this->select(page);
}
this->pages.append(page);
performLayout();
this->performLayout();
return page;
}
@ -56,20 +61,24 @@ Notebook::addPage(bool select)
void
Notebook::removePage(NotebookPage *page)
{
int index = pages.indexOf(page);
int index = this->pages.indexOf(page);
if (pages.size() == 1) {
select(NULL);
this->select(NULL);
} else if (index == pages.count() - 1) {
select(pages[index - 1]);
this->select(pages[index - 1]);
} else {
select(pages[index + 1]);
this->select(pages[index + 1]);
}
delete page->tab;
delete page;
pages.removeOne(page);
this->pages.removeOne(page);
if (this->pages.size() == 0) {
addPage();
}
performLayout();
}
@ -95,6 +104,36 @@ Notebook::select(NotebookPage *page)
performLayout();
}
NotebookPage *
Notebook::tabAt(QPoint point, int &index)
{
int i = 0;
for (auto *page : pages) {
if (page->tab->geometry().contains(point)) {
index = i;
return page;
}
i++;
}
index = -1;
return nullptr;
}
void
Notebook::rearrangePage(NotebookPage *page, int index)
{
int i1 = pages.indexOf(page);
pages.move(pages.indexOf(page), index);
int i2 = pages.indexOf(page);
performLayout();
}
void
Notebook::performLayout()
{
@ -109,10 +148,10 @@ Notebook::performLayout()
(i == this->pages.last() ? tabHeight : 0) + x + i->tab->width() >
width()) {
y += i->tab->height();
i->tab->move(0, y);
i->tab->moveAnimated(QPoint(0, y));
x = i->tab->width();
} else {
i->tab->move(x, y);
i->tab->moveAnimated(QPoint(x, y));
x += i->tab->width();
}

View file

@ -33,6 +33,9 @@ public:
void performLayout();
NotebookPage *tabAt(QPoint point, int &index);
void rearrangePage(NotebookPage *page, int index);
protected:
void resizeEvent(QResizeEvent *);
@ -50,7 +53,7 @@ private:
NotebookButton settingsButton;
NotebookButton userButton;
NotebookPage *selectedPage = nullptr;
NotebookPage *selectedPage;
};
}
}

View file

@ -10,6 +10,8 @@ namespace widgets {
NotebookTab::NotebookTab(Notebook *notebook)
: QWidget(notebook)
// , posAnimation(this, "pos")
// , posAnimated(false)
, notebook(notebook)
, text("<no title>")
, selected(false)
@ -19,36 +21,56 @@ NotebookTab::NotebookTab(Notebook *notebook)
, mouseDownX(false)
, highlightStyle(HighlightNone)
{
calcSize();
this->calcSize();
this->setAcceptDrops(true);
setAcceptDrops(true);
QObject::connect(&settings::Settings::getHideTabX(),
SIGNAL(settings::BoolSetting::valueChanged(bool)), this,
SLOT(NotebookTab::hideTabXChanged(bool)));
this->installEventFilter(this);
QObject::connect(&settings::Settings::getInstance().getHideTabX(),
&settings::BoolSetting::valueChanged, this,
&NotebookTab::hideTabXChanged);
this->setMouseTracking(true);
}
NotebookTab::~NotebookTab()
{
QObject::disconnect(&settings::Settings::getHideTabX(),
SIGNAL(settings::BoolSetting::valueChanged(bool)), this,
SLOT(NotebookTab::hideTabXChanged(bool)));
QObject::disconnect(&settings::Settings::getInstance().getHideTabX(),
&settings::BoolSetting::valueChanged, this,
&NotebookTab::hideTabXChanged);
}
void
NotebookTab::calcSize()
{
if (settings::Settings::getHideTabX().get()) {
if (settings::Settings::getInstance().getHideTabX().get()) {
this->resize(this->fontMetrics().width(this->text) + 8, 24);
} else {
this->resize(this->fontMetrics().width(this->text) + 8 + 24, 24);
}
}
void
NotebookTab::moveAnimated(QPoint pos)
{
move(pos);
// if (posAnimated == false) {
// move(pos);
// posAnimated = true;
// return;
// }
// if (this->posAnimation.endValue() == pos) {
// return;
// }
// this->posAnimation.stop();
// this->posAnimation.setDuration(50);
// this->posAnimation.setStartValue(this->pos());
// this->posAnimation.setEndValue(pos);
// this->posAnimation.start();
}
void
NotebookTab::paintEvent(QPaintEvent *)
{
@ -77,25 +99,28 @@ NotebookTab::paintEvent(QPaintEvent *)
painter.setPen(fg);
QRect rect(0, 0,
width() - (settings::Settings::getHideTabX().get() ? 0 : 16),
height());
QRect rect(
0, 0,
width() -
(settings::Settings::getInstance().getHideTabX().get() ? 0 : 16),
height());
painter.drawText(rect, this->text, QTextOption(Qt::AlignCenter));
if (!settings::Settings::getHideTabX().get() && (mouseOver || selected)) {
if (mouseOverX) {
painter.fillRect(getXRect(), QColor(0, 0, 0, 64));
if (!settings::Settings::getInstance().getHideTabX().get() &&
(this->mouseOver || this->selected)) {
if (this->mouseOverX) {
painter.fillRect(this->getXRect(), QColor(0, 0, 0, 64));
if (mouseDownX) {
painter.fillRect(getXRect(), QColor(0, 0, 0, 64));
if (this->mouseDownX) {
painter.fillRect(this->getXRect(), QColor(0, 0, 0, 64));
}
}
painter.drawLine(getXRect().topLeft() + QPoint(4, 4),
getXRect().bottomRight() + QPoint(-4, -4));
painter.drawLine(getXRect().topRight() + QPoint(-4, 4),
getXRect().bottomLeft() + QPoint(4, -4));
painter.drawLine(this->getXRect().topLeft() + QPoint(4, 4),
this->getXRect().bottomRight() + QPoint(-4, -4));
painter.drawLine(this->getXRect().topRight() + QPoint(-4, 4),
this->getXRect().bottomLeft() + QPoint(4, -4));
}
}
@ -156,6 +181,17 @@ NotebookTab::mouseMoveEvent(QMouseEvent *event)
this->repaint();
}
if (this->mouseDown && !this->rect().contains(event->pos())) {
QPoint relPoint = this->mapToParent(event->pos());
int index;
NotebookPage *page = notebook->tabAt(relPoint, index);
if (page != nullptr && page != this->page) {
notebook->rearrangePage(this->page, index);
}
}
}
}
}

View file

@ -1,6 +1,7 @@
#ifndef NOTEBOOKTAB_H
#define NOTEBOOKTAB_H
#include <QPropertyAnimation>
#include <QWidget>
namespace chatterino {
@ -20,7 +21,7 @@ public:
HighlightNewMessage
};
NotebookTab(Notebook *notebook);
explicit NotebookTab(Notebook *notebook);
~NotebookTab();
void calcSize();
@ -65,6 +66,8 @@ public:
repaint();
}
void moveAnimated(QPoint pos);
protected:
void paintEvent(QPaintEvent *) override;
@ -78,6 +81,9 @@ protected:
void mouseMoveEvent(QMouseEvent *event) override;
private:
// QPropertyAnimation posAnimation;
// bool posAnimated;
Notebook *notebook;
QString text;
@ -98,7 +104,7 @@ private:
private slots:
void
hideTabXChanged(bool value)
hideTabXChanged(bool)
{
calcSize();
repaint();

View file

@ -54,6 +54,8 @@ SettingsDialog::SettingsDialog()
void
SettingsDialog::addTabs()
{
settings::Settings &settings = settings::Settings::getInstance();
QVBoxLayout *vbox;
// Appearance
@ -80,12 +82,17 @@ SettingsDialog::addTabs()
auto group = new QGroupBox("Messages");
auto v = new QVBoxLayout();
v->addWidget(createCheckbox("Show timestamp", ""));
v->addWidget(createCheckbox("Show seconds in timestamp", ""));
v->addWidget(
createCheckbox("Show timestamp", settings.getShowTimestamps()));
v->addWidget(createCheckbox("Show seconds in timestamp",
settings.getShowTimestampSeconds()));
v->addWidget(createCheckbox(
"Allow sending duplicate messages (add a space at the end)", ""));
v->addWidget(createCheckbox("Seperate messages", ""));
v->addWidget(createCheckbox("Show message length", ""));
"Allow sending duplicate messages (add a space at the end)",
settings.getAllowDouplicateMessages()));
v->addWidget(createCheckbox("Seperate messages",
settings.getSeperateMessages()));
v->addWidget(createCheckbox("Show message length",
settings.getShowMessageLength()));
group->setLayout(v);
@ -99,11 +106,15 @@ SettingsDialog::addTabs()
// Behaviour
vbox = new QVBoxLayout();
vbox->addWidget(createCheckbox("Hide input box if empty", ""));
vbox->addWidget(createCheckbox("Hide input box if empty",
settings.getHideEmptyInput()));
vbox->addWidget(
createCheckbox("Mention users with a @ (except in commands)", ""));
vbox->addWidget(createCheckbox("Window always on top", ""));
vbox->addWidget(createCheckbox("Show last read message indicator", ""));
createCheckbox("Mention users with a @ (except in commands)",
settings.getMentionUsersWithAt()));
vbox->addWidget(
createCheckbox("Window always on top", settings.getWindowTopMost()));
vbox->addWidget(createCheckbox("Show last read message indicator",
settings.getShowLastMessageIndicator()));
{
auto v = new QVBoxLayout();
@ -128,14 +139,66 @@ SettingsDialog::addTabs()
addTab(vbox, "Commands", ":/images/CustomActionEditor_16x.png");
// Emotes
vbox = new QVBoxLayout();
vbox->addWidget(createCheckbox("Enable Twitch Emotes",
settings.getEnableTwitchEmotes()));
vbox->addWidget(createCheckbox("Enable BetterTTV Emotes",
settings.getEnableBttvEmotes()));
vbox->addWidget(createCheckbox("Enable FrankerFaceZ Emotes",
settings.getEnableFfzEmotes()));
vbox->addWidget(
createCheckbox("Enable Gif Emotes", settings.getEnableGifs()));
vbox->addWidget(
createCheckbox("Enable Emojis", settings.getEnableEmojis()));
vbox->addWidget(createCheckbox("Enable Twitch Emotes",
settings.getEnableTwitchEmotes()));
vbox->addStretch(1);
addTab(vbox, "Emotes", ":/images/Emoji_Color_1F60A_19.png");
// Ignored Users
vbox = new QVBoxLayout();
vbox->addStretch(1);
addTab(vbox, "Ignored Users",
":/images/StatusAnnotations_Blocked_16xLG_color.png");
// Ignored Messages
vbox = new QVBoxLayout();
vbox->addStretch(1);
addTab(vbox, "Ignored Messages", ":/images/Filter_16x.png");
// Links
vbox = new QVBoxLayout();
vbox->addStretch(1);
addTab(vbox, "Links", ":/images/VSO_Link_blue_16x.png");
// Highlighting
vbox = new QVBoxLayout();
vbox->addStretch(1);
addTab(vbox, "Highlighting", ":/images/format_Bold_16xLG.png");
// Whispers
vbox = new QVBoxLayout();
vbox->addStretch(1);
addTab(vbox, "Whispers", ":/images/Message_16xLG.png");
// Add stretch
tabs.addStretch(1);
}
QCheckBox *
SettingsDialog::createCheckbox(QString title, QString settingsId)
SettingsDialog::createCheckbox(const QString &title,
settings::BoolSetting &setting)
{
return new QCheckBox(title);
auto checkbox = new QCheckBox(title);
QObject::connect(checkbox, &QCheckBox::toggled, this,
[&setting, this](bool state) { setting.set(state); });
return checkbox;
}
void

View file

@ -1,6 +1,7 @@
#ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H
#include "settings/settings.h"
#include "widgets/settingsdialogtab.h"
#include <QButtonGroup>
@ -39,7 +40,8 @@ private:
SettingsDialogTab *selectedTab = NULL;
QCheckBox *createCheckbox(QString title, QString settingsId);
QCheckBox *createCheckbox(const QString &title,
settings::BoolSetting &setting);
};
}
}