Browse Source

ChatLog::selectAll, refactoring of actions (issue #808)

pull/974/head
krepa098 11 years ago
parent
commit
a558733507
  1. 31
      src/chatlog/chatlog.cpp
  2. 5
      src/chatlog/chatlog.h
  3. 7
      src/widget/form/genericchatform.cpp
  4. 1
      src/widget/form/genericchatform.h

31
src/chatlog/chatlog.cpp

@ -61,13 +61,20 @@ ChatLog::ChatLog(QWidget* parent) @@ -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) @@ -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())

5
src/chatlog/chatlog.h

@ -47,6 +47,8 @@ public: @@ -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: @@ -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;

7
src/widget/form/genericchatform.cpp

@ -146,7 +146,7 @@ GenericChatForm::GenericChatForm(QWidget *parent) @@ -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) @@ -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);

1
src/widget/form/genericchatform.h

@ -73,6 +73,7 @@ protected slots: @@ -73,6 +73,7 @@ protected slots:
void onSaveLogClicked();
void onCopyLogClicked();
void clearChatArea(bool);
void onSelectAllClicked();
protected:
QString resolveToxID(const ToxID &id);

Loading…
Cancel
Save