mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +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);
|
switchToFilter(filterId);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
|
_controller->window().widget()->globalForceClicks(
|
||||||
|
) | rpl::start_with_next([=](QPoint globalPosition) {
|
||||||
|
processGlobalForceClick(globalPosition);
|
||||||
|
}, lifetime());
|
||||||
|
|
||||||
session().data().stories().incrementPreloadingMainSources();
|
session().data().stories().incrementPreloadingMainSources();
|
||||||
|
|
||||||
handleChatListEntryRefreshes();
|
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) {
|
void InnerWidget::mousePressEvent(QMouseEvent *e) {
|
||||||
selectByMouse(e->globalPos());
|
selectByMouse(e->globalPos());
|
||||||
|
|
||||||
|
@ -1761,6 +1776,7 @@ void InnerWidget::mousePressReleased(
|
||||||
Qt::MouseButton button,
|
Qt::MouseButton button,
|
||||||
Qt::KeyboardModifiers modifiers) {
|
Qt::KeyboardModifiers modifiers) {
|
||||||
_chatPreviewTimer.cancel();
|
_chatPreviewTimer.cancel();
|
||||||
|
_pressButton = Qt::NoButton;
|
||||||
|
|
||||||
auto wasDragging = (_dragging != nullptr);
|
auto wasDragging = (_dragging != nullptr);
|
||||||
if (wasDragging) {
|
if (wasDragging) {
|
||||||
|
@ -3598,8 +3614,11 @@ ChosenRow InnerWidget::computeChosenRow() const {
|
||||||
|
|
||||||
bool InnerWidget::isUserpicPress() const {
|
bool InnerWidget::isUserpicPress() const {
|
||||||
return (_lastRowLocalMouseX >= 0)
|
return (_lastRowLocalMouseX >= 0)
|
||||||
&& (_lastRowLocalMouseX < _st->nameLeft)
|
&& (_lastRowLocalMouseX < _st->nameLeft);
|
||||||
&& (width() > _narrowWidth);
|
}
|
||||||
|
|
||||||
|
bool InnerWidget::isUserpicPressOnWide() const {
|
||||||
|
return isUserpicPress() && (width() > _narrowWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InnerWidget::pressShowsPreview(bool onlyUserpic) const {
|
bool InnerWidget::pressShowsPreview(bool onlyUserpic) const {
|
||||||
|
@ -3625,7 +3644,7 @@ bool InnerWidget::chooseRow(
|
||||||
ChosenRow row,
|
ChosenRow row,
|
||||||
Qt::KeyboardModifiers modifiers) {
|
Qt::KeyboardModifiers modifiers) {
|
||||||
row.newWindow = (modifiers & Qt::ControlModifier);
|
row.newWindow = (modifiers & Qt::ControlModifier);
|
||||||
row.userpicClick = isUserpicPress();
|
row.userpicClick = isUserpicPressOnWide();
|
||||||
return row;
|
return row;
|
||||||
};
|
};
|
||||||
auto chosen = modifyChosenRow(computeChosenRow(), modifiers);
|
auto chosen = modifyChosenRow(computeChosenRow(), modifiers);
|
||||||
|
|
|
@ -123,6 +123,7 @@ public:
|
||||||
void resizeEmptyLabel();
|
void resizeEmptyLabel();
|
||||||
|
|
||||||
[[nodiscard]] bool isUserpicPress() const;
|
[[nodiscard]] bool isUserpicPress() const;
|
||||||
|
[[nodiscard]] bool isUserpicPressOnWide() const;
|
||||||
[[nodiscard]] bool pressShowsPreview(bool onlyUserpic) const;
|
[[nodiscard]] bool pressShowsPreview(bool onlyUserpic) const;
|
||||||
void cancelChatPreview();
|
void cancelChatPreview();
|
||||||
void showChatPreview(bool onlyUserpic);
|
void showChatPreview(bool onlyUserpic);
|
||||||
|
@ -258,6 +259,7 @@ private:
|
||||||
QPoint globalPosition,
|
QPoint globalPosition,
|
||||||
Qt::MouseButton button,
|
Qt::MouseButton button,
|
||||||
Qt::KeyboardModifiers modifiers);
|
Qt::KeyboardModifiers modifiers);
|
||||||
|
void processGlobalForceClick(QPoint globalPosition);
|
||||||
void clearIrrelevantState();
|
void clearIrrelevantState();
|
||||||
void selectByMouse(QPoint globalPosition);
|
void selectByMouse(QPoint globalPosition);
|
||||||
void preloadRowsData();
|
void preloadRowsData();
|
||||||
|
|
|
@ -28,6 +28,10 @@ public:
|
||||||
|
|
||||||
void updateWindowIcon() override;
|
void updateWindowIcon() override;
|
||||||
|
|
||||||
|
rpl::producer<QPoint> globalForceClicks() override {
|
||||||
|
return _forceClicks.events();
|
||||||
|
}
|
||||||
|
|
||||||
class Private;
|
class Private;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -85,7 +89,9 @@ private:
|
||||||
QAction *psMonospace = nullptr;
|
QAction *psMonospace = nullptr;
|
||||||
QAction *psClearFormat = nullptr;
|
QAction *psClearFormat = nullptr;
|
||||||
|
|
||||||
|
rpl::event_stream<QPoint> _forceClicks;
|
||||||
int _customTitleHeight = 0;
|
int _customTitleHeight = 0;
|
||||||
|
int _lastPressureStage = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -310,6 +310,16 @@ bool MainWindow::nativeEvent(
|
||||||
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
Core::Sandbox::Instance().customEnterFromEventLoop([&] {
|
||||||
imeCompositionStartReceived();
|
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;
|
return false;
|
||||||
|
|
|
@ -144,6 +144,10 @@ public:
|
||||||
Core::WindowPosition initial,
|
Core::WindowPosition initial,
|
||||||
QSize minSize) const;
|
QSize minSize) const;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual rpl::producer<QPoint> globalForceClicks() {
|
||||||
|
return rpl::never<QPoint>();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void leaveEventHook(QEvent *e) override;
|
void leaveEventHook(QEvent *e) override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue