Slightly improved code style in HistoryView::Document.
This commit is contained in:
parent
098e797045
commit
d8d9441731
|
@ -267,17 +267,18 @@ void ResolveDocument(
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const auto &location = document->location(true);
|
const auto &location = document->location(true);
|
||||||
|
const auto mime = u"image/"_q;
|
||||||
if (!location.isEmpty() && location.accessEnable()) {
|
if (!location.isEmpty() && location.accessEnable()) {
|
||||||
const auto guard = gsl::finally([&] {
|
const auto guard = gsl::finally([&] {
|
||||||
location.accessDisable();
|
location.accessDisable();
|
||||||
});
|
});
|
||||||
const auto path = location.name();
|
const auto path = location.name();
|
||||||
if (Core::MimeTypeForFile(QFileInfo(path)).name().startsWith("image/")
|
if (Core::MimeTypeForFile(QFileInfo(path)).name().startsWith(mime)
|
||||||
&& QImageReader(path).canRead()) {
|
&& QImageReader(path).canRead()) {
|
||||||
showDocument();
|
showDocument();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (document->mimeString().startsWith("image/")
|
} else if (document->mimeString().startsWith(mime)
|
||||||
&& !media->bytes().isEmpty()) {
|
&& !media->bytes().isEmpty()) {
|
||||||
auto bytes = media->bytes();
|
auto bytes = media->bytes();
|
||||||
auto buffer = QBuffer(&bytes);
|
auto buffer = QBuffer(&bytes);
|
||||||
|
|
|
@ -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_cursor_state.h"
|
||||||
#include "history/view/history_view_transcribe_button.h"
|
#include "history/view/history_view_transcribe_button.h"
|
||||||
#include "history/view/media/history_view_media_common.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_values.h"
|
||||||
#include "ui/text/format_song_document_name.h"
|
#include "ui/text/format_song_document_name.h"
|
||||||
#include "ui/text/text_utilities.h"
|
#include "ui/text/text_utilities.h"
|
||||||
#include "ui/chat/message_bubble.h"
|
|
||||||
#include "ui/chat/chat_style.h"
|
#include "ui/chat/chat_style.h"
|
||||||
#include "ui/cached_round_corners.h"
|
|
||||||
#include "ui/painter.h"
|
#include "ui/painter.h"
|
||||||
#include "ui/power_saving.h"
|
#include "ui/power_saving.h"
|
||||||
#include "ui/rect.h"
|
#include "ui/rect.h"
|
||||||
#include "ui/ui_utility.h"
|
|
||||||
#include "data/data_session.h"
|
#include "data/data_session.h"
|
||||||
#include "data/data_document.h"
|
#include "data/data_document.h"
|
||||||
#include "data/data_document_media.h"
|
#include "data/data_document_media.h"
|
||||||
#include "data/data_document_resolver.h"
|
#include "data/data_document_resolver.h"
|
||||||
#include "data/data_media_types.h"
|
|
||||||
#include "data/data_file_click_handler.h"
|
#include "data/data_file_click_handler.h"
|
||||||
#include "data/data_file_origin.h"
|
|
||||||
#include "api/api_transcribes.h"
|
#include "api/api_transcribes.h"
|
||||||
#include "apiwrap.h"
|
#include "apiwrap.h"
|
||||||
#include "styles/style_chat.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) {
|
[[nodiscard]] QString CleanTagSymbols(const QString &value) {
|
||||||
auto result = QString();
|
auto result = QString();
|
||||||
const auto begin = value.begin(), end = value.end();
|
const auto begin = value.begin(), end = value.end();
|
||||||
|
@ -648,7 +665,7 @@ void Document::draw(
|
||||||
validateThumbnail(thumbed, st.thumbSize, rounding);
|
validateThumbnail(thumbed, st.thumbSize, rounding);
|
||||||
p.drawImage(rthumb, thumbed->thumbnail);
|
p.drawImage(rthumb, thumbed->thumbnail);
|
||||||
if (context.selected()) {
|
if (context.selected()) {
|
||||||
fillThumbnailOverlay(p, rthumb, rounding, context);
|
FillThumbnailOverlay(p, rthumb, rounding, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (radial || (!loaded && !_data->loading()) || _data->waitingForAlbum()) {
|
if (radial || (!loaded && !_data->loading()) || _data->waitingForAlbum()) {
|
||||||
|
@ -970,29 +987,6 @@ void Document::validateThumbnail(
|
||||||
thumbed->rounding = rounding;
|
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 {
|
bool Document::hasHeavyPart() const {
|
||||||
return (_dataMedia != nullptr);
|
return (_dataMedia != nullptr);
|
||||||
}
|
}
|
||||||
|
@ -1709,7 +1703,7 @@ bool DrawThumbnailAsSongCover(
|
||||||
const style::color &colored,
|
const style::color &colored,
|
||||||
const std::shared_ptr<Data::DocumentMedia> &dataMedia,
|
const std::shared_ptr<Data::DocumentMedia> &dataMedia,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
const bool selected) {
|
bool selected) {
|
||||||
if (!dataMedia) {
|
if (!dataMedia) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,9 @@ namespace Data {
|
||||||
class DocumentMedia;
|
class DocumentMedia;
|
||||||
} // namespace Data
|
} // namespace Data
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui::Text {
|
||||||
namespace Text {
|
|
||||||
class String;
|
class String;
|
||||||
} // namespace Text
|
} // namespace Ui::Text
|
||||||
} // namespace Ui
|
|
||||||
|
|
||||||
namespace HistoryView {
|
namespace HistoryView {
|
||||||
|
|
||||||
|
@ -101,11 +99,6 @@ protected:
|
||||||
bool dataLoaded() const override;
|
bool dataLoaded() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct StateFromPlayback {
|
|
||||||
int64 statusSize = 0;
|
|
||||||
bool showPause = false;
|
|
||||||
TimeId realDuration = 0;
|
|
||||||
};
|
|
||||||
enum class LayoutMode {
|
enum class LayoutMode {
|
||||||
Full,
|
Full,
|
||||||
Grouped,
|
Grouped,
|
||||||
|
@ -139,11 +132,6 @@ private:
|
||||||
not_null<const HistoryDocumentThumbed*> thumbed,
|
not_null<const HistoryDocumentThumbed*> thumbed,
|
||||||
int size,
|
int size,
|
||||||
Ui::BubbleRounding rounding) const;
|
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;
|
void setStatusSize(int64 newSize, TimeId realDuration = 0) const;
|
||||||
bool updateStatusText() const; // returns showPause
|
bool updateStatusText() const; // returns showPause
|
||||||
|
@ -191,6 +179,6 @@ bool DrawThumbnailAsSongCover(
|
||||||
const style::color &colored,
|
const style::color &colored,
|
||||||
const std::shared_ptr<Data::DocumentMedia> &dataMedia,
|
const std::shared_ptr<Data::DocumentMedia> &dataMedia,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
const bool selected = false);
|
bool selected = false);
|
||||||
|
|
||||||
} // namespace HistoryView
|
} // namespace HistoryView
|
||||||
|
|
Loading…
Reference in New Issue