mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 07:33:52 +02:00
Replaced creating of drag'n'drop area in HistoryWidget with new way.
This commit is contained in:
parent
9bf2940375
commit
24d02d5461
2 changed files with 14 additions and 98 deletions
|
@ -299,9 +299,6 @@ HistoryWidget::HistoryWidget(
|
||||||
return recordingAnimationCallback(now);
|
return recordingAnimationCallback(now);
|
||||||
})
|
})
|
||||||
, _kbScroll(this, st::botKbScroll)
|
, _kbScroll(this, st::botKbScroll)
|
||||||
, _attachDragState(DragState::None)
|
|
||||||
, _attachDragDocument(this)
|
|
||||||
, _attachDragPhoto(this)
|
|
||||||
, _topShadow(this) {
|
, _topShadow(this) {
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
|
@ -455,16 +452,18 @@ HistoryWidget::HistoryWidget(
|
||||||
_botKeyboardHide->addClickHandler([=] { toggleKeyboard(); });
|
_botKeyboardHide->addClickHandler([=] { toggleKeyboard(); });
|
||||||
_botCommandStart->addClickHandler([=] { startBotCommand(); });
|
_botCommandStart->addClickHandler([=] { startBotCommand(); });
|
||||||
|
|
||||||
_attachDragDocument->hide();
|
|
||||||
_attachDragPhoto->hide();
|
|
||||||
|
|
||||||
_topShadow->hide();
|
_topShadow->hide();
|
||||||
|
|
||||||
_attachDragDocument->setDroppedCallback([=](const QMimeData *data) {
|
_attachDragAreas = DragArea::SetupDragAreaToContainer(
|
||||||
|
this,
|
||||||
|
crl::guard(this, [=] { return (!_history || !_canSendMessages); }),
|
||||||
|
crl::guard(this, [=](bool f) { _field->setAcceptDrops(f); }),
|
||||||
|
crl::guard(this, [=] { updateControlsGeometry(); }));
|
||||||
|
_attachDragAreas.document->setDroppedCallback([=](const QMimeData *data) {
|
||||||
confirmSendingFiles(data, CompressConfirm::No);
|
confirmSendingFiles(data, CompressConfirm::No);
|
||||||
ActivateWindow(controller);
|
ActivateWindow(controller);
|
||||||
});
|
});
|
||||||
_attachDragPhoto->setDroppedCallback([=](const QMimeData *data) {
|
_attachDragAreas.photo->setDroppedCallback([=](const QMimeData *data) {
|
||||||
confirmSendingFiles(data, CompressConfirm::Yes);
|
confirmSendingFiles(data, CompressConfirm::Yes);
|
||||||
ActivateWindow(controller);
|
ActivateWindow(controller);
|
||||||
});
|
});
|
||||||
|
@ -1239,8 +1238,8 @@ void HistoryWidget::orderWidgets() {
|
||||||
_tabbedPanel->raise();
|
_tabbedPanel->raise();
|
||||||
}
|
}
|
||||||
_raiseEmojiSuggestions();
|
_raiseEmojiSuggestions();
|
||||||
_attachDragDocument->raise();
|
_attachDragAreas.document->raise();
|
||||||
_attachDragPhoto->raise();
|
_attachDragAreas.photo->raise();
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::updateStickersByEmoji() {
|
void HistoryWidget::updateStickersByEmoji() {
|
||||||
|
@ -2068,8 +2067,8 @@ void HistoryWidget::refreshScheduledToggle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HistoryWidget::contentOverlapped(const QRect &globalRect) {
|
bool HistoryWidget::contentOverlapped(const QRect &globalRect) {
|
||||||
return (_attachDragDocument->overlaps(globalRect)
|
return (_attachDragAreas.document->overlaps(globalRect)
|
||||||
|| _attachDragPhoto->overlaps(globalRect)
|
|| _attachDragAreas.photo->overlaps(globalRect)
|
||||||
|| _fieldAutocomplete->overlaps(globalRect)
|
|| _fieldAutocomplete->overlaps(globalRect)
|
||||||
|| (_tabbedPanel && _tabbedPanel->overlaps(globalRect))
|
|| (_tabbedPanel && _tabbedPanel->overlaps(globalRect))
|
||||||
|| (_inlineResults && _inlineResults->overlaps(globalRect)));
|
|| (_inlineResults && _inlineResults->overlaps(globalRect)));
|
||||||
|
@ -3411,30 +3410,7 @@ void HistoryWidget::sendButtonClicked() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::dragEnterEvent(QDragEnterEvent *e) {
|
|
||||||
if (!_history || !_canSendMessages) return;
|
|
||||||
|
|
||||||
_attachDragState = Storage::ComputeMimeDataState(e->mimeData());
|
|
||||||
updateDragAreas();
|
|
||||||
|
|
||||||
if (_attachDragState != DragState::None) {
|
|
||||||
e->setDropAction(Qt::IgnoreAction);
|
|
||||||
e->accept();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HistoryWidget::dragLeaveEvent(QDragLeaveEvent *e) {
|
|
||||||
if (_attachDragState != DragState::None || !_attachDragPhoto->isHidden() || !_attachDragDocument->isHidden()) {
|
|
||||||
_attachDragState = DragState::None;
|
|
||||||
updateDragAreas();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HistoryWidget::leaveEventHook(QEvent *e) {
|
void HistoryWidget::leaveEventHook(QEvent *e) {
|
||||||
if (_attachDragState != DragState::None || !_attachDragPhoto->isHidden() || !_attachDragDocument->isHidden()) {
|
|
||||||
_attachDragState = DragState::None;
|
|
||||||
updateDragAreas();
|
|
||||||
}
|
|
||||||
if (hasMouseTracking()) {
|
if (hasMouseTracking()) {
|
||||||
mouseMoveEvent(nullptr);
|
mouseMoveEvent(nullptr);
|
||||||
}
|
}
|
||||||
|
@ -3505,10 +3481,6 @@ void HistoryWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
_replyForwardPressed = false;
|
_replyForwardPressed = false;
|
||||||
update(0, _field->y() - st::historySendPadding - st::historyReplyHeight, width(), st::historyReplyHeight);
|
update(0, _field->y() - st::historySendPadding - st::historyReplyHeight, width(), st::historyReplyHeight);
|
||||||
}
|
}
|
||||||
if (_attachDragState != DragState::None || !_attachDragPhoto->isHidden() || !_attachDragDocument->isHidden()) {
|
|
||||||
_attachDragState = DragState::None;
|
|
||||||
updateDragAreas();
|
|
||||||
}
|
|
||||||
if (_recording) {
|
if (_recording) {
|
||||||
stopRecording(_peer && _inField);
|
stopRecording(_peer && _inField);
|
||||||
}
|
}
|
||||||
|
@ -3685,34 +3657,6 @@ QRect HistoryWidget::floatPlayerAvailableRect() {
|
||||||
return _peer ? mapToGlobal(_scroll->geometry()) : mapToGlobal(rect());
|
return _peer ? mapToGlobal(_scroll->geometry()) : mapToGlobal(rect());
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::updateDragAreas() {
|
|
||||||
_field->setAcceptDrops(_attachDragState == DragState::None);
|
|
||||||
updateControlsGeometry();
|
|
||||||
|
|
||||||
switch (_attachDragState) {
|
|
||||||
case DragState::None:
|
|
||||||
_attachDragDocument->otherLeave();
|
|
||||||
_attachDragPhoto->otherLeave();
|
|
||||||
break;
|
|
||||||
case DragState::Files:
|
|
||||||
_attachDragDocument->setText(tr::lng_drag_files_here(tr::now), tr::lng_drag_to_send_files(tr::now));
|
|
||||||
_attachDragDocument->otherEnter();
|
|
||||||
_attachDragPhoto->hideFast();
|
|
||||||
break;
|
|
||||||
case DragState::PhotoFiles:
|
|
||||||
_attachDragDocument->setText(tr::lng_drag_images_here(tr::now), tr::lng_drag_to_send_no_compression(tr::now));
|
|
||||||
_attachDragPhoto->setText(tr::lng_drag_photos_here(tr::now), tr::lng_drag_to_send_quick(tr::now));
|
|
||||||
_attachDragDocument->otherEnter();
|
|
||||||
_attachDragPhoto->otherEnter();
|
|
||||||
break;
|
|
||||||
case DragState::Image:
|
|
||||||
_attachDragPhoto->setText(tr::lng_drag_images_here(tr::now), tr::lng_drag_to_send_quick(tr::now));
|
|
||||||
_attachDragDocument->hideFast();
|
|
||||||
_attachDragPhoto->otherEnter();
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HistoryWidget::readyToForward() const {
|
bool HistoryWidget::readyToForward() const {
|
||||||
return _canSendMessages && !_toForward.empty();
|
return _canSendMessages && !_toForward.empty();
|
||||||
}
|
}
|
||||||
|
@ -3851,12 +3795,6 @@ bool HistoryWidget::kbWasHidden() const {
|
||||||
return _history && (_keyboard->forMsgId() == FullMsgId(_history->channelId(), _history->lastKeyboardHiddenId));
|
return _history && (_keyboard->forMsgId() == FullMsgId(_history->channelId(), _history->lastKeyboardHiddenId));
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::dropEvent(QDropEvent *e) {
|
|
||||||
_attachDragState = DragState::None;
|
|
||||||
updateDragAreas();
|
|
||||||
e->acceptProposedAction();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HistoryWidget::toggleKeyboard(bool manual) {
|
void HistoryWidget::toggleKeyboard(bool manual) {
|
||||||
auto fieldEnabled = canWriteMessage() && !_a_show.animating();
|
auto fieldEnabled = canWriteMessage() && !_a_show.animating();
|
||||||
if (_kbShown || _kbReplyTo) {
|
if (_kbShown || _kbReplyTo) {
|
||||||
|
@ -4598,23 +4536,6 @@ void HistoryWidget::updateControlsGeometry() {
|
||||||
_membersDropdown->setMaxHeight(countMembersDropdownHeightMax());
|
_membersDropdown->setMaxHeight(countMembersDropdownHeightMax());
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (_attachDragState) {
|
|
||||||
case DragState::Files:
|
|
||||||
_attachDragDocument->resize(width() - st::dragMargin.left() - st::dragMargin.right(), height() - st::dragMargin.top() - st::dragMargin.bottom());
|
|
||||||
_attachDragDocument->move(st::dragMargin.left(), st::dragMargin.top());
|
|
||||||
break;
|
|
||||||
case DragState::PhotoFiles:
|
|
||||||
_attachDragDocument->resize(width() - st::dragMargin.left() - st::dragMargin.right(), (height() - st::dragMargin.top() - st::dragMargin.bottom()) / 2);
|
|
||||||
_attachDragDocument->move(st::dragMargin.left(), st::dragMargin.top());
|
|
||||||
_attachDragPhoto->resize(_attachDragDocument->width(), _attachDragDocument->height());
|
|
||||||
_attachDragPhoto->move(st::dragMargin.left(), height() - _attachDragPhoto->height() - st::dragMargin.bottom());
|
|
||||||
break;
|
|
||||||
case DragState::Image:
|
|
||||||
_attachDragPhoto->resize(width() - st::dragMargin.left() - st::dragMargin.right(), height() - st::dragMargin.top() - st::dragMargin.bottom());
|
|
||||||
_attachDragPhoto->move(st::dragMargin.left(), st::dragMargin.top());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto topShadowLeft = (Adaptive::OneColumn() || _inGrab) ? 0 : st::lineWidth;
|
auto topShadowLeft = (Adaptive::OneColumn() || _inGrab) ? 0 : st::lineWidth;
|
||||||
auto topShadowRight = (Adaptive::ThreeColumn() && !_inGrab && _peer) ? st::lineWidth : 0;
|
auto topShadowRight = (Adaptive::ThreeColumn() && !_inGrab && _peer) ? st::lineWidth : 0;
|
||||||
_topShadow->setGeometryToLeft(
|
_topShadow->setGeometryToLeft(
|
||||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "history/history_drag_area.h"
|
||||||
#include "ui/widgets/tooltip.h"
|
#include "ui/widgets/tooltip.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "chat_helpers/field_autocomplete.h"
|
#include "chat_helpers/field_autocomplete.h"
|
||||||
|
@ -124,9 +125,6 @@ public:
|
||||||
void checkHistoryActivation();
|
void checkHistoryActivation();
|
||||||
|
|
||||||
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
void leaveToChildEvent(QEvent *e, QWidget *child) override;
|
||||||
void dragEnterEvent(QDragEnterEvent *e) override;
|
|
||||||
void dragLeaveEvent(QDragLeaveEvent *e) override;
|
|
||||||
void dropEvent(QDropEvent *e) override;
|
|
||||||
|
|
||||||
bool isItemCompletelyHidden(HistoryItem *item) const;
|
bool isItemCompletelyHidden(HistoryItem *item) const;
|
||||||
void updateTopBarSelection();
|
void updateTopBarSelection();
|
||||||
|
@ -328,7 +326,6 @@ private slots:
|
||||||
private:
|
private:
|
||||||
using TabbedPanel = ChatHelpers::TabbedPanel;
|
using TabbedPanel = ChatHelpers::TabbedPanel;
|
||||||
using TabbedSelector = ChatHelpers::TabbedSelector;
|
using TabbedSelector = ChatHelpers::TabbedSelector;
|
||||||
using DragState = Storage::MimeDataState;
|
|
||||||
struct PinnedBar {
|
struct PinnedBar {
|
||||||
PinnedBar(MsgId msgId, HistoryWidget *parent);
|
PinnedBar(MsgId msgId, HistoryWidget *parent);
|
||||||
~PinnedBar();
|
~PinnedBar();
|
||||||
|
@ -567,8 +564,6 @@ private:
|
||||||
void animatedScrollToItem(MsgId msgId);
|
void animatedScrollToItem(MsgId msgId);
|
||||||
void animatedScrollToY(int scrollTo, HistoryItem *attachTo = nullptr);
|
void animatedScrollToY(int scrollTo, HistoryItem *attachTo = nullptr);
|
||||||
|
|
||||||
void updateDragAreas();
|
|
||||||
|
|
||||||
// when scroll position or scroll area size changed this method
|
// when scroll position or scroll area size changed this method
|
||||||
// updates the boundings of the visible area in HistoryInner
|
// updates the boundings of the visible area in HistoryInner
|
||||||
void visibleAreaUpdated();
|
void visibleAreaUpdated();
|
||||||
|
@ -728,8 +723,8 @@ private:
|
||||||
|
|
||||||
object_ptr<InlineBots::Layout::Widget> _inlineResults = { nullptr };
|
object_ptr<InlineBots::Layout::Widget> _inlineResults = { nullptr };
|
||||||
std::unique_ptr<TabbedPanel> _tabbedPanel;
|
std::unique_ptr<TabbedPanel> _tabbedPanel;
|
||||||
DragState _attachDragState;
|
|
||||||
object_ptr<DragArea> _attachDragDocument, _attachDragPhoto;
|
DragArea::Areas _attachDragAreas;
|
||||||
|
|
||||||
Fn<void()> _raiseEmojiSuggestions;
|
Fn<void()> _raiseEmojiSuggestions;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue