added basic buggy text copying

This commit is contained in:
fourtf
2018-01-16 02:39:31 +01:00
parent a33ac76f99
commit 0ca916717c
6 changed files with 68 additions and 274 deletions
+6 -34
View File
@@ -235,48 +235,20 @@ const MessageLayoutElement *MessageLayout::getElementAt(QPoint point)
return this->container.getElementAt(point);
}
// XXX(pajlada): This is probably not the optimal way to calculate this
int MessageLayout::getLastCharacterIndex() const
{
// fourtf: xD
// // find out in which line the cursor is
// int lineNumber = 0, lineStart = 0, lineEnd = 0;
// for (size_t i = 0; i < this->wordParts.size(); i++) {
// const LayoutItem &part = this->wordParts[i];
// if (part.getLineNumber() != lineNumber) {
// lineStart = i;
// lineNumber = part.getLineNumber();
// }
// lineEnd = i + 1;
// }
// // count up to the cursor
// int index = 0;
// for (int i = 0; i < lineStart; i++) {
// const LayoutItem &part = this->wordParts[i];
// index += part.getWord().isImage() ? 2 : part.getText().length() + 1;
// }
// for (int i = lineStart; i < lineEnd; i++) {
// const LayoutItem &part = this->wordParts[i];
// index += part.getCharacterLength();
// }
// return index;
return 0;
return this->container.getLastCharacterIndex();
}
int MessageLayout::getSelectionIndex(QPoint position)
{
return this->container.getSelectionIndex(position);
}
void MessageLayout::addSelectionText(QString &str, int from, int to)
{
this->container.addSelectionText(str, from, to);
}
} // namespace layouts
} // namespace messages
} // namespace chatterino
+1
View File
@@ -49,6 +49,7 @@ public:
const MessageLayoutElement *getElementAt(QPoint point);
int getLastCharacterIndex() const;
int getSelectionIndex(QPoint position);
void addSelectionText(QString &str, int from, int to);
// Misc
bool isDisabled() const;
@@ -379,6 +379,41 @@ int MessageLayoutContainer::getSelectionIndex(QPoint point)
return index;
}
// fourtf: no idea if this is acurate LOL
int MessageLayoutContainer::getLastCharacterIndex() const
{
if (this->lines.size() == 0) {
return 0;
}
return this->lines.back().endCharIndex;
}
void MessageLayoutContainer::addSelectionText(QString &str, int from, int to)
{
int index = 0;
bool xd = true;
for (std::unique_ptr<MessageLayoutElement> &ele : this->elements) {
int c = ele->getSelectionIndexCount();
if (xd) {
if (index + c > from) {
ele->addCopyTextToString(str, index - from, to - from);
xd = false;
}
} else {
if (index + c > from) {
ele->addCopyTextToString(str, 0, index - to);
break;
} else {
ele->addCopyTextToString(str);
}
}
index += c;
}
}
} // namespace layouts
} // namespace messages
} // namespace chatterino
@@ -71,6 +71,8 @@ public:
// selection
int getSelectionIndex(QPoint point);
int getLastCharacterIndex() const;
void addSelectionText(QString &str, int from, int to);
private:
struct Line {
+10 -1
View File
@@ -54,7 +54,11 @@ ImageLayoutElement::ImageLayoutElement(MessageElement &_creator, Image &_image,
void ImageLayoutElement::addCopyTextToString(QString &str, int from, int to) const
{
str += "<image>";
str += this->image.getName();
if (this->hasTrailingSpace()) {
str += " ";
}
}
int ImageLayoutElement::getSelectionIndexCount()
@@ -117,6 +121,11 @@ TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text, Q
void TextLayoutElement::addCopyTextToString(QString &str, int from, int to) const
{
str += this->text.mid(from, to - from);
if (this->hasTrailingSpace()) {
str += " ";
}
}
int TextLayoutElement::getSelectionIndexCount()