From a5587335071cb2828f8b98ea7b17d4aeaf29ff15 Mon Sep 17 00:00:00 2001 From: krepa098 Date: Mon, 26 Jan 2015 19:32:33 +0100 Subject: [PATCH] ChatLog::selectAll, refactoring of actions (issue #808) --- src/chatlog/chatlog.cpp | 31 ++++++++++++++++++++++++----- src/chatlog/chatlog.h | 5 ++--- src/widget/form/genericchatform.cpp | 7 ++++++- src/widget/form/genericchatform.h | 1 + 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index f3b595c3b..5a7e80d7a 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -61,13 +61,20 @@ ChatLog::ChatLog(QWidget* parent) selGraphItem->setZValue(-10.0); //behind all items // copy action (ie. Ctrl+C) - copyAction = new QAction(this); + QAction* copyAction = new QAction(this); + copyAction->setIcon(QIcon::fromTheme("edit-copy")); + copyAction->setText(tr("Copy")); copyAction->setShortcut(QKeySequence::Copy); + connect(copyAction, &QAction::triggered, this, [this](bool) { copySelectedText(); }); addAction(copyAction); - connect(copyAction, &QAction::triggered, this, [this](bool) - { - copySelectedText(); - }); + + // select all action (ie. Ctrl+A) + QAction* selectAllAction = new QAction(this); + selectAllAction->setIcon(QIcon::fromTheme("edit-select-all")); + selectAllAction->setText(tr("Select all")); + selectAllAction->setShortcut(QKeySequence::SelectAll); + connect(selectAllAction, &QAction::triggered, this, [this](bool) { selectAll(); }); + addAction(selectAllAction); // This timer is used to scroll the view while the user is // moving the mouse past the top/bottom edge of the widget while selecting. @@ -544,6 +551,20 @@ void ChatLog::scrollToLine(ChatLine::Ptr line) verticalScrollBar()->setValue(line->boundingSceneRect().top()); } +void ChatLog::selectAll() +{ + if(lines.empty()) + return; + + clearSelection(); + + selectionMode = Multi; + selFirstRow = 0; + selLastRow = lines.size()-1; + + updateMultiSelectionRect(); +} + void ChatLog::checkVisibility() { if(lines.empty()) diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 890a67acd..4461d2b3c 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -47,6 +47,8 @@ public: void setTypingNotification(ChatLine::Ptr notification); void setTypingNotificationVisible(bool visible); void scrollToLine(ChatLine::Ptr line); + void selectAll(); + QString getSelectedText() const; bool isEmpty() const; @@ -126,9 +128,6 @@ private: bool workerStb = false; ChatLine::Ptr workerAnchorLine; - // actions - QAction* copyAction = nullptr; - // layout QMarginsF margins = QMarginsF(10.0,10.0,10.0,10.0); qreal lineSpacing = 5.0f; diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index 7cc2d86f0..5511df2e9 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -146,7 +146,7 @@ GenericChatForm::GenericChatForm(QWidget *parent) fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect); - menu.addAction(QIcon::fromTheme("edit-copy"), tr("Copy"), this, SLOT(onCopyLogClicked())); + menu.addActions(chatWidget->actions()); menu.addSeparator(); menu.addAction(QIcon::fromTheme("document-save"), tr("Save chat log"), this, SLOT(onSaveLogClicked())); menu.addAction(QIcon::fromTheme("edit-clear"), tr("Clear displayed messages"), this, SLOT(clearChatArea(bool))); @@ -323,6 +323,11 @@ void GenericChatForm::clearChatArea(bool notinform) emit chatAreaCleared(); } +void GenericChatForm::onSelectAllClicked() +{ + chatWidget->selectAll(); +} + QString GenericChatForm::resolveToxID(const ToxID &id) { Friend *f = FriendList::findFriend(id); diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index b741ab6b0..73463af76 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -73,6 +73,7 @@ protected slots: void onSaveLogClicked(); void onCopyLogClicked(); void clearChatArea(bool); + void onSelectAllClicked(); protected: QString resolveToxID(const ToxID &id);