diff --git a/widget/emoticonswidget.cpp b/widget/emoticonswidget.cpp index bab7abe8d..f471e8729 100644 --- a/widget/emoticonswidget.cpp +++ b/widget/emoticonswidget.cpp @@ -66,6 +66,7 @@ EmoticonsWidget::EmoticonsWidget(QWidget *parent) : { QRadioButton* pageButton = new QRadioButton; pageButton->setProperty("pageIndex", i); + pageButton->setCursor(Qt::PointingHandCursor); pageButton->setChecked(i == 0); buttonLayout->addWidget(pageButton); @@ -80,6 +81,7 @@ EmoticonsWidget::EmoticonsWidget(QWidget *parent) : button->setIcon(SmileyPack::getInstance().getAsIcon(set[0])); button->setToolTip(set.join(" ")); button->setProperty("sequence", set[0]); + button->setCursor(Qt::PointingHandCursor); button->setFlat(true); connect(button, &QPushButton::clicked, this, &EmoticonsWidget::onSmileyClicked); diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 6863107bb..788596dd6 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -19,6 +19,9 @@ #include #include #include +#include +#include +#include #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()); + } + } +} diff --git a/widget/form/chatform.h b/widget/form/chatform.h index fd270fd64..4604d54e3 100644 --- a/widget/form/chatform.h +++ b/widget/form/chatform.h @@ -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; diff --git a/widget/form/genericchatform.cpp b/widget/form/genericchatform.cpp index 0e765b397..cff9e3b50 100644 --- a/widget/form/genericchatform.cpp +++ b/widget/form/genericchatform.cpp @@ -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 diff --git a/widget/form/genericchatform.h b/widget/form/genericchatform.h index 72dc94fd9..c824d5e85 100644 --- a/widget/form/genericchatform.h +++ b/widget/form/genericchatform.h @@ -17,7 +17,7 @@ #ifndef GENERICCHATFORM_H #define GENERICCHATFORM_H -#include +#include #include #include @@ -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; diff --git a/widget/form/groupchatform.cpp b/widget/form/groupchatform.cpp index 907787fd3..4dc6c7e0d 100644 --- a/widget/form/groupchatform.cpp +++ b/widget/form/groupchatform.cpp @@ -19,7 +19,10 @@ #include "widget/groupwidget.h" #include "widget/tool/chattextedit.h" #include "widget/croppinglabel.h" +#include "core.h" #include +#include +#include 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); + } +} + diff --git a/widget/form/groupchatform.h b/widget/form/groupchatform.h index cdf20a113..a544034de 100644 --- a/widget/form/groupchatform.h +++ b/widget/form/groupchatform.h @@ -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; diff --git a/widget/friendwidget.cpp b/widget/friendwidget.cpp index fcb6a416f..869bc4192 100644 --- a/widget/friendwidget.cpp +++ b/widget/friendwidget.cpp @@ -24,6 +24,9 @@ #include "widget/form/chatform.h" #include #include +#include +#include +#include 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); + } +} diff --git a/widget/friendwidget.h b/widget/friendwidget.h index a1bae68a1..aa225d533 100644 --- a/widget/friendwidget.h +++ b/widget/friendwidget.h @@ -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