2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Handle channel event log mouse events.

This commit is contained in:
John Preston
2017-06-22 00:38:31 +03:00
parent 1791b251ad
commit e39b95175b
50 changed files with 1298 additions and 668 deletions

View File

@@ -92,6 +92,9 @@ OverviewInner::OverviewInner(OverviewWidget *overview, Ui::ScrollArea *scroll, P
invalidateCache();
}
});
subscribe(App::wnd()->dragFinished(), [this] {
dragActionUpdate(QCursor::pos());
});
if (_type == OverviewLinks || _type == OverviewFiles) {
_search->show();
@@ -469,8 +472,8 @@ void OverviewInner::dragActionStart(const QPoint &screenPos, Qt::MouseButton but
_dragItem = _mousedItem;
_dragItemIndex = _mousedItemIndex;
_dragStartPos = mapMouseToItem(mapFromGlobal(screenPos), _dragItem, _dragItemIndex);
_dragWasInactive = App::wnd()->inactivePress();
if (_dragWasInactive) App::wnd()->inactivePress(false);
_dragWasInactive = App::wnd()->wasInactivePress();
if (_dragWasInactive) App::wnd()->setInactivePress(false);
if (ClickHandler::getPressed() && _selected.isEmpty()) {
_dragAction = PrepareDrag;
} else if (!_selected.isEmpty()) {
@@ -564,7 +567,7 @@ void OverviewInner::dragActionFinish(const QPoint &screenPos, Qt::MouseButton bu
_overview->updateTopBarSelection();
}
void OverviewInner::onDragExec() {
void OverviewInner::performDrag() {
if (_dragAction != Dragging) return;
bool uponSelected = false;
@@ -596,25 +599,20 @@ void OverviewInner::onDragExec() {
updateDragSelection(0, -1, 0, -1, false);
_overview->noSelectingScroll();
QDrag *drag = new QDrag(App::wnd());
QMimeData *mimeData = new QMimeData;
auto mimeData = std::make_unique<QMimeData>();
if (!sel.isEmpty()) mimeData->setText(sel);
if (!urls.isEmpty()) mimeData->setUrls(urls);
if (forwardSelected) {
mimeData->setData(qsl("application/x-td-forward-selected"), "1");
}
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
// We don't receive mouseReleaseEvent when drag is finished.
ClickHandler::unpressed();
if (App::main()) App::main()->updateAfterDrag();
// This call enters event loop and can destroy any QObject.
App::wnd()->launchDrag(std::move(mimeData));
return;
} else {
QString forwardMimeType;
HistoryMedia *pressedMedia = nullptr;
if (HistoryItem *pressedLnkItem = App::pressedLinkItem()) {
if (auto pressedLnkItem = App::pressedLinkItem()) {
if ((pressedMedia = pressedLnkItem->getMedia())) {
if (forwardMimeType.isEmpty() && pressedMedia->dragItemByHandler(pressedHandler)) {
forwardMimeType = qsl("application/x-td-forward-pressed-link");
@@ -622,12 +620,10 @@ void OverviewInner::onDragExec() {
}
}
if (!forwardMimeType.isEmpty()) {
QDrag *drag = new QDrag(App::wnd());
QMimeData *mimeData = new QMimeData;
auto mimeData = std::make_unique<QMimeData>();
mimeData->setData(qsl("application/x-td-forward-pressed-link"), "1");
if (DocumentData *document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
QString filepath = document->filepath(DocumentData::FilePathResolveChecked);
if (auto document = (pressedMedia ? pressedMedia->getDocument() : nullptr)) {
auto filepath = document->filepath(DocumentData::FilePathResolveChecked);
if (!filepath.isEmpty()) {
QList<QUrl> urls;
urls.push_back(QUrl::fromLocalFile(filepath));
@@ -635,12 +631,8 @@ void OverviewInner::onDragExec() {
}
}
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction);
// We don't receive mouseReleaseEvent when drag is finished.
ClickHandler::unpressed();
if (App::main()) App::main()->updateAfterDrag();
// This call enters event loop and can destroy any QObject.
App::wnd()->launchDrag(std::move(mimeData));
return;
}
}
@@ -904,7 +896,7 @@ void OverviewInner::onUpdateSelected() {
item = media->getItem();
index = i;
if (upon) {
media->getState(lnk, cursorState, m.x() - col * w - st::overviewPhotoSkip, m.y() - _marginTop - row * vsize - st::overviewPhotoSkip);
media->getState(lnk, cursorState, m - QPoint(col * w + st::overviewPhotoSkip, _marginTop + row * vsize + st::overviewPhotoSkip));
lnkhost = media;
}
}
@@ -940,7 +932,7 @@ void OverviewInner::onUpdateSelected() {
if (auto media = _items.at(i)->toMediaItem()) {
item = media->getItem();
index = i;
media->getState(lnk, cursorState, m.x() - _rowsLeft, m.y() - _marginTop - top);
media->getState(lnk, cursorState, m - QPoint(_rowsLeft, _marginTop + top));
lnkhost = media;
}
break;
@@ -989,7 +981,7 @@ void OverviewInner::onUpdateSelected() {
if (_mousedItem != _dragItem || (m - _dragStartPos).manhattanLength() >= QApplication::startDragDistance()) {
if (_dragAction == PrepareDrag) {
_dragAction = Dragging;
QTimer::singleShot(1, this, SLOT(onDragExec()));
InvokeQueued(this, [this] { performDrag(); });
} else if (_dragAction == PrepareSelect) {
_dragAction = Selecting;
}
@@ -2267,7 +2259,7 @@ void OverviewWidget::grabFinish() {
_topShadow->show();
}
void OverviewWidget::ui_repaintHistoryItem(const HistoryItem *item) {
void OverviewWidget::ui_repaintHistoryItem(gsl::not_null<const HistoryItem*> item) {
if (peer() == item->history()->peer || migratePeer() == item->history()->peer) {
_inner->repaintItem(item);
}
@@ -2283,10 +2275,6 @@ SelectedItemSet OverviewWidget::getSelectedItems() const {
return _inner->getSelectedItems();
}
void OverviewWidget::updateAfterDrag() {
_inner->dragActionUpdate(QCursor::pos());
}
OverviewWidget::~OverviewWidget() {
onClearSelected();
updateTopBarSelection();