mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added emote button and text length label
This commit is contained in:
parent
9165d5cc2e
commit
8d85f91c4d
17 changed files with 268 additions and 72 deletions
|
@ -9,6 +9,8 @@ namespace chatterino {
|
||||||
namespace settings {
|
namespace settings {
|
||||||
class BoolSetting : public Setting
|
class BoolSetting : public Setting
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BoolSetting(const QString &name, bool defaultValue)
|
BoolSetting(const QString &name, bool defaultValue)
|
||||||
: Setting(name)
|
: Setting(name)
|
||||||
|
|
|
@ -10,6 +10,8 @@ namespace settings {
|
||||||
|
|
||||||
class FloatSetting : public Setting
|
class FloatSetting : public Setting
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FloatSetting(const QString &name, qreal defaultValue,
|
FloatSetting(const QString &name, qreal defaultValue,
|
||||||
qreal minValue = std::numeric_limits<qreal>::min(),
|
qreal minValue = std::numeric_limits<qreal>::min(),
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace chatterino {
|
||||||
namespace settings {
|
namespace settings {
|
||||||
class IntSetting : public Setting
|
class IntSetting : public Setting
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IntSetting(const QString &name, int defaultValue)
|
IntSetting(const QString &name, int defaultValue)
|
||||||
: Setting(name)
|
: Setting(name)
|
||||||
|
|
|
@ -7,8 +7,10 @@
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace settings {
|
namespace settings {
|
||||||
|
|
||||||
class Setting
|
class Setting : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Setting(const QString &name)
|
explicit Setting(const QString &name)
|
||||||
: name(name)
|
: name(name)
|
||||||
|
|
|
@ -31,7 +31,7 @@ BoolSetting Settings::enableGifAnimations("", true);
|
||||||
BoolSetting Settings::enableGifs("", true);
|
BoolSetting Settings::enableGifs("", true);
|
||||||
BoolSetting Settings::inlineWhispers("", true);
|
BoolSetting Settings::inlineWhispers("", true);
|
||||||
BoolSetting Settings::windowTopMost("", true);
|
BoolSetting Settings::windowTopMost("", true);
|
||||||
BoolSetting Settings::compactTabs("", false);
|
BoolSetting Settings::hideTabX("", false);
|
||||||
|
|
||||||
QSettings Settings::settings(
|
QSettings Settings::settings(
|
||||||
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
|
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation),
|
||||||
|
|
|
@ -71,7 +71,7 @@ private:
|
||||||
settingsItems.push_back(&enableGifs);
|
settingsItems.push_back(&enableGifs);
|
||||||
settingsItems.push_back(&inlineWhispers);
|
settingsItems.push_back(&inlineWhispers);
|
||||||
settingsItems.push_back(&windowTopMost);
|
settingsItems.push_back(&windowTopMost);
|
||||||
settingsItems.push_back(&compactTabs);
|
settingsItems.push_back(&hideTabX);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QSettings settings;
|
static QSettings settings;
|
||||||
|
@ -91,135 +91,135 @@ private:
|
||||||
|
|
||||||
// settings
|
// settings
|
||||||
public:
|
public:
|
||||||
static StringSetting
|
static StringSetting &
|
||||||
getTheme()
|
getTheme()
|
||||||
{
|
{
|
||||||
return Settings::theme;
|
return Settings::theme;
|
||||||
}
|
}
|
||||||
static StringSetting
|
static StringSetting &
|
||||||
getUser()
|
getUser()
|
||||||
{
|
{
|
||||||
return Settings::user;
|
return Settings::user;
|
||||||
}
|
}
|
||||||
static FloatSetting
|
static FloatSetting &
|
||||||
getEmoteScale()
|
getEmoteScale()
|
||||||
{
|
{
|
||||||
return Settings::emoteScale;
|
return Settings::emoteScale;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getScaleEmotesByLineHeight()
|
getScaleEmotesByLineHeight()
|
||||||
{
|
{
|
||||||
return Settings::scaleEmotesByLineHeight;
|
return Settings::scaleEmotesByLineHeight;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getShowTimestamps()
|
getShowTimestamps()
|
||||||
{
|
{
|
||||||
return Settings::showTimestamps;
|
return Settings::showTimestamps;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getShowTimestampSeconds()
|
getShowTimestampSeconds()
|
||||||
{
|
{
|
||||||
return Settings::showTimestampSeconds;
|
return Settings::showTimestampSeconds;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getAllowDouplicateMessages()
|
getAllowDouplicateMessages()
|
||||||
{
|
{
|
||||||
return Settings::allowDouplicateMessages;
|
return Settings::allowDouplicateMessages;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getLinksDoubleClickOnly()
|
getLinksDoubleClickOnly()
|
||||||
{
|
{
|
||||||
return Settings::linksDoubleClickOnly;
|
return Settings::linksDoubleClickOnly;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getHideEmptyInput()
|
getHideEmptyInput()
|
||||||
{
|
{
|
||||||
return Settings::hideEmptyInput;
|
return Settings::hideEmptyInput;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getShowMessageLength()
|
getShowMessageLength()
|
||||||
{
|
{
|
||||||
return Settings::showMessageLength;
|
return Settings::showMessageLength;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getSeperateMessages()
|
getSeperateMessages()
|
||||||
{
|
{
|
||||||
return Settings::seperateMessages;
|
return Settings::seperateMessages;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getMentionUsersWithAt()
|
getMentionUsersWithAt()
|
||||||
{
|
{
|
||||||
return Settings::mentionUsersWithAt;
|
return Settings::mentionUsersWithAt;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getAllowCommandsAtEnd()
|
getAllowCommandsAtEnd()
|
||||||
{
|
{
|
||||||
return Settings::allowCommandsAtEnd;
|
return Settings::allowCommandsAtEnd;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableHighlights()
|
getEnableHighlights()
|
||||||
{
|
{
|
||||||
return Settings::enableHighlights;
|
return Settings::enableHighlights;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableHighlightSound()
|
getEnableHighlightSound()
|
||||||
{
|
{
|
||||||
return Settings::enableHighlightSound;
|
return Settings::enableHighlightSound;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableHighlightTaskbar()
|
getEnableHighlightTaskbar()
|
||||||
{
|
{
|
||||||
return Settings::enableHighlightTaskbar;
|
return Settings::enableHighlightTaskbar;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getCustomHighlightSound()
|
getCustomHighlightSound()
|
||||||
{
|
{
|
||||||
return Settings::customHighlightSound;
|
return Settings::customHighlightSound;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableTwitchEmotes()
|
getEnableTwitchEmotes()
|
||||||
{
|
{
|
||||||
return Settings::enableTwitchEmotes;
|
return Settings::enableTwitchEmotes;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableBttvEmotes()
|
getEnableBttvEmotes()
|
||||||
{
|
{
|
||||||
return Settings::enableBttvEmotes;
|
return Settings::enableBttvEmotes;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableFFzEmotes()
|
getEnableFFzEmotes()
|
||||||
{
|
{
|
||||||
return Settings::enableFFzEmotes;
|
return Settings::enableFFzEmotes;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableEmojis()
|
getEnableEmojis()
|
||||||
{
|
{
|
||||||
return Settings::enableEmojis;
|
return Settings::enableEmojis;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableGifAnimations()
|
getEnableGifAnimations()
|
||||||
{
|
{
|
||||||
return Settings::enableGifAnimations;
|
return Settings::enableGifAnimations;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getEnableGifs()
|
getEnableGifs()
|
||||||
{
|
{
|
||||||
return Settings::enableGifs;
|
return Settings::enableGifs;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getInlineWhispers()
|
getInlineWhispers()
|
||||||
{
|
{
|
||||||
return Settings::inlineWhispers;
|
return Settings::inlineWhispers;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getWindowTopMost()
|
getWindowTopMost()
|
||||||
{
|
{
|
||||||
return Settings::windowTopMost;
|
return Settings::windowTopMost;
|
||||||
}
|
}
|
||||||
static BoolSetting
|
static BoolSetting &
|
||||||
getCompactTabs()
|
getHideTabX()
|
||||||
{
|
{
|
||||||
return Settings::compactTabs;
|
return Settings::hideTabX;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -248,7 +248,7 @@ private:
|
||||||
static BoolSetting enableGifs;
|
static BoolSetting enableGifs;
|
||||||
static BoolSetting inlineWhispers;
|
static BoolSetting inlineWhispers;
|
||||||
static BoolSetting windowTopMost;
|
static BoolSetting windowTopMost;
|
||||||
static BoolSetting compactTabs;
|
static BoolSetting hideTabX;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ namespace settings {
|
||||||
|
|
||||||
class StringSetting : public Setting
|
class StringSetting : public Setting
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StringSetting(const QString &name, const QString &defaultValue)
|
StringSetting(const QString &name, const QString &defaultValue)
|
||||||
: Setting(name)
|
: Setting(name)
|
||||||
|
|
|
@ -63,13 +63,11 @@ ChatWidgetHeader::ChatWidgetHeader(ChatWidget *parent)
|
||||||
|
|
||||||
// middle
|
// middle
|
||||||
this->middleLabel.setAlignment(Qt::AlignCenter);
|
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,
|
connect(&this->middleLabel, &SignalLabel::mouseDoubleClick, this,
|
||||||
&ChatWidgetHeader::mouseDoubleClickEvent);
|
&ChatWidgetHeader::mouseDoubleClickEvent);
|
||||||
|
// connect(&this->middleLabel, &SignalLabel::mouseDown, this,
|
||||||
|
// &ChatWidgetHeader::mouseDoubleClickEvent);
|
||||||
|
|
||||||
// right
|
// right
|
||||||
this->rightLabel.setMinimumWidth(height());
|
this->rightLabel.setMinimumWidth(height());
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
namespace widgets {
|
namespace widgets {
|
||||||
|
|
||||||
ChatWidgetHeaderButton::ChatWidgetHeaderButton()
|
ChatWidgetHeaderButton::ChatWidgetHeaderButton(int spacing)
|
||||||
: QWidget()
|
: QWidget()
|
||||||
, hbox()
|
, hbox()
|
||||||
, label()
|
, label()
|
||||||
|
@ -19,9 +19,9 @@ ChatWidgetHeaderButton::ChatWidgetHeaderButton()
|
||||||
label.setAlignment(Qt::AlignCenter);
|
label.setAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
hbox.setMargin(0);
|
hbox.setMargin(0);
|
||||||
hbox.addSpacing(6);
|
hbox.addSpacing(spacing);
|
||||||
hbox.addWidget(&this->label);
|
hbox.addWidget(&this->label);
|
||||||
hbox.addSpacing(6);
|
hbox.addSpacing(spacing);
|
||||||
|
|
||||||
QObject::connect(&this->label, &SignalLabel::mouseUp, this,
|
QObject::connect(&this->label, &SignalLabel::mouseUp, this,
|
||||||
&ChatWidgetHeaderButton::labelMouseUp);
|
&ChatWidgetHeaderButton::labelMouseUp);
|
||||||
|
|
|
@ -16,7 +16,7 @@ class ChatWidgetHeaderButton : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ChatWidgetHeaderButton();
|
explicit ChatWidgetHeaderButton(int spacing = 6);
|
||||||
|
|
||||||
SignalLabel &
|
SignalLabel &
|
||||||
getLabel()
|
getLabel()
|
||||||
|
|
|
@ -8,13 +8,46 @@ namespace widgets {
|
||||||
|
|
||||||
ChatWidgetInput::ChatWidgetInput()
|
ChatWidgetInput::ChatWidgetInput()
|
||||||
: hbox()
|
: hbox()
|
||||||
|
, vbox()
|
||||||
|
, editContainer()
|
||||||
, edit()
|
, edit()
|
||||||
|
, textLengthLabel()
|
||||||
|
, emotesLabel(0)
|
||||||
{
|
{
|
||||||
this->setLayout(&hbox);
|
this->setLayout(&this->hbox);
|
||||||
|
|
||||||
this->setMaximumHeight(150);
|
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(
|
||||||
|
"<img src=':/images/Emoji_Color_1F60A_19.png' width='12' height='12' "
|
||||||
|
"/>");
|
||||||
|
|
||||||
|
// 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);
|
edit.setStyleSheet(ColorScheme::instance().InputStyleSheet);
|
||||||
}
|
}
|
||||||
|
@ -28,5 +61,15 @@ ChatWidgetInput::paintEvent(QPaintEvent *)
|
||||||
painter.setPen(ColorScheme::instance().ChatInputBorder);
|
painter.setPen(ColorScheme::instance().ChatInputBorder);
|
||||||
painter.drawRect(0, 0, width() - 1, height() - 1);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,10 @@
|
||||||
#define CHATWIDGETINPUT_H
|
#define CHATWIDGETINPUT_H
|
||||||
|
|
||||||
#include "resizingtextedit.h"
|
#include "resizingtextedit.h"
|
||||||
|
#include "widgets/chatwidgetheaderbutton.h"
|
||||||
|
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
@ -23,9 +25,18 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
|
|
||||||
|
void resizeEvent(QResizeEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHBoxLayout hbox;
|
QHBoxLayout hbox;
|
||||||
|
QVBoxLayout vbox;
|
||||||
|
QHBoxLayout editContainer;
|
||||||
ResizingTextEdit edit;
|
ResizingTextEdit edit;
|
||||||
|
QLabel textLengthLabel;
|
||||||
|
ChatWidgetHeaderButton emotesLabel;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void refreshTheme();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,38 +21,59 @@ Notebook::Notebook(QWidget *parent)
|
||||||
{
|
{
|
||||||
connect(&this->settingsButton, SIGNAL(clicked()), this,
|
connect(&this->settingsButton, SIGNAL(clicked()), this,
|
||||||
SLOT(settingsButtonClicked()));
|
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.resize(24, 24);
|
||||||
this->settingsButton.icon = NotebookButton::IconSettings;
|
this->settingsButton.icon = NotebookButton::IconSettings;
|
||||||
|
|
||||||
this->userButton.resize(24, 24);
|
this->userButton.resize(24, 24);
|
||||||
this->userButton.move(24, 0);
|
this->userButton.move(24, 0);
|
||||||
this->userButton.icon = NotebookButton::IconUser;
|
this->userButton.icon = NotebookButton::IconUser;
|
||||||
|
|
||||||
this->addButton.resize(24, 24);
|
this->addButton.resize(24, 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
Notebook::settingsButtonClicked()
|
|
||||||
{
|
|
||||||
SettingsDialog *a = new SettingsDialog();
|
|
||||||
|
|
||||||
a->show();
|
|
||||||
}
|
|
||||||
|
|
||||||
NotebookPage *
|
NotebookPage *
|
||||||
Notebook::addPage()
|
Notebook::addPage(bool select)
|
||||||
{
|
{
|
||||||
auto tab = new NotebookTab(this);
|
auto tab = new NotebookTab(this);
|
||||||
auto page = new NotebookPage(this, tab);
|
auto page = new NotebookPage(this, tab);
|
||||||
|
|
||||||
if (this->pages.count() == 0) {
|
if (select || this->pages.count() == 0) {
|
||||||
select(page);
|
this->select(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->pages.append(page);
|
this->pages.append(page);
|
||||||
|
|
||||||
|
performLayout();
|
||||||
|
|
||||||
return page;
|
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
|
void
|
||||||
Notebook::select(NotebookPage *page)
|
Notebook::select(NotebookPage *page)
|
||||||
{
|
{
|
||||||
|
@ -111,5 +132,24 @@ Notebook::resizeEvent(QResizeEvent *)
|
||||||
{
|
{
|
||||||
performLayout();
|
performLayout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Notebook::settingsButtonClicked()
|
||||||
|
{
|
||||||
|
SettingsDialog *a = new SettingsDialog();
|
||||||
|
|
||||||
|
a->show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Notebook::usersButtonClicked()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Notebook::addPageButtonClicked()
|
||||||
|
{
|
||||||
|
addPage(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,12 +16,13 @@ class Notebook : public QWidget
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Notebook(QWidget *parent);
|
|
||||||
|
|
||||||
NotebookPage *addPage();
|
|
||||||
|
|
||||||
enum HighlightType { none, highlighted, newMessage };
|
enum HighlightType { none, highlighted, newMessage };
|
||||||
|
|
||||||
|
Notebook(QWidget *parent);
|
||||||
|
|
||||||
|
NotebookPage *addPage(bool select = false);
|
||||||
|
|
||||||
|
void removePage(NotebookPage *page);
|
||||||
void select(NotebookPage *page);
|
void select(NotebookPage *page);
|
||||||
|
|
||||||
NotebookPage *
|
NotebookPage *
|
||||||
|
@ -39,6 +40,8 @@ protected:
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void settingsButtonClicked();
|
void settingsButtonClicked();
|
||||||
|
void usersButtonClicked();
|
||||||
|
void addPageButtonClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<NotebookPage *> pages;
|
QList<NotebookPage *> pages;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "widgets/notebooktab.h"
|
#include "widgets/notebooktab.h"
|
||||||
#include "colorscheme.h"
|
#include "colorscheme.h"
|
||||||
|
#include "settings/settings.h"
|
||||||
#include "widgets/notebook.h"
|
#include "widgets/notebook.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
@ -14,17 +15,38 @@ NotebookTab::NotebookTab(Notebook *notebook)
|
||||||
, selected(false)
|
, selected(false)
|
||||||
, mouseOver(false)
|
, mouseOver(false)
|
||||||
, mouseDown(false)
|
, mouseDown(false)
|
||||||
|
, mouseOverX(false)
|
||||||
|
, mouseDownX(false)
|
||||||
, highlightStyle(HighlightNone)
|
, highlightStyle(HighlightNone)
|
||||||
{
|
{
|
||||||
calcSize();
|
calcSize();
|
||||||
|
|
||||||
setAcceptDrops(true);
|
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
|
void
|
||||||
NotebookTab::calcSize()
|
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
|
void
|
||||||
|
@ -54,26 +76,53 @@ NotebookTab::paintEvent(QPaintEvent *)
|
||||||
}
|
}
|
||||||
|
|
||||||
painter.setPen(fg);
|
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
|
void
|
||||||
NotebookTab::mousePressEvent(QMouseEvent *)
|
NotebookTab::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
this->mouseDown = true;
|
this->mouseDown = true;
|
||||||
|
this->mouseDownX = this->getXRect().contains(event->pos());
|
||||||
|
|
||||||
repaint();
|
this->repaint();
|
||||||
|
|
||||||
this->notebook->select(page);
|
this->notebook->select(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotebookTab::mouseReleaseEvent(QMouseEvent *)
|
NotebookTab::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
this->mouseDown = false;
|
this->mouseDown = false;
|
||||||
|
|
||||||
|
if (this->mouseDownX) {
|
||||||
|
this->mouseDownX = false;
|
||||||
|
|
||||||
|
this->notebook->removePage(this->page);
|
||||||
|
} else {
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
NotebookTab::enterEvent(QEvent *)
|
NotebookTab::enterEvent(QEvent *)
|
||||||
|
@ -86,7 +135,7 @@ NotebookTab::enterEvent(QEvent *)
|
||||||
void
|
void
|
||||||
NotebookTab::leaveEvent(QEvent *)
|
NotebookTab::leaveEvent(QEvent *)
|
||||||
{
|
{
|
||||||
this->mouseOver = false;
|
this->mouseOverX = this->mouseOver = false;
|
||||||
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
@ -96,5 +145,17 @@ NotebookTab::dragEnterEvent(QDragEnterEvent *event)
|
||||||
{
|
{
|
||||||
this->notebook->select(page);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
NotebookTab(Notebook *notebook);
|
NotebookTab(Notebook *notebook);
|
||||||
|
~NotebookTab();
|
||||||
|
|
||||||
void calcSize();
|
void calcSize();
|
||||||
|
|
||||||
|
@ -65,14 +66,16 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *) override;
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
|
void mouseReleaseEvent(QMouseEvent *event) override;
|
||||||
void enterEvent(QEvent *) Q_DECL_OVERRIDE;
|
void enterEvent(QEvent *) override;
|
||||||
void leaveEvent(QEvent *) Q_DECL_OVERRIDE;
|
void leaveEvent(QEvent *) override;
|
||||||
|
|
||||||
void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE;
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
||||||
|
|
||||||
|
void mouseMoveEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Notebook *notebook;
|
Notebook *notebook;
|
||||||
|
@ -82,7 +85,24 @@ private:
|
||||||
bool selected;
|
bool selected;
|
||||||
bool mouseOver;
|
bool mouseOver;
|
||||||
bool mouseDown;
|
bool mouseDown;
|
||||||
|
bool mouseOverX;
|
||||||
|
bool mouseDownX;
|
||||||
|
|
||||||
HighlightStyle highlightStyle;
|
HighlightStyle highlightStyle;
|
||||||
|
|
||||||
|
QRect
|
||||||
|
getXRect()
|
||||||
|
{
|
||||||
|
return QRect(this->width() - 20, 4, 16, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void
|
||||||
|
hideTabXChanged(bool value)
|
||||||
|
{
|
||||||
|
calcSize();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,8 @@ protected:
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
emit mouseDown();
|
emit mouseDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event->ignore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -44,6 +46,14 @@ protected:
|
||||||
if (event->button() == Qt::LeftButton) {
|
if (event->button() == Qt::LeftButton) {
|
||||||
emit mouseUp();
|
emit mouseUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event->ignore();
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void
|
||||||
|
mouseMoveEvent(QMouseEvent *event) override
|
||||||
|
{
|
||||||
|
event->ignore();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue