mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-17 22:57:11 +02:00
Moved generic document preview info to separated file.
This commit is contained in:
parent
6e2f8eb9a7
commit
c6071d1148
8 changed files with 168 additions and 134 deletions
|
@ -702,6 +702,8 @@ PRIVATE
|
|||
lang/lang_numbers_animation.h
|
||||
lang/lang_translator.cpp
|
||||
lang/lang_translator.h
|
||||
layout/layout_document_generic_preview.cpp
|
||||
layout/layout_document_generic_preview.h
|
||||
main/main_account.cpp
|
||||
main/main_account.h
|
||||
main/main_app_config.cpp
|
||||
|
|
|
@ -7,120 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "layout.h"
|
||||
|
||||
#include "data/data_document.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "mainwidget.h"
|
||||
#include "storage/file_upload.h"
|
||||
#include "mainwindow.h"
|
||||
#include "core/file_utilities.h"
|
||||
#include "boxes/add_contact_box.h"
|
||||
#include "boxes/confirm_box.h"
|
||||
#include "media/audio/media_audio.h"
|
||||
#include "storage/localstorage.h"
|
||||
#include "history/view/history_view_cursor_state.h"
|
||||
#include "ui/cached_round_corners.h"
|
||||
|
||||
int32 documentColorIndex(DocumentData *document, QString &ext) {
|
||||
auto colorIndex = 0;
|
||||
|
||||
auto name = document
|
||||
? (document->filename().isEmpty()
|
||||
? (document->sticker()
|
||||
? tr::lng_in_dlg_sticker(tr::now)
|
||||
: qsl("Unknown File"))
|
||||
: document->filename())
|
||||
: tr::lng_message_empty(tr::now);
|
||||
name = name.toLower();
|
||||
auto lastDot = name.lastIndexOf('.');
|
||||
auto mime = document
|
||||
? document->mimeString().toLower()
|
||||
: QString();
|
||||
if (name.endsWith(qstr(".doc")) ||
|
||||
name.endsWith(qstr(".docx")) ||
|
||||
name.endsWith(qstr(".txt")) ||
|
||||
name.endsWith(qstr(".psd")) ||
|
||||
mime.startsWith(qstr("text/"))) {
|
||||
colorIndex = 0;
|
||||
} else if (
|
||||
name.endsWith(qstr(".xls")) ||
|
||||
name.endsWith(qstr(".xlsx")) ||
|
||||
name.endsWith(qstr(".csv"))) {
|
||||
colorIndex = 1;
|
||||
} else if (
|
||||
name.endsWith(qstr(".pdf")) ||
|
||||
name.endsWith(qstr(".ppt")) ||
|
||||
name.endsWith(qstr(".pptx")) ||
|
||||
name.endsWith(qstr(".key"))) {
|
||||
colorIndex = 2;
|
||||
} else if (
|
||||
name.endsWith(qstr(".zip")) ||
|
||||
name.endsWith(qstr(".rar")) ||
|
||||
name.endsWith(qstr(".ai")) ||
|
||||
name.endsWith(qstr(".mp3")) ||
|
||||
name.endsWith(qstr(".mov")) ||
|
||||
name.endsWith(qstr(".avi"))) {
|
||||
colorIndex = 3;
|
||||
} else {
|
||||
auto ch = (lastDot >= 0 && lastDot + 1 < name.size())
|
||||
? name.at(lastDot + 1)
|
||||
: (name.isEmpty()
|
||||
? (mime.isEmpty() ? '0' : mime.at(0))
|
||||
: name.at(0));
|
||||
colorIndex = (ch.unicode() % 4);
|
||||
}
|
||||
|
||||
ext = document
|
||||
? ((lastDot < 0 || lastDot + 2 > name.size())
|
||||
? name
|
||||
: name.mid(lastDot + 1))
|
||||
: QString();
|
||||
|
||||
return colorIndex;
|
||||
}
|
||||
|
||||
style::color documentColor(int32 colorIndex) {
|
||||
const style::color colors[] = {
|
||||
st::msgFile1Bg,
|
||||
st::msgFile2Bg,
|
||||
st::msgFile3Bg,
|
||||
st::msgFile4Bg
|
||||
};
|
||||
return colors[colorIndex & 3];
|
||||
}
|
||||
|
||||
style::color documentDarkColor(int32 colorIndex) {
|
||||
static style::color colors[] = {
|
||||
st::msgFile1BgDark,
|
||||
st::msgFile2BgDark,
|
||||
st::msgFile3BgDark,
|
||||
st::msgFile4BgDark
|
||||
};
|
||||
return colors[colorIndex & 3];
|
||||
}
|
||||
|
||||
style::color documentOverColor(int32 colorIndex) {
|
||||
static style::color colors[] = {
|
||||
st::msgFile1BgOver,
|
||||
st::msgFile2BgOver,
|
||||
st::msgFile3BgOver,
|
||||
st::msgFile4BgOver
|
||||
};
|
||||
return colors[colorIndex & 3];
|
||||
}
|
||||
|
||||
style::color documentSelectedColor(int32 colorIndex) {
|
||||
static style::color colors[] = {
|
||||
st::msgFile1BgSelected,
|
||||
st::msgFile2BgSelected,
|
||||
st::msgFile3BgSelected,
|
||||
st::msgFile4BgSelected
|
||||
};
|
||||
return colors[colorIndex & 3];
|
||||
}
|
||||
|
||||
Ui::CachedRoundCorners documentCorners(int32 colorIndex) {
|
||||
return Ui::CachedRoundCorners(Ui::Doc1Corners + (colorIndex & 3));
|
||||
}
|
||||
|
||||
[[nodiscard]] HistoryView::TextState LayoutItemBase::getState(
|
||||
QPoint point,
|
||||
|
|
|
@ -14,17 +14,6 @@ struct TextState;
|
|||
struct StateRequest;
|
||||
} // namespace HistoryView
|
||||
|
||||
namespace Ui {
|
||||
enum CachedRoundCorners : int;
|
||||
} // namespace Ui
|
||||
|
||||
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);
|
||||
Ui::CachedRoundCorners documentCorners(int colorIndex);
|
||||
|
||||
class PaintContextBase {
|
||||
public:
|
||||
PaintContextBase(crl::time ms, bool selecting) : ms(ms), selecting(selecting) {
|
||||
|
|
122
Telegram/SourceFiles/layout/layout_document_generic_preview.cpp
Normal file
122
Telegram/SourceFiles/layout/layout_document_generic_preview.cpp
Normal file
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "layout/layout_document_generic_preview.h"
|
||||
|
||||
#include "data/data_document.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "styles/style_media_view.h"
|
||||
|
||||
namespace Layout {
|
||||
|
||||
const style::icon *DocumentGenericPreview::icon() const {
|
||||
switch (index) {
|
||||
case 0: return &st::mediaviewFileBlue;
|
||||
case 1: return &st::mediaviewFileGreen;
|
||||
case 2: return &st::mediaviewFileRed;
|
||||
case 3: return &st::mediaviewFileYellow;
|
||||
}
|
||||
Unexpected("Color index in DocumentGenericPreview::icon.");
|
||||
}
|
||||
|
||||
DocumentGenericPreview DocumentGenericPreview::Create(
|
||||
DocumentData *document) {
|
||||
auto colorIndex = 0;
|
||||
|
||||
const auto name = (document
|
||||
? (document->filename().isEmpty()
|
||||
? (document->sticker()
|
||||
? tr::lng_in_dlg_sticker(tr::now)
|
||||
: qsl("Unknown File"))
|
||||
: document->filename())
|
||||
: tr::lng_message_empty(tr::now)).toLower();
|
||||
auto lastDot = name.lastIndexOf('.');
|
||||
const auto mime = document
|
||||
? document->mimeString().toLower()
|
||||
: QString();
|
||||
if (name.endsWith(qstr(".doc")) ||
|
||||
name.endsWith(qstr(".docx")) ||
|
||||
name.endsWith(qstr(".txt")) ||
|
||||
name.endsWith(qstr(".psd")) ||
|
||||
mime.startsWith(qstr("text/"))) {
|
||||
colorIndex = 0;
|
||||
} else if (
|
||||
name.endsWith(qstr(".xls")) ||
|
||||
name.endsWith(qstr(".xlsx")) ||
|
||||
name.endsWith(qstr(".csv"))) {
|
||||
colorIndex = 1;
|
||||
} else if (
|
||||
name.endsWith(qstr(".pdf")) ||
|
||||
name.endsWith(qstr(".ppt")) ||
|
||||
name.endsWith(qstr(".pptx")) ||
|
||||
name.endsWith(qstr(".key"))) {
|
||||
colorIndex = 2;
|
||||
} else if (
|
||||
name.endsWith(qstr(".zip")) ||
|
||||
name.endsWith(qstr(".rar")) ||
|
||||
name.endsWith(qstr(".ai")) ||
|
||||
name.endsWith(qstr(".mp3")) ||
|
||||
name.endsWith(qstr(".mov")) ||
|
||||
name.endsWith(qstr(".avi"))) {
|
||||
colorIndex = 3;
|
||||
} else {
|
||||
auto ch = (lastDot >= 0 && lastDot + 1 < name.size())
|
||||
? name.at(lastDot + 1)
|
||||
: (name.isEmpty()
|
||||
? (mime.isEmpty() ? '0' : mime.at(0))
|
||||
: name.at(0));
|
||||
colorIndex = (ch.unicode() % 4) & 3;
|
||||
}
|
||||
|
||||
const auto ext = document
|
||||
? ((lastDot < 0 || lastDot + 2 > name.size())
|
||||
? name
|
||||
: name.mid(lastDot + 1))
|
||||
: QString();
|
||||
|
||||
switch (colorIndex) {
|
||||
case 0: return {
|
||||
.index = colorIndex,
|
||||
.color = st::msgFile1Bg,
|
||||
.dark = st::msgFile1BgDark,
|
||||
.over = st::msgFile1BgOver,
|
||||
.selected = st::msgFile1BgSelected,
|
||||
.ext = ext,
|
||||
};
|
||||
case 1: return {
|
||||
.index = colorIndex,
|
||||
.color = st::msgFile2Bg,
|
||||
.dark = st::msgFile2BgDark,
|
||||
.over = st::msgFile2BgOver,
|
||||
.selected = st::msgFile2BgSelected,
|
||||
.ext = ext,
|
||||
};
|
||||
case 2: return {
|
||||
.index = colorIndex,
|
||||
.color = st::msgFile3Bg,
|
||||
.dark = st::msgFile3BgDark,
|
||||
.over = st::msgFile3BgOver,
|
||||
.selected = st::msgFile3BgSelected,
|
||||
.ext = ext,
|
||||
};
|
||||
case 3: return {
|
||||
.index = colorIndex,
|
||||
.color = st::msgFile4Bg,
|
||||
.dark = st::msgFile4BgDark,
|
||||
.over = st::msgFile4BgOver,
|
||||
.selected = st::msgFile4BgSelected,
|
||||
.ext = ext,
|
||||
};
|
||||
}
|
||||
Unexpected("Color index in CreateDocumentGenericPreview.");
|
||||
}
|
||||
|
||||
// Ui::CachedRoundCorners DocumentCorners(int32 colorIndex) {
|
||||
// return Ui::CachedRoundCorners(Ui::Doc1Corners + (colorIndex & 3));
|
||||
// }
|
||||
|
||||
} // namespace Layout
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace Layout {
|
||||
|
||||
struct DocumentGenericPreview final {
|
||||
static DocumentGenericPreview Create(DocumentData *document);
|
||||
const style::icon *icon() const;
|
||||
const int index;
|
||||
const style::color &color;
|
||||
const style::color &dark;
|
||||
const style::color &over;
|
||||
const style::color &selected;
|
||||
const QString ext;
|
||||
};
|
||||
|
||||
// Ui::CachedRoundCorners DocumentCorners(int colorIndex);
|
||||
|
||||
} // namespace Layout
|
|
@ -65,6 +65,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "main/main_session.h"
|
||||
#include "main/main_session_settings.h"
|
||||
#include "layout.h"
|
||||
#include "layout/layout_document_generic_preview.h"
|
||||
#include "storage/file_download.h"
|
||||
#include "storage/storage_account.h"
|
||||
#include "calls/calls_instance.h"
|
||||
|
@ -2437,10 +2438,10 @@ void OverlayWidget::displayDocument(
|
|||
refreshCaption(item);
|
||||
|
||||
_docIconRect = QRect((width() - st::mediaviewFileIconSize) / 2, (height() - st::mediaviewFileIconSize) / 2, st::mediaviewFileIconSize, st::mediaviewFileIconSize);
|
||||
int32 colorIndex = documentColorIndex(_document, _docExt);
|
||||
_docIconColor = documentColor(colorIndex);
|
||||
const style::icon *thumbs[] = { &st::mediaviewFileBlue, &st::mediaviewFileGreen, &st::mediaviewFileRed, &st::mediaviewFileYellow };
|
||||
_docIcon = thumbs[colorIndex];
|
||||
const auto docGeneric = Layout::DocumentGenericPreview::Create(_document);
|
||||
_docExt = docGeneric.ext;
|
||||
_docIconColor = docGeneric.color;
|
||||
_docIcon = docGeneric.icon();
|
||||
|
||||
int32 extmaxw = (st::mediaviewFileIconSize - st::mediaviewFileExtPadding * 2);
|
||||
_docExtWidth = st::mediaviewFileExtFont->width(_docExt);
|
||||
|
|
|
@ -933,9 +933,10 @@ Document::Document(
|
|||
}),
|
||||
parent->fullId()))
|
||||
, _st(st)
|
||||
, _generic(::Layout::DocumentGenericPreview::Create(_data))
|
||||
, _date(langDateTime(base::unixtime::parse(_data->date)))
|
||||
, _datew(st::normalFont->width(_date))
|
||||
, _colorIndex(documentColorIndex(_data, _ext)) {
|
||||
, _ext(_generic.ext)
|
||||
, _datew(st::normalFont->width(_date)) {
|
||||
_name.setMarkedText(
|
||||
st::defaultTextStyle,
|
||||
Ui::Text::FormatSongNameFor(_data).textWithEntities(),
|
||||
|
@ -1110,7 +1111,7 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
|
|||
p.fillRect(rthumb, st::overviewFileThumbBg);
|
||||
}
|
||||
} else {
|
||||
p.fillRect(rthumb, documentColor(_colorIndex));
|
||||
p.fillRect(rthumb, _generic.color);
|
||||
if (!radial && loaded && !_ext.isEmpty()) {
|
||||
p.setFont(st::overviewFileExtFont);
|
||||
p.setPen(st::overviewFileExtFg);
|
||||
|
@ -1127,10 +1128,15 @@ void Document::paint(Painter &p, const QRect &clip, TextSelection selection, con
|
|||
auto radialOpacity = (radial && loaded && !_data->uploading()) ? _radial->opacity() : 1;
|
||||
p.setPen(Qt::NoPen);
|
||||
if (selected) {
|
||||
p.setBrush(wthumb ? st::msgDateImgBgSelected : documentSelectedColor(_colorIndex));
|
||||
p.setBrush(wthumb
|
||||
? st::msgDateImgBgSelected
|
||||
: _generic.selected);
|
||||
} else {
|
||||
auto over = ClickHandler::showAsActive(_data->loading() ? _cancell : _savel);
|
||||
p.setBrush(anim::brush(wthumb ? st::msgDateImgBg : documentDarkColor(_colorIndex), wthumb ? st::msgDateImgBgOver : documentOverColor(_colorIndex), _a_iconOver.value(over ? 1. : 0.)));
|
||||
p.setBrush(anim::brush(
|
||||
wthumb ? st::msgDateImgBg : _generic.dark,
|
||||
wthumb ? st::msgDateImgBgOver : _generic.over,
|
||||
_a_iconOver.value(over ? 1. : 0.)));
|
||||
}
|
||||
p.setOpacity(radialOpacity * p.opacity());
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#pragma once
|
||||
|
||||
#include "layout.h"
|
||||
#include "layout/layout_document_generic_preview.h"
|
||||
#include "media/clip/media_clip_reader.h"
|
||||
#include "core/click_handler_types.h"
|
||||
#include "ui/effects/animations.h"
|
||||
|
@ -372,6 +373,7 @@ private:
|
|||
ClickHandlerPtr _msgl, _namel;
|
||||
|
||||
const style::OverviewFileLayout &_st;
|
||||
const ::Layout::DocumentGenericPreview _generic;
|
||||
|
||||
bool _thumbLoaded = false;
|
||||
QPixmap _thumb;
|
||||
|
@ -379,7 +381,7 @@ private:
|
|||
Ui::Text::String _name;
|
||||
QString _date, _ext;
|
||||
int32 _datew, _extw;
|
||||
int32 _thumbw, _colorIndex;
|
||||
int32 _thumbw;
|
||||
|
||||
bool withThumb() const;
|
||||
bool updateStatusText();
|
||||
|
|
Loading…
Add table
Reference in a new issue