Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(genericchatform): add "Quote selected text" feature to chat window
Browse files Browse the repository at this point in the history
add "Quote selected text" feature to chat window context menu and set keyboard shortcut ALT+Q
  • Loading branch information
fazotron committed Jun 6, 2016
1 parent 792103f commit 40a805c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/widget/form/genericchatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ GenericChatForm::GenericChatForm(QWidget *parent)
QString(), this, SLOT(onSaveLogClicked()));
clearAction = menu.addAction(QIcon::fromTheme("edit-clear"),
QString(), this, SLOT(clearChatArea(bool)));

quoteAction = menu.addAction(QIcon(),
QString(), this, SLOT(quoteSelectedText()));

menu.addSeparator();

connect(emoteButton, &QPushButton::clicked,
Expand All @@ -199,6 +203,7 @@ GenericChatForm::GenericChatForm(QWidget *parent)
this, &GenericChatForm::onChatContextMenuRequested);

new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_L, this, SLOT(clearChatArea()));
new QShortcut(Qt::ALT + Qt::Key_Q, this, SLOT(quoteSelectedText()));

chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css"));
headWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatHead.css"));
Expand Down Expand Up @@ -562,6 +567,26 @@ void GenericChatForm::onShowMessagesClicked()
}
}

void GenericChatForm::quoteSelectedText()
{
QString selectedText = chatWidget->getSelectedText();

if (selectedText.isEmpty())
return;

// forming pretty quote text
// 1. insert "> " to the begining of quote;
// 2. replace all possible line terminators with "\n> ";
// 3. append new line to the end of quote.
QString quote = selectedText;

quote.insert(0, "> ");
quote.replace(QRegExp(QString("\r\n|[\r\n\u2028\u2029]")), QString("\n> "));
quote.append("\n");

msgEdit->append(quote);
}

void GenericChatForm::retranslateUi()
{
QString callObjectName = callButton->objectName();
Expand All @@ -587,6 +612,7 @@ void GenericChatForm::retranslateUi()
screenshotButton->setToolTip(tr("Send a screenshot"));
saveChatAction->setText(tr("Save chat log"));
clearAction->setText(tr("Clear displayed messages"));
quoteAction->setText(tr("Quote selected text"));
}

void GenericChatForm::showNetcam()
Expand Down
3 changes: 2 additions & 1 deletion src/widget/form/genericchatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ protected slots:
void hideFileMenu();
void onShowMessagesClicked();
void onSplitterMoved(int pos, int index);
void quoteSelectedText();

private:
void retranslateUi();
Expand All @@ -109,7 +110,7 @@ protected slots:
virtual bool eventFilter(QObject* object, QEvent* event) final override;

protected:
QAction* saveChatAction, *clearAction;
QAction* saveChatAction, *clearAction, *quoteAction;
ToxId previousId;
QDateTime prevMsgDateTime;
Widget *parent;
Expand Down
4 changes: 4 additions & 0 deletions translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,10 @@ will be sent to them when they appear online to you.</source>
<source>Clear displayed messages</source>
<translation>Очистить показываемые сообщения</translation>
</message>
<message>
<source>Quote selected text</source>
<translation>Цитировать выделенное</translation>
</message>
<message>
<source>Not sent</source>
<translation>Не отправлено</translation>
Expand Down

0 comments on commit 40a805c

Please sign in to comment.