mirror-chatterino2/src/messages/word.cpp

135 lines
2.1 KiB
C++
Raw Normal View History

2017-01-18 21:30:23 +01:00
#include "messages/word.h"
2017-04-14 17:52:22 +02:00
namespace chatterino {
namespace messages {
2017-01-05 16:07:20 +01:00
// Image word
2017-04-12 17:46:44 +02:00
Word::Word(LazyLoadedImage *image, Type type, const QString &copytext, 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
}
// Text word
2017-04-12 17:46:44 +02:00
Word::Word(const QString &text, Type type, const QColor &color, const QString &copytext,
const QString &tooltip, const Link &link)
: _image(NULL)
, _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-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-04-14 17:52:22 +02:00
} // namespace messages
} // namespace chatterino