diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index e93ad02069..992b479ce6 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -139,6 +139,8 @@ enum { WrongPasscodeTimeout = 1500, SessionsShortPollTimeout = 60000, + + ChoosePeerByDragTimeout = 1000, // 1 second mouse not moved to choose dialog when dragging a file }; inline bool isServiceUser(uint64 id) { diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 94168759a4..f0f4fdd9be 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -1410,6 +1410,9 @@ DialogsWidget::DialogsWidget(MainWidget *parent) : QWidget(parent) connect(&_newGroup, SIGNAL(clicked()), this, SLOT(onNewGroup())); connect(&_cancelSearch, SIGNAL(clicked()), this, SLOT(onCancelSearch())); + _chooseByDragTimer.setSingleShot(true); + connect(&_chooseByDragTimer, SIGNAL(timeout()), this, SLOT(onChooseByDrag())); + setAcceptDrops(true); _searchTimer.setSingleShot(true); @@ -1628,6 +1631,10 @@ void DialogsWidget::onNeedSearchMessages() { } } +void DialogsWidget::onChooseByDrag() { + list.choosePeer(); +} + void DialogsWidget::searchMessages(const QString &query) { if (_filter.text() != query) { _filter.setText(query); @@ -1774,15 +1781,20 @@ void DialogsWidget::dragEnterEvent(QDragEnterEvent *e) { e->setDropAction(Qt::CopyAction); e->accept(); updateDragInScroll(scroll.geometry().contains(e->pos())); - } else if (false && App::main() && App::main()->getDragState(e->mimeData()) != DragStateNone) { + } else if (App::main() && App::main()->getDragState(e->mimeData()) != DragStateNone) { e->setDropAction(Qt::CopyAction); e->accept(); } + _chooseByDragTimer.stop(); } void DialogsWidget::dragMoveEvent(QDragMoveEvent *e) { if (scroll.geometry().contains(e->pos())) { - if (_dragForward) updateDragInScroll(true); + if (_dragForward) { + updateDragInScroll(true); + } else { + _chooseByDragTimer.start(ChoosePeerByDragTimeout); + } PeerData *p = list.updateFromParentDrag(mapToGlobal(e->pos())); if (p) { e->setDropAction(Qt::CopyAction); @@ -1798,7 +1810,11 @@ void DialogsWidget::dragMoveEvent(QDragMoveEvent *e) { } void DialogsWidget::dragLeaveEvent(QDragLeaveEvent *e) { - if (_dragForward) updateDragInScroll(false); + if (_dragForward) { + updateDragInScroll(false); + } else { + _chooseByDragTimer.stop(); + } list.leaveEvent(0); e->accept(); } @@ -1815,6 +1831,7 @@ void DialogsWidget::updateDragInScroll(bool inScroll) { } void DialogsWidget::dropEvent(QDropEvent *e) { + _chooseByDragTimer.stop(); if (scroll.geometry().contains(e->pos())) { PeerData *p = list.updateFromParentDrag(mapToGlobal(e->pos())); if (p) { @@ -1822,7 +1839,7 @@ void DialogsWidget::dropEvent(QDropEvent *e) { if (e->mimeData()->hasFormat(qsl("application/x-td-forward-selected"))) { App::main()->onForward(p->id, true); } else { - App::main()->showPeer(p->id, 0, false, true); + App::main()->onFilesDrop(p->id, e->mimeData()); } } } diff --git a/Telegram/SourceFiles/dialogswidget.h b/Telegram/SourceFiles/dialogswidget.h index 863570d9ec..1d1cf6661b 100644 --- a/Telegram/SourceFiles/dialogswidget.h +++ b/Telegram/SourceFiles/dialogswidget.h @@ -236,11 +236,14 @@ public slots: bool onSearchMessages(bool searchCache = false); void onNeedSearchMessages(); + void onChooseByDrag(); + private: bool _drawShadow; bool _dragInScroll, _dragForward; + QTimer _chooseByDragTimer; void unreadCountsReceived(const QVector &dialogs); bool dialogsFailed(const RPCError &error); diff --git a/Telegram/SourceFiles/dropdown.cpp b/Telegram/SourceFiles/dropdown.cpp index 9be6f8c1ae..edf365b07e 100644 --- a/Telegram/SourceFiles/dropdown.cpp +++ b/Telegram/SourceFiles/dropdown.cpp @@ -384,7 +384,7 @@ void DragArea::dragLeaveEvent(QDragLeaveEvent *e) { void DragArea::dropEvent(QDropEvent *e) { static_cast(parentWidget())->dropEvent(e); if (e->isAccepted()) { - emit dropped(e); + emit dropped(e->mimeData()); } } diff --git a/Telegram/SourceFiles/dropdown.h b/Telegram/SourceFiles/dropdown.h index dff92377a5..84968ca263 100644 --- a/Telegram/SourceFiles/dropdown.h +++ b/Telegram/SourceFiles/dropdown.h @@ -110,7 +110,7 @@ public: signals: - void dropped(QDropEvent *e); + void dropped(const QMimeData *data); public slots: diff --git a/Telegram/SourceFiles/historywidget.cpp b/Telegram/SourceFiles/historywidget.cpp index 480c84563a..4b76e85641 100644 --- a/Telegram/SourceFiles/historywidget.cpp +++ b/Telegram/SourceFiles/historywidget.cpp @@ -2243,8 +2243,8 @@ HistoryWidget::HistoryWidget(QWidget *parent) : TWidget(parent) _attachDragDocument.hide(); _attachDragPhoto.hide(); - connect(&_attachDragDocument, SIGNAL(dropped(QDropEvent*)), this, SLOT(onDocumentDrop(QDropEvent*))); - connect(&_attachDragPhoto, SIGNAL(dropped(QDropEvent*)), this, SLOT(onPhotoDrop(QDropEvent*))); + connect(&_attachDragDocument, SIGNAL(dropped(const QMimeData*)), this, SLOT(onDocumentDrop(const QMimeData*))); + connect(&_attachDragPhoto, SIGNAL(dropped(const QMimeData*)), this, SLOT(onPhotoDrop(const QMimeData*))); } void HistoryWidget::start() { @@ -3931,15 +3931,45 @@ void HistoryWidget::dropEvent(QDropEvent *e) { e->acceptProposedAction(); } -void HistoryWidget::onDocumentDrop(QDropEvent *e) { +void HistoryWidget::onPhotoDrop(const QMimeData *data) { if (!hist) return; - QStringList files = getMediasFromMime(e->mimeData()); + if (data->hasImage()) { + QImage image = qvariant_cast(data->imageData()); + if (image.isNull()) return; + + uploadImage(image, false, data->text()); + } else { + QStringList files = getMediasFromMime(data); + if (files.isEmpty()) return; + + uploadMedias(files, ToPreparePhoto); + } +} + +void HistoryWidget::onDocumentDrop(const QMimeData *data) { + if (!hist) return; + + QStringList files = getMediasFromMime(data); if (files.isEmpty()) return; uploadMedias(files, ToPrepareDocument); } +void HistoryWidget::onFilesDrop(const QMimeData *data) { + if (data->hasImage()) { + QImage image = qvariant_cast(data->imageData()); + if (image.isNull()) return; + + uploadImage(image, false, data->text()); + } else { + QStringList files = getMediasFromMime(data); + if (files.isEmpty()) return; + + uploadMedias(files, ToPrepareAuto); + } +} + void HistoryWidget::onKbToggle(bool manual) { if (_kbShown || _kbReplyTo) { _kbHide.hide(); @@ -4009,22 +4039,6 @@ void HistoryWidget::onCmdStart() { _field.moveCursor(QTextCursor::End); } -void HistoryWidget::onPhotoDrop(QDropEvent *e) { - if (!hist) return; - - if (e->mimeData()->hasImage()) { - QImage image = qvariant_cast(e->mimeData()->imageData()); - if (image.isNull()) return; - - uploadImage(image); - } else { - QStringList files = getMediasFromMime(e->mimeData()); - if (files.isEmpty()) return; - - uploadMedias(files, ToPreparePhoto); - } -} - void HistoryWidget::contextMenuEvent(QContextMenuEvent *e) { if (!_list) return; diff --git a/Telegram/SourceFiles/historywidget.h b/Telegram/SourceFiles/historywidget.h index bfdb609a8a..61bf91ec50 100644 --- a/Telegram/SourceFiles/historywidget.h +++ b/Telegram/SourceFiles/historywidget.h @@ -509,8 +509,9 @@ public slots: void onPhotoSelect(); void onDocumentSelect(); - void onPhotoDrop(QDropEvent *e); - void onDocumentDrop(QDropEvent *e); + void onPhotoDrop(const QMimeData *data); + void onDocumentDrop(const QMimeData *data); + void onFilesDrop(const QMimeData *data); void onKbToggle(bool manual = true); void onCmdStart(); diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 03750f421c..b3229f9250 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -571,6 +571,11 @@ void MainWidget::onSendPaths(const PeerId &peer) { history.onSendPaths(peer); } +void MainWidget::onFilesDrop(const PeerId &peer, const QMimeData *data) { + showPeer(peer, 0, false, true); + history.onFilesDrop(data); +} + void MainWidget::noHider(HistoryHider *destroyed) { if (hider == destroyed) { hider = 0; @@ -616,12 +621,13 @@ void MainWidget::hiderLayer(HistoryHider *h) { hider = h; connect(hider, SIGNAL(forwarded()), &dialogs, SLOT(onCancelSearch())); - dialogsToUp(); if (cWideMode()) { hider->show(); resizeEvent(0); dialogs.activate(); } else { + dialogsToUp(); + hider->hide(); dialogs.enableShadow(false); QPixmap animCache = myGrab(this, QRect(0, 0, _dialogsWidth, height())); diff --git a/Telegram/SourceFiles/mainwidget.h b/Telegram/SourceFiles/mainwidget.h index c0ca4cc7a2..cbeddd97d5 100644 --- a/Telegram/SourceFiles/mainwidget.h +++ b/Telegram/SourceFiles/mainwidget.h @@ -257,6 +257,7 @@ public: void onForward(const PeerId &peer, bool forwardSelected); void onShareContact(const PeerId &peer, UserData *contact); void onSendPaths(const PeerId &peer); + void onFilesDrop(const PeerId &peer, const QMimeData *data); bool selectingPeer(bool withConfirm = false); void offerPeer(PeerId peer); void focusPeerSelect();