started media redesign (does not compile!)

This commit is contained in:
John Preston 2015-12-08 22:07:50 +03:00
parent 0b96dd5362
commit 6bad3b4d7e
12 changed files with 575 additions and 436 deletions

View File

@ -664,6 +664,7 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
"lng_save_file" = "Save file"; "lng_save_file" = "Save file";
"lng_save_downloaded" = "{ready} / {total} {mb}"; "lng_save_downloaded" = "{ready} / {total} {mb}";
"lng_duration_and_size" = "{duration}, {size}"; "lng_duration_and_size" = "{duration}, {size}";
"lng_duration_played" = "{played} / {duration}";
"lng_choose_images" = "Choose images"; "lng_choose_images" = "Choose images";
"lng_context_view_profile" = "View profile"; "lng_context_view_profile" = "View profile";

View File

@ -1165,8 +1165,6 @@ introErrLabelTextStyle: textStyle(defaultTextStyle) {
lineHeight: 27px; lineHeight: 27px;
} }
mediaMaxWidth: 250px;
mediaFont: font(fsize);
mediaPadding: margins(7px, 6px, 7px, 6px); mediaPadding: margins(7px, 6px, 7px, 6px);
mediaThumbSize: 48px; mediaThumbSize: 48px;
mediaNameTop: 3px; mediaNameTop: 3px;
@ -1191,26 +1189,13 @@ mediaInUnreadColor: #999;
mediaInUnreadSelectColor: #7b95aa; mediaInUnreadSelectColor: #7b95aa;
mediaUnreadSize: 4px; mediaUnreadSize: 4px;
mediaUnreadSkip: 5px; mediaUnreadSkip: 5px;
mediaSaveDelta: 14px; // between bubble and download
mediaSaveButton: flatButton(btnDefFlat) {
color: #507da2;
overColor: #507da2;
downColor: #507da2;
bgColor: white; msgFileMenuSize: size(36px, 36px);
overBgColor: overBg; msgFileSize: 44px;
downBgColor: overBg; msgFilePadding: margins(14px, 12px, 10px, 12px);
msgFileThumbSize: 72px;
width: -28px; msgFileThumbPadding: margins(10px, 10px, 14px, 10px);
height: 34px; msgFileMinWidth: 294px;
textTop: 7px;
overTextTop: 7px;
downTextTop: 8px;
font: font(fsize);
overFont: font(fsize);
}
sendPadding: 9px; sendPadding: 9px;
btnSend: flatButton(btnDefFlat) { btnSend: flatButton(btnDefFlat) {

View File

@ -148,7 +148,7 @@ void StickerSetInner::paintEvent(QPaintEvent *e) {
doc->thumb->load(); doc->thumb->load();
} else { } else {
bool already = !doc->already().isEmpty(), hasdata = !doc->data.isEmpty(); bool already = !doc->already().isEmpty(), hasdata = !doc->data.isEmpty();
if (!doc->loader && doc->status != FileFailed && !already && !hasdata) { if (!already && !hasdata && !doc->loader && doc->status == FileReady) {
doc->save(QString()); doc->save(QString());
} }
if (doc->sticker()->img->isNull() && (already || hasdata)) { if (doc->sticker()->img->isNull() && (already || hasdata)) {

View File

@ -1332,7 +1332,7 @@ void StickerPanInner::paintEvent(QPaintEvent *e) {
sticker->thumb->load(); sticker->thumb->load();
} else { } else {
bool already = !sticker->already().isEmpty(), hasdata = !sticker->data.isEmpty(); bool already = !sticker->already().isEmpty(), hasdata = !sticker->data.isEmpty();
if (!sticker->loader && sticker->status != FileFailed && !already && !hasdata) { if (!already && !hasdata && !sticker->loader && sticker->status == FileReady) {
sticker->save(QString()); sticker->save(QString());
} }
if (sticker->sticker()->img->isNull() && (already || hasdata)) { if (sticker->sticker()->img->isNull() && (already || hasdata)) {
@ -1521,7 +1521,7 @@ void StickerPanInner::preloadImages() {
sticker->thumb->load(); sticker->thumb->load();
} else { } else {
bool already = !sticker->already().isEmpty(), hasdata = !sticker->data.isEmpty(); bool already = !sticker->already().isEmpty(), hasdata = !sticker->data.isEmpty();
if (!sticker->loader && sticker->status != FileFailed && !already && !hasdata) { if (!already && !hasdata && !sticker->loader && sticker->status == FileReady) {
sticker->save(QString()); sticker->save(QString());
} }
//if (sticker->sticker->img->isNull() && (already || hasdata)) { //if (sticker->sticker->img->isNull() && (already || hasdata)) {

View File

@ -83,13 +83,13 @@ void FileUploader::currentFailed() {
} else if (j->type() == PrepareDocument) { } else if (j->type() == PrepareDocument) {
DocumentData *doc = App::document(j->id()); DocumentData *doc = App::document(j->id());
if (doc->status == FileUploading) { if (doc->status == FileUploading) {
doc->status = FileFailed; doc->status = FileUploadFailed;
} }
emit documentFailed(j.key()); emit documentFailed(j.key());
} else if (j->type() == PrepareAudio) { } else if (j->type() == PrepareAudio) {
AudioData *audio = App::audio(j->id()); AudioData *audio = App::audio(j->id());
if (audio->status == FileUploading) { if (audio->status == FileUploading) {
audio->status = FileFailed; audio->status = FileUploadFailed;
} }
emit audioFailed(j.key()); emit audioFailed(j.key());
} }

File diff suppressed because it is too large Load Diff

View File

@ -108,6 +108,7 @@ enum HistoryMediaType {
MediaTypeContact, MediaTypeContact,
MediaTypeAudio, MediaTypeAudio,
MediaTypeDocument, MediaTypeDocument,
MediaTypeGif,
MediaTypeSticker, MediaTypeSticker,
MediaTypeImageLink, MediaTypeImageLink,
MediaTypeWebPage, MediaTypeWebPage,
@ -131,6 +132,7 @@ inline MediaOverviewType mediaToOverviewType(HistoryMediaType t) {
case MediaTypePhoto: return OverviewPhotos; case MediaTypePhoto: return OverviewPhotos;
case MediaTypeVideo: return OverviewVideos; case MediaTypeVideo: return OverviewVideos;
case MediaTypeDocument: return OverviewDocuments; case MediaTypeDocument: return OverviewDocuments;
case MediaTypeGif: return OverviewDocuments;
// case MediaTypeSticker: return OverviewDocuments; // case MediaTypeSticker: return OverviewDocuments;
case MediaTypeAudio: return OverviewAudios; case MediaTypeAudio: return OverviewAudios;
} }
@ -1163,6 +1165,8 @@ public:
virtual QString getCaption() const { virtual QString getCaption() const {
return QString(); return QString();
} }
virtual bool needsBubble(const HistoryItem *parent) const = 0;
virtual bool customTime() const = 0;
int32 currentWidth() const { int32 currentWidth() const {
return qMin(w, _maxw); return qMin(w, _maxw);
@ -1217,6 +1221,12 @@ public:
QString getCaption() const { QString getCaption() const {
return _caption.original(); return _caption.original();
} }
bool needsBubble(const HistoryItem *parent) const {
return !_caption.isEmpty() || parent->toHistoryReply();
}
bool customTime() const {
return _caption.isEmpty();
}
private: private:
int16 pixw, pixh; int16 pixw, pixh;
@ -1259,6 +1269,13 @@ public:
} }
ImagePtr replyPreview(); ImagePtr replyPreview();
bool needsBubble(const HistoryItem *parent) const {
return !_caption.isEmpty() || parent->toHistoryReply();
}
bool customTime() const {
return _caption.isEmpty();
}
private: private:
VideoData *data; VideoData *data;
TextLinkPtr _openl, _savel, _cancell; TextLinkPtr _openl, _savel, _cancell;
@ -1300,6 +1317,13 @@ public:
void updateFrom(const MTPMessageMedia &media); void updateFrom(const MTPMessageMedia &media);
bool needsBubble(const HistoryItem *parent) const {
return true;
}
bool customTime() const {
return false;
}
private: private:
AudioData *data; AudioData *data;
TextLinkPtr _openl, _savel, _cancell; TextLinkPtr _openl, _savel, _cancell;
@ -1316,6 +1340,10 @@ public:
HistoryDocument(DocumentData *document); HistoryDocument(DocumentData *document);
void initDimensions(const HistoryItem *parent); void initDimensions(const HistoryItem *parent);
bool withThumb() const {
return !_data->song() && !_data->thumb->isNull() && _data->thumb->width() && _data->thumb->height();
}
void draw(Painter &p, const HistoryItem *parent, bool selected, int32 width = -1) const; void draw(Painter &p, const HistoryItem *parent, bool selected, int32 width = -1) const;
int32 resize(int32 width, const HistoryItem *parent); int32 resize(int32 width, const HistoryItem *parent);
HistoryMediaType type() const { HistoryMediaType type() const {
@ -1326,13 +1354,13 @@ public:
bool hasPoint(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const; bool hasPoint(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
int32 countHeight(const HistoryItem *parent, int32 width = -1) const; int32 countHeight(const HistoryItem *parent, int32 width = -1) const;
bool uploading() const { bool uploading() const {
return (data->status == FileUploading); return (_data->status == FileUploading);
} }
void getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const; void getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
HistoryMedia *clone() const; HistoryMedia *clone() const;
DocumentData *document() { DocumentData *document() {
return data; return _data;
} }
void regItem(HistoryItem *item); void regItem(HistoryItem *item);
@ -1341,24 +1369,95 @@ public:
void updateFrom(const MTPMessageMedia &media); void updateFrom(const MTPMessageMedia &media);
bool hasReplyPreview() const { bool hasReplyPreview() const {
return !data->thumb->isNull(); return !_data->thumb->isNull();
} }
ImagePtr replyPreview(); ImagePtr replyPreview();
void drawInPlaylist(Painter &p, const HistoryItem *parent, bool selected, bool over, int32 width) const; void drawInPlaylist(Painter &p, const HistoryItem *parent, bool selected, bool over, int32 width) const;
TextLinkPtr linkInPlaylist(); TextLinkPtr linkInPlaylist();
bool needsBubble(const HistoryItem *parent) const {
return true;
}
bool customTime() const {
return false;
}
private: private:
DocumentData *data; DocumentData *_data;
TextLinkPtr _openl, _savel, _cancell;
int32 _namew;
QString _name;
int32 _thumbw, _thumbx, _thumby;
// >= 0 will contain download / upload string, _statusSize = loaded bytes
// < 0 will contain played string, _statusSize = seconds played
// 0x7FFFFF0 will contain status for not yet downloaded file
// 0x7FFFFF1 will contain status for already downloaded file
// 0x7FFFFF2 will contain status for failed to download / upload file
mutable int32 _statusSize;
mutable QString _statusText;
};
class HistoryGif : public HistoryMedia {
public:
HistoryGif(DocumentData *document);
void initDimensions(const HistoryItem *parent);
void draw(Painter &p, const HistoryItem *parent, bool selected, int32 width = -1) const;
int32 resize(int32 width, const HistoryItem *parent);
HistoryMediaType type() const {
return MediaTypeGif;
}
const QString inDialogsText() const;
const QString inHistoryText() const;
bool hasPoint(int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
int32 countHeight(const HistoryItem *parent, int32 width = -1) const;
bool uploading() const {
return (_data->status == FileUploading);
}
void getState(TextLinkPtr &lnk, HistoryCursorState &state, int32 x, int32 y, const HistoryItem *parent, int32 width = -1) const;
HistoryMedia *clone() const;
DocumentData *document() {
return _data;
}
void regItem(HistoryItem *item);
void unregItem(HistoryItem *item);
void updateFrom(const MTPMessageMedia &media);
bool hasReplyPreview() const {
return !_data->thumb->isNull();
}
ImagePtr replyPreview();
void drawInPlaylist(Painter &p, const HistoryItem *parent, bool selected, bool over, int32 width) const;
TextLinkPtr linkInPlaylist();
bool needsBubble(const HistoryItem *parent) const {
return parent->toHistoryReply();
}
bool customTime() const {
return true;
}
private:
DocumentData *_data;
TextLinkPtr _openl, _savel, _cancell; TextLinkPtr _openl, _savel, _cancell;
int32 _namew; int32 _namew;
QString _name, _size; QString _name, _size;
int32 _thumbw, _thumbx, _thumby; int32 _thumbw, _thumbx, _thumby;
mutable QString _dldTextCache, _uplTextCache; mutable QString _statusText;
mutable int32 _dldDone, _uplDone; mutable int32 _statusSize; // -1 will contain just size string, -2 will contain "failed" language key
}; };
class HistorySticker : public HistoryMedia { class HistorySticker : public HistoryMedia {
@ -1388,6 +1487,13 @@ public:
void updateFrom(const MTPMessageMedia &media); void updateFrom(const MTPMessageMedia &media);
bool needsBubble(const HistoryItem *parent) const {
return false;
}
bool customTime() const {
return true;
}
private: private:
int16 pixw, pixh; int16 pixw, pixh;
@ -1416,6 +1522,13 @@ public:
void updateFrom(const MTPMessageMedia &media); void updateFrom(const MTPMessageMedia &media);
bool needsBubble(const HistoryItem *parent) const {
return true;
}
bool customTime() const {
return false;
}
private: private:
int32 userId; int32 userId;
int32 phonew; int32 phonew;
@ -1461,6 +1574,13 @@ public:
return data; return data;
} }
bool needsBubble(const HistoryItem *parent) const {
return true;
}
bool customTime() const {
return false;
}
private: private:
WebPageData *data; WebPageData *data;
TextLinkPtr _openl, _attachl; TextLinkPtr _openl, _attachl;
@ -1552,6 +1672,13 @@ public:
return true; return true;
} }
bool needsBubble(const HistoryItem *parent) const {
return !_title.isEmpty() || !_description.isEmpty() || parent->toHistoryReply();
}
bool customTime() const {
return true;
}
private: private:
ImageLinkData *data; ImageLinkData *data;
Text _title, _description; Text _title, _description;
@ -1574,9 +1701,11 @@ public:
void fromNameUpdated() const; void fromNameUpdated() const;
bool justMedia() const { bool justMedia() const {
return _media && _text.isEmpty(); return _text.isEmpty();
}
bool drawBubble() const {
return _media ? (!justMedia() || _media->needsBubble(this)) : true;
} }
bool uploading() const; bool uploading() const;
void drawInfo(Painter &p, int32 right, int32 bottom, bool selected, InfoDisplayType type) const; void drawInfo(Painter &p, int32 right, int32 bottom, bool selected, InfoDisplayType type) const;

View File

@ -5449,7 +5449,18 @@ void HistoryWidget::onPhotoProgress(const FullMsgId &newId) {
void HistoryWidget::onDocumentProgress(const FullMsgId &newId) { void HistoryWidget::onDocumentProgress(const FullMsgId &newId) {
if (!MTP::authedId()) return; if (!MTP::authedId()) return;
if (HistoryItem *item = App::histItemById(newId)) { if (HistoryItem *item = App::histItemById(newId)) {
DocumentData *doc = (item->getMedia() && item->getMedia()->type() == MediaTypeDocument) ? static_cast<HistoryDocument*>(item->getMedia())->document() : 0; HistoryMedia *media = item->getMedia();
DocumentData *doc = 0;
if (media) {
HistoryMediaType type = media->type();
if (type == MediaTypeDocument) {
doc = static_cast<HistoryDocument*>(item->getMedia())->document();
} else if (type == MediaTypeGif) {
doc = static_cast<HistoryGif*>(item->getMedia())->document();
} else if (type == MediaTypeSticker) {
doc = static_cast<HistorySticker*>(item->getMedia())->document();
}
}
if (!item->fromChannel()) { if (!item->fromChannel()) {
updateSendAction(item->history(), SendActionUploadFile, doc ? doc->uploadOffset : 0); updateSendAction(item->history(), SendActionUploadFile, doc ? doc->uploadOffset : 0);
} }

View File

@ -274,7 +274,7 @@ QSize StickerPreviewWidget::currentDimensions() const {
QPixmap StickerPreviewWidget::currentImage() const { QPixmap StickerPreviewWidget::currentImage() const {
if (_doc && _cacheStatus != CacheLoaded) { if (_doc && _cacheStatus != CacheLoaded) {
bool already = !_doc->already().isEmpty(), hasdata = !_doc->data.isEmpty(); bool already = !_doc->already().isEmpty(), hasdata = !_doc->data.isEmpty();
if (!_doc->loader && _doc->status != FileFailed && !already && !hasdata) { if (!already && !hasdata && !_doc->loader && _doc->status == FileReady) {
_doc->save(QString()); _doc->save(QString());
} }
if (_doc->sticker()->img->isNull() && (already || hasdata)) { if (_doc->sticker()->img->isNull() && (already || hasdata)) {

View File

@ -1654,7 +1654,10 @@ void MainWidget::onDownloadPathSettings() {
void MainWidget::videoLoadFailed(mtpFileLoader *loader, bool started) { void MainWidget::videoLoadFailed(mtpFileLoader *loader, bool started) {
loadFailed(loader, started, SLOT(videoLoadRetry())); loadFailed(loader, started, SLOT(videoLoadRetry()));
VideoData *video = App::video(loader->objId()); VideoData *video = App::video(loader->objId());
if (video && video->loader) video->finish(); if (video) {
if (video->loader) video->finish();
video->status = FileDownloadFailed;
}
} }
void MainWidget::videoLoadRetry() { void MainWidget::videoLoadRetry() {
@ -1811,7 +1814,7 @@ void MainWidget::audioLoadFailed(mtpFileLoader *loader, bool started) {
loadFailed(loader, started, SLOT(audioLoadRetry())); loadFailed(loader, started, SLOT(audioLoadRetry()));
AudioData *audio = App::audio(loader->objId()); AudioData *audio = App::audio(loader->objId());
if (audio) { if (audio) {
audio->status = FileFailed; audio->status = FileDownloadFailed;
if (audio->loader) audio->finish(); if (audio->loader) audio->finish();
} }
} }
@ -1907,7 +1910,7 @@ void MainWidget::documentLoadFailed(mtpFileLoader *loader, bool started) {
DocumentData *document = App::document(loader->objId()); DocumentData *document = App::document(loader->objId());
if (document) { if (document) {
if (document->loader) document->finish(); if (document->loader) document->finish();
document->status = FileFailed; document->status = FileDownloadFailed;
} }
} }

View File

@ -435,7 +435,7 @@ void MediaView::step_state(uint64 ms, bool timer) {
if (dt < 1) result = true; if (dt < 1) result = true;
} }
if (_doc && _docRadialStart > 0) { if (_doc && _docRadialStart > 0) {
float64 prg = _doc->loader ? qMax(_doc->loader->currentProgress(), 0.0001) : (_doc->status == FileFailed ? 0 : (_doc->already().isEmpty() ? 0 : 1)); float64 prg = _doc->loader ? qMax(_doc->loader->currentProgress(), 0.0001) : (_doc->status == FileDownloadFailed ? 0 : (_doc->already().isEmpty() ? 0 : 1));
if (prg != a_docRadial.to()) { if (prg != a_docRadial.to()) {
a_docRadial.start(prg); a_docRadial.start(prg);
_docRadialStart = _docRadialLast; _docRadialStart = _docRadialLast;
@ -1514,6 +1514,7 @@ void MediaView::moveToNext(int32 delta) {
switch (item->getMedia()->type()) { switch (item->getMedia()->type()) {
case MediaTypePhoto: displayPhoto(static_cast<HistoryPhoto*>(item->getMedia())->photo(), item); preloadData(delta); break; case MediaTypePhoto: displayPhoto(static_cast<HistoryPhoto*>(item->getMedia())->photo(), item); preloadData(delta); break;
case MediaTypeDocument: displayDocument(static_cast<HistoryDocument*>(item->getMedia())->document(), item); preloadData(delta); break; case MediaTypeDocument: displayDocument(static_cast<HistoryDocument*>(item->getMedia())->document(), item); preloadData(delta); break;
case MediaTypeGif: displayDocument(static_cast<HistoryGif*>(item->getMedia())->document(), item); preloadData(delta); break;
case MediaTypeSticker: displayDocument(static_cast<HistorySticker*>(item->getMedia())->document(), item); preloadData(delta); break; case MediaTypeSticker: displayDocument(static_cast<HistorySticker*>(item->getMedia())->document(), item); preloadData(delta); break;
} }
} else { } else {
@ -1561,6 +1562,7 @@ void MediaView::preloadData(int32 delta) {
switch (media->type()) { switch (media->type()) {
case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->full->load(); break; case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->full->load(); break;
case MediaTypeDocument: static_cast<HistoryDocument*>(media)->document()->thumb->load(); break; case MediaTypeDocument: static_cast<HistoryDocument*>(media)->document()->thumb->load(); break;
case MediaTypeGif: static_cast<HistoryGif*>(media)->document()->thumb->load(); break;
case MediaTypeSticker: static_cast<HistorySticker*>(media)->document()->sticker()->img->load(); break; case MediaTypeSticker: static_cast<HistorySticker*>(media)->document()->sticker()->img->load(); break;
} }
} }
@ -1584,6 +1586,7 @@ void MediaView::preloadData(int32 delta) {
switch (media->type()) { switch (media->type()) {
case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->forget(); break; case MediaTypePhoto: static_cast<HistoryPhoto*>(media)->photo()->forget(); break;
case MediaTypeDocument: static_cast<HistoryDocument*>(media)->document()->forget(); break; case MediaTypeDocument: static_cast<HistoryDocument*>(media)->document()->forget(); break;
case MediaTypeGif: static_cast<HistoryGif*>(media)->document()->forget(); break;
case MediaTypeSticker: static_cast<HistorySticker*>(media)->document()->forget(); break; case MediaTypeSticker: static_cast<HistorySticker*>(media)->document()->forget(); break;
} }
} }

View File

@ -784,7 +784,8 @@ private:
}; };
enum FileStatus { enum FileStatus {
FileFailed = -1, FileDownloadFailed = -2,
FileUploadFailed = -1,
FileUploading = 0, FileUploading = 0,
FileReady = 1, FileReady = 1,
}; };