Improve similar channels pseudo-widget.
This commit is contained in:
parent
30d72f1d1d
commit
2df6729f2d
|
@ -1428,12 +1428,17 @@ void HistoryInner::onTouchScrollTimer() {
|
|||
} else if (_touchScrollState == Ui::TouchScrollState::Auto || _touchScrollState == Ui::TouchScrollState::Acceleration) {
|
||||
int32 elapsed = int32(nowTime - _touchTime);
|
||||
QPoint delta = _touchSpeed * elapsed / 1000;
|
||||
bool hasScrolled = consumeScrollAction(delta)
|
||||
|| _widget->touchScroll(delta);
|
||||
const auto consumedHorizontal = consumeScrollAction(delta);
|
||||
if (consumedHorizontal) {
|
||||
_horizontalScrollLocked = true;
|
||||
}
|
||||
const auto hasScrolled = consumedHorizontal
|
||||
|| (!_horizontalScrollLocked && _widget->touchScroll(delta));
|
||||
|
||||
if (_touchSpeed.isNull() || !hasScrolled) {
|
||||
_touchScrollState = Ui::TouchScrollState::Manual;
|
||||
_touchScroll = false;
|
||||
_horizontalScrollLocked = false;
|
||||
_touchScrollTimer.cancel();
|
||||
} else {
|
||||
_touchTime = nowTime;
|
||||
|
@ -1507,10 +1512,13 @@ void HistoryInner::touchDeaccelerate(int32 elapsed) {
|
|||
|
||||
void HistoryInner::touchEvent(QTouchEvent *e) {
|
||||
if (e->type() == QEvent::TouchCancel) { // cancel
|
||||
if (!_touchInProgress) return;
|
||||
if (!_touchInProgress) {
|
||||
return;
|
||||
}
|
||||
_touchInProgress = false;
|
||||
_touchSelectTimer.cancel();
|
||||
_touchScroll = _touchSelect = false;
|
||||
_horizontalScrollLocked = false;
|
||||
_touchScrollState = Ui::TouchScrollState::Manual;
|
||||
mouseActionCancel();
|
||||
return;
|
||||
|
@ -1527,10 +1535,12 @@ void HistoryInner::touchEvent(QTouchEvent *e) {
|
|||
e->accept();
|
||||
return; // ignore mouse press, that was hiding context menu
|
||||
}
|
||||
if (_touchInProgress) return;
|
||||
if (e->touchPoints().isEmpty()) return;
|
||||
if (_touchInProgress || e->touchPoints().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_touchInProgress = true;
|
||||
_horizontalScrollLocked = false;
|
||||
if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
||||
_touchScrollState = Ui::TouchScrollState::Acceleration;
|
||||
_touchWaitingAcceleration = true;
|
||||
|
@ -1546,8 +1556,9 @@ void HistoryInner::touchEvent(QTouchEvent *e) {
|
|||
} break;
|
||||
|
||||
case QEvent::TouchUpdate: {
|
||||
if (!_touchInProgress) return;
|
||||
if (_touchSelect) {
|
||||
if (!_touchInProgress) {
|
||||
return;
|
||||
} else if (_touchSelect) {
|
||||
mouseActionUpdate(_touchPos);
|
||||
} else if (!_touchScroll && (_touchPos - _touchStart).manhattanLength() >= QApplication::startDragDistance()) {
|
||||
_touchSelectTimer.cancel();
|
||||
|
@ -1568,7 +1579,9 @@ void HistoryInner::touchEvent(QTouchEvent *e) {
|
|||
} break;
|
||||
|
||||
case QEvent::TouchEnd: {
|
||||
if (!_touchInProgress) return;
|
||||
if (!_touchInProgress) {
|
||||
return;
|
||||
}
|
||||
_touchInProgress = false;
|
||||
auto weak = Ui::MakeWeak(this);
|
||||
if (_touchSelect) {
|
||||
|
@ -1584,6 +1597,7 @@ void HistoryInner::touchEvent(QTouchEvent *e) {
|
|||
_touchTime = crl::now();
|
||||
} else if (_touchScrollState == Ui::TouchScrollState::Auto) {
|
||||
_touchScrollState = Ui::TouchScrollState::Manual;
|
||||
_horizontalScrollLocked = false;
|
||||
_touchScroll = false;
|
||||
touchResetSpeed();
|
||||
} else if (_touchScrollState == Ui::TouchScrollState::Acceleration) {
|
||||
|
@ -1626,7 +1640,9 @@ void HistoryInner::mouseActionUpdate(const QPoint &screenPos) {
|
|||
|
||||
void HistoryInner::touchScrollUpdated(const QPoint &screenPos) {
|
||||
_touchPos = screenPos;
|
||||
if (!consumeScrollAction(_touchPos - _touchPrevPos)) {
|
||||
if (consumeScrollAction(_touchPos - _touchPrevPos)) {
|
||||
_horizontalScrollLocked = true;
|
||||
} else if (!_horizontalScrollLocked) {
|
||||
_widget->touchScroll(_touchPos - _touchPrevPos);
|
||||
}
|
||||
touchUpdateSpeed();
|
||||
|
@ -4452,7 +4468,7 @@ void HistoryInner::onParentGeometryChanged() {
|
|||
}
|
||||
|
||||
bool HistoryInner::consumeScrollAction(QPoint delta) {
|
||||
const auto horizontal = std::abs(delta.x()) > std::abs(delta.y());
|
||||
const auto horizontal = (std::abs(delta.x()) > std::abs(delta.y()));
|
||||
if (!horizontal || !_acceptsHorizontalScroll || !Element::Moused()) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -492,6 +492,7 @@ private:
|
|||
bool _useCornerReaction = false;
|
||||
bool _canHaveFromUserpicsSponsored = false;
|
||||
bool _acceptsHorizontalScroll = false;
|
||||
bool _horizontalScrollLocked = false;
|
||||
|
||||
QPoint _trippleClickPoint;
|
||||
base::Timer _trippleClickTimer;
|
||||
|
|
|
@ -220,7 +220,7 @@ void SimilarChannels::draw(Painter &p, const PaintContext &context) const {
|
|||
if (!channel.participants.isEmpty()) {
|
||||
validateParticipansBg(channel);
|
||||
const auto participants = channel.participantsRect.translated(
|
||||
QPoint(-_scrollLeft, 0));
|
||||
geometry.topLeft());
|
||||
q->drawImage(participants.topLeft(), channel.participantsBg);
|
||||
const auto badge = participants.marginsRemoved(
|
||||
st::chatSimilarBadgePadding);
|
||||
|
@ -303,14 +303,18 @@ void SimilarChannels::validateParticipansBg(const Channel &channel) const {
|
|||
channel.thumbnail->image(photo).copy(
|
||||
QRect(photo / 3, photo / 3, photo / 3, photo / 3)));
|
||||
|
||||
const auto lightness = color.lightness();
|
||||
if (!base::in_range(lightness, 160, 208)) {
|
||||
color = color.toHsl();
|
||||
color.setHsl(
|
||||
color.hue(),
|
||||
color.saturation(),
|
||||
std::clamp(lightness, 160, 208));
|
||||
color = color.toRgb();
|
||||
const auto hsl = color.toHsl();
|
||||
constexpr auto kMinSaturation = 0;
|
||||
constexpr auto kMaxSaturation = 96;
|
||||
constexpr auto kMinLightness = 160;
|
||||
constexpr auto kMaxLightness = 208;
|
||||
if (!base::in_range(hsl.saturation(), kMinSaturation, kMaxSaturation)
|
||||
|| !base::in_range(hsl.lightness(), kMinLightness, kMaxLightness)) {
|
||||
color = QColor::fromHsl(
|
||||
hsl.hue(),
|
||||
std::clamp(hsl.saturation(), kMinSaturation, kMaxSaturation),
|
||||
std::clamp(hsl.lightness(), kMinLightness, kMaxLightness)
|
||||
).toRgb();
|
||||
}
|
||||
|
||||
result.fill(color);
|
||||
|
@ -425,8 +429,8 @@ QSize SimilarChannels::countOptimalSize() {
|
|||
const auto width = length + st::chatSimilarBadgeIcon.width();
|
||||
const auto delta = (outer.width() - width) / 2;
|
||||
const auto badge = QRect(
|
||||
x + delta,
|
||||
y + st::chatSimilarBadgeTop,
|
||||
delta,
|
||||
st::chatSimilarBadgeTop,
|
||||
outer.width() - 2 * delta,
|
||||
st::chatSimilarBadgeFont->height);
|
||||
_channels.back().participantsRect = badge.marginsAdded(
|
||||
|
|
Loading…
Reference in New Issue