tdesktop/Telegram/SourceFiles/layout.h

137 lines
3.3 KiB
C
Raw Normal View History

2015-12-20 14:05:07 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
2015-12-20 14:05:07 +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"
namespace HistoryView {
struct TextState;
struct StateRequest;
} // namespace HistoryView
enum RoundCorners : int;
constexpr auto FullSelection = TextSelection { 0xFFFF, 0xFFFF };
2015-12-20 14:05:07 +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));
}
[[nodiscard]] inline TextSelection AddGroupItemSelection(
TextSelection selection,
int index) {
Expects(index >= 0 && index < 0x0F);
const auto bit = uint16(1U << index);
return TextSelection(
0xFFFF,
IsSubGroupSelection(selection) ? (selection.to | bit) : bit);
}
[[nodiscard]] inline TextSelection RemoveGroupItemSelection(
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);
style::color documentColor(int colorIndex);
style::color documentDarkColor(int colorIndex);
style::color documentOverColor(int colorIndex);
style::color documentSelectedColor(int colorIndex);
RoundCorners documentCorners(int colorIndex);
2015-12-21 13:14:29 +00:00
class PaintContextBase {
public:
PaintContextBase(crl::time ms, bool selecting) : ms(ms), selecting(selecting) {
}
crl::time ms;
bool selecting;
};
class LayoutItemBase
: public RuntimeComposer<LayoutItemBase>
, public ClickHandlerHost {
2015-12-20 14:05:07 +00:00
public:
using TextState = HistoryView::TextState;
using StateRequest = HistoryView::StateRequest;
LayoutItemBase() {
2015-12-20 14:05:07 +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;
}
[[nodiscard]] virtual TextState getState(
QPoint point,
StateRequest request) const;
2017-10-13 19:07:04 +00:00
[[nodiscard]] virtual TextSelection adjustSelection(
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
}
virtual ~LayoutItemBase() {
}
protected:
int _width = 0;
int _height = 0;
int _maxw = 0;
int _minh = 0;
};