Slightly improved code style in HistoryView::Document.

This commit is contained in:
23rd 2024-01-04 13:39:43 +03:00
parent 098e797045
commit d8d9441731
3 changed files with 31 additions and 48 deletions

View File

@ -267,17 +267,18 @@ void ResolveDocument(
return false;
}
const auto &location = document->location(true);
const auto mime = u"image/"_q;
if (!location.isEmpty() && location.accessEnable()) {
const auto guard = gsl::finally([&] {
location.accessDisable();
});
const auto path = location.name();
if (Core::MimeTypeForFile(QFileInfo(path)).name().startsWith("image/")
if (Core::MimeTypeForFile(QFileInfo(path)).name().startsWith(mime)
&& QImageReader(path).canRead()) {
showDocument();
return true;
}
} else if (document->mimeString().startsWith("image/")
} else if (document->mimeString().startsWith(mime)
&& !media->bytes().isEmpty()) {
auto bytes = media->bytes();
auto buffer = QBuffer(&bytes);

View File

@ -23,24 +23,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_cursor_state.h"
#include "history/view/history_view_transcribe_button.h"
#include "history/view/media/history_view_media_common.h"
#include "ui/image/image.h"
#include "ui/text/format_values.h"
#include "ui/text/format_song_document_name.h"
#include "ui/text/text_utilities.h"
#include "ui/chat/message_bubble.h"
#include "ui/chat/chat_style.h"
#include "ui/cached_round_corners.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "ui/rect.h"
#include "ui/ui_utility.h"
#include "data/data_session.h"
#include "data/data_document.h"
#include "data/data_document_media.h"
#include "data/data_document_resolver.h"
#include "data/data_media_types.h"
#include "data/data_file_click_handler.h"
#include "data/data_file_origin.h"
#include "api/api_transcribes.h"
#include "apiwrap.h"
#include "styles/style_chat.h"
@ -145,6 +139,29 @@ void DrawCornerBadgeTTL(
};
}
void FillThumbnailOverlay(
QPainter &p,
QRect rect,
Ui::BubbleRounding rounding,
const PaintContext &context) {
using Corner = Ui::BubbleCornerRounding;
using Radius = Ui::CachedCornerRadius;
auto corners = Ui::CornersPixmaps();
const auto &st = context.st;
const auto lookup = [&](Corner corner) {
switch (corner) {
case Corner::None: return Radius::Small;
case Corner::Small: return Radius::ThumbSmall;
case Corner::Large: return Radius::ThumbLarge;
}
Unexpected("Corner value in FillThumbnailOverlay.");
};
for (auto i = 0; i != 4; ++i) {
corners.p[i] = st->msgSelectOverlayCorners(lookup(rounding[i])).p[i];
}
Ui::FillComplexOverlayRect(p, rect, st->msgSelectOverlay(), corners);
}
[[nodiscard]] QString CleanTagSymbols(const QString &value) {
auto result = QString();
const auto begin = value.begin(), end = value.end();
@ -648,7 +665,7 @@ void Document::draw(
validateThumbnail(thumbed, st.thumbSize, rounding);
p.drawImage(rthumb, thumbed->thumbnail);
if (context.selected()) {
fillThumbnailOverlay(p, rthumb, rounding, context);
FillThumbnailOverlay(p, rthumb, rounding, context);
}
if (radial || (!loaded && !_data->loading()) || _data->waitingForAlbum()) {
@ -970,29 +987,6 @@ void Document::validateThumbnail(
thumbed->rounding = rounding;
}
void Document::fillThumbnailOverlay(
QPainter &p,
QRect rect,
Ui::BubbleRounding rounding,
const PaintContext &context) const {
using Corner = Ui::BubbleCornerRounding;
using Radius = Ui::CachedCornerRadius;
auto corners = Ui::CornersPixmaps();
const auto &st = context.st;
const auto lookup = [&](Corner corner) {
switch (corner) {
case Corner::None: return Radius::Small;
case Corner::Small: return Radius::ThumbSmall;
case Corner::Large: return Radius::ThumbLarge;
}
Unexpected("Corner value in Document::fillThumbnailOverlay.");
};
for (auto i = 0; i != 4; ++i) {
corners.p[i] = st->msgSelectOverlayCorners(lookup(rounding[i])).p[i];
}
Ui::FillComplexOverlayRect(p, rect, st->msgSelectOverlay(), corners);
}
bool Document::hasHeavyPart() const {
return (_dataMedia != nullptr);
}
@ -1709,7 +1703,7 @@ bool DrawThumbnailAsSongCover(
const style::color &colored,
const std::shared_ptr<Data::DocumentMedia> &dataMedia,
const QRect &rect,
const bool selected) {
bool selected) {
if (!dataMedia) {
return false;
}

View File

@ -17,11 +17,9 @@ namespace Data {
class DocumentMedia;
} // namespace Data
namespace Ui {
namespace Text {
namespace Ui::Text {
class String;
} // namespace Text
} // namespace Ui
} // namespace Ui::Text
namespace HistoryView {
@ -101,11 +99,6 @@ protected:
bool dataLoaded() const override;
private:
struct StateFromPlayback {
int64 statusSize = 0;
bool showPause = false;
TimeId realDuration = 0;
};
enum class LayoutMode {
Full,
Grouped,
@ -139,11 +132,6 @@ private:
not_null<const HistoryDocumentThumbed*> thumbed,
int size,
Ui::BubbleRounding rounding) const;
void fillThumbnailOverlay(
QPainter &p,
QRect rect,
Ui::BubbleRounding rounding,
const PaintContext &context) const;
void setStatusSize(int64 newSize, TimeId realDuration = 0) const;
bool updateStatusText() const; // returns showPause
@ -191,6 +179,6 @@ bool DrawThumbnailAsSongCover(
const style::color &colored,
const std::shared_ptr<Data::DocumentMedia> &dataMedia,
const QRect &rect,
const bool selected = false);
bool selected = false);
} // namespace HistoryView