2015-12-20 14:05:07 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2015-12-20 14:05:07 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2015-12-20 14:05:07 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "base/runtime_composer.h"
|
2016-09-29 11:37:16 +00:00
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
namespace HistoryView {
|
|
|
|
struct TextState;
|
|
|
|
struct StateRequest;
|
|
|
|
} // namespace HistoryView
|
2018-01-11 19:33:26 +00:00
|
|
|
|
2017-04-06 16:49:42 +00:00
|
|
|
constexpr auto FullSelection = TextSelection { 0xFFFF, 0xFFFF };
|
2015-12-20 14:05:07 +00:00
|
|
|
|
2017-12-15 16:25:47 +00:00
|
|
|
inline bool IsSubGroupSelection(TextSelection selection) {
|
|
|
|
return (selection.from == 0xFFFF) && (selection.to != 0xFFFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool IsGroupItemSelection(
|
|
|
|
TextSelection selection,
|
|
|
|
int index) {
|
|
|
|
Expects(index >= 0 && index < 0x0F);
|
|
|
|
|
|
|
|
return IsSubGroupSelection(selection) && (selection.to & (1 << index));
|
|
|
|
}
|
|
|
|
|
2017-12-16 17:05:58 +00:00
|
|
|
[[nodiscard]] inline TextSelection AddGroupItemSelection(
|
2017-12-15 16:25:47 +00:00
|
|
|
TextSelection selection,
|
|
|
|
int index) {
|
|
|
|
Expects(index >= 0 && index < 0x0F);
|
|
|
|
|
|
|
|
const auto bit = uint16(1U << index);
|
|
|
|
return TextSelection(
|
|
|
|
0xFFFF,
|
|
|
|
IsSubGroupSelection(selection) ? (selection.to | bit) : bit);
|
|
|
|
}
|
|
|
|
|
2017-12-16 17:05:58 +00:00
|
|
|
[[nodiscard]] inline TextSelection RemoveGroupItemSelection(
|
2017-12-15 16:25:47 +00:00
|
|
|
TextSelection selection,
|
|
|
|
int index) {
|
|
|
|
Expects(index >= 0 && index < 0x0F);
|
|
|
|
|
|
|
|
const auto bit = uint16(1U << index);
|
|
|
|
return IsSubGroupSelection(selection)
|
|
|
|
? TextSelection(0xFFFF, selection.to & ~bit)
|
|
|
|
: selection;
|
|
|
|
}
|
|
|
|
|
2015-12-21 13:14:29 +00:00
|
|
|
static const int32 FileStatusSizeReady = 0x7FFFFFF0;
|
|
|
|
static const int32 FileStatusSizeLoaded = 0x7FFFFFF1;
|
|
|
|
static const int32 FileStatusSizeFailed = 0x7FFFFFF2;
|
|
|
|
|
|
|
|
QString formatSizeText(qint64 size);
|
|
|
|
QString formatDownloadText(qint64 ready, qint64 total);
|
|
|
|
QString formatDurationText(qint64 duration);
|
2017-04-27 21:17:00 +00:00
|
|
|
QString formatDurationWords(qint64 duration);
|
2015-12-21 13:14:29 +00:00
|
|
|
QString formatDurationAndSizeText(qint64 duration, qint64 size);
|
|
|
|
QString formatGifAndSizeText(qint64 size);
|
|
|
|
QString formatPlayedText(qint64 played, qint64 duration);
|
|
|
|
|
|
|
|
int32 documentColorIndex(DocumentData *document, QString &ext);
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color documentColor(int colorIndex);
|
|
|
|
style::color documentDarkColor(int colorIndex);
|
|
|
|
style::color documentOverColor(int colorIndex);
|
|
|
|
style::color documentSelectedColor(int colorIndex);
|
2016-11-03 10:33:57 +00:00
|
|
|
RoundCorners documentCorners(int colorIndex);
|
2015-12-21 13:14:29 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
class PaintContextBase {
|
2015-12-22 12:49:42 +00:00
|
|
|
public:
|
2019-02-19 06:57:53 +00:00
|
|
|
PaintContextBase(crl::time ms, bool selecting) : ms(ms), selecting(selecting) {
|
2015-12-22 12:49:42 +00:00
|
|
|
}
|
2019-02-19 06:57:53 +00:00
|
|
|
crl::time ms;
|
2015-12-22 12:49:42 +00:00
|
|
|
bool selecting;
|
2016-01-03 23:38:47 +00:00
|
|
|
|
2015-12-22 12:49:42 +00:00
|
|
|
};
|
|
|
|
|
2018-01-14 16:02:25 +00:00
|
|
|
class LayoutItemBase
|
|
|
|
: public RuntimeComposer<LayoutItemBase>
|
|
|
|
, public ClickHandlerHost {
|
2015-12-20 14:05:07 +00:00
|
|
|
public:
|
2018-01-27 13:59:24 +00:00
|
|
|
using TextState = HistoryView::TextState;
|
|
|
|
using StateRequest = HistoryView::StateRequest;
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
LayoutItemBase() {
|
2015-12-20 14:05:07 +00:00
|
|
|
}
|
2016-04-12 21:31:28 +00:00
|
|
|
|
|
|
|
LayoutItemBase(const LayoutItemBase &other) = delete;
|
|
|
|
LayoutItemBase &operator=(const LayoutItemBase &other) = delete;
|
2015-12-20 14:05:07 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
int maxWidth() const {
|
2015-12-20 14:05:07 +00:00
|
|
|
return _maxw;
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
int minHeight() const {
|
2015-12-20 14:05:07 +00:00
|
|
|
return _minh;
|
|
|
|
}
|
|
|
|
virtual void initDimensions() = 0;
|
2017-06-21 21:38:31 +00:00
|
|
|
virtual int resizeGetHeight(int width) {
|
2015-12-20 14:05:07 +00:00
|
|
|
_width = qMin(width, _maxw);
|
|
|
|
_height = _minh;
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
[[nodiscard]] virtual TextState getState(
|
2018-01-11 19:33:26 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const;
|
2017-10-13 19:07:04 +00:00
|
|
|
[[nodiscard]] virtual TextSelection adjustSelection(
|
2018-01-11 19:33:26 +00:00
|
|
|
TextSelection selection,
|
|
|
|
TextSelectType type) const;
|
2015-12-20 14:05:07 +00:00
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
int width() const {
|
2015-12-20 14:05:07 +00:00
|
|
|
return _width;
|
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
int height() const {
|
2015-12-20 14:05:07 +00:00
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:38:31 +00:00
|
|
|
bool hasPoint(QPoint point) const {
|
|
|
|
return QRect(0, 0, width(), height()).contains(point);
|
2015-12-20 14:05:07 +00:00
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
virtual ~LayoutItemBase() {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
int _width = 0;
|
|
|
|
int _height = 0;
|
|
|
|
int _maxw = 0;
|
|
|
|
int _minh = 0;
|
|
|
|
|
|
|
|
};
|