improve "last message read" indicator (#802)

This commit is contained in:
pphop 2018-10-20 16:25:24 +05:00 committed by pajlada
parent 54c1efe531
commit a584259785
5 changed files with 77 additions and 5 deletions

View file

@ -183,10 +183,15 @@ void MessageLayout::paint(QPainter &painter, int width, int y, int messageIndex,
// draw last read message line
if (isLastReadMessage) {
QColor color =
QColor color;
if (getSettings()->lastMessageColor != "") {
color = QColor(getSettings()->lastMessageColor.getValue());
} else {
color =
isWindowFocused
? app->themes->tabs.selected.backgrounds.regular.color()
: app->themes->tabs.selected.backgrounds.unfocused.color();
}
QBrush brush(color, static_cast<Qt::BrushStyle>(
getSettings()->lastMessagePattern.getValue()));

View file

@ -33,6 +33,8 @@ public:
"/appearance/messages/showLastMessageIndicator", false};
IntSetting lastMessagePattern = {"/appearance/messages/lastMessagePattern",
Qt::VerPattern};
QStringSetting lastMessageColor = {"/appearance/messages/lastMessageColor",
""};
BoolSetting showEmptyInput = {"/appearance/showEmptyInputBox", true};
BoolSetting showMessageLength = {"/appearance/messages/showMessageLength",
false};

View file

@ -11,6 +11,7 @@
#include "widgets/helper/NotebookButton.hpp"
#include "widgets/helper/NotebookTab.hpp"
#include "widgets/helper/Shortcut.hpp"
#include "widgets/splits/Split.hpp"
#include "widgets/splits/SplitContainer.hpp"
#include <QDebug>
@ -490,4 +491,17 @@ SplitContainer *SplitNotebook::getOrAddSelectedPage()
: this->addPage();
}
void SplitNotebook::select(QWidget *page)
{
if (auto selectedPage = this->getSelectedPage()) {
if (auto splitContainer =
dynamic_cast<SplitContainer *>(selectedPage)) {
for (auto split : splitContainer->getSplits()) {
split->updateLastReadMessage();
}
}
}
this->Notebook::select(page);
}
} // namespace chatterino

View file

@ -30,7 +30,7 @@ public:
void removeCurrentPage();
int indexOf(QWidget *page) const;
void select(QWidget *page);
virtual void select(QWidget *page);
void selectIndex(int index);
void selectNextTab();
void selectPreviousTab();
@ -90,6 +90,7 @@ public:
SplitContainer *addPage(bool select = false);
SplitContainer *getOrAddSelectedPage();
void select(QWidget *page) override;
private:
void addCustomButtons();

View file

@ -11,6 +11,7 @@
#include "widgets/helper/ChannelView.hpp"
#include "widgets/helper/Line.hpp"
#include <QColorDialog>
#include <QFontDialog>
#include <QFormLayout>
#include <QGroupBox>
@ -351,11 +352,60 @@ void LookPage::addLastReadMessageIndicatorPatternSelector(
}();
});
// color picker
QLabel *colorPreview = new QLabel();
auto updatePreviewColor = [colorPreview](QColor newColor) {
QPixmap pixmap(16, 16);
pixmap.fill(QColor(0, 0, 0, 255));
QPainter painter(&pixmap);
QBrush brush(newColor);
painter.fillRect(1, 1, pixmap.width() - 2, pixmap.height() - 2, brush);
colorPreview->setPixmap(pixmap);
};
auto getCurrentColor = []() {
return getSettings()->lastMessageColor != ""
? QColor(getSettings()->lastMessageColor.getValue())
: getApp()
->themes->tabs.selected.backgrounds.regular.color();
};
updatePreviewColor(getCurrentColor());
QPushButton *button = new QPushButton("Select Color");
button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Policy::Fixed);
QObject::connect(
button, &QPushButton::clicked, [updatePreviewColor, getCurrentColor]() {
QColor newColor = QColorDialog::getColor(getCurrentColor());
if (newColor.isValid()) {
updatePreviewColor(newColor);
getSettings()->lastMessageColor = newColor.name();
}
});
QPushButton *resetButton = new QPushButton("Reset Color");
resetButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Policy::Fixed);
QObject::connect(
resetButton, &QPushButton::clicked, [updatePreviewColor]() {
QColor defaultColor =
getApp()->themes->tabs.selected.backgrounds.regular.color();
updatePreviewColor(defaultColor);
getSettings()->lastMessageColor = "";
});
// layout
auto hbox = layout.emplace<QHBoxLayout>().withoutMargin();
hbox.append(this->createCheckBox(LAST_MSG,
getSettings()->showLastMessageIndicator));
hbox.append(combo);
hbox.append(colorPreview);
hbox.append(button);
hbox.append(resetButton);
hbox->addStretch(1);
}