mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 21:57:10 +02:00
Show preview on Force-Click on macOS.
This commit is contained in:
parent
d6e827e982
commit
2b9e7a6b25
5 changed files with 44 additions and 3 deletions
|
@ -332,6 +332,11 @@ InnerWidget::InnerWidget(
|
|||
switchToFilter(filterId);
|
||||
}, lifetime());
|
||||
|
||||
_controller->window().widget()->globalForceClicks(
|
||||
) | rpl::start_with_next([=](QPoint globalPosition) {
|
||||
processGlobalForceClick(globalPosition);
|
||||
}, lifetime());
|
||||
|
||||
session().data().stories().incrementPreloadingMainSources();
|
||||
|
||||
handleChatListEntryRefreshes();
|
||||
|
@ -1424,6 +1429,16 @@ void InnerWidget::selectByMouse(QPoint globalPosition) {
|
|||
}
|
||||
}
|
||||
|
||||
void InnerWidget::processGlobalForceClick(QPoint globalPosition) {
|
||||
const auto parent = parentWidget();
|
||||
if (_pressButton == Qt::LeftButton
|
||||
&& parent->rect().contains(parent->mapFromGlobal(globalPosition))
|
||||
&& pressShowsPreview(false)) {
|
||||
_chatPreviewWillBeFor = computeChosenRow().key;
|
||||
showChatPreview(false);
|
||||
}
|
||||
}
|
||||
|
||||
void InnerWidget::mousePressEvent(QMouseEvent *e) {
|
||||
selectByMouse(e->globalPos());
|
||||
|
||||
|
@ -1761,6 +1776,7 @@ void InnerWidget::mousePressReleased(
|
|||
Qt::MouseButton button,
|
||||
Qt::KeyboardModifiers modifiers) {
|
||||
_chatPreviewTimer.cancel();
|
||||
_pressButton = Qt::NoButton;
|
||||
|
||||
auto wasDragging = (_dragging != nullptr);
|
||||
if (wasDragging) {
|
||||
|
@ -3598,8 +3614,11 @@ ChosenRow InnerWidget::computeChosenRow() const {
|
|||
|
||||
bool InnerWidget::isUserpicPress() const {
|
||||
return (_lastRowLocalMouseX >= 0)
|
||||
&& (_lastRowLocalMouseX < _st->nameLeft)
|
||||
&& (width() > _narrowWidth);
|
||||
&& (_lastRowLocalMouseX < _st->nameLeft);
|
||||
}
|
||||
|
||||
bool InnerWidget::isUserpicPressOnWide() const {
|
||||
return isUserpicPress() && (width() > _narrowWidth);
|
||||
}
|
||||
|
||||
bool InnerWidget::pressShowsPreview(bool onlyUserpic) const {
|
||||
|
@ -3625,7 +3644,7 @@ bool InnerWidget::chooseRow(
|
|||
ChosenRow row,
|
||||
Qt::KeyboardModifiers modifiers) {
|
||||
row.newWindow = (modifiers & Qt::ControlModifier);
|
||||
row.userpicClick = isUserpicPress();
|
||||
row.userpicClick = isUserpicPressOnWide();
|
||||
return row;
|
||||
};
|
||||
auto chosen = modifyChosenRow(computeChosenRow(), modifiers);
|
||||
|
|
|
@ -123,6 +123,7 @@ public:
|
|||
void resizeEmptyLabel();
|
||||
|
||||
[[nodiscard]] bool isUserpicPress() const;
|
||||
[[nodiscard]] bool isUserpicPressOnWide() const;
|
||||
[[nodiscard]] bool pressShowsPreview(bool onlyUserpic) const;
|
||||
void cancelChatPreview();
|
||||
void showChatPreview(bool onlyUserpic);
|
||||
|
@ -258,6 +259,7 @@ private:
|
|||
QPoint globalPosition,
|
||||
Qt::MouseButton button,
|
||||
Qt::KeyboardModifiers modifiers);
|
||||
void processGlobalForceClick(QPoint globalPosition);
|
||||
void clearIrrelevantState();
|
||||
void selectByMouse(QPoint globalPosition);
|
||||
void preloadRowsData();
|
||||
|
|
|
@ -28,6 +28,10 @@ public:
|
|||
|
||||
void updateWindowIcon() override;
|
||||
|
||||
rpl::producer<QPoint> globalForceClicks() override {
|
||||
return _forceClicks.events();
|
||||
}
|
||||
|
||||
class Private;
|
||||
|
||||
protected:
|
||||
|
@ -85,7 +89,9 @@ private:
|
|||
QAction *psMonospace = nullptr;
|
||||
QAction *psClearFormat = nullptr;
|
||||
|
||||
rpl::event_stream<QPoint> _forceClicks;
|
||||
int _customTitleHeight = 0;
|
||||
int _lastPressureStage = 0;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -310,6 +310,16 @@ bool MainWindow::nativeEvent(
|
|||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||
imeCompositionStartReceived();
|
||||
});
|
||||
} else if ([event type] == NSEventTypePressure) {
|
||||
const auto stage = [event stage];
|
||||
if (_lastPressureStage != stage) {
|
||||
_lastPressureStage = stage;
|
||||
if (stage == 2) {
|
||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||
_forceClicks.fire(QCursor::pos());
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -144,6 +144,10 @@ public:
|
|||
Core::WindowPosition initial,
|
||||
QSize minSize) const;
|
||||
|
||||
[[nodiscard]] virtual rpl::producer<QPoint> globalForceClicks() {
|
||||
return rpl::never<QPoint>();
|
||||
}
|
||||
|
||||
protected:
|
||||
void leaveEventHook(QEvent *e) override;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue