mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-31 06:35:14 +00:00
Selection of text in attachments: captions, web page previews.
Text/HistoryItem/HistoryMedia::getState() unified. Text::getStateElided added. Tested with web page previews only.
This commit is contained in:
@@ -729,7 +729,7 @@ protected:
|
||||
|
||||
};
|
||||
|
||||
class HistoryMessage; // dynamic_cast optimize
|
||||
class HistoryMessage;
|
||||
|
||||
enum HistoryCursorState {
|
||||
HistoryDefaultCursorState,
|
||||
@@ -738,6 +738,36 @@ enum HistoryCursorState {
|
||||
HistoryInForwardedCursorState,
|
||||
};
|
||||
|
||||
struct HistoryTextState {
|
||||
HistoryTextState() = default;
|
||||
HistoryTextState(const Text::StateResult &state)
|
||||
: cursor(state.uponSymbol ? HistoryInTextCursorState : HistoryDefaultCursorState)
|
||||
, link(state.link)
|
||||
, afterSymbol(state.afterSymbol)
|
||||
, symbol(state.symbol) {
|
||||
}
|
||||
HistoryTextState &operator=(const Text::StateResult &state) {
|
||||
cursor = state.uponSymbol ? HistoryInTextCursorState : HistoryDefaultCursorState;
|
||||
link = state.link;
|
||||
afterSymbol = state.afterSymbol;
|
||||
symbol = state.symbol;
|
||||
return *this;
|
||||
}
|
||||
HistoryCursorState cursor = HistoryDefaultCursorState;
|
||||
ClickHandlerPtr link;
|
||||
bool afterSymbol = false;
|
||||
uint16 symbol = 0;
|
||||
};
|
||||
|
||||
struct HistoryStateRequest {
|
||||
Text::StateRequest::Flags flags = Text::StateRequest::Flag::LookupLink;
|
||||
Text::StateRequest forText() const {
|
||||
Text::StateRequest result;
|
||||
result.flags = flags;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
enum InfoDisplayType {
|
||||
InfoDisplayDefault,
|
||||
InfoDisplayOverImage,
|
||||
@@ -936,7 +966,7 @@ public:
|
||||
int naturalHeight() const;
|
||||
|
||||
void paint(Painter &p, const QRect &clip) const;
|
||||
void getState(ClickHandlerPtr &lnk, int x, int y) const;
|
||||
ClickHandlerPtr getState(int x, int y) const;
|
||||
|
||||
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active);
|
||||
void clickHandlerPressedChanged(const ClickHandlerPtr &p, bool pressed);
|
||||
@@ -1068,7 +1098,7 @@ public:
|
||||
}
|
||||
return resizeGetHeight_(width);
|
||||
}
|
||||
virtual void draw(Painter &p, const QRect &r, uint32 selection, uint64 ms) const = 0;
|
||||
virtual void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const = 0;
|
||||
|
||||
virtual void dependencyItemRemoved(HistoryItem *dependency) {
|
||||
}
|
||||
@@ -1216,17 +1246,11 @@ public:
|
||||
virtual bool hasPoint(int x, int y) const {
|
||||
return false;
|
||||
}
|
||||
virtual void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const {
|
||||
lnk.clear();
|
||||
state = HistoryDefaultCursorState;
|
||||
}
|
||||
virtual void getSymbol(uint16 &symbol, bool &after, bool &upon, int x, int y) const { // from text
|
||||
upon = hasPoint(x, y);
|
||||
symbol = upon ? 0xFFFF : 0;
|
||||
after = false;
|
||||
}
|
||||
virtual uint32 adjustSelection(uint16 from, uint16 to, TextSelectType type) const {
|
||||
return (from << 16) | to;
|
||||
|
||||
virtual HistoryTextState getState(int x, int y, HistoryStateRequest request) const = 0;
|
||||
|
||||
virtual TextSelection adjustSelection(TextSelection selection, TextSelectType type) const {
|
||||
return selection;
|
||||
}
|
||||
|
||||
// ClickHandlerHost interface
|
||||
@@ -1251,7 +1275,7 @@ public:
|
||||
}
|
||||
virtual void previousItemChanged();
|
||||
|
||||
virtual QString selectedText(uint32 selection) const {
|
||||
virtual QString selectedText(TextSelection selection) const {
|
||||
return qsl("[-]");
|
||||
}
|
||||
virtual QString inDialogsText() const {
|
||||
@@ -1514,6 +1538,13 @@ protected:
|
||||
return const_cast<ReplyKeyboard*>(static_cast<const HistoryItem*>(this)->inlineReplyKeyboard());
|
||||
}
|
||||
|
||||
TextSelection toMediaSelection(TextSelection selection) const {
|
||||
return unshiftSelection(selection, _text);
|
||||
}
|
||||
TextSelection fromMediaSelection(TextSelection selection) const {
|
||||
return shiftSelection(selection, _text);
|
||||
}
|
||||
|
||||
Text _text = { int(st::msgMinWidth) };
|
||||
int32 _textWidth, _textHeight;
|
||||
|
||||
@@ -1624,8 +1655,8 @@ public:
|
||||
_width = qMin(width, _maxw);
|
||||
return _height;
|
||||
}
|
||||
virtual void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const = 0;
|
||||
virtual void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const = 0;
|
||||
virtual void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const = 0;
|
||||
virtual HistoryTextState getState(int x, int y, HistoryStateRequest request) const = 0;
|
||||
|
||||
// if we are in selecting items mode perhaps we want to
|
||||
// toggle selection instead of activating the pressed link
|
||||
@@ -1636,6 +1667,10 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual TextSelection adjustSelection(TextSelection selection, TextSelectType type) const {
|
||||
return selection;
|
||||
}
|
||||
|
||||
// if we press and drag this link should we drag the item
|
||||
virtual bool dragItemByHandler(const ClickHandlerPtr &p) const = 0;
|
||||
|
||||
@@ -1829,8 +1864,12 @@ public:
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override {
|
||||
return _caption.adjustSelection(selection, type);
|
||||
}
|
||||
|
||||
const QString inDialogsText() const override;
|
||||
const QString inHistoryText() const override;
|
||||
@@ -1902,8 +1941,12 @@ public:
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override {
|
||||
return _caption.adjustSelection(selection, type);
|
||||
}
|
||||
|
||||
const QString inDialogsText() const override;
|
||||
const QString inHistoryText() const override;
|
||||
@@ -2015,8 +2058,15 @@ public:
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override {
|
||||
if (auto captioned = Get<HistoryDocumentCaptioned>()) {
|
||||
return captioned->_caption.adjustSelection(selection, type);
|
||||
}
|
||||
return selection;
|
||||
}
|
||||
|
||||
const QString inDialogsText() const override;
|
||||
const QString inHistoryText() const override;
|
||||
@@ -2095,8 +2145,12 @@ public:
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override {
|
||||
return _caption.adjustSelection(selection, type);
|
||||
}
|
||||
|
||||
const QString inDialogsText() const override;
|
||||
const QString inHistoryText() const override;
|
||||
@@ -2183,8 +2237,8 @@ public:
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const override {
|
||||
return true;
|
||||
@@ -2255,8 +2309,8 @@ public:
|
||||
|
||||
void initDimensions() override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const override {
|
||||
return true;
|
||||
@@ -2318,8 +2372,10 @@ public:
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int width) override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override;
|
||||
|
||||
bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const override {
|
||||
return _attach && _attach->toggleSelectionByHandlerClick(p);
|
||||
@@ -2376,6 +2432,13 @@ public:
|
||||
~HistoryWebPage();
|
||||
|
||||
private:
|
||||
TextSelection toDescriptionSelection(TextSelection selection) const {
|
||||
return unshiftSelection(selection, _title);
|
||||
}
|
||||
TextSelection fromDescriptionSelection(TextSelection selection) const {
|
||||
return shiftSelection(selection, _title);
|
||||
}
|
||||
|
||||
WebPageData *_data;
|
||||
ClickHandlerPtr _openl;
|
||||
HistoryMedia *_attach;
|
||||
@@ -2440,8 +2503,10 @@ public:
|
||||
void initDimensions() override;
|
||||
int resizeGetHeight(int32 width) override;
|
||||
|
||||
void draw(Painter &p, const QRect &r, bool selected, uint64 ms) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override;
|
||||
|
||||
bool toggleSelectionByHandlerClick(const ClickHandlerPtr &p) const override {
|
||||
return p == _link;
|
||||
@@ -2467,6 +2532,13 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
TextSelection toDescriptionSelection(TextSelection selection) const {
|
||||
return unshiftSelection(selection, _title);
|
||||
}
|
||||
TextSelection fromDescriptionSelection(TextSelection selection) const {
|
||||
return shiftSelection(selection, _title);
|
||||
}
|
||||
|
||||
LocationData *_data;
|
||||
Text _title, _description;
|
||||
ClickHandlerPtr _link;
|
||||
@@ -2538,7 +2610,7 @@ public:
|
||||
void drawInfo(Painter &p, int32 right, int32 bottom, int32 width, bool selected, InfoDisplayType type) const override;
|
||||
void setViewsCount(int32 count) override;
|
||||
void setId(MsgId newId) override;
|
||||
void draw(Painter &p, const QRect &r, uint32 selection, uint64 ms) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
|
||||
void dependencyItemRemoved(HistoryItem *dependency) override;
|
||||
|
||||
@@ -2547,12 +2619,9 @@ public:
|
||||
bool hasPoint(int x, int y) const override;
|
||||
bool pointInTime(int32 right, int32 bottom, int x, int y, InfoDisplayType type) const override;
|
||||
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
void getSymbol(uint16 &symbol, bool &after, bool &upon, int x, int y) const override;
|
||||
uint32 adjustSelection(uint16 from, uint16 to, TextSelectType type) const override {
|
||||
return _text.adjustSelection(from, to, type);
|
||||
}
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override;
|
||||
|
||||
// ClickHandlerHost interface
|
||||
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override {
|
||||
@@ -2573,7 +2642,7 @@ public:
|
||||
int32 addToOverview(AddToOverviewMethod method) override;
|
||||
void eraseFromOverview();
|
||||
|
||||
QString selectedText(uint32 selection) const override;
|
||||
QString selectedText(TextSelection selection) const override;
|
||||
QString inDialogsText() const override;
|
||||
HistoryMedia *getMedia() const override;
|
||||
void setText(const QString &text, const EntitiesInText &entities) override;
|
||||
@@ -2763,12 +2832,12 @@ public:
|
||||
|
||||
void countPositionAndSize(int32 &left, int32 &width) const;
|
||||
|
||||
void draw(Painter &p, const QRect &r, uint32 selection, uint64 ms) const override;
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const override;
|
||||
bool hasPoint(int x, int y) const override;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const override;
|
||||
void getSymbol(uint16 &symbol, bool &after, bool &upon, int x, int y) const override;
|
||||
uint32 adjustSelection(uint16 from, uint16 to, TextSelectType type) const override {
|
||||
return _text.adjustSelection(from, to, type);
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const override;
|
||||
|
||||
TextSelection adjustSelection(TextSelection selection, TextSelectType type) const override {
|
||||
return _text.adjustSelection(selection, type);
|
||||
}
|
||||
|
||||
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override {
|
||||
@@ -2789,7 +2858,7 @@ public:
|
||||
bool serviceMsg() const override {
|
||||
return true;
|
||||
}
|
||||
QString selectedText(uint32 selection) const override;
|
||||
QString selectedText(TextSelection selection) const override;
|
||||
QString inDialogsText() const override;
|
||||
QString inReplyText() const override;
|
||||
|
||||
@@ -2824,12 +2893,8 @@ public:
|
||||
return _create(history, newItem, date);
|
||||
}
|
||||
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const;
|
||||
void getSymbol(uint16 &symbol, bool &after, bool &upon, int x, int y) const {
|
||||
symbol = 0xFFFF;
|
||||
after = false;
|
||||
upon = false;
|
||||
}
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const;
|
||||
|
||||
QString selectedText(uint32 selection) const {
|
||||
return QString();
|
||||
}
|
||||
@@ -2877,13 +2942,9 @@ public:
|
||||
return _create(history, wasMinId, date);
|
||||
}
|
||||
|
||||
void draw(Painter &p, const QRect &r, uint32 selection, uint64 ms) const;
|
||||
void getState(ClickHandlerPtr &lnk, HistoryCursorState &state, int x, int y) const;
|
||||
void getSymbol(uint16 &symbol, bool &after, bool &upon, int x, int y) const {
|
||||
symbol = 0xFFFF;
|
||||
after = false;
|
||||
upon = false;
|
||||
}
|
||||
void draw(Painter &p, const QRect &r, TextSelection selection, uint64 ms) const;
|
||||
HistoryTextState getState(int x, int y, HistoryStateRequest request) const;
|
||||
|
||||
QString selectedText(uint32 selection) const {
|
||||
return QString();
|
||||
}
|
||||
|
Reference in New Issue
Block a user