Added triple clicking to select the whole message.
This commit is contained in:
@@ -278,6 +278,11 @@ int MessageLayout::getLastCharacterIndex() const
|
||||
return this->container_->getLastCharacterIndex();
|
||||
}
|
||||
|
||||
int MessageLayout::getFirstMessageCharacterIndex() const
|
||||
{
|
||||
return this->container_->getFirstMessageCharacterIndex();
|
||||
}
|
||||
|
||||
int MessageLayout::getSelectionIndex(QPoint position)
|
||||
{
|
||||
return this->container_->getSelectionIndex(position);
|
||||
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
// Elements
|
||||
const MessageLayoutElement *getElementAt(QPoint point);
|
||||
int getLastCharacterIndex() const;
|
||||
int getFirstMessageCharacterIndex() const;
|
||||
int getSelectionIndex(QPoint position);
|
||||
void addSelectionText(QString &str, int from = 0, int to = INT_MAX,
|
||||
CopyMode copymode = CopyMode::Everything);
|
||||
|
||||
@@ -505,6 +505,26 @@ int MessageLayoutContainer::getLastCharacterIndex() const
|
||||
return this->lines_.back().endCharIndex;
|
||||
}
|
||||
|
||||
int MessageLayoutContainer::getFirstMessageCharacterIndex() const
|
||||
{
|
||||
static FlagsEnum<MessageElementFlag> flags;
|
||||
flags.set(MessageElementFlag::Username);
|
||||
flags.set(MessageElementFlag::Timestamp);
|
||||
flags.set(MessageElementFlag::Badges);
|
||||
|
||||
// Get the index of the first character of the real message
|
||||
// (no badges/timestamps/username)
|
||||
int index = 0;
|
||||
for (auto &element : this->elements_) {
|
||||
if (element.get()->getFlags().hasAny(flags)) {
|
||||
index += element.get()->getSelectionIndexCount();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
void MessageLayoutContainer::addSelectionText(QString &str, int from, int to,
|
||||
CopyMode copymode)
|
||||
{
|
||||
|
||||
@@ -75,6 +75,7 @@ struct MessageLayoutContainer {
|
||||
// selection
|
||||
int getSelectionIndex(QPoint point);
|
||||
int getLastCharacterIndex() const;
|
||||
int getFirstMessageCharacterIndex() const;
|
||||
void addSelectionText(QString &str, int from, int to, CopyMode copymode);
|
||||
|
||||
bool isCollapsed();
|
||||
|
||||
@@ -74,6 +74,11 @@ const QString &MessageLayoutElement::getText() const
|
||||
return this->text_;
|
||||
}
|
||||
|
||||
FlagsEnum<MessageElementFlag> MessageLayoutElement::getFlags() const
|
||||
{
|
||||
return this->creator_.getFlags();
|
||||
}
|
||||
|
||||
//
|
||||
// IMAGE
|
||||
//
|
||||
@@ -157,17 +162,17 @@ TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text,
|
||||
const QSize &_size, QColor _color,
|
||||
FontStyle _style, float _scale)
|
||||
: MessageLayoutElement(_creator, _size)
|
||||
, text(_text)
|
||||
, color(_color)
|
||||
, style(_style)
|
||||
, scale(_scale)
|
||||
{
|
||||
this->setText(_text);
|
||||
}
|
||||
|
||||
void TextLayoutElement::addCopyTextToString(QString &str, int from,
|
||||
int to) const
|
||||
{
|
||||
str += this->text.mid(from, to - from);
|
||||
str += this->getText().mid(from, to - from);
|
||||
|
||||
if (this->hasTrailingSpace()) {
|
||||
str += " ";
|
||||
@@ -176,7 +181,7 @@ void TextLayoutElement::addCopyTextToString(QString &str, int from,
|
||||
|
||||
int TextLayoutElement::getSelectionIndexCount() const
|
||||
{
|
||||
return this->text.length() + (this->trailingSpace ? 1 : 0);
|
||||
return this->getText().length() + (this->trailingSpace ? 1 : 0);
|
||||
}
|
||||
|
||||
void TextLayoutElement::paint(QPainter &painter)
|
||||
@@ -189,7 +194,7 @@ void TextLayoutElement::paint(QPainter &painter)
|
||||
|
||||
painter.drawText(
|
||||
QRectF(this->getRect().x(), this->getRect().y(), 10000, 10000),
|
||||
this->text, QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
this->getText(), QTextOption(Qt::AlignLeft | Qt::AlignTop));
|
||||
}
|
||||
|
||||
void TextLayoutElement::paintAnimated(QPainter &, int)
|
||||
@@ -208,8 +213,8 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
|
||||
|
||||
int x = this->getRect().left();
|
||||
|
||||
for (int i = 0; i < this->text.size(); i++) {
|
||||
int w = metrics.width(this->text[i]);
|
||||
for (int i = 0; i < this->getText().size(); i++) {
|
||||
int w = metrics.width(this->getText()[i]);
|
||||
|
||||
if (x + w > abs.x()) {
|
||||
return i;
|
||||
@@ -229,10 +234,10 @@ int TextLayoutElement::getXFromIndex(int index)
|
||||
|
||||
if (index <= 0) {
|
||||
return this->getRect().left();
|
||||
} else if (index < this->text.size()) {
|
||||
} else if (index < this->getText().size()) {
|
||||
int x = 0;
|
||||
for (int i = 0; i < index; i++) {
|
||||
x += metrics.width(this->text[i]);
|
||||
x += metrics.width(this->getText()[i]);
|
||||
}
|
||||
return x + this->getRect().left();
|
||||
} else {
|
||||
|
||||
@@ -6,8 +6,10 @@
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <climits>
|
||||
|
||||
#include "common/FlagsEnum.hpp"
|
||||
#include "messages/Link.hpp"
|
||||
#include "messages/MessageColor.hpp"
|
||||
#include "messages/MessageElement.hpp"
|
||||
|
||||
class QPainter;
|
||||
|
||||
@@ -41,6 +43,7 @@ public:
|
||||
virtual int getXFromIndex(int index) = 0;
|
||||
const Link &getLink() const;
|
||||
const QString &getText() const;
|
||||
FlagsEnum<MessageElementFlag> getFlags() const;
|
||||
|
||||
protected:
|
||||
bool trailingSpace = true;
|
||||
@@ -90,7 +93,6 @@ protected:
|
||||
int getXFromIndex(int index) override;
|
||||
|
||||
private:
|
||||
QString text;
|
||||
QColor color;
|
||||
FontStyle style;
|
||||
float scale;
|
||||
|
||||
Reference in New Issue
Block a user