mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Added display of full filenames for documents in tooltips.
This commit is contained in:
parent
c1b2d7ed4c
commit
38f5cda800
5 changed files with 77 additions and 2 deletions
|
@ -15,6 +15,7 @@ constexpr auto kPhotoLinkMediaProperty = 0x02;
|
|||
constexpr auto kDocumentLinkMediaProperty = 0x03;
|
||||
constexpr auto kSendReactionEmojiProperty = 0x04;
|
||||
constexpr auto kReactionsCountEmojiProperty = 0x05;
|
||||
constexpr auto kDocumentFilenameTooltipProperty = 0x06;
|
||||
|
||||
namespace Ui {
|
||||
class Show;
|
||||
|
|
|
@ -53,6 +53,10 @@ DocumentClickHandler::DocumentClickHandler(
|
|||
reinterpret_cast<qulonglong>(_document.get()));
|
||||
}
|
||||
|
||||
QString DocumentClickHandler::tooltip() const {
|
||||
return property(kDocumentFilenameTooltipProperty).value<QString>();
|
||||
}
|
||||
|
||||
DocumentOpenClickHandler::DocumentOpenClickHandler(
|
||||
not_null<DocumentData*> document,
|
||||
Fn<void(FullMsgId)> &&callback,
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
not_null<DocumentData*> document,
|
||||
FullMsgId context = FullMsgId());
|
||||
|
||||
QString tooltip() const override;
|
||||
|
||||
[[nodiscard]] not_null<DocumentData*> document() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "media/player/media_player_instance.h"
|
||||
#include "history/history_item_components.h"
|
||||
#include "history/history.h"
|
||||
#include "core/click_handler_types.h" // kDocumentFilenameTooltipProperty.
|
||||
#include "history/view/history_view_element.h"
|
||||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "history/view/history_view_transcribe_button.h"
|
||||
|
@ -178,6 +179,7 @@ Document::Document(
|
|||
createComponents(!caption.isEmpty());
|
||||
if (const auto named = Get<HistoryDocumentNamed>()) {
|
||||
fillNamedFromData(named);
|
||||
_tooltipFilename.setTooltipText(named->name);
|
||||
}
|
||||
|
||||
setDocumentLinks(_data, realParent);
|
||||
|
@ -647,11 +649,13 @@ void Document::draw(
|
|||
} else if (auto named = Get<HistoryDocumentNamed>()) {
|
||||
p.setFont(st::semiboldFont);
|
||||
p.setPen(stm->historyFileNameFg);
|
||||
if (namewidth < named->namew) {
|
||||
const auto elided = (namewidth < named->namew);
|
||||
if (elided) {
|
||||
p.drawTextLeft(nameleft, nametop, width, st::semiboldFont->elided(named->name, namewidth, Qt::ElideMiddle));
|
||||
} else {
|
||||
p.drawTextLeft(nameleft, nametop, width, named->name, named->namew);
|
||||
}
|
||||
_tooltipFilename.setElided(elided);
|
||||
}
|
||||
|
||||
auto statusText = voiceStatusOverride.isEmpty() ? _statusText : voiceStatusOverride;
|
||||
|
@ -926,11 +930,15 @@ TextState Document::textState(
|
|||
const auto nameleft = st.padding.left() + st.thumbSize + st.thumbSkip;
|
||||
const auto nametop = st.nameTop - topMinus;
|
||||
const auto nameright = st.padding.right();
|
||||
auto namewidth = width - nameleft - nameright;
|
||||
const auto linktop = st.linkTop - topMinus;
|
||||
auto bottom = st.padding.top() + st.thumbSize + st.padding.bottom() - topMinus;
|
||||
const auto rthumb = style::rtlrect(st.padding.left(), st.padding.top() - topMinus, st.thumbSize, st.thumbSize, width);
|
||||
const auto innerSize = st::msgFileLayout.thumbSize;
|
||||
const auto inner = QRect(rthumb.x() + (rthumb.width() - innerSize) / 2, rthumb.y() + (rthumb.height() - innerSize) / 2, innerSize, innerSize);
|
||||
|
||||
const auto filenameMoused = QRect(nameleft, nametop, namewidth, st::semiboldFont->height).contains(point);
|
||||
_tooltipFilename.setMoused(filenameMoused);
|
||||
if (const auto thumbed = Get<HistoryDocumentThumbed>()) {
|
||||
if ((_data->loading() || _data->uploading()) && rthumb.contains(point)) {
|
||||
result.link = _cancell;
|
||||
|
@ -958,7 +966,6 @@ TextState Document::textState(
|
|||
}
|
||||
|
||||
const auto voice = Get<HistoryDocumentVoice>();
|
||||
auto namewidth = width - nameleft - nameright;
|
||||
auto transcribeLength = 0;
|
||||
auto transcribeHeight = 0;
|
||||
auto painth = layout.height();
|
||||
|
@ -1035,8 +1042,10 @@ TextState Document::textState(
|
|||
} else {
|
||||
result.link = _savel;
|
||||
}
|
||||
_tooltipFilename.updateTooltipForLink(result.link.get());
|
||||
return result;
|
||||
}
|
||||
_tooltipFilename.updateTooltipForState(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1388,6 +1397,48 @@ Ui::Text::String Document::createCaption() {
|
|||
return File::createCaption(_realParent);
|
||||
}
|
||||
|
||||
void Document::TooltipFilename::setElided(bool value) {
|
||||
if (_elided != value) {
|
||||
_elided = value;
|
||||
_stale = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Document::TooltipFilename::setMoused(bool value) {
|
||||
if (_moused != value) {
|
||||
_moused = value;
|
||||
_stale = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Document::TooltipFilename::setTooltipText(QString text) {
|
||||
if (_tooltip != text) {
|
||||
_tooltip = text;
|
||||
_stale = true;
|
||||
}
|
||||
}
|
||||
|
||||
void Document::TooltipFilename::updateTooltipForLink(ClickHandler *link) {
|
||||
if (_lastLink != link) {
|
||||
_lastLink = link;
|
||||
_stale = true;
|
||||
}
|
||||
if (_stale && link) {
|
||||
_stale = false;
|
||||
link->setProperty(
|
||||
kDocumentFilenameTooltipProperty,
|
||||
(_elided && _moused) ? _tooltip : QString());
|
||||
}
|
||||
}
|
||||
|
||||
void Document::TooltipFilename::updateTooltipForState(
|
||||
TextState &state) const {
|
||||
if (_elided && _moused) {
|
||||
state.customTooltip = true;
|
||||
state.customTooltipText = _tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
bool DrawThumbnailAsSongCover(
|
||||
Painter &p,
|
||||
const style::color &colored,
|
||||
|
|
|
@ -157,6 +157,23 @@ private:
|
|||
mutable QImage _iconCache;
|
||||
mutable QImage _cornerDownloadCache;
|
||||
|
||||
class TooltipFilename {
|
||||
public:
|
||||
void setElided(bool value);
|
||||
void setMoused(bool value);
|
||||
void setTooltipText(QString text);
|
||||
void updateTooltipForLink(ClickHandler *link);
|
||||
void updateTooltipForState(TextState &state) const;
|
||||
private:
|
||||
ClickHandler *_lastLink = nullptr;
|
||||
bool _elided = false;
|
||||
bool _moused = false;
|
||||
bool _stale = false;
|
||||
QString _tooltip;
|
||||
};
|
||||
|
||||
mutable TooltipFilename _tooltipFilename;
|
||||
|
||||
};
|
||||
|
||||
bool DrawThumbnailAsSongCover(
|
||||
|
|
Loading…
Add table
Reference in a new issue