added moderation buttons

This commit is contained in:
fourtf
2018-01-17 14:14:31 +01:00
parent 252f648ff8
commit 6d6b99f3ef
15 changed files with 367 additions and 76 deletions
+82 -8
View File
@@ -41,11 +41,22 @@ MessageLayoutElement *MessageLayoutElement::setTrailingSpace(bool value)
return this;
}
MessageLayoutElement *MessageLayoutElement::setLink(const Link &_link)
{
this->link = _link;
return this;
}
const Link &MessageLayoutElement::getLink() const
{
return this->link;
}
//
// IMAGE
//
ImageLayoutElement::ImageLayoutElement(MessageElement &_creator, Image &_image, QSize _size)
ImageLayoutElement::ImageLayoutElement(MessageElement &_creator, Image *_image, const QSize &_size)
: MessageLayoutElement(_creator, _size)
, image(_image)
{
@@ -54,7 +65,7 @@ ImageLayoutElement::ImageLayoutElement(MessageElement &_creator, Image &_image,
void ImageLayoutElement::addCopyTextToString(QString &str, int from, int to) const
{
str += this->image.getName();
str += this->image->getName();
if (this->hasTrailingSpace()) {
str += " ";
@@ -68,9 +79,9 @@ int ImageLayoutElement::getSelectionIndexCount()
void ImageLayoutElement::paint(QPainter &painter)
{
const QPixmap *pixmap = this->image.getPixmap();
const QPixmap *pixmap = this->image->getPixmap();
if (pixmap != nullptr && !this->image.isAnimated()) {
if (pixmap != nullptr && !this->image->isAnimated()) {
// fourtf: make it use qreal values
painter.drawPixmap(QRectF(this->getRect()), *pixmap, QRectF());
}
@@ -78,12 +89,12 @@ void ImageLayoutElement::paint(QPainter &painter)
void ImageLayoutElement::paintAnimated(QPainter &painter, int yOffset)
{
if (this->image.isAnimated()) {
if (this->image.getPixmap() != nullptr) {
if (this->image->isAnimated()) {
if (this->image->getPixmap() != nullptr) {
// fourtf: make it use qreal values
QRect rect = this->getRect();
rect.moveTop(rect.y() + yOffset);
painter.drawPixmap(QRectF(rect), *this->image.getPixmap(), QRectF());
painter.drawPixmap(QRectF(rect), *this->image->getPixmap(), QRectF());
}
}
}
@@ -109,7 +120,7 @@ int ImageLayoutElement::getXFromIndex(int index)
// TEXT
//
TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text, QSize _size,
TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text, const QSize &_size,
QColor _color, FontStyle _style, float _scale)
: MessageLayoutElement(_creator, _size)
, text(_text)
@@ -188,6 +199,69 @@ int TextLayoutElement::getXFromIndex(int index)
return this->getRect().right();
}
}
// TEXT ICON
TextIconLayoutElement::TextIconLayoutElement(MessageElement &creator, const QString &_line1,
const QString &_line2, float _scale, const QSize &size)
: MessageLayoutElement(creator, size)
, scale(_scale)
, line1(_line1)
, line2(_line2)
{
}
void TextIconLayoutElement::addCopyTextToString(QString &str, int from, int to) const
{
}
int TextIconLayoutElement::getSelectionIndexCount()
{
return this->trailingSpace ? 2 : 1;
}
void TextIconLayoutElement::paint(QPainter &painter)
{
QFont font = singletons::FontManager::getInstance().getFont(FontStyle::Tiny, this->scale);
painter.setBrush(singletons::ThemeManager::getInstance().messages.textColors.regular);
painter.setFont(font);
QTextOption option;
option.setAlignment(Qt::AlignHCenter);
if (this->line2.isEmpty()) {
QRect rect(this->getRect());
painter.drawText(rect, this->line1, option);
} else {
painter.drawText(
QPoint(this->getRect().x(), this->getRect().y() + this->getRect().height() / 2),
this->line1);
painter.drawText(
QPoint(this->getRect().x(), this->getRect().y() + this->getRect().height()),
this->line2);
}
}
void TextIconLayoutElement::paintAnimated(QPainter &painter, int yOffset)
{
}
int TextIconLayoutElement::getMouseOverIndex(const QPoint &abs)
{
return 0;
}
int TextIconLayoutElement::getXFromIndex(int index)
{
if (index <= 0) {
return this->getRect().left();
} else if (index == 1) {
// fourtf: remove space width
return this->getRect().right();
} else {
return this->getRect().right();
}
}
} // namespace layouts
} // namespace messages
} // namespace chatterino
+29 -3
View File
@@ -7,6 +7,7 @@
#include <boost/noncopyable.hpp>
#include <climits>
#include "messages/link.hpp"
#include "messages/messagecolor.hpp"
#include "singletons/fontmanager.hpp"
@@ -30,6 +31,7 @@ public:
bool hasTrailingSpace() const;
MessageLayoutElement *setTrailingSpace(bool value);
MessageLayoutElement *setLink(const Link &link);
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const = 0;
virtual int getSelectionIndexCount() = 0;
@@ -37,12 +39,14 @@ public:
virtual void paintAnimated(QPainter &painter, int yOffset) = 0;
virtual int getMouseOverIndex(const QPoint &abs) = 0;
virtual int getXFromIndex(int index) = 0;
const Link &getLink() const;
protected:
bool trailingSpace = true;
private:
QRect rect;
Link link;
// bool isInNewLine;
MessageElement &creator;
};
@@ -51,7 +55,7 @@ private:
class ImageLayoutElement : public MessageLayoutElement
{
public:
ImageLayoutElement(MessageElement &creator, Image &image, QSize size);
ImageLayoutElement(MessageElement &creator, Image *image, const QSize &size);
protected:
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
@@ -62,14 +66,14 @@ protected:
virtual int getXFromIndex(int index) override;
private:
Image &image;
Image *image;
};
// TEXT
class TextLayoutElement : public MessageLayoutElement
{
public:
TextLayoutElement(MessageElement &creator, QString &text, QSize size, QColor color,
TextLayoutElement(MessageElement &creator, QString &text, const QSize &size, QColor color,
FontStyle style, float scale);
protected:
@@ -86,6 +90,28 @@ private:
FontStyle style;
float scale;
};
// TEXT ICON
// two lines of text (characters) in the size of a normal chat badge
class TextIconLayoutElement : public MessageLayoutElement
{
public:
TextIconLayoutElement(MessageElement &creator, const QString &line1, const QString &line2,
float scale, const QSize &size);
protected:
virtual void addCopyTextToString(QString &str, int from = 0, int to = INT_MAX) const override;
virtual int getSelectionIndexCount() override;
virtual void paint(QPainter &painter) override;
virtual void paintAnimated(QPainter &painter, int yOffset) override;
virtual int getMouseOverIndex(const QPoint &abs) override;
virtual int getXFromIndex(int index) override;
private:
QString line1;
QString line2;
float scale;
};
} // namespace layouts
} // namespace messages
} // namespace chatterino