mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
drag&drop support
This commit is contained in:
parent
458636e6d6
commit
ad5a175f7d
|
@ -19,6 +19,9 @@
|
|||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QMimeData>
|
||||
#include <QFileInfo>
|
||||
#include <QDragEnterEvent>
|
||||
#include "chatform.h"
|
||||
#include "friend.h"
|
||||
#include "widget/friendwidget.h"
|
||||
|
@ -52,6 +55,8 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
||||
connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked);
|
||||
connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed);
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
ChatForm::~ChatForm()
|
||||
|
@ -472,3 +477,23 @@ void ChatForm::onAvatarChange(int FriendId, const QPixmap &pic)
|
|||
|
||||
avatarLabel->setPixmap(pic);
|
||||
}
|
||||
|
||||
void ChatForm::dragEnterEvent(QDragEnterEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasUrls())
|
||||
ev->acceptProposedAction();
|
||||
}
|
||||
|
||||
void ChatForm::dropEvent(QDropEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasUrls())
|
||||
{
|
||||
for (QUrl url : ev->mimeData()->urls())
|
||||
{
|
||||
QFileInfo info(url.path());
|
||||
|
||||
if (info.exists())
|
||||
Core::getInstance()->sendFile(f->friendId, info.fileName(), info.absoluteFilePath(), info.size());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,6 +69,11 @@ private slots:
|
|||
void onFileTansBtnClicked(QString widgetName, QString buttonName);
|
||||
void onFileSendFailed(int FriendId, const QString &fname);
|
||||
|
||||
protected:
|
||||
// drag & drop
|
||||
void dragEnterEvent(QDragEnterEvent* ev);
|
||||
void dropEvent(QDropEvent* ev);
|
||||
|
||||
private:
|
||||
Friend* f;
|
||||
CroppingLabel *statusMessageLabel;
|
||||
|
|
|
@ -27,12 +27,12 @@
|
|||
#include "widget/chatareawidget.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
|
||||
GenericChatForm::GenericChatForm(QObject *parent) :
|
||||
QObject(parent)
|
||||
GenericChatForm::GenericChatForm(QWidget *parent) :
|
||||
QWidget(parent)
|
||||
{
|
||||
curRow = 0;
|
||||
|
||||
mainWidget = new QWidget(); headWidget = new QWidget();
|
||||
headWidget = new QWidget();
|
||||
|
||||
nameLabel = new CroppingLabel();
|
||||
avatarLabel = new QLabel();
|
||||
|
@ -84,7 +84,7 @@ GenericChatForm::GenericChatForm(QObject *parent) :
|
|||
micButton->setObjectName("green");
|
||||
micButton->setStyleSheet(micButtonStylesheet);
|
||||
|
||||
mainWidget->setLayout(mainLayout);
|
||||
setLayout(mainLayout);
|
||||
mainLayout->addWidget(chatWidget);
|
||||
mainLayout->addLayout(mainFootLayout);
|
||||
mainLayout->setMargin(0);
|
||||
|
@ -129,10 +129,10 @@ void GenericChatForm::setName(const QString &newName)
|
|||
|
||||
void GenericChatForm::show(Ui::MainWindow &ui)
|
||||
{
|
||||
ui.mainContent->layout()->addWidget(mainWidget);
|
||||
ui.mainContent->layout()->addWidget(this);
|
||||
ui.mainHead->layout()->addWidget(headWidget);
|
||||
mainWidget->show();
|
||||
headWidget->show();
|
||||
QWidget::show();
|
||||
}
|
||||
|
||||
void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
||||
|
@ -172,12 +172,6 @@ void GenericChatForm::addMessage(QString author, QString message, QDateTime date
|
|||
previousName = author;
|
||||
}
|
||||
|
||||
GenericChatForm::~GenericChatForm()
|
||||
{
|
||||
delete mainWidget;
|
||||
delete headWidget;
|
||||
}
|
||||
|
||||
void GenericChatForm::onEmoteButtonClicked()
|
||||
{
|
||||
// don't show the smiley selection widget if there are no smileys available
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#ifndef GENERICCHATFORM_H
|
||||
#define GENERICCHATFORM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QPoint>
|
||||
#include <QDateTime>
|
||||
|
||||
|
@ -35,12 +35,11 @@ namespace Ui {
|
|||
class MainWindow;
|
||||
}
|
||||
|
||||
class GenericChatForm : public QObject
|
||||
class GenericChatForm : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GenericChatForm(QObject *parent = 0);
|
||||
virtual ~GenericChatForm();
|
||||
GenericChatForm(QWidget *parent = 0);
|
||||
|
||||
virtual void setName(const QString &newName);
|
||||
virtual void show(Ui::MainWindow &ui);
|
||||
|
@ -62,7 +61,7 @@ protected slots:
|
|||
protected:
|
||||
CroppingLabel *nameLabel;
|
||||
QLabel *avatarLabel;
|
||||
QWidget *mainWidget, *headWidget;
|
||||
QWidget *headWidget;
|
||||
QPushButton *fileButton, *emoteButton, *callButton, *videoButton, *volButton, *micButton;
|
||||
QVBoxLayout *headTextLayout;
|
||||
ChatTextEdit *msgEdit;
|
||||
|
|
|
@ -19,7 +19,10 @@
|
|||
#include "widget/groupwidget.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
#include "widget/croppinglabel.h"
|
||||
#include "core.h"
|
||||
#include <QPushButton>
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
|
||||
GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
: group(chatGroup)
|
||||
|
@ -58,11 +61,8 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
|||
|
||||
connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
||||
connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered()));
|
||||
}
|
||||
|
||||
GroupChatForm::~GroupChatForm()
|
||||
{
|
||||
|
||||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void GroupChatForm::onSendTriggered()
|
||||
|
@ -94,3 +94,19 @@ void GroupChatForm::onUserListChanged()
|
|||
names.chop(2);
|
||||
namesList->setText(names);
|
||||
}
|
||||
|
||||
void GroupChatForm::dragEnterEvent(QDragEnterEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasFormat("friend"))
|
||||
ev->acceptProposedAction();
|
||||
}
|
||||
|
||||
void GroupChatForm::dropEvent(QDropEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasFormat("friend"))
|
||||
{
|
||||
int friendId = ev->mimeData()->data("friend").toInt();
|
||||
Core::getInstance()->groupInviteFriend(friendId, group->groupId);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,13 +27,18 @@ class GroupChatForm : public GenericChatForm
|
|||
Q_OBJECT
|
||||
public:
|
||||
GroupChatForm(Group* chatGroup);
|
||||
~GroupChatForm();
|
||||
|
||||
void addGroupMessage(QString message, int peerId);
|
||||
void onUserListChanged();
|
||||
|
||||
private slots:
|
||||
void onSendTriggered();
|
||||
|
||||
protected:
|
||||
// drag & drop
|
||||
void dragEnterEvent(QDragEnterEvent* ev);
|
||||
void dropEvent(QDropEvent* ev);
|
||||
|
||||
private:
|
||||
Group* group;
|
||||
QLabel *nusersLabel, *namesList;
|
||||
|
|
|
@ -24,6 +24,9 @@
|
|||
#include "widget/form/chatform.h"
|
||||
#include <QContextMenuEvent>
|
||||
#include <QMenu>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QApplication>
|
||||
|
||||
FriendWidget::FriendWidget(int FriendId, QString id)
|
||||
: friendId(FriendId), isDefaultAvatar{true}
|
||||
|
@ -203,3 +206,28 @@ void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
|
|||
QPixmap scaled = pic.scaled(40,40,Qt::KeepAspectRatio,Qt::SmoothTransformation);
|
||||
avatar.setPixmap(scaled);
|
||||
}
|
||||
|
||||
void FriendWidget::mousePressEvent(QMouseEvent *ev)
|
||||
{
|
||||
if (ev->button() == Qt::LeftButton)
|
||||
dragStartPos = ev->pos();
|
||||
}
|
||||
|
||||
void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
||||
{
|
||||
if (!(ev->buttons() & Qt::LeftButton))
|
||||
return;
|
||||
|
||||
if ((dragStartPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
|
||||
{
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* mdata = new QMimeData;
|
||||
mdata->setData("friend", QString::number(friendId).toLatin1());
|
||||
|
||||
drag->setMimeData(mdata);
|
||||
if (avatar.pixmap())
|
||||
drag->setPixmap(*avatar.pixmap());
|
||||
|
||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,11 +44,16 @@ signals:
|
|||
public slots:
|
||||
void onAvatarChange(int FriendId, const QPixmap& pic);
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* ev);
|
||||
void mouseMoveEvent(QMouseEvent* ev);
|
||||
|
||||
public:
|
||||
int friendId;
|
||||
QLabel avatar, statusPic;
|
||||
CroppingLabel name, statusMessage;
|
||||
bool isDefaultAvatar;
|
||||
QPoint dragStartPos;
|
||||
};
|
||||
|
||||
#endif // FRIENDWIDGET_H
|
||||
|
|
Loading…
Reference in New Issue
Block a user