2017-06-11 09:31:45 +02:00
|
|
|
#include "messages/word.hpp"
|
2017-01-18 21:30:23 +01:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
namespace chatterino {
|
|
|
|
namespace messages {
|
2017-01-05 16:07:20 +01:00
|
|
|
|
2017-01-05 16:59:01 +01:00
|
|
|
// Image word
|
2017-04-12 17:46:44 +02:00
|
|
|
Word::Word(LazyLoadedImage *image, Type type, const QString ©text, const QString &tooltip,
|
|
|
|
const Link &link)
|
|
|
|
: _image(image)
|
|
|
|
, _text()
|
|
|
|
, _color()
|
2017-01-18 04:33:30 +01:00
|
|
|
, _isImage(true)
|
2017-04-12 17:46:44 +02:00
|
|
|
, _type(type)
|
|
|
|
, _copyText(copytext)
|
|
|
|
, _tooltip(tooltip)
|
|
|
|
, _link(link)
|
|
|
|
, _characterWidthCache()
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-01-18 04:33:30 +01:00
|
|
|
image->getWidth(); // professional segfault test
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
|
|
|
|
2017-01-05 16:59:01 +01:00
|
|
|
// Text word
|
2017-04-12 17:46:44 +02:00
|
|
|
Word::Word(const QString &text, Type type, const QColor &color, const QString ©text,
|
|
|
|
const QString &tooltip, const Link &link)
|
2017-06-11 09:37:30 +02:00
|
|
|
: _image(nullptr)
|
2017-04-12 17:46:44 +02:00
|
|
|
, _text(text)
|
|
|
|
, _color(color)
|
2017-01-18 04:33:30 +01:00
|
|
|
, _isImage(false)
|
2017-04-12 17:46:44 +02:00
|
|
|
, _type(type)
|
|
|
|
, _copyText(copytext)
|
|
|
|
, _tooltip(tooltip)
|
|
|
|
, _link(link)
|
|
|
|
, _characterWidthCache()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LazyLoadedImage &Word::getImage() const
|
|
|
|
{
|
|
|
|
return *_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Word::getText() const
|
|
|
|
{
|
|
|
|
return _text;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Word::getWidth() const
|
|
|
|
{
|
|
|
|
return _width;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Word::getHeight() const
|
|
|
|
{
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Word::setSize(int width, int height)
|
|
|
|
{
|
|
|
|
_width = width;
|
|
|
|
_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Word::isImage() const
|
|
|
|
{
|
|
|
|
return _isImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Word::isText() const
|
|
|
|
{
|
|
|
|
return !_isImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Word::getCopyText() const
|
|
|
|
{
|
|
|
|
return _copyText;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Word::hasTrailingSpace() const
|
2017-01-05 16:07:20 +01:00
|
|
|
{
|
2017-04-12 17:46:44 +02:00
|
|
|
return _hasTrailingSpace;
|
2017-01-05 16:07:20 +01:00
|
|
|
}
|
2017-03-11 11:32:19 +01:00
|
|
|
|
2017-04-12 17:46:44 +02:00
|
|
|
QFont &Word::getFont() const
|
|
|
|
{
|
|
|
|
return FontManager::getInstance().getFont(_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
QFontMetrics &Word::getFontMetrics() const
|
|
|
|
{
|
|
|
|
return FontManager::getInstance().getFontMetrics(_font);
|
|
|
|
}
|
|
|
|
|
|
|
|
Word::Type Word::getType() const
|
|
|
|
{
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QString &Word::getTooltip() const
|
|
|
|
{
|
|
|
|
return _tooltip;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QColor &Word::getColor() const
|
|
|
|
{
|
|
|
|
return _color;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Link &Word::getLink() const
|
|
|
|
{
|
|
|
|
return _link;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Word::getXOffset() const
|
|
|
|
{
|
|
|
|
return _xOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Word::getYOffset() const
|
|
|
|
{
|
|
|
|
return _yOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Word::setOffset(int xOffset, int yOffset)
|
|
|
|
{
|
|
|
|
_xOffset = std::max(0, xOffset);
|
|
|
|
_yOffset = std::max(0, yOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<short> &Word::getCharacterWidthCache() const
|
|
|
|
{
|
|
|
|
return _characterWidthCache;
|
|
|
|
}
|
2017-06-07 10:09:24 +02:00
|
|
|
|
2017-04-14 17:52:22 +02:00
|
|
|
} // namespace messages
|
|
|
|
} // namespace chatterino
|