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
+17 -7
View File
@@ -258,6 +258,18 @@ QString ChannelView::getSelectedText()
return text;
}
bool ChannelView::hasSelection()
{
return !this->selection.isEmpty();
}
void ChannelView::clearSelection()
{
this->selection = Selection();
layoutMessages();
update();
}
messages::LimitedQueueSnapshot<SharedMessageRef> ChannelView::getMessagesSnapshot()
{
return this->messages.getSnapshot();
@@ -338,6 +350,8 @@ void ChannelView::setSelection(const SelectionItem &start, const SelectionItem &
// selections
this->selection = Selection(start, end);
this->selectionChanged();
// qDebug() << min.messageIndex << ":" << min.charIndex << " " << max.messageIndex << ":"
// << max.charIndex;
}
@@ -552,10 +566,8 @@ void ChannelView::drawMessageSelection(QPainter &painter, messages::MessageRef *
if (part.getWord().isText()) {
int offset = this->selection.min.charIndex - charIndex;
std::vector<short> &characterWidth = part.getWord().getCharacterWidthCache();
for (int j = 0; j < offset; j++) {
rect.setLeft(rect.left() + characterWidth[j]);
rect.setLeft(rect.left() + part.getCharacterWidth(j));
}
if (isSingleWord) {
@@ -564,7 +576,7 @@ void ChannelView::drawMessageSelection(QPainter &painter, messages::MessageRef *
rect.setRight(part.getX());
for (int j = 0; j < offset + length; j++) {
rect.setRight(rect.right() + characterWidth[j]);
rect.setRight(rect.right() + part.getCharacterWidth(j));
}
painter.fillRect(rect, selectionColor);
@@ -616,14 +628,12 @@ void ChannelView::drawMessageSelection(QPainter &painter, messages::MessageRef *
if (part.getWord().isText()) {
int offset = this->selection.min.charIndex - charIndex;
std::vector<short> &characterWidth = part.getWord().getCharacterWidthCache();
int length = (this->selection.max.charIndex - charIndex) - offset;
rect.setRight(part.getX());
for (int j = 0; j < offset + length; j++) {
rect.setRight(rect.right() + characterWidth[j]);
rect.setRight(rect.right() + part.getCharacterWidth(j));
}
} else {
if (this->selection.max.charIndex == charIndex) {
+3
View File
@@ -89,6 +89,8 @@ public:
void updateGifEmotes();
ScrollBar &getScrollBar();
QString getSelectedText();
bool hasSelection();
void clearSelection();
void setChannel(std::shared_ptr<Channel> channel);
messages::LimitedQueueSnapshot<messages::SharedMessageRef> getMessagesSnapshot();
@@ -97,6 +99,7 @@ public:
void clearMessages();
boost::signals2::signal<void(QMouseEvent *)> mouseDown;
boost::signals2::signal<void()> selectionChanged;
protected:
virtual void resizeEvent(QResizeEvent *) override;
+5 -3
View File
@@ -74,9 +74,6 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent)
// CTRL+R: Change Channel
ezShortcut(this, "CTRL+R", &ChatWidget::doChangeChannel);
// CTRL+C: Copy
// ezShortcut(this, "CTRL+B", &ChatWidget::doCopy);
#ifndef NDEBUG
// F12: Toggle message spawning
ezShortcut(this, "ALT+Q", &ChatWidget::doToggleMessageSpawning);
@@ -90,6 +87,11 @@ ChatWidget::ChatWidget(ChannelManager &_channelManager, NotebookPage *parent)
this->input.textInput.installEventFilter(parent);
this->view.mouseDown.connect([this](QMouseEvent *) { this->giveFocus(Qt::MouseFocusReason); });
this->view.selectionChanged.connect([this]() {
if (view.hasSelection()) {
this->input.clearSelection();
}
});
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &ChatWidget::test);
+2
View File
@@ -39,6 +39,8 @@ class NotebookPage;
// Each sub-element has a reference to the parent Chat Widget
class ChatWidget : public BaseWidget
{
friend class ChatWidgetInput;
Q_OBJECT
public:
+20 -3
View File
@@ -161,15 +161,22 @@ ChatWidgetInput::ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &emoteMan
notebook->previousTab();
}
} else if (event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier) {
event->accept();
this->chatWidget->doCopy();
if (this->chatWidget->view.hasSelection()) {
this->chatWidget->doCopy();
event->accept();
}
}
});
this->textLengthVisibleChangedConnection =
SettingsManager::getInstance().showMessageLength.valueChanged.connect(
[this](const bool &value) { this->textLengthLabel.setHidden(!value); });
QObject::connect(&this->textInput, &QTextEdit::copyAvailable, [this](bool available) {
if (available) {
this->chatWidget->view.clearSelection();
}
});
}
ChatWidgetInput::~ChatWidgetInput()
@@ -177,6 +184,16 @@ ChatWidgetInput::~ChatWidgetInput()
this->textLengthVisibleChangedConnection.disconnect();
}
void ChatWidgetInput::clearSelection()
{
QTextCursor c = this->textInput.textCursor();
c.setPosition(c.position());
c.setPosition(c.position(), QTextCursor::KeepAnchor);
this->textInput.setTextCursor(c);
}
void ChatWidgetInput::refreshTheme()
{
QPalette palette;
+2
View File
@@ -29,6 +29,8 @@ public:
ChatWidgetInput(ChatWidget *_chatWidget, EmoteManager &, WindowManager &);
~ChatWidgetInput();
void clearSelection();
protected:
virtual void paintEvent(QPaintEvent *) override;
virtual void resizeEvent(QResizeEvent *) override;