Commit cdc978bf authored by Edric Milaret's avatar Edric Milaret

im: add copy/paste features

Also move the im code to live in his own class

Refs #74690

Change-Id: Ifa5b45a82f9b6b885e09d0207b5f15a4675b7409
parent 3e6aefed
......@@ -42,7 +42,9 @@ SOURCES += main.cpp\
historydelegate.cpp \
contactdelegate.cpp \
selectareadialog.cpp \
accountserializationadapter.cpp
accountserializationadapter.cpp \
instantmessagingwidget.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -60,7 +62,8 @@ HEADERS += mainwindow.h \
historydelegate.h \
contactdelegate.h \
selectareadialog.h \
accountserializationadapter.h
accountserializationadapter.h \
instantmessagingwidget.h
FORMS += mainwindow.ui \
callwidget.ui \
......@@ -70,7 +73,8 @@ FORMS += mainwindow.ui \
accountdetails.ui \
aboutdialog.ui \
pivotviewwidget.ui \
wizarddialog.ui
wizarddialog.ui \
instantmessagingwidget.ui
win32: LIBS += -lole32 -luuid -lshlwapi
......
......@@ -227,53 +227,6 @@ CallWidget::callStateChanged(Call* call, Call::State previousState)
ui->callStateLabel->setText("Call State : " + call->toHumanStateName());
}
void
CallWidget::setMediaText(Call *call)
{
if (call != nullptr) {
connect(call, SIGNAL(mediaAdded(Media::Media*)),
this, SLOT(mediaAdd(Media::Media*)));
Media::Text *textMedia = call->addOutgoingMedia<Media::Text>();
connect(ui->messageInput, &QLineEdit::returnPressed, [=]()
{
textMedia->send(ui->messageInput->text());
ui->messageInput->clear();
});
ui->messageInput->show();
} else {
ui->messageOutput->disconnect();
ui->messageInput->disconnect();
ui->messageOutput->hide();
ui->messageInput->hide();
}
}
void
CallWidget::mediaAdd(Media::Media *media)
{
switch(media->type()) {
case Media::Media::Type::AUDIO:
break;
case Media::Media::Type::VIDEO:
break;
case Media::Media::Type::TEXT:
if (media->direction() == Media::Text::Direction::IN) {
ui->messageOutput->setModel(
static_cast<Media::Text*>(media)->recording()->
instantMessagingModel());
connect(ui->messageOutput->model(),
SIGNAL(rowsInserted(const QModelIndex&, int, int)),
ui->messageOutput, SLOT(scrollToBottom()));
ui->messageOutput->show();
}
break;
case Media::Media::Type::FILE:
break;
default:
break;
}
}
void
CallWidget::on_callList_activated(const QModelIndex &index)
{
......@@ -370,10 +323,10 @@ CallWidget::setActualCall(Call* value)
actualCall_ = value;
ui->holdButton->setEnabled(actualCall_ != nullptr);
ui->hangupButton->setEnabled(actualCall_ != nullptr);
ui->messageInput->setEnabled(actualCall_ != nullptr);
ui->messageOutput->setEnabled(actualCall_ != nullptr);
setMediaText(actualCall_);
ui->instantMessagingWidget->setVisible(actualCall_ != nullptr);
ui->instantMessagingWidget->setMediaText(actualCall_);
}
void
CallWidget::on_sortComboBox_currentIndexChanged(int index)
{
......
......@@ -25,11 +25,11 @@
#include <QMenu>
#include "navwidget.h"
#include "instantmessagingwidget.h"
#include "callmodel.h"
#include "video/renderer.h"
#include "video/previewmanager.h"
#include "categorizedhistorymodel.h"
namespace Ui {
......@@ -67,7 +67,6 @@ private slots:
void addedCall(Call *call, Call *parent);
void callStateChanged(Call *call, Call::State previousState);
void findRingAccount(QModelIndex idx1, QModelIndex idx2, QVector<int> vec);
void mediaAdd(Media::Media* media);
private:
Ui::CallWidget *ui;
......@@ -80,7 +79,6 @@ private:
private:
void findRingAccount();
void setActualCall(Call *value);
void setMediaText(Call* call);
};
#endif // CALLWIDGET_H
......@@ -217,7 +217,7 @@
<string>Hold/Unhold</string>
</property>
<property name="icon">
<iconset resource="ressources.qrc">
<iconset>
<normaloff>:/images/phone-paused.png</normaloff>:/images/phone-paused.png</iconset>
</property>
</widget>
......@@ -237,7 +237,7 @@
<string>Hangup</string>
</property>
<property name="icon">
<iconset resource="ressources.qrc">
<iconset>
<normaloff>:/images/phone-hangup.png</normaloff>:/images/phone-hangup.png</iconset>
</property>
</widget>
......@@ -296,7 +296,7 @@
<string>Accept</string>
</property>
<property name="icon">
<iconset resource="ressources.qrc">
<iconset>
<normaloff>:/images/phone.png</normaloff>:/images/phone.png</iconset>
</property>
</widget>
......@@ -307,7 +307,7 @@
<string>Refuse</string>
</property>
<property name="icon">
<iconset resource="ressources.qrc">
<iconset>
<normaloff>:/images/phone-hangup.png</normaloff>:/images/phone-hangup.png</iconset>
</property>
</widget>
......@@ -348,7 +348,7 @@
<string/>
</property>
<property name="icon">
<iconset resource="ressources.qrc">
<iconset>
<normaloff>:/images/speaker-off.png</normaloff>:/images/speaker-off.png</iconset>
</property>
<property name="iconSize">
......@@ -372,7 +372,7 @@
<string/>
</property>
<property name="icon">
<iconset resource="ressources.qrc">
<iconset>
<normaloff>:/images/microphone-off.png</normaloff>:/images/microphone-off.png</iconset>
</property>
<property name="iconSize">
......@@ -398,32 +398,13 @@
</widget>
</item>
<item>
<widget class="QListView" name="messageOutput">
<widget class="InstantMessagingWidget" name="instantMessagingWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="flow">
<enum>QListView::TopToBottom</enum>
</property>
<property name="isWrapping" stdset="0">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="messageInput">
<property name="placeholderText">
<string>Send text message...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
......@@ -438,9 +419,13 @@
<header>videowidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>InstantMessagingWidget</class>
<extends>QWidget</extends>
<header>instantmessagingwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
</resources>
<resources/>
<connections/>
</ui>
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "instantmessagingwidget.h"
#include "ui_instantmessagingwidget.h"
#include <QApplication>
#include <QClipboard>
#include <QMenu>
#include "media/text.h"
#include "media/textrecording.h"
InstantMessagingWidget::InstantMessagingWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::InstantMessagingWidget)
{
ui->setupUi(this);
ui->messageInput->hide();
ui->messageOutput->hide();
ui->messageOutput->setContextMenuPolicy(Qt::ActionsContextMenu);
auto copyAction = new QAction("Copy", this);
ui->messageOutput->addAction(copyAction);
connect(copyAction, &QAction::triggered, [=]() {
copyToClipboard();
});
}
InstantMessagingWidget::~InstantMessagingWidget()
{
delete ui;
}
void
InstantMessagingWidget::setMediaText(Call *call)
{
if (call != nullptr) {
connect(call, SIGNAL(mediaAdded(Media::Media*)),
this, SLOT(mediaAdd(Media::Media*)));
Media::Text *textMedia = call->addOutgoingMedia<Media::Text>();
connect(ui->messageInput, &QLineEdit::returnPressed, [=]()
{
textMedia->send(ui->messageInput->text());
ui->messageInput->clear();
});
ui->messageInput->show();
} else {
ui->messageOutput->disconnect();
ui->messageInput->disconnect();
ui->messageOutput->hide();
ui->messageInput->hide();
}
}
void
InstantMessagingWidget::mediaAdd(Media::Media *media)
{
switch(media->type()) {
case Media::Media::Type::AUDIO:
break;
case Media::Media::Type::VIDEO:
break;
case Media::Media::Type::TEXT:
if (media->direction() == Media::Text::Direction::IN) {
ui->messageOutput->setModel(
static_cast<Media::Text*>(media)->recording()->
instantMessagingModel());
connect(ui->messageOutput->model(),
SIGNAL(rowsInserted(const QModelIndex&, int, int)),
ui->messageOutput, SLOT(scrollToBottom()));
ui->messageOutput->show();
}
break;
case Media::Media::Type::FILE:
break;
default:
break;
}
}
void
InstantMessagingWidget::keyPressEvent(QKeyEvent *event)
{
if (event->matches(QKeySequence::Copy)) {
copyToClipboard();
}
}
void
InstantMessagingWidget::copyToClipboard()
{
auto idx = ui->messageOutput->currentIndex();
if (idx.isValid()) {
auto text = ui->messageOutput->model()->data(idx);
QApplication::clipboard()->setText(text.value<QString>());
}
}
/***************************************************************************
* Copyright (C) 2015 by Savoir-Faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com>*
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#ifndef INSTANTMESSAGINGWIDGET_H
#define INSTANTMESSAGINGWIDGET_H
#include <QWidget>
#include <QKeyEvent>
#include "call.h"
#include "media/media.h"
namespace Ui {
class InstantMessagingWidget;
}
class InstantMessagingWidget : public QWidget
{
Q_OBJECT
public:
explicit InstantMessagingWidget(QWidget *parent = 0);
~InstantMessagingWidget();
void setMediaText(Call* call);
protected:
virtual void keyPressEvent(QKeyEvent *event);
private slots:
void mediaAdd(Media::Media *media);
private:
Ui::InstantMessagingWidget *ui;
void copyToClipboard();
};
#endif // INSTANTMESSAGINGWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InstantMessagingWidget</class>
<widget class="QWidget" name="InstantMessagingWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="messageOutput">
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="messageInput">
<property name="placeholderText">
<string>Send text message...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
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