added text selection
This commit is contained in:
+48
-37
@@ -6,15 +6,12 @@ namespace messages {
|
||||
// Image word
|
||||
Word::Word(LazyLoadedImage *image, Type type, const QString ©text, const QString &tooltip,
|
||||
const Link &link)
|
||||
: _image(image)
|
||||
, _text()
|
||||
, _color()
|
||||
: image(image)
|
||||
, _isImage(true)
|
||||
, _type(type)
|
||||
, _copyText(copytext)
|
||||
, _tooltip(tooltip)
|
||||
, _link(link)
|
||||
, _characterWidthCache()
|
||||
, type(type)
|
||||
, copyText(copytext)
|
||||
, tooltip(tooltip)
|
||||
, link(link)
|
||||
{
|
||||
image->getWidth(); // professional segfault test
|
||||
}
|
||||
@@ -22,113 +19,127 @@ Word::Word(LazyLoadedImage *image, Type type, const QString ©text, const QSt
|
||||
// Text word
|
||||
Word::Word(const QString &text, Type type, const QColor &color, const QString ©text,
|
||||
const QString &tooltip, const Link &link)
|
||||
: _image(nullptr)
|
||||
, _text(text)
|
||||
, _color(color)
|
||||
: image(nullptr)
|
||||
, text(text)
|
||||
, color(color)
|
||||
, _isImage(false)
|
||||
, _type(type)
|
||||
, _copyText(copytext)
|
||||
, _tooltip(tooltip)
|
||||
, _link(link)
|
||||
, _characterWidthCache()
|
||||
, type(type)
|
||||
, copyText(copytext)
|
||||
, tooltip(tooltip)
|
||||
, link(link)
|
||||
{
|
||||
}
|
||||
|
||||
LazyLoadedImage &Word::getImage() const
|
||||
{
|
||||
return *_image;
|
||||
return *this->image;
|
||||
}
|
||||
|
||||
const QString &Word::getText() const
|
||||
{
|
||||
return _text;
|
||||
return this->text;
|
||||
}
|
||||
|
||||
int Word::getWidth() const
|
||||
{
|
||||
return _width;
|
||||
return this->width;
|
||||
}
|
||||
|
||||
int Word::getHeight() const
|
||||
{
|
||||
return _height;
|
||||
return this->height;
|
||||
}
|
||||
|
||||
void Word::setSize(int width, int height)
|
||||
{
|
||||
_width = width;
|
||||
_height = height;
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
bool Word::isImage() const
|
||||
{
|
||||
return _isImage;
|
||||
return this->_isImage;
|
||||
}
|
||||
|
||||
bool Word::isText() const
|
||||
{
|
||||
return !_isImage;
|
||||
return !this->_isImage;
|
||||
}
|
||||
|
||||
const QString &Word::getCopyText() const
|
||||
{
|
||||
return _copyText;
|
||||
return this->copyText;
|
||||
}
|
||||
|
||||
bool Word::hasTrailingSpace() const
|
||||
{
|
||||
return _hasTrailingSpace;
|
||||
return this->_hasTrailingSpace;
|
||||
}
|
||||
|
||||
QFont &Word::getFont() const
|
||||
{
|
||||
return FontManager::getInstance().getFont(_font);
|
||||
return FontManager::getInstance().getFont(this->font);
|
||||
}
|
||||
|
||||
QFontMetrics &Word::getFontMetrics() const
|
||||
{
|
||||
return FontManager::getInstance().getFontMetrics(_font);
|
||||
return FontManager::getInstance().getFontMetrics(this->font);
|
||||
}
|
||||
|
||||
Word::Type Word::getType() const
|
||||
{
|
||||
return _type;
|
||||
return this->type;
|
||||
}
|
||||
|
||||
const QString &Word::getTooltip() const
|
||||
{
|
||||
return _tooltip;
|
||||
return this->tooltip;
|
||||
}
|
||||
|
||||
const QColor &Word::getColor() const
|
||||
{
|
||||
return _color;
|
||||
return this->color;
|
||||
}
|
||||
|
||||
const Link &Word::getLink() const
|
||||
{
|
||||
return _link;
|
||||
return this->link;
|
||||
}
|
||||
|
||||
int Word::getXOffset() const
|
||||
{
|
||||
return _xOffset;
|
||||
return this->xOffset;
|
||||
}
|
||||
|
||||
int Word::getYOffset() const
|
||||
{
|
||||
return _yOffset;
|
||||
return this->yOffset;
|
||||
}
|
||||
|
||||
void Word::setOffset(int xOffset, int yOffset)
|
||||
{
|
||||
_xOffset = std::max(0, xOffset);
|
||||
_yOffset = std::max(0, yOffset);
|
||||
this->xOffset = std::max(0, xOffset);
|
||||
this->yOffset = std::max(0, yOffset);
|
||||
}
|
||||
|
||||
int Word::getCharacterLength() const
|
||||
{
|
||||
return this->isImage() ? 2 : this->getText().length() + 1;
|
||||
}
|
||||
|
||||
std::vector<short> &Word::getCharacterWidthCache() const
|
||||
{
|
||||
return _characterWidthCache;
|
||||
// lock not required because there is only one gui thread
|
||||
// std::lock_guard<std::mutex> lock(this->charWidthCacheMutex);
|
||||
|
||||
if (this->charWidthCache.size() == 0 && this->isText()) {
|
||||
for (int i = 0; i < this->getText().length(); i++) {
|
||||
this->charWidthCache.push_back(this->getFontMetrics().charWidth(this->getText(), i));
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: on font change
|
||||
return this->charWidthCache;
|
||||
}
|
||||
|
||||
} // namespace messages
|
||||
|
||||
Reference in New Issue
Block a user