Commit 464e0c7d authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Sébastien Blin

shortcuts: add various keyboard shortcuts in callwidget and settingswidget

Change-Id: If4cd542e4f041f1847e6f2a5057bfa16b9235546
parent 6dffef78
......@@ -51,6 +51,7 @@
#include <QScrollBar>
#include <QWebEngineScript>
#include <QMimeData>
#include <QShortcut>
#include <algorithm>
#include <memory>
......@@ -118,6 +119,9 @@ CallWidget::CallWidget(QWidget* parent) :
ui->spinnerLabel->setMovie(miniSpinner_);
ui->spinnerLabel->hide();
// shortcuts
registerShortCuts();
// connections
connect(ui->currentAccountComboBox, &CurrentAccountComboBox::settingsButtonClicked,
this, &CallWidget::settingsButtonClicked);
......@@ -275,6 +279,7 @@ CallWidget::navigated(bool to)
* in case of a resolution change.
*/
ui->videoView->resetPreview();
setFocus();
} else {
QObject::disconnect(smartlistSelectionConnection_);
smartListModel_.reset(nullptr);
......@@ -1488,6 +1493,154 @@ CallWidget::updateChatviewFrame()
ui->messageView->updateChatviewFrame(accInfo.enabled, contactInfo.isBanned, temp, bestName, bestId);
}
void
CallWidget::registerShortCuts()
{
//shortcuts
auto startAudioCallSC = new QShortcut(QKeySequence(tr("Shift+Ctrl+C", "Start an audio call")), this);
auto startVideoCallSC = new QShortcut(QKeySequence(tr("Shift+Ctrl+X", "Start an video call")), this);
auto clearConvHistorySC = new QShortcut(QKeySequence(tr("Shift+Ctrl+L", "Clear history")), this);
auto blockContactSC = new QShortcut(QKeySequence(tr("Shift+Ctrl+B", "Block contact")), this);
auto copyContactNameSC = new QShortcut(QKeySequence(tr("Shift+Ctrl+J", "Copy contact name")), this);
auto openAccountListSC = new QShortcut(QKeySequence(tr("Ctrl+J", "Open account list")), this);
auto focusOnSmartListSC = new QShortcut(QKeySequence(tr("Ctrl+L", "Focus on smart list")), this);
auto focusOnSmartListNextElementSC = new QShortcut(QKeySequence(tr("Ctrl+Down", "Focus on the next element on smart list")), this);
auto focusOnSmartListPrevElementSC = new QShortcut(QKeySequence(tr("Ctrl+Up", "Focus on the previous element on smart list")), this);
auto focusOnContactSearchBarSC = new QShortcut(QKeySequence(tr("Ctrl+F", "Focus on contact search bar")), this);
auto answerCallSC = new QShortcut(QKeySequence(tr("Ctrl+Y", "Answer an incoming call")), this);
auto declineCallSC = new QShortcut(QKeySequence(tr("Ctrl+D", "Decline the call")), this);
auto maximizeScreenSC = new QShortcut(QKeySequence(tr("F11", "Maximize Screen")), this);
auto navigateToMediaSettingsSC = new QShortcut(QKeySequence(tr("Ctrl+M", "Navigate to media setting")), this);
auto navigateToGeneralSettingsSC = new QShortcut(QKeySequence(tr("Ctrl+G", "Navigate to general setting")), this);
auto navigateToAccountSettingsSC = new QShortcut(QKeySequence(tr("Ctrl+I", "Navigate to account setting")), this);
// connections
connect(startAudioCallSC, &QShortcut::activated,
[this] {
auto convModel = LRCInstance::getCurrentConversationModel();
auto convUid = LRCInstance::getCurrentConvUid();
if (convModel && !convUid.empty())
convModel->placeAudioOnlyCall(convUid);
});
connect(startVideoCallSC, &QShortcut::activated,
[this] {
auto convModel = LRCInstance::getCurrentConversationModel();
auto convUid = LRCInstance::getCurrentConvUid();
if (convModel && !convUid.empty())
convModel->placeCall(convUid);
});
connect(clearConvHistorySC, &QShortcut::activated,
[this] {
auto convModel = LRCInstance::getCurrentConversationModel();
auto convUid = LRCInstance::getCurrentConvUid();
if (convModel && !convUid.empty()) {
auto reply = Utils::getReplyMessageBox(this,
QString("Clear Conversation History"),
QString("Do you really want to clear the conversation history with this contact ?"));
if (reply)
convModel->clearHistory(convUid);
}
});
connect(blockContactSC, &QShortcut::activated,
[this] {
auto convModel = LRCInstance::getCurrentConversationModel();
auto convUid = LRCInstance::getCurrentConvUid();
if (convModel && !convUid.empty()) {
auto reply = Utils::getReplyMessageBox(this,
QString("Block Contact"),
QString("Do you really want to block this contact ?"));
if (reply)
convModel->removeConversation(convUid, true);
}
});
connect(copyContactNameSC, &QShortcut::activated,
[this] {
QPointer<QClipboard> clipboard = QApplication::clipboard();
clipboard->setText(QString::fromStdString(
Utils::bestIdForContact(LRCInstance::getCurrentAccountInfo().contactModel->getContact(LRCInstance::getCurrentConversation().participants.front()))
));
});
connect(openAccountListSC, &QShortcut::activated,
[this] {
ui->currentAccountComboBox->activateComboBox();
});
connect(focusOnSmartListSC, &QShortcut::activated,
[this] {
ui->smartList->setCurrentIndex(ui->smartList->model()->index(0, 0));
});
connect(focusOnSmartListNextElementSC, &QShortcut::activated,
[this] {
ui->smartList->setCurrentIndex(ui->smartList->model()->index(ui->smartList->currentIndex().row() + 1, 0));
});
connect(focusOnSmartListPrevElementSC, &QShortcut::activated,
[this] {
ui->smartList->setCurrentIndex(ui->smartList->model()->index(ui->smartList->currentIndex().row() - 1, 0));
});
connect(focusOnContactSearchBarSC, &QShortcut::activated,
[this] {
ui->ringContactLineEdit->setFocus();
});
connect(answerCallSC, &QShortcut::activated,
[this] {
auto& convInfo = LRCInstance::getCurrentConversation();
if (!convInfo.callId.empty())
LRCInstance::getCurrentCallModel()->accept(convInfo.callId);
});
connect(declineCallSC, &QShortcut::activated,
[this] {
auto& convInfo = LRCInstance::getCurrentConversation();
auto status = LRCInstance::getCallInfoForConversation(convInfo)->status;
if (!convInfo.callId.empty()) {
if (status == lrc::api::call::Status::IN_PROGRESS || status == lrc::api::call::Status::OUTGOING_RINGING) {
LRCInstance::getCurrentCallModel()->hangUp(convInfo.callId);
} else if (status == lrc::api::call::Status::INCOMING_RINGING) {
LRCInstance::getCurrentCallModel()->refuse(convInfo.callId);
}
}
});
connect(maximizeScreenSC, &QShortcut::activated,
[this] {
if (MainWindow::instance().windowState().testFlag(Qt::WindowFullScreen) == true) {
MainWindow::instance().showNormal();
}
else {
MainWindow::instance().showFullScreen();
}
});
connect(navigateToMediaSettingsSC, &QShortcut::activated,
[this] {
emit NavigationSettingsPageRequested(SettingsMenu::Media);
});
connect(navigateToGeneralSettingsSC, &QShortcut::activated,
[this] {
emit NavigationSettingsPageRequested(SettingsMenu::General);
});
connect(navigateToAccountSettingsSC, &QShortcut::activated,
[this] {
emit NavigationSettingsPageRequested(SettingsMenu::Account);
});
}
void
CallWidget::ShowContextMenu(const QPoint& pos)
{
......@@ -1559,4 +1712,4 @@ void
CallWidget::Copy()
{
ui->messageView->copySelectedText(clipboard_);
}
}
\ No newline at end of file
......@@ -133,6 +133,7 @@ private:
void connectAccount(const std::string& accId);
void setCallPanelVisibility(bool visible);
void updateChatviewFrame();
void registerShortCuts();
QMenu* menu_;
QClipboard* clipboard_;
......
......@@ -43,6 +43,8 @@ public:
void setCurrentIndex(int index);
void updateComboBoxDisplay();
void canPlaceAudioOnlyCall(const std::string& convUid) { emit placeAudioOnlyCall(convUid); }
void activateComboBox() { showPopup(); }
void deactivateComboBox() { hidePopup(); }
signals:
void settingsButtonClicked();
......
......@@ -63,6 +63,13 @@ MainWindow::MainWindow(QWidget* parent)
}
}
connect(ui->callwidget, &NavWidget::NavigationSettingsPageRequested,
[this](SettingsMenu settingsPage) {
ui->settingswidget->navigated(true);
Utils::setStackWidget(ui->navStack, ui->navStack->widget(ScreenEnum::SetttingsScreen));
ui->settingswidget->setSelected(settingsPage);
});
connect(ui->navStack, SIGNAL(currentChanged(int)),
this, SLOT(slotCurrentChanged(int)),
Qt::QueuedConnection);
......
......@@ -138,32 +138,41 @@ MessageWebView::~MessageWebView()
{
}
void MessageWebView::dragEnterEvent(QDragEnterEvent* event)
void
MessageWebView::dragEnterEvent(QDragEnterEvent* event)
{
event->accept();
dragDroplabel_->show();
}
void MessageWebView::dragLeaveEvent(QDragLeaveEvent* event)
void
MessageWebView::dragLeaveEvent(QDragLeaveEvent* event)
{
event->accept();
}
void MessageWebView::dragMoveEvent(QDragMoveEvent* event)
void
MessageWebView::dragMoveEvent(QDragMoveEvent* event)
{
event->accept();
}
void MessageWebView::dropEvent(QDropEvent* event)
void
MessageWebView::dropEvent(QDropEvent* event)
{
event->accept();
}
void MessageWebView::resizeEvent(QResizeEvent *event)
void
MessageWebView::resizeEvent(QResizeEvent *event)
{
event->accept();
// resize label as messagewebview resizes
dragDroplabel_->setGeometry(this->x(),this->y(),this->width(),this->height());
}
bool MessageWebView::eventFilter(QObject *watched, QEvent *event)
bool
MessageWebView::eventFilter(QObject *watched, QEvent *event)
{
if (watched != dragDroplabel_) {
return false;
......@@ -206,7 +215,8 @@ bool MessageWebView::eventFilter(QObject *watched, QEvent *event)
}
}
void MessageWebView::setMessagesContent(const QString& text)
void
MessageWebView::setMessagesContent(const QString& text)
{
page()->runJavaScript(QStringLiteral("replaceText(`%1`)").arg(text));
}
......@@ -237,19 +247,22 @@ MessageWebView::setMessagesFileContent(const QString &path)
page()->runJavaScript(param);
}
void MessageWebView::copySelectedText(QClipboard* clipboard)
void
MessageWebView::copySelectedText(QClipboard* clipboard)
{
page()->runJavaScript(QStringLiteral("copy_text_selected();"), [clipboard, this](const QVariant& v) {
clipboard->setText(v.toString());
});
}
bool MessageWebView::textSelected()
bool
MessageWebView::textSelected()
{
return textSelected_;
}
void MessageWebView::runJsText()
void
MessageWebView::runJsText()
{
page()->runJavaScript(QStringLiteral("isTextSelected();"), [&, this](const QVariant &val) {
textSelected_ = val.toBool();
......@@ -297,7 +310,8 @@ MessageWebView::setRecordButtonsVisibility(bool visible)
page()->runJavaScript(s, QWebEngineScript::MainWorld);
}
void MessageWebView::buildView()
void
MessageWebView::buildView()
{
auto html = Utils::QByteArrayFromFile(":/chatview.html");
page()->setHtml(html, QUrl(":/chatview.html"));
......@@ -358,7 +372,8 @@ MessageWebView::removeStyleSheet(const QString &name)
page()->scripts().remove(script);
}
void MessageWebView::clear()
void
MessageWebView::clear()
{
QString s = QString::fromLatin1("clearMessages();");
page()->runJavaScript(s, QWebEngineScript::MainWorld);
......
......@@ -28,6 +28,12 @@ enum ScreenEnum {
END
};
enum SettingsMenu {
Account,
General,
Media
};
class NavWidget : public QWidget
{
Q_OBJECT
......@@ -41,6 +47,7 @@ public:
signals:
void NavigationRequested(ScreenEnum screen);
void NavigationSettingsPageRequested(SettingsMenu settingsPage);
protected slots:
virtual void slotAccountListChanged() = 0;
......
This diff is collapsed.
......@@ -47,6 +47,8 @@ public:
explicit SettingsWidget(QWidget* parent = nullptr);
~SettingsWidget();
void setSelected(SettingsMenu sel);
// NavWidget
virtual void navigated(bool to);
virtual void updateCustomUI();
......@@ -56,11 +58,6 @@ public slots:
private:
Ui::SettingsWidget* ui;
enum SettingsMenu {
Account,
General,
Media
};
enum RegName {
BLANK,
INVALIDFORM,
......@@ -70,7 +67,6 @@ private:
};
void setAvatar(PhotoboothWidget* avatarWidget);
void setSelected(SettingsMenu sel);
void updateAccountInfoDisplayed();
void resizeEvent(QResizeEvent* event);
bool sipPasswordHidden_ {false};
......@@ -90,6 +86,7 @@ private:
void stopPreviewing();
void startAudioMeter(bool async = true);
void stopAudioMeter(bool async = true);
void registerShortcuts();
QList<QMetaObject::Connection> accountConnections_;
QString registeredName_;
......@@ -109,6 +106,7 @@ private:
const int itemHeight_ = 55;
int previousDeviceSize_ {static_cast<int>(LRCInstance::avModel().getDevices().size())};
bool deviceWasEmpty_ {false};
QSet<int> keyPressed_;
QMovie* lookupSpinnerMovie_;
QPixmap statusSuccessPixmap_;
......
......@@ -581,6 +581,13 @@ Utils::isContactValid(const std::string& contactUid, const lrc::api::Conversatio
!contact.profileInfo.uri.empty();
}
bool Utils::getReplyMessageBox(QWidget* widget, const QString& title, const QString& text)
{
if (QMessageBox::question(widget, title, text, QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes)
return true;
return false;
}
QImage
Utils::conversationPhoto(const std::string & convUid, const lrc::api::account::Info& accountInfo)
{
......
......@@ -29,6 +29,7 @@
#include <QStackedWidget>
#include <QTextDocument>
#include <QItemDelegate>
#include <QMessageBox>
#include <QtGlobal>
#include <QCryptographicHash>
#include <QListWidget>
......@@ -94,6 +95,7 @@ lrc::api::profile::Type profileType(const lrc::api::conversation::Info & conv, c
std::string formatTimeString(const std::time_t& timestamp);
bool isInteractionGenerated(const lrc::api::interaction::Type& interaction);
bool isContactValid(const std::string& contactUid, const lrc::api::ConversationModel& model);
bool getReplyMessageBox(QWidget* widget, const QString& title, const QString& text);
// image
QImage getCirclePhoto(const QImage original, int sizePhoto);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment