fixed accountpopup background color

This commit is contained in:
fourtf
2018-05-25 13:02:14 +02:00
parent f72e1b5d82
commit b68b7ecb10
5 changed files with 72 additions and 67 deletions
+48 -47
View File
@@ -21,9 +21,9 @@ namespace chatterino {
namespace messages { namespace messages {
namespace layouts { namespace layouts {
MessageLayout::MessageLayout(MessagePtr _message) MessageLayout::MessageLayout(MessagePtr message)
: message(_message) : m_message(message)
, buffer(nullptr) , m_buffer(nullptr)
{ {
util::DebugCount::increase("message layout"); util::DebugCount::increase("message layout");
} }
@@ -35,13 +35,13 @@ MessageLayout::~MessageLayout()
Message *MessageLayout::getMessage() Message *MessageLayout::getMessage()
{ {
return this->message.get(); return this->m_message.get();
} }
// Height // Height
int MessageLayout::getHeight() const int MessageLayout::getHeight() const
{ {
return container.getHeight(); return m_container.getHeight();
} }
// Layout // Layout
@@ -55,28 +55,28 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
bool layoutRequired = false; bool layoutRequired = false;
// check if width changed // check if width changed
bool widthChanged = width != this->currentLayoutWidth; bool widthChanged = width != this->m_currentLayoutWidth;
layoutRequired |= widthChanged; layoutRequired |= widthChanged;
this->currentLayoutWidth = width; this->m_currentLayoutWidth = width;
// check if emotes changed // check if emotes changed
bool imagesChanged = this->emoteGeneration != app->emotes->getGeneration(); bool imagesChanged = this->m_emoteGeneration != app->emotes->getGeneration();
layoutRequired |= imagesChanged; layoutRequired |= imagesChanged;
this->emoteGeneration = app->emotes->getGeneration(); this->m_emoteGeneration = app->emotes->getGeneration();
// check if text changed // check if text changed
bool textChanged = this->fontGeneration != app->fonts->getGeneration(); bool textChanged = this->m_fontGeneration != app->fonts->getGeneration();
layoutRequired |= textChanged; layoutRequired |= textChanged;
this->fontGeneration = app->fonts->getGeneration(); this->m_fontGeneration = app->fonts->getGeneration();
// check if work mask changed // check if work mask changed
bool wordMaskChanged = this->currentWordFlags != flags; // app->settings->getWordTypeMask(); bool wordMaskChanged = this->m_currentWordFlags != flags; // app->settings->getWordTypeMask();
layoutRequired |= wordMaskChanged; layoutRequired |= wordMaskChanged;
this->currentWordFlags = flags; // app->settings->getWordTypeMask(); this->m_currentWordFlags = flags; // app->settings->getWordTypeMask();
// check if timestamp format changed // check if timestamp format changed
bool timestampFormatChanged = this->timestampFormat != app->settings->timestampFormat; bool timestampFormatChanged = this->m_timestampFormat != app->settings->timestampFormat;
this->timestampFormat = app->settings->timestampFormat.getValue(); this->m_timestampFormat = app->settings->timestampFormat.getValue();
layoutRequired |= timestampFormatChanged; layoutRequired |= timestampFormatChanged;
@@ -85,9 +85,9 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
this->flags &= ~RequiresLayout; this->flags &= ~RequiresLayout;
// check if dpi changed // check if dpi changed
bool scaleChanged = this->scale != scale; bool scaleChanged = this->m_scale != scale;
layoutRequired |= scaleChanged; layoutRequired |= scaleChanged;
this->scale = scale; this->m_scale = scale;
imagesChanged |= scaleChanged; imagesChanged |= scaleChanged;
textChanged |= scaleChanged; textChanged |= scaleChanged;
@@ -121,30 +121,30 @@ bool MessageLayout::layout(int width, float scale, MessageElement::Flags flags)
void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags) void MessageLayout::actuallyLayout(int width, MessageElement::Flags _flags)
{ {
auto messageFlags = this->message->flags.value; auto messageFlags = this->m_message->flags.value;
if (this->flags & MessageLayout::Expanded || if (this->flags & MessageLayout::Expanded ||
(_flags & MessageElement::ModeratorTools && (_flags & MessageElement::ModeratorTools &&
!(this->message->flags & Message::MessageFlags::Disabled))) { !(this->m_message->flags & Message::MessageFlags::Disabled))) {
messageFlags = Message::MessageFlags(messageFlags & ~Message::MessageFlags::Collapsed); messageFlags = Message::MessageFlags(messageFlags & ~Message::MessageFlags::Collapsed);
} }
this->container.begin(width, this->scale, messageFlags); this->m_container.begin(width, this->m_scale, messageFlags);
for (const std::unique_ptr<MessageElement> &element : this->message->getElements()) { for (const std::unique_ptr<MessageElement> &element : this->m_message->getElements()) {
element->addToContainer(this->container, _flags); element->addToContainer(this->m_container, _flags);
} }
if (this->height != this->container.getHeight()) { if (this->m_height != this->m_container.getHeight()) {
this->deleteBuffer(); this->deleteBuffer();
} }
this->container.end(); this->m_container.end();
this->height = this->container.getHeight(); this->m_height = this->m_container.getHeight();
// collapsed state // collapsed state
this->flags &= ~Flags::Collapsed; this->flags &= ~Flags::Collapsed;
if (this->container.isCollapsed()) { if (this->m_container.isCollapsed()) {
this->flags |= Flags::Collapsed; this->flags |= Flags::Collapsed;
} }
} }
@@ -154,7 +154,7 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
bool isLastReadMessage, bool isWindowFocused) bool isLastReadMessage, bool isWindowFocused)
{ {
auto app = getApp(); auto app = getApp();
QPixmap *pixmap = this->buffer.get(); QPixmap *pixmap = this->m_buffer.get();
// create new buffer if required // create new buffer if required
if (!pixmap) { if (!pixmap) {
@@ -164,15 +164,16 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
(int)(this->container.getHeight() * painter.device()->devicePixelRatioF())); (int)(this->container.getHeight() * painter.device()->devicePixelRatioF()));
pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF()); pixmap->setDevicePixelRatio(painter.device()->devicePixelRatioF());
#else #else
pixmap = new QPixmap(this->container.getWidth(), std::max(16, this->container.getHeight())); pixmap =
new QPixmap(this->m_container.getWidth(), std::max(16, this->m_container.getHeight()));
#endif #endif
this->buffer = std::shared_ptr<QPixmap>(pixmap); this->m_buffer = std::shared_ptr<QPixmap>(pixmap);
this->bufferValid = false; this->m_bufferValid = false;
util::DebugCount::increase("message drawing buffers"); util::DebugCount::increase("message drawing buffers");
} }
if (!this->bufferValid || !selection.isEmpty()) { if (!this->m_bufferValid || !selection.isEmpty()) {
this->updateBuffer(pixmap, messageIndex, selection); this->updateBuffer(pixmap, messageIndex, selection);
} }
@@ -181,21 +182,21 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
// painter.drawPixmap(0, y, this->container.width, this->container.getHeight(), *pixmap); // painter.drawPixmap(0, y, this->container.width, this->container.getHeight(), *pixmap);
// draw gif emotes // draw gif emotes
this->container.paintAnimatedElements(painter, y); this->m_container.paintAnimatedElements(painter, y);
// draw disabled // draw disabled
if (this->message->flags.HasFlag(Message::Disabled)) { if (this->m_message->flags.HasFlag(Message::Disabled)) {
painter.fillRect(0, y, pixmap->width(), pixmap->height(), app->themes->messages.disabled); painter.fillRect(0, y, pixmap->width(), pixmap->height(), app->themes->messages.disabled);
} }
// draw selection // draw selection
if (!selection.isEmpty()) { if (!selection.isEmpty()) {
this->container.paintSelection(painter, messageIndex, selection, y); this->m_container.paintSelection(painter, messageIndex, selection, y);
} }
// draw message seperation line // draw message seperation line
if (app->settings->seperateMessages.getValue()) { if (app->settings->seperateMessages.getValue()) {
painter.fillRect(0, y + this->container.getHeight() - 1, this->container.getWidth(), 1, painter.fillRect(0, y + this->m_container.getHeight() - 1, this->m_container.getWidth(), 1,
app->themes->splits.messageSeperator); app->themes->splits.messageSeperator);
} }
@@ -206,11 +207,11 @@ void MessageLayout::paint(QPainter &painter, int y, int messageIndex, Selection
QBrush brush(color, Qt::VerPattern); QBrush brush(color, Qt::VerPattern);
painter.fillRect(0, y + this->container.getHeight() - 1, this->container.getWidth(), 1, painter.fillRect(0, y + this->m_container.getHeight() - 1, this->m_container.getWidth(), 1,
brush); brush);
} }
this->bufferValid = true; this->m_bufferValid = true;
} }
void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/) void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selection & /*selection*/)
@@ -223,7 +224,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
// draw background // draw background
QColor backgroundColor; QColor backgroundColor;
if (this->message->flags & Message::Highlighted) { if (this->m_message->flags & Message::Highlighted) {
backgroundColor = app->themes->messages.backgrounds.highlighted; backgroundColor = app->themes->messages.backgrounds.highlighted;
} else if (app->settings->alternateMessageBackground.getValue() && } else if (app->settings->alternateMessageBackground.getValue() &&
this->flags & MessageLayout::AlternateBackground) { this->flags & MessageLayout::AlternateBackground) {
@@ -234,7 +235,7 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
painter.fillRect(buffer->rect(), backgroundColor); painter.fillRect(buffer->rect(), backgroundColor);
// draw message // draw message
this->container.paintElements(painter); this->m_container.paintElements(painter);
#ifdef FOURTF #ifdef FOURTF
// debug // debug
@@ -252,15 +253,15 @@ void MessageLayout::updateBuffer(QPixmap *buffer, int /*messageIndex*/, Selectio
void MessageLayout::invalidateBuffer() void MessageLayout::invalidateBuffer()
{ {
this->bufferValid = false; this->m_bufferValid = false;
} }
void MessageLayout::deleteBuffer() void MessageLayout::deleteBuffer()
{ {
if (this->buffer != nullptr) { if (this->m_buffer != nullptr) {
util::DebugCount::decrease("message drawing buffers"); util::DebugCount::decrease("message drawing buffers");
this->buffer = nullptr; this->m_buffer = nullptr;
} }
} }
@@ -269,7 +270,7 @@ void MessageLayout::deleteCache()
this->deleteBuffer(); this->deleteBuffer();
#ifdef XD #ifdef XD
this->container.clear(); this->m_container.clear();
#endif #endif
} }
@@ -282,22 +283,22 @@ void MessageLayout::deleteCache()
const MessageLayoutElement *MessageLayout::getElementAt(QPoint point) const MessageLayoutElement *MessageLayout::getElementAt(QPoint point)
{ {
// go through all words and return the first one that contains the point. // go through all words and return the first one that contains the point.
return this->container.getElementAt(point); return this->m_container.getElementAt(point);
} }
int MessageLayout::getLastCharacterIndex() const int MessageLayout::getLastCharacterIndex() const
{ {
return this->container.getLastCharacterIndex(); return this->m_container.getLastCharacterIndex();
} }
int MessageLayout::getSelectionIndex(QPoint position) int MessageLayout::getSelectionIndex(QPoint position)
{ {
return this->container.getSelectionIndex(position); return this->m_container.getSelectionIndex(position);
} }
void MessageLayout::addSelectionText(QString &str, int from, int to) void MessageLayout::addSelectionText(QString &str, int from, int to)
{ {
this->container.addSelectionText(str, from, to); this->m_container.addSelectionText(str, from, to);
} }
} // namespace layouts } // namespace layouts
+15 -15
View File
@@ -27,7 +27,7 @@ public:
Expanded = 1 << 5, Expanded = 1 << 5,
}; };
MessageLayout(MessagePtr message); MessageLayout(MessagePtr m_message);
~MessageLayout(); ~MessageLayout();
Message *getMessage(); Message *getMessage();
@@ -39,7 +39,7 @@ public:
util::FlagsEnum<Flags> flags; util::FlagsEnum<Flags> flags;
// Layout // Layout
bool layout(int width, float scale, MessageElement::Flags flags); bool layout(int width, float m_scale, MessageElement::Flags flags);
// Painting // Painting
void paint(QPainter &painter, int y, int messageIndex, Selection &selection, void paint(QPainter &painter, int y, int messageIndex, Selection &selection,
@@ -59,23 +59,23 @@ public:
private: private:
// variables // variables
MessagePtr message; MessagePtr m_message;
MessageLayoutContainer container; MessageLayoutContainer m_container;
std::shared_ptr<QPixmap> buffer = nullptr; std::shared_ptr<QPixmap> m_buffer = nullptr;
bool bufferValid = false; bool m_bufferValid = false;
int height = 0; int m_height = 0;
int currentLayoutWidth = -1; int m_currentLayoutWidth = -1;
int fontGeneration = -1; int m_fontGeneration = -1;
int emoteGeneration = -1; int m_emoteGeneration = -1;
QString timestampFormat; QString m_timestampFormat;
float scale = -1; float m_scale = -1;
unsigned int bufferUpdatedCount = 0; unsigned int m_bufferUpdatedCount = 0;
MessageElement::Flags currentWordFlags = MessageElement::None; MessageElement::Flags m_currentWordFlags = MessageElement::None;
int collapsedHeight = 32; int m_collapsedHeight = 32;
// methods // methods
void actuallyLayout(int width, MessageElement::Flags flags); void actuallyLayout(int width, MessageElement::Flags flags);
+2 -2
View File
@@ -273,9 +273,9 @@ void AccountPopupWidget::loadAvatar(const QUrl &avatarUrl)
void AccountPopupWidget::scaleChangedEvent(float newDpi) void AccountPopupWidget::scaleChangedEvent(float newDpi)
{ {
this->setStyleSheet(QString("* { font-size: <font-size>px; }") this->setStyleSheet(QString("* { font-size: <font-size>px; }")
.replace("<font-size>", QString::number((int)(12 * newDpi)))); .replace("<font-size>", QString::number(int(12 * newDpi))));
this->ui->lblAvatar->setFixedSize((int)(100 * newDpi), (int)(100 * newDpi)); this->ui->lblAvatar->setFixedSize(int(100 * newDpi), int(100 * newDpi));
} }
void AccountPopupWidget::updateButtons(QWidget *layout, bool state) void AccountPopupWidget::updateButtons(QWidget *layout, bool state)
+2 -1
View File
@@ -19,9 +19,10 @@ class Channel;
namespace widgets { namespace widgets {
class AccountPopupWidget : public BaseWindow class AccountPopupWidget final : public BaseWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
AccountPopupWidget(ChannelPtr _channel); AccountPopupWidget(ChannelPtr _channel);
+5 -2
View File
@@ -36,6 +36,8 @@ AccountSwitchPopupWidget::AccountSwitchPopupWidget(QWidget *parent)
}); });
this->setLayout(vbox); this->setLayout(vbox);
// this->setStyleSheet("background: #333");
} }
void AccountSwitchPopupWidget::refresh() void AccountSwitchPopupWidget::refresh()
@@ -48,11 +50,12 @@ void AccountSwitchPopupWidget::focusOutEvent(QFocusEvent *)
this->hide(); this->hide();
} }
void AccountSwitchPopupWidget::paintEvent(QPaintEvent *event) void AccountSwitchPopupWidget::paintEvent(QPaintEvent *)
{ {
QPainter painter(this); QPainter painter(this);
painter.fillRect(this->rect(), QColor(255, 255, 255)); painter.setPen(QColor("#999"));
painter.drawRect(0, 0, this->width() - 1, this->height() - 1);
} }
} // namespace widgets } // namespace widgets