mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
Added triple clicking to select the whole message.
This commit is contained in:
parent
7c367b73e6
commit
5c2cdce516
8 changed files with 64 additions and 12 deletions
|
@ -278,6 +278,11 @@ int MessageLayout::getLastCharacterIndex() const
|
||||||
return this->container_->getLastCharacterIndex();
|
return this->container_->getLastCharacterIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int MessageLayout::getFirstMessageCharacterIndex() const
|
||||||
|
{
|
||||||
|
return this->container_->getFirstMessageCharacterIndex();
|
||||||
|
}
|
||||||
|
|
||||||
int MessageLayout::getSelectionIndex(QPoint position)
|
int MessageLayout::getSelectionIndex(QPoint position)
|
||||||
{
|
{
|
||||||
return this->container_->getSelectionIndex(position);
|
return this->container_->getSelectionIndex(position);
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
// Elements
|
// Elements
|
||||||
const MessageLayoutElement *getElementAt(QPoint point);
|
const MessageLayoutElement *getElementAt(QPoint point);
|
||||||
int getLastCharacterIndex() const;
|
int getLastCharacterIndex() const;
|
||||||
|
int getFirstMessageCharacterIndex() const;
|
||||||
int getSelectionIndex(QPoint position);
|
int getSelectionIndex(QPoint position);
|
||||||
void addSelectionText(QString &str, int from = 0, int to = INT_MAX,
|
void addSelectionText(QString &str, int from = 0, int to = INT_MAX,
|
||||||
CopyMode copymode = CopyMode::Everything);
|
CopyMode copymode = CopyMode::Everything);
|
||||||
|
|
|
@ -505,6 +505,26 @@ int MessageLayoutContainer::getLastCharacterIndex() const
|
||||||
return this->lines_.back().endCharIndex;
|
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,
|
void MessageLayoutContainer::addSelectionText(QString &str, int from, int to,
|
||||||
CopyMode copymode)
|
CopyMode copymode)
|
||||||
{
|
{
|
||||||
|
|
|
@ -75,6 +75,7 @@ struct MessageLayoutContainer {
|
||||||
// selection
|
// selection
|
||||||
int getSelectionIndex(QPoint point);
|
int getSelectionIndex(QPoint point);
|
||||||
int getLastCharacterIndex() const;
|
int getLastCharacterIndex() const;
|
||||||
|
int getFirstMessageCharacterIndex() const;
|
||||||
void addSelectionText(QString &str, int from, int to, CopyMode copymode);
|
void addSelectionText(QString &str, int from, int to, CopyMode copymode);
|
||||||
|
|
||||||
bool isCollapsed();
|
bool isCollapsed();
|
||||||
|
|
|
@ -74,6 +74,11 @@ const QString &MessageLayoutElement::getText() const
|
||||||
return this->text_;
|
return this->text_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FlagsEnum<MessageElementFlag> MessageLayoutElement::getFlags() const
|
||||||
|
{
|
||||||
|
return this->creator_.getFlags();
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// IMAGE
|
// IMAGE
|
||||||
//
|
//
|
||||||
|
@ -157,17 +162,17 @@ TextLayoutElement::TextLayoutElement(MessageElement &_creator, QString &_text,
|
||||||
const QSize &_size, QColor _color,
|
const QSize &_size, QColor _color,
|
||||||
FontStyle _style, float _scale)
|
FontStyle _style, float _scale)
|
||||||
: MessageLayoutElement(_creator, _size)
|
: MessageLayoutElement(_creator, _size)
|
||||||
, text(_text)
|
|
||||||
, color(_color)
|
, color(_color)
|
||||||
, style(_style)
|
, style(_style)
|
||||||
, scale(_scale)
|
, scale(_scale)
|
||||||
{
|
{
|
||||||
|
this->setText(_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextLayoutElement::addCopyTextToString(QString &str, int from,
|
void TextLayoutElement::addCopyTextToString(QString &str, int from,
|
||||||
int to) const
|
int to) const
|
||||||
{
|
{
|
||||||
str += this->text.mid(from, to - from);
|
str += this->getText().mid(from, to - from);
|
||||||
|
|
||||||
if (this->hasTrailingSpace()) {
|
if (this->hasTrailingSpace()) {
|
||||||
str += " ";
|
str += " ";
|
||||||
|
@ -176,7 +181,7 @@ void TextLayoutElement::addCopyTextToString(QString &str, int from,
|
||||||
|
|
||||||
int TextLayoutElement::getSelectionIndexCount() const
|
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)
|
void TextLayoutElement::paint(QPainter &painter)
|
||||||
|
@ -189,7 +194,7 @@ void TextLayoutElement::paint(QPainter &painter)
|
||||||
|
|
||||||
painter.drawText(
|
painter.drawText(
|
||||||
QRectF(this->getRect().x(), this->getRect().y(), 10000, 10000),
|
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)
|
void TextLayoutElement::paintAnimated(QPainter &, int)
|
||||||
|
@ -208,8 +213,8 @@ int TextLayoutElement::getMouseOverIndex(const QPoint &abs) const
|
||||||
|
|
||||||
int x = this->getRect().left();
|
int x = this->getRect().left();
|
||||||
|
|
||||||
for (int i = 0; i < this->text.size(); i++) {
|
for (int i = 0; i < this->getText().size(); i++) {
|
||||||
int w = metrics.width(this->text[i]);
|
int w = metrics.width(this->getText()[i]);
|
||||||
|
|
||||||
if (x + w > abs.x()) {
|
if (x + w > abs.x()) {
|
||||||
return i;
|
return i;
|
||||||
|
@ -229,10 +234,10 @@ int TextLayoutElement::getXFromIndex(int index)
|
||||||
|
|
||||||
if (index <= 0) {
|
if (index <= 0) {
|
||||||
return this->getRect().left();
|
return this->getRect().left();
|
||||||
} else if (index < this->text.size()) {
|
} else if (index < this->getText().size()) {
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for (int i = 0; i < index; i++) {
|
for (int i = 0; i < index; i++) {
|
||||||
x += metrics.width(this->text[i]);
|
x += metrics.width(this->getText()[i]);
|
||||||
}
|
}
|
||||||
return x + this->getRect().left();
|
return x + this->getRect().left();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -6,8 +6,10 @@
|
||||||
#include <boost/noncopyable.hpp>
|
#include <boost/noncopyable.hpp>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
|
|
||||||
|
#include "common/FlagsEnum.hpp"
|
||||||
#include "messages/Link.hpp"
|
#include "messages/Link.hpp"
|
||||||
#include "messages/MessageColor.hpp"
|
#include "messages/MessageColor.hpp"
|
||||||
|
#include "messages/MessageElement.hpp"
|
||||||
|
|
||||||
class QPainter;
|
class QPainter;
|
||||||
|
|
||||||
|
@ -41,6 +43,7 @@ public:
|
||||||
virtual int getXFromIndex(int index) = 0;
|
virtual int getXFromIndex(int index) = 0;
|
||||||
const Link &getLink() const;
|
const Link &getLink() const;
|
||||||
const QString &getText() const;
|
const QString &getText() const;
|
||||||
|
FlagsEnum<MessageElementFlag> getFlags() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool trailingSpace = true;
|
bool trailingSpace = true;
|
||||||
|
@ -90,7 +93,6 @@ protected:
|
||||||
int getXFromIndex(int index) override;
|
int getXFromIndex(int index) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString text;
|
|
||||||
QColor color;
|
QColor color;
|
||||||
FontStyle style;
|
FontStyle style;
|
||||||
float scale;
|
float scale;
|
||||||
|
|
|
@ -120,6 +120,10 @@ ChannelView::ChannelView(BaseWidget *parent)
|
||||||
QObject::connect(shortcut, &QShortcut::activated, [this] {
|
QObject::connect(shortcut, &QShortcut::activated, [this] {
|
||||||
QGuiApplication::clipboard()->setText(this->getSelectedText());
|
QGuiApplication::clipboard()->setText(this->getSelectedText());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this->clickTimer_ = new QTimer(this);
|
||||||
|
this->clickTimer_->setSingleShot(true);
|
||||||
|
this->clickTimer_->setInterval(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelView::initializeLayout()
|
void ChannelView::initializeLayout()
|
||||||
|
@ -1023,12 +1027,13 @@ void ChannelView::mouseReleaseEvent(QMouseEvent *event)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle the click
|
// handle the click
|
||||||
this->handleMouseClick(event, hoverLayoutElement, layout.get());
|
this->handleMouseClick(event, hoverLayoutElement, layout.get(),
|
||||||
|
messageIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChannelView::handleMouseClick(QMouseEvent *event,
|
void ChannelView::handleMouseClick(QMouseEvent *event,
|
||||||
const MessageLayoutElement *hoveredElement,
|
const MessageLayoutElement *hoveredElement,
|
||||||
MessageLayout *layout)
|
MessageLayout *layout, int &messageIndex)
|
||||||
{
|
{
|
||||||
switch (event->button()) {
|
switch (event->button()) {
|
||||||
case Qt::LeftButton: {
|
case Qt::LeftButton: {
|
||||||
|
@ -1038,6 +1043,16 @@ void ChannelView::handleMouseClick(QMouseEvent *event,
|
||||||
this->showingLatestMessages_ = false;
|
this->showingLatestMessages_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->clickTimer_->isActive()) {
|
||||||
|
auto firstRealCharacterIndex =
|
||||||
|
layout->getFirstMessageCharacterIndex();
|
||||||
|
SelectionItem msgStart(messageIndex,
|
||||||
|
firstRealCharacterIndex);
|
||||||
|
SelectionItem msgEnd(messageIndex,
|
||||||
|
layout->getLastCharacterIndex());
|
||||||
|
this->setSelection(msgStart, msgEnd);
|
||||||
|
}
|
||||||
|
|
||||||
// this->pausedBySelection = false;
|
// this->pausedBySelection = false;
|
||||||
this->selecting_ = false;
|
this->selecting_ = false;
|
||||||
// this->pauseTimeout.stop();
|
// this->pauseTimeout.stop();
|
||||||
|
@ -1191,6 +1206,8 @@ void ChannelView::mouseDoubleClickEvent(QMouseEvent *event)
|
||||||
layout->getSelectionIndex(relativePos) - mouseInWordIndex;
|
layout->getSelectionIndex(relativePos) - mouseInWordIndex;
|
||||||
const int wordEnd = wordStart + hoverLayoutElement->getText().length();
|
const int wordEnd = wordStart + hoverLayoutElement->getText().length();
|
||||||
|
|
||||||
|
this->clickTimer_->start();
|
||||||
|
|
||||||
SelectionItem wordMin(messageIndex, wordStart);
|
SelectionItem wordMin(messageIndex, wordStart);
|
||||||
SelectionItem wordMax(messageIndex, wordEnd);
|
SelectionItem wordMax(messageIndex, wordEnd);
|
||||||
this->setSelection(wordMin, wordMax);
|
this->setSelection(wordMin, wordMax);
|
||||||
|
|
|
@ -108,7 +108,7 @@ private:
|
||||||
|
|
||||||
void handleMouseClick(QMouseEvent *event,
|
void handleMouseClick(QMouseEvent *event,
|
||||||
const MessageLayoutElement *hoverLayoutElement,
|
const MessageLayoutElement *hoverLayoutElement,
|
||||||
MessageLayout *layout);
|
MessageLayout *layout, int &messageIndex);
|
||||||
void addContextMenuItems(const MessageLayoutElement *hoveredElement,
|
void addContextMenuItems(const MessageLayoutElement *hoveredElement,
|
||||||
MessageLayout *layout);
|
MessageLayout *layout);
|
||||||
int getLayoutWidth() const;
|
int getLayoutWidth() const;
|
||||||
|
@ -149,6 +149,7 @@ private:
|
||||||
bool isRightMouseDown_ = false;
|
bool isRightMouseDown_ = false;
|
||||||
QPointF lastPressPosition_;
|
QPointF lastPressPosition_;
|
||||||
QPointF lastRightPressPosition_;
|
QPointF lastRightPressPosition_;
|
||||||
|
QTimer *clickTimer_;
|
||||||
|
|
||||||
Selection selection_;
|
Selection selection_;
|
||||||
bool selecting_ = false;
|
bool selecting_ = false;
|
||||||
|
|
Loading…
Reference in a new issue