From 8d85f91c4df57fb5cf20c27e2de59504fea1df0b Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 22 Jan 2017 05:58:23 +0100 Subject: [PATCH] added emote button and text length label --- settings/boolsetting.h | 2 + settings/floatsetting.h | 2 + settings/intsetting.h | 2 + settings/setting.h | 4 +- settings/settings.cpp | 2 +- settings/settings.h | 60 ++++++++++++------------ settings/stringsetting.h | 2 + widgets/chatwidgetheader.cpp | 8 ++-- widgets/chatwidgetheaderbutton.cpp | 6 +-- widgets/chatwidgetheaderbutton.h | 2 +- widgets/chatwidgetinput.cpp | 49 +++++++++++++++++-- widgets/chatwidgetinput.h | 11 +++++ widgets/notebook.cpp | 62 +++++++++++++++++++----- widgets/notebook.h | 11 +++-- widgets/notebooktab.cpp | 75 +++++++++++++++++++++++++++--- widgets/notebooktab.h | 32 ++++++++++--- widgets/signallabel.h | 10 ++++ 17 files changed, 268 insertions(+), 72 deletions(-) diff --git a/settings/boolsetting.h b/settings/boolsetting.h index 31215417c..a56390b39 100644 --- a/settings/boolsetting.h +++ b/settings/boolsetting.h @@ -9,6 +9,8 @@ namespace chatterino { namespace settings { class BoolSetting : public Setting { + Q_OBJECT + public: BoolSetting(const QString &name, bool defaultValue) : Setting(name) diff --git a/settings/floatsetting.h b/settings/floatsetting.h index 39909d114..ee2a9ff09 100644 --- a/settings/floatsetting.h +++ b/settings/floatsetting.h @@ -10,6 +10,8 @@ namespace settings { class FloatSetting : public Setting { + Q_OBJECT + public: FloatSetting(const QString &name, qreal defaultValue, qreal minValue = std::numeric_limits::min(), diff --git a/settings/intsetting.h b/settings/intsetting.h index 11ab3b25c..244eb6938 100644 --- a/settings/intsetting.h +++ b/settings/intsetting.h @@ -9,6 +9,8 @@ namespace chatterino { namespace settings { class IntSetting : public Setting { + Q_OBJECT + public: IntSetting(const QString &name, int defaultValue) : Setting(name) diff --git a/settings/setting.h b/settings/setting.h index ef76dd3a0..093e7ced8 100644 --- a/settings/setting.h +++ b/settings/setting.h @@ -7,8 +7,10 @@ namespace chatterino { namespace settings { -class Setting +class Setting : public QObject { + Q_OBJECT + public: explicit Setting(const QString &name) : name(name) diff --git a/settings/settings.cpp b/settings/settings.cpp index fad974199..5262a897c 100644 --- a/settings/settings.cpp +++ b/settings/settings.cpp @@ -31,7 +31,7 @@ BoolSetting Settings::enableGifAnimations("", true); BoolSetting Settings::enableGifs("", true); BoolSetting Settings::inlineWhispers("", true); BoolSetting Settings::windowTopMost("", true); -BoolSetting Settings::compactTabs("", false); +BoolSetting Settings::hideTabX("", false); QSettings Settings::settings( QStandardPaths::writableLocation(QStandardPaths::AppDataLocation), diff --git a/settings/settings.h b/settings/settings.h index 6f1445a18..741841272 100644 --- a/settings/settings.h +++ b/settings/settings.h @@ -71,7 +71,7 @@ private: settingsItems.push_back(&enableGifs); settingsItems.push_back(&inlineWhispers); settingsItems.push_back(&windowTopMost); - settingsItems.push_back(&compactTabs); + settingsItems.push_back(&hideTabX); } static QSettings settings; @@ -91,135 +91,135 @@ private: // settings public: - static StringSetting + static StringSetting & getTheme() { return Settings::theme; } - static StringSetting + static StringSetting & getUser() { return Settings::user; } - static FloatSetting + static FloatSetting & getEmoteScale() { return Settings::emoteScale; } - static BoolSetting + static BoolSetting & getScaleEmotesByLineHeight() { return Settings::scaleEmotesByLineHeight; } - static BoolSetting + static BoolSetting & getShowTimestamps() { return Settings::showTimestamps; } - static BoolSetting + static BoolSetting & getShowTimestampSeconds() { return Settings::showTimestampSeconds; } - static BoolSetting + static BoolSetting & getAllowDouplicateMessages() { return Settings::allowDouplicateMessages; } - static BoolSetting + static BoolSetting & getLinksDoubleClickOnly() { return Settings::linksDoubleClickOnly; } - static BoolSetting + static BoolSetting & getHideEmptyInput() { return Settings::hideEmptyInput; } - static BoolSetting + static BoolSetting & getShowMessageLength() { return Settings::showMessageLength; } - static BoolSetting + static BoolSetting & getSeperateMessages() { return Settings::seperateMessages; } - static BoolSetting + static BoolSetting & getMentionUsersWithAt() { return Settings::mentionUsersWithAt; } - static BoolSetting + static BoolSetting & getAllowCommandsAtEnd() { return Settings::allowCommandsAtEnd; } - static BoolSetting + static BoolSetting & getEnableHighlights() { return Settings::enableHighlights; } - static BoolSetting + static BoolSetting & getEnableHighlightSound() { return Settings::enableHighlightSound; } - static BoolSetting + static BoolSetting & getEnableHighlightTaskbar() { return Settings::enableHighlightTaskbar; } - static BoolSetting + static BoolSetting & getCustomHighlightSound() { return Settings::customHighlightSound; } - static BoolSetting + static BoolSetting & getEnableTwitchEmotes() { return Settings::enableTwitchEmotes; } - static BoolSetting + static BoolSetting & getEnableBttvEmotes() { return Settings::enableBttvEmotes; } - static BoolSetting + static BoolSetting & getEnableFFzEmotes() { return Settings::enableFFzEmotes; } - static BoolSetting + static BoolSetting & getEnableEmojis() { return Settings::enableEmojis; } - static BoolSetting + static BoolSetting & getEnableGifAnimations() { return Settings::enableGifAnimations; } - static BoolSetting + static BoolSetting & getEnableGifs() { return Settings::enableGifs; } - static BoolSetting + static BoolSetting & getInlineWhispers() { return Settings::inlineWhispers; } - static BoolSetting + static BoolSetting & getWindowTopMost() { return Settings::windowTopMost; } - static BoolSetting - getCompactTabs() + static BoolSetting & + getHideTabX() { - return Settings::compactTabs; + return Settings::hideTabX; } private: @@ -248,7 +248,7 @@ private: static BoolSetting enableGifs; static BoolSetting inlineWhispers; static BoolSetting windowTopMost; - static BoolSetting compactTabs; + static BoolSetting hideTabX; }; } } diff --git a/settings/stringsetting.h b/settings/stringsetting.h index cdda8b74d..8f0f5661f 100644 --- a/settings/stringsetting.h +++ b/settings/stringsetting.h @@ -10,6 +10,8 @@ namespace settings { class StringSetting : public Setting { + Q_OBJECT + public: StringSetting(const QString &name, const QString &defaultValue) : Setting(name) diff --git a/widgets/chatwidgetheader.cpp b/widgets/chatwidgetheader.cpp index 291121366..c3ccafc9c 100644 --- a/widgets/chatwidgetheader.cpp +++ b/widgets/chatwidgetheader.cpp @@ -63,13 +63,11 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent) // middle this->middleLabel.setAlignment(Qt::AlignCenter); - /*QObject::connect(&this->middleLabel, - * SIGNAL(mouseDoubleClickEvent(QMouseEvent)), this, - * SLOT(mouseDoubleClickEvent)); - * mouseDoubleClickEvent is not a signal, its an event handler - */ + connect(&this->middleLabel, &SignalLabel::mouseDoubleClick, this, &ChatWidgetHeader::mouseDoubleClickEvent); + // connect(&this->middleLabel, &SignalLabel::mouseDown, this, + // &ChatWidgetHeader::mouseDoubleClickEvent); // right this->rightLabel.setMinimumWidth(height()); diff --git a/widgets/chatwidgetheaderbutton.cpp b/widgets/chatwidgetheaderbutton.cpp index 974eb2f48..88def818a 100644 --- a/widgets/chatwidgetheaderbutton.cpp +++ b/widgets/chatwidgetheaderbutton.cpp @@ -7,7 +7,7 @@ namespace chatterino { namespace widgets { -ChatWidgetHeaderButton::ChatWidgetHeaderButton() +ChatWidgetHeaderButton::ChatWidgetHeaderButton(int spacing) : QWidget() , hbox() , label() @@ -19,9 +19,9 @@ ChatWidgetHeaderButton::ChatWidgetHeaderButton() label.setAlignment(Qt::AlignCenter); hbox.setMargin(0); - hbox.addSpacing(6); + hbox.addSpacing(spacing); hbox.addWidget(&this->label); - hbox.addSpacing(6); + hbox.addSpacing(spacing); QObject::connect(&this->label, &SignalLabel::mouseUp, this, &ChatWidgetHeaderButton::labelMouseUp); diff --git a/widgets/chatwidgetheaderbutton.h b/widgets/chatwidgetheaderbutton.h index d70cce1bd..0b422e9e9 100644 --- a/widgets/chatwidgetheaderbutton.h +++ b/widgets/chatwidgetheaderbutton.h @@ -16,7 +16,7 @@ class ChatWidgetHeaderButton : public QWidget Q_OBJECT public: - ChatWidgetHeaderButton(); + explicit ChatWidgetHeaderButton(int spacing = 6); SignalLabel & getLabel() diff --git a/widgets/chatwidgetinput.cpp b/widgets/chatwidgetinput.cpp index b6fba718d..489db3abf 100644 --- a/widgets/chatwidgetinput.cpp +++ b/widgets/chatwidgetinput.cpp @@ -8,13 +8,46 @@ namespace widgets { ChatWidgetInput::ChatWidgetInput() : hbox() + , vbox() + , editContainer() , edit() + , textLengthLabel() + , emotesLabel(0) { - this->setLayout(&hbox); - + this->setLayout(&this->hbox); this->setMaximumHeight(150); + this->hbox.setMargin(4); - this->hbox.addWidget(&edit); + this->hbox.addLayout(&this->editContainer); + this->hbox.addLayout(&this->vbox); + + this->editContainer.addWidget(&this->edit); + this->editContainer.setMargin(4); + + this->vbox.addWidget(&this->textLengthLabel); + this->vbox.addStretch(1); + this->vbox.addWidget(&this->emotesLabel); + + this->textLengthLabel.setText("100"); + this->textLengthLabel.setAlignment(Qt::AlignRight); + this->emotesLabel.getLabel().setTextFormat(Qt::RichText); + this->emotesLabel.getLabel().setText( + ""); + + // this->emotesLabel.setMaximumSize(12, 12); + + this->refreshTheme(); +} + +void +ChatWidgetInput::refreshTheme() +{ + QPalette palette; + + palette.setColor(QPalette::Foreground, ColorScheme::instance().Text); + + this->textLengthLabel.setPalette(palette); edit.setStyleSheet(ColorScheme::instance().InputStyleSheet); } @@ -28,5 +61,15 @@ ChatWidgetInput::paintEvent(QPaintEvent *) painter.setPen(ColorScheme::instance().ChatInputBorder); painter.drawRect(0, 0, width() - 1, height() - 1); } + +void +ChatWidgetInput::resizeEvent(QResizeEvent *) +{ + if (height() == this->maximumHeight()) { + edit.setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + } else { + edit.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + } +} } } diff --git a/widgets/chatwidgetinput.h b/widgets/chatwidgetinput.h index ef797da6f..9ce7ca5cb 100644 --- a/widgets/chatwidgetinput.h +++ b/widgets/chatwidgetinput.h @@ -2,8 +2,10 @@ #define CHATWIDGETINPUT_H #include "resizingtextedit.h" +#include "widgets/chatwidgetheaderbutton.h" #include +#include #include #include #include @@ -23,9 +25,18 @@ public: protected: void paintEvent(QPaintEvent *); + void resizeEvent(QResizeEvent *); + private: QHBoxLayout hbox; + QVBoxLayout vbox; + QHBoxLayout editContainer; ResizingTextEdit edit; + QLabel textLengthLabel; + ChatWidgetHeaderButton emotesLabel; + +private slots: + void refreshTheme(); }; } } diff --git a/widgets/notebook.cpp b/widgets/notebook.cpp index 88a3501f0..26a1d10c1 100644 --- a/widgets/notebook.cpp +++ b/widgets/notebook.cpp @@ -21,38 +21,59 @@ Notebook::Notebook(QWidget *parent) { connect(&this->settingsButton, SIGNAL(clicked()), this, SLOT(settingsButtonClicked())); + connect(&this->userButton, SIGNAL(clicked()), this, + SLOT(usersButtonClicked())); + connect(&this->addButton, SIGNAL(clicked()), this, + SLOT(addPageButtonClicked())); this->settingsButton.resize(24, 24); this->settingsButton.icon = NotebookButton::IconSettings; + this->userButton.resize(24, 24); this->userButton.move(24, 0); this->userButton.icon = NotebookButton::IconUser; + this->addButton.resize(24, 24); } -void -Notebook::settingsButtonClicked() -{ - SettingsDialog *a = new SettingsDialog(); - - a->show(); -} - NotebookPage * -Notebook::addPage() +Notebook::addPage(bool select) { auto tab = new NotebookTab(this); auto page = new NotebookPage(this, tab); - if (this->pages.count() == 0) { - select(page); + if (select || this->pages.count() == 0) { + this->select(page); } this->pages.append(page); + performLayout(); + return page; } +void +Notebook::removePage(NotebookPage *page) +{ + int index = pages.indexOf(page); + + if (pages.size() == 1) { + select(NULL); + } else if (index == pages.count() - 1) { + select(pages[index - 1]); + } else { + select(pages[index + 1]); + } + + delete page->tab; + delete page; + + pages.removeOne(page); + + performLayout(); +} + void Notebook::select(NotebookPage *page) { @@ -111,5 +132,24 @@ Notebook::resizeEvent(QResizeEvent *) { performLayout(); } + +void +Notebook::settingsButtonClicked() +{ + SettingsDialog *a = new SettingsDialog(); + + a->show(); +} + +void +Notebook::usersButtonClicked() +{ +} + +void +Notebook::addPageButtonClicked() +{ + addPage(true); +} } } diff --git a/widgets/notebook.h b/widgets/notebook.h index bed32a1ea..3c33687e0 100644 --- a/widgets/notebook.h +++ b/widgets/notebook.h @@ -16,12 +16,13 @@ class Notebook : public QWidget Q_OBJECT public: - Notebook(QWidget *parent); - - NotebookPage *addPage(); - enum HighlightType { none, highlighted, newMessage }; + Notebook(QWidget *parent); + + NotebookPage *addPage(bool select = false); + + void removePage(NotebookPage *page); void select(NotebookPage *page); NotebookPage * @@ -39,6 +40,8 @@ protected: public slots: void settingsButtonClicked(); + void usersButtonClicked(); + void addPageButtonClicked(); private: QList pages; diff --git a/widgets/notebooktab.cpp b/widgets/notebooktab.cpp index 4bdc0495f..131801af7 100644 --- a/widgets/notebooktab.cpp +++ b/widgets/notebooktab.cpp @@ -1,5 +1,6 @@ #include "widgets/notebooktab.h" #include "colorscheme.h" +#include "settings/settings.h" #include "widgets/notebook.h" #include @@ -14,17 +15,38 @@ NotebookTab::NotebookTab(Notebook *notebook) , selected(false) , mouseOver(false) , mouseDown(false) + , mouseOverX(false) + , mouseDownX(false) , highlightStyle(HighlightNone) { calcSize(); setAcceptDrops(true); + + QObject::connect(&settings::Settings::getHideTabX(), + SIGNAL(settings::BoolSetting::valueChanged(bool)), this, + SLOT(NotebookTab::hideTabXChanged(bool))); + + this->installEventFilter(this); + + this->setMouseTracking(true); +} + +NotebookTab::~NotebookTab() +{ + QObject::disconnect(&settings::Settings::getHideTabX(), + SIGNAL(settings::BoolSetting::valueChanged(bool)), this, + SLOT(NotebookTab::hideTabXChanged(bool))); } void NotebookTab::calcSize() { - resize(fontMetrics().width(this->text) + 8, 24); + if (settings::Settings::getHideTabX().get()) { + this->resize(this->fontMetrics().width(this->text) + 8, 24); + } else { + this->resize(this->fontMetrics().width(this->text) + 8 + 24, 24); + } } void @@ -54,25 +76,52 @@ NotebookTab::paintEvent(QPaintEvent *) } painter.setPen(fg); - painter.drawText(4, (height() + fontMetrics().height()) / 2, this->text); + + QRect rect(0, 0, + width() - (settings::Settings::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 (mouseDownX) { + painter.fillRect(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)); + } } void -NotebookTab::mousePressEvent(QMouseEvent *) +NotebookTab::mousePressEvent(QMouseEvent *event) { this->mouseDown = true; + this->mouseDownX = this->getXRect().contains(event->pos()); - repaint(); + this->repaint(); this->notebook->select(page); } void -NotebookTab::mouseReleaseEvent(QMouseEvent *) +NotebookTab::mouseReleaseEvent(QMouseEvent *event) { this->mouseDown = false; - repaint(); + if (this->mouseDownX) { + this->mouseDownX = false; + + this->notebook->removePage(this->page); + } else { + repaint(); + } } void @@ -86,7 +135,7 @@ NotebookTab::enterEvent(QEvent *) void NotebookTab::leaveEvent(QEvent *) { - this->mouseOver = false; + this->mouseOverX = this->mouseOver = false; repaint(); } @@ -96,5 +145,17 @@ NotebookTab::dragEnterEvent(QDragEnterEvent *event) { this->notebook->select(page); } + +void +NotebookTab::mouseMoveEvent(QMouseEvent *event) +{ + bool overX = this->getXRect().contains(event->pos()); + + if (overX != this->mouseOverX) { + this->mouseOverX = overX; + + this->repaint(); + } +} } } diff --git a/widgets/notebooktab.h b/widgets/notebooktab.h index 127f2d4fb..147c9350a 100644 --- a/widgets/notebooktab.h +++ b/widgets/notebooktab.h @@ -21,6 +21,7 @@ public: }; NotebookTab(Notebook *notebook); + ~NotebookTab(); void calcSize(); @@ -65,14 +66,16 @@ public: } protected: - void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + void paintEvent(QPaintEvent *) override; - void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE; - void enterEvent(QEvent *) Q_DECL_OVERRIDE; - void leaveEvent(QEvent *) Q_DECL_OVERRIDE; + void mousePressEvent(QMouseEvent *event) override; + void mouseReleaseEvent(QMouseEvent *event) override; + void enterEvent(QEvent *) override; + void leaveEvent(QEvent *) override; - void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE; + void dragEnterEvent(QDragEnterEvent *event) override; + + void mouseMoveEvent(QMouseEvent *event) override; private: Notebook *notebook; @@ -82,7 +85,24 @@ private: bool selected; bool mouseOver; bool mouseDown; + bool mouseOverX; + bool mouseDownX; + HighlightStyle highlightStyle; + + QRect + getXRect() + { + return QRect(this->width() - 20, 4, 16, 16); + } + +private slots: + void + hideTabXChanged(bool value) + { + calcSize(); + repaint(); + } }; } } diff --git a/widgets/signallabel.h b/widgets/signallabel.h index 4053de56b..2b52aa1c3 100644 --- a/widgets/signallabel.h +++ b/widgets/signallabel.h @@ -36,6 +36,8 @@ protected: if (event->button() == Qt::LeftButton) { emit mouseDown(); } + + event->ignore(); } void @@ -44,6 +46,14 @@ protected: if (event->button() == Qt::LeftButton) { emit mouseUp(); } + + event->ignore(); + } + + virtual void + mouseMoveEvent(QMouseEvent *event) override + { + event->ignore(); } };