fixed ctrl+c to copy text

This commit is contained in:
fourtf
2017-09-21 02:20:02 +02:00
parent 9d671ac873
commit ab641abd9c
9 changed files with 66 additions and 17 deletions
+5 -2
View File
@@ -141,13 +141,16 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
int width = 0;
std::vector<short> &charWidths = word.getCharacterWidthCache();
int charOffset = 0;
for (int i = 2; i <= text.length(); i++) {
if ((width = width + charWidths[i - 1]) + MARGIN_LEFT > right) {
QString mid = text.mid(start, i - start - 1);
_wordParts.push_back(WordPart(word, MARGIN_LEFT, y, width, word.getHeight(),
lineNumber, mid, mid, false));
lineNumber, mid, mid, false, charOffset));
charOffset = i;
y += metrics.height();
@@ -162,7 +165,7 @@ bool MessageRef::layout(int width, bool enableEmoteMargins)
width = metrics.width(mid);
_wordParts.push_back(WordPart(word, MARGIN_LEFT, y - word.getHeight(), width,
word.getHeight(), lineNumber, mid, mid));
word.getHeight(), lineNumber, mid, mid, charOffset));
x = width + MARGIN_LEFT + spaceWidth;
lineHeight = word.getHeight();
+8 -1
View File
@@ -15,11 +15,13 @@ WordPart::WordPart(Word &word, int x, int y, int lineNumber, const QString &copy
, _height(word.getHeight())
, _lineNumber(lineNumber)
, _trailingSpace(!word.getCopyText().isEmpty() && word.hasTrailingSpace() & allowTrailingSpace)
, wordCharOffset(0)
{
}
WordPart::WordPart(Word &word, int x, int y, int width, int height, int lineNumber,
const QString &copyText, const QString &customText, bool allowTrailingSpace)
const QString &copyText, const QString &customText, bool allowTrailingSpace,
int wordCharOffset)
: _word(word)
, _copyText(copyText)
, _text(customText)
@@ -29,6 +31,7 @@ WordPart::WordPart(Word &word, int x, int y, int width, int height, int lineNumb
, _height(height)
, _lineNumber(lineNumber)
, _trailingSpace(!word.getCopyText().isEmpty() && word.hasTrailingSpace() & allowTrailingSpace)
, wordCharOffset(wordCharOffset)
{
}
@@ -110,5 +113,9 @@ int WordPart::getCharacterLength() const
return this->getWord().isImage() ? 2 : this->getText().length() + 1;
}
short WordPart::getCharacterWidth(int index) const
{
return this->getWord().getCharacterWidthCache().at(index + this->wordCharOffset);
}
} // namespace messages
} // namespace chatterino
+4 -1
View File
@@ -15,7 +15,8 @@ public:
bool allowTrailingSpace = true);
WordPart(Word &getWord, int getX, int getY, int getWidth, int getHeight, int _lineNumber,
const QString &getCopyText, const QString &customText, bool allowTrailingSpace = true);
const QString &getCopyText, const QString &customText, bool allowTrailingSpace = true,
int wordCharOffset = 0);
const Word &getWord() const;
int getWidth() const;
@@ -32,6 +33,7 @@ public:
const QString &getText() const;
int getLineNumber() const;
int getCharacterLength() const;
short getCharacterWidth(int index) const;
private:
Word &_word;
@@ -47,6 +49,7 @@ private:
int _lineNumber;
bool _trailingSpace;
int wordCharOffset;
};
} // namespace messages