2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2014-12-01 10:47:38 +00:00
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
2015-10-03 13:16:42 +00:00
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2016-02-08 10:56:18 +00:00
|
|
|
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
enum TouchScrollState {
|
|
|
|
TouchScrollManual, // Scrolling manually with the finger on the screen
|
|
|
|
TouchScrollAuto, // Scrolling automatically
|
|
|
|
TouchScrollAcceleration // Scrolling automatically but a finger is on the screen
|
|
|
|
};
|
|
|
|
|
|
|
|
class ScrollArea;
|
|
|
|
|
|
|
|
class ScrollShadow : public QWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ScrollShadow(ScrollArea *parent, const style::flatScroll *st);
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
void changeVisibility(bool shown);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
const style::flatScroll *_st;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
class ScrollBar : public QWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ScrollBar(ScrollArea *parent, bool vertical, const style::flatScroll *st);
|
|
|
|
|
|
|
|
void recountSize();
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent *e);
|
|
|
|
void enterEvent(QEvent *e);
|
|
|
|
void leaveEvent(QEvent *e);
|
|
|
|
void mouseMoveEvent(QMouseEvent *e);
|
|
|
|
void mousePressEvent(QMouseEvent *e);
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e);
|
|
|
|
void resizeEvent(QResizeEvent *e);
|
|
|
|
|
2015-12-08 12:33:37 +00:00
|
|
|
void step_appearance(float64 ms, bool timer);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void hideTimeout(int64 dt);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
2015-07-17 19:17:37 +00:00
|
|
|
void onValueChanged();
|
2015-04-02 10:33:19 +00:00
|
|
|
void updateBar(bool force = false);
|
2014-05-30 08:53:19 +00:00
|
|
|
void onHideTimer();
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
void topShadowVisibility(bool);
|
|
|
|
void bottomShadowVisibility(bool);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
ScrollArea *area();
|
2014-05-30 08:53:19 +00:00
|
|
|
const style::flatScroll *_st;
|
|
|
|
|
|
|
|
bool _vertical;
|
|
|
|
bool _over, _overbar, _moving;
|
|
|
|
bool _topSh, _bottomSh;
|
|
|
|
|
|
|
|
QPoint _dragStart;
|
|
|
|
QScrollBar *_connected;
|
|
|
|
|
|
|
|
int32 _startFrom, _scrollMax;
|
|
|
|
|
|
|
|
int64 _hideIn;
|
|
|
|
QTimer _hideTimer;
|
|
|
|
|
|
|
|
anim::cvalue a_bg, a_bar;
|
2015-12-08 12:33:37 +00:00
|
|
|
Animation _a_appearance;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
QRect _bar;
|
|
|
|
};
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
class SplittedWidget : public TWidget {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
SplittedWidget(QWidget *parent) : TWidget(parent), _otherWidth(0) {
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
|
|
|
}
|
|
|
|
void paintEvent(QPaintEvent *e); // paintEvent done through paintRegion
|
|
|
|
void setHeight(int32 newHeight) {
|
|
|
|
resize(width(), newHeight);
|
|
|
|
emit resizeOther();
|
|
|
|
}
|
|
|
|
void update(int x, int y, int w, int h) {
|
|
|
|
update(QRect(x, y, w, h));
|
|
|
|
}
|
|
|
|
void update(const QRect&);
|
|
|
|
void update(const QRegion&);
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
void update() {
|
|
|
|
update(0, 0, fullWidth(), height());
|
|
|
|
}
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
|
|
void resizeOther();
|
|
|
|
void updateOther(const QRect&);
|
|
|
|
void updateOther(const QRegion&);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
int32 otherWidth() const {
|
|
|
|
return _otherWidth;
|
|
|
|
}
|
|
|
|
int32 fullWidth() const {
|
|
|
|
return width() + otherWidth();
|
|
|
|
}
|
|
|
|
virtual void paintRegion(Painter &p, const QRegion ®ion, bool paintingOther) = 0;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
int32 _otherWidth;
|
|
|
|
void setOtherWidth(int32 otherWidth) {
|
|
|
|
_otherWidth = otherWidth;
|
|
|
|
}
|
|
|
|
void resize(int32 w, int32 h) {
|
|
|
|
TWidget::resize(w, h);
|
|
|
|
}
|
|
|
|
friend class ScrollArea;
|
|
|
|
friend class SplittedWidgetOther;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class SplittedWidgetOther;
|
2014-05-30 08:53:19 +00:00
|
|
|
class ScrollArea : public QScrollArea {
|
|
|
|
Q_OBJECT
|
2016-06-15 17:13:46 +00:00
|
|
|
T_WIDGET
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
ScrollArea(QWidget *parent, const style::flatScroll &st = st::scrollDef, bool handleTouch = true);
|
|
|
|
|
|
|
|
int scrollWidth() const;
|
|
|
|
int scrollHeight() const;
|
|
|
|
int scrollLeftMax() const;
|
|
|
|
int scrollTopMax() const;
|
|
|
|
int scrollLeft() const;
|
|
|
|
int scrollTop() const;
|
|
|
|
|
|
|
|
void setWidget(QWidget *widget);
|
2016-05-24 16:13:07 +00:00
|
|
|
void setOwnedWidget(QWidget *widget);
|
2015-09-29 13:24:39 +00:00
|
|
|
QWidget *takeWidget();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
void rangeChanged(int oldMax, int newMax, bool vertical);
|
|
|
|
|
2015-02-03 15:02:46 +00:00
|
|
|
void updateColors(const style::color &bar, const style::color &bg, const style::color &barOver, const style::color &bgOver);
|
|
|
|
|
2016-06-16 15:17:39 +00:00
|
|
|
bool focusNextPrevChild(bool next) override;
|
2016-06-15 17:13:46 +00:00
|
|
|
void setMovingByScrollBar(bool movingByScrollBar);
|
2015-09-13 17:27:29 +00:00
|
|
|
|
2016-06-16 15:17:39 +00:00
|
|
|
bool viewportEvent(QEvent *e) override;
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
|
2015-06-15 17:19:24 +00:00
|
|
|
~ScrollArea();
|
|
|
|
|
2016-06-15 17:13:46 +00:00
|
|
|
protected:
|
|
|
|
|
2016-06-16 15:17:39 +00:00
|
|
|
bool eventFilter(QObject *obj, QEvent *e) override;
|
|
|
|
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
void moveEvent(QMoveEvent *e) override;
|
|
|
|
void touchEvent(QTouchEvent *e);
|
|
|
|
|
2016-06-15 17:13:46 +00:00
|
|
|
void enterEventHook(QEvent *e);
|
|
|
|
void leaveEventHook(QEvent *e);
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
public slots:
|
|
|
|
|
|
|
|
void scrollToY(int toTop, int toBottom = -1);
|
2015-05-08 12:45:14 +00:00
|
|
|
void disableScroll(bool dis);
|
2014-05-30 08:53:19 +00:00
|
|
|
void onScrolled();
|
|
|
|
|
|
|
|
void onTouchTimer();
|
|
|
|
void onTouchScrollTimer();
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
void onResizeOther();
|
|
|
|
void onUpdateOther(const QRect&);
|
|
|
|
void onUpdateOther(const QRegion&);
|
|
|
|
void onVerticalScroll();
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void scrolled();
|
|
|
|
void scrollStarted();
|
|
|
|
void scrollFinished();
|
|
|
|
void geometryChanged();
|
|
|
|
|
2015-05-08 12:45:14 +00:00
|
|
|
protected:
|
|
|
|
|
2016-06-16 15:17:39 +00:00
|
|
|
void scrollContentsBy(int dx, int dy) override;
|
2015-05-08 12:45:14 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
bool touchScroll(const QPoint &delta);
|
|
|
|
|
|
|
|
void touchScrollUpdated(const QPoint &screenPos);
|
|
|
|
|
|
|
|
void touchResetSpeed();
|
|
|
|
void touchUpdateSpeed();
|
|
|
|
void touchDeaccelerate(int32 elapsed);
|
|
|
|
|
2015-05-08 12:45:14 +00:00
|
|
|
bool _disabled;
|
2016-05-24 16:13:07 +00:00
|
|
|
bool _ownsWidget = false; // if true, the widget is deleted in destructor.
|
2016-06-15 17:13:46 +00:00
|
|
|
bool _movingByScrollBar = false;
|
2015-05-08 12:45:14 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
style::flatScroll _st;
|
|
|
|
ScrollBar hor, vert;
|
|
|
|
ScrollShadow topSh, bottomSh;
|
|
|
|
int32 _horValue, _vertValue;
|
|
|
|
|
|
|
|
bool _touchEnabled;
|
|
|
|
QTimer _touchTimer;
|
|
|
|
bool _touchScroll, _touchPress, _touchRightButton;
|
|
|
|
QPoint _touchStart, _touchPrevPos, _touchPos;
|
|
|
|
|
|
|
|
TouchScrollState _touchScrollState;
|
|
|
|
bool _touchPrevPosValid, _touchWaitingAcceleration;
|
|
|
|
QPoint _touchSpeed;
|
|
|
|
uint64 _touchSpeedTime, _touchAccelerationTime, _touchTime;
|
|
|
|
QTimer _touchScrollTimer;
|
|
|
|
|
|
|
|
bool _widgetAcceptsTouch;
|
|
|
|
|
2015-09-29 13:24:39 +00:00
|
|
|
friend class SplittedWidgetOther;
|
|
|
|
SplittedWidgetOther *_other;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class SplittedWidgetOther : public TWidget {
|
|
|
|
public:
|
|
|
|
SplittedWidgetOther(ScrollArea *parent) : TWidget(parent) {
|
|
|
|
}
|
|
|
|
void paintEvent(QPaintEvent *e);
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2016-06-17 18:18:01 +00:00
|
|
|
|
|
|
|
class ScrolledWidget : public TWidget {
|
2016-06-20 11:31:12 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
public:
|
|
|
|
ScrolledWidget(QWidget *parent = nullptr) : TWidget(parent) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Count new height for width=newWidth and resize to it.
|
|
|
|
void resizeToWidth(int newWidth) {
|
|
|
|
resize(newWidth, resizeGetHeight(newWidth));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Updates the area that is visible inside the scroll container.
|
|
|
|
virtual void setVisibleTopBottom(int visibleTop, int visibleBottom) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Resizes content and counts natural widget height for the desired width.
|
|
|
|
virtual int resizeGetHeight(int newWidth) {
|
|
|
|
return height();
|
|
|
|
}
|
|
|
|
|
2016-06-20 11:31:12 +00:00
|
|
|
signals:
|
|
|
|
void heightUpdated();
|
|
|
|
|
2016-06-17 18:18:01 +00:00
|
|
|
};
|