2015-12-20 14:05:07 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2015-12-20 14:05:07 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2015-12-20 14:05:07 +00:00
|
|
|
*/
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "layout.h"
|
2015-12-20 14:05:07 +00:00
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_document.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2015-12-20 14:05:07 +00:00
|
|
|
#include "mainwidget.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/file_upload.h"
|
2016-04-12 21:31:28 +00:00
|
|
|
#include "mainwindow.h"
|
2017-02-28 14:05:30 +00:00
|
|
|
#include "core/file_utilities.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "boxes/add_contact_box.h"
|
|
|
|
#include "boxes/confirm_box.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/view/history_view_cursor_state.h"
|
2020-10-13 15:11:53 +00:00
|
|
|
#include "ui/cached_round_corners.h"
|
2015-12-20 14:05:07 +00:00
|
|
|
|
2015-12-21 13:14:29 +00:00
|
|
|
int32 documentColorIndex(DocumentData *document, QString &ext) {
|
2017-11-05 11:00:48 +00:00
|
|
|
auto colorIndex = 0;
|
|
|
|
|
|
|
|
auto name = document
|
|
|
|
? (document->filename().isEmpty()
|
|
|
|
? (document->sticker()
|
2019-06-19 15:09:03 +00:00
|
|
|
? tr::lng_in_dlg_sticker(tr::now)
|
2017-11-05 11:00:48 +00:00
|
|
|
: qsl("Unknown File"))
|
|
|
|
: document->filename())
|
2019-06-19 15:09:03 +00:00
|
|
|
: tr::lng_message_empty(tr::now);
|
2015-12-21 13:14:29 +00:00
|
|
|
name = name.toLower();
|
2017-11-05 11:00:48 +00:00
|
|
|
auto lastDot = name.lastIndexOf('.');
|
|
|
|
auto mime = document
|
|
|
|
? document->mimeString().toLower()
|
|
|
|
: QString();
|
2015-12-21 13:14:29 +00:00
|
|
|
if (name.endsWith(qstr(".doc")) ||
|
2020-01-02 11:25:52 +00:00
|
|
|
name.endsWith(qstr(".docx")) ||
|
2015-12-21 13:14:29 +00:00
|
|
|
name.endsWith(qstr(".txt")) ||
|
|
|
|
name.endsWith(qstr(".psd")) ||
|
2017-11-05 11:00:48 +00:00
|
|
|
mime.startsWith(qstr("text/"))) {
|
2015-12-21 13:14:29 +00:00
|
|
|
colorIndex = 0;
|
|
|
|
} else if (
|
|
|
|
name.endsWith(qstr(".xls")) ||
|
2019-06-02 16:46:59 +00:00
|
|
|
name.endsWith(qstr(".xlsx")) ||
|
2017-11-05 11:00:48 +00:00
|
|
|
name.endsWith(qstr(".csv"))) {
|
2015-12-21 13:14:29 +00:00
|
|
|
colorIndex = 1;
|
|
|
|
} else if (
|
|
|
|
name.endsWith(qstr(".pdf")) ||
|
|
|
|
name.endsWith(qstr(".ppt")) ||
|
2019-06-02 16:46:59 +00:00
|
|
|
name.endsWith(qstr(".pptx")) ||
|
2017-11-05 11:00:48 +00:00
|
|
|
name.endsWith(qstr(".key"))) {
|
2015-12-21 13:14:29 +00:00
|
|
|
colorIndex = 2;
|
|
|
|
} else if (
|
|
|
|
name.endsWith(qstr(".zip")) ||
|
|
|
|
name.endsWith(qstr(".rar")) ||
|
|
|
|
name.endsWith(qstr(".ai")) ||
|
|
|
|
name.endsWith(qstr(".mp3")) ||
|
|
|
|
name.endsWith(qstr(".mov")) ||
|
2017-11-05 11:00:48 +00:00
|
|
|
name.endsWith(qstr(".avi"))) {
|
2015-12-21 13:14:29 +00:00
|
|
|
colorIndex = 3;
|
|
|
|
} else {
|
2017-11-05 11:00:48 +00:00
|
|
|
auto ch = (lastDot >= 0 && lastDot + 1 < name.size())
|
|
|
|
? name.at(lastDot + 1)
|
|
|
|
: (name.isEmpty()
|
|
|
|
? (mime.isEmpty() ? '0' : mime.at(0))
|
|
|
|
: name.at(0));
|
2015-12-21 13:14:29 +00:00
|
|
|
colorIndex = (ch.unicode() % 4);
|
|
|
|
}
|
|
|
|
|
2017-11-05 11:00:48 +00:00
|
|
|
ext = document
|
|
|
|
? ((lastDot < 0 || lastDot + 2 > name.size())
|
|
|
|
? name
|
|
|
|
: name.mid(lastDot + 1))
|
|
|
|
: QString();
|
2015-12-21 13:14:29 +00:00
|
|
|
|
|
|
|
return colorIndex;
|
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color documentColor(int32 colorIndex) {
|
|
|
|
const style::color colors[] = {
|
|
|
|
st::msgFile1Bg,
|
|
|
|
st::msgFile2Bg,
|
|
|
|
st::msgFile3Bg,
|
|
|
|
st::msgFile4Bg
|
2016-11-03 10:33:57 +00:00
|
|
|
};
|
2016-12-23 13:21:01 +00:00
|
|
|
return colors[colorIndex & 3];
|
2015-12-21 13:14:29 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color documentDarkColor(int32 colorIndex) {
|
|
|
|
static style::color colors[] = {
|
|
|
|
st::msgFile1BgDark,
|
|
|
|
st::msgFile2BgDark,
|
|
|
|
st::msgFile3BgDark,
|
|
|
|
st::msgFile4BgDark
|
2016-11-03 10:33:57 +00:00
|
|
|
};
|
2016-12-23 13:21:01 +00:00
|
|
|
return colors[colorIndex & 3];
|
2016-01-03 14:32:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color documentOverColor(int32 colorIndex) {
|
|
|
|
static style::color colors[] = {
|
|
|
|
st::msgFile1BgOver,
|
|
|
|
st::msgFile2BgOver,
|
|
|
|
st::msgFile3BgOver,
|
|
|
|
st::msgFile4BgOver
|
2016-11-03 10:33:57 +00:00
|
|
|
};
|
2016-12-23 13:21:01 +00:00
|
|
|
return colors[colorIndex & 3];
|
2016-01-03 14:32:13 +00:00
|
|
|
}
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color documentSelectedColor(int32 colorIndex) {
|
|
|
|
static style::color colors[] = {
|
|
|
|
st::msgFile1BgSelected,
|
|
|
|
st::msgFile2BgSelected,
|
|
|
|
st::msgFile3BgSelected,
|
|
|
|
st::msgFile4BgSelected
|
2016-11-03 10:33:57 +00:00
|
|
|
};
|
2016-12-23 13:21:01 +00:00
|
|
|
return colors[colorIndex & 3];
|
2016-01-03 14:32:13 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 15:11:53 +00:00
|
|
|
Ui::CachedRoundCorners documentCorners(int32 colorIndex) {
|
|
|
|
return Ui::CachedRoundCorners(Ui::Doc1Corners + (colorIndex & 3));
|
2015-12-21 13:14:29 +00:00
|
|
|
}
|
2016-06-29 15:21:21 +00:00
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
[[nodiscard]] HistoryView::TextState LayoutItemBase::getState(
|
2018-01-11 19:33:26 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2018-01-11 19:33:26 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] TextSelection LayoutItemBase::adjustSelection(
|
|
|
|
TextSelection selection,
|
|
|
|
TextSelectType type) const {
|
|
|
|
return selection;
|
|
|
|
}
|