files and contacts in PhotoSendBox redesigned

This commit is contained in:
John Preston 2015-12-19 17:37:28 +03:00
parent f3065eb654
commit cd700b16c6
9 changed files with 134 additions and 96 deletions

View File

@ -29,17 +29,17 @@ Copyright (c) 2014-2015 John Preston, https://desktop.telegram.org
PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth) PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxWideWidth)
, _file(file) , _file(file)
, _thumbx(0)
, _thumby(0)
, _thumbw(0)
, _thumbh(0)
, _namew(0)
, _textw(0)
, _caption(this, st::confirmCaptionArea, lang(lng_photo_caption)) , _caption(this, st::confirmCaptionArea, lang(lng_photo_caption))
, _compressedFromSettings(_file->type == PrepareAuto) , _compressedFromSettings(_file->type == PrepareAuto)
, _compressed(this, lang(lng_send_image_compressed), _compressedFromSettings ? cCompressPastedImage() : true) , _compressed(this, lang(lng_send_image_compressed), _compressedFromSettings ? cCompressPastedImage() : true)
, _send(this, lang(lng_send_button), st::defaultBoxButton) , _send(this, lang(lng_send_button), st::defaultBoxButton)
, _cancel(this, lang(lng_cancel), st::cancelBoxButton) , _cancel(this, lang(lng_cancel), st::cancelBoxButton)
, _thumbx(0)
, _thumby(0)
, _thumbw(0)
, _thumbh(0)
, _statusw(0)
, _isImage(false)
, _replyTo(_file->to.replyTo) , _replyTo(_file->to.replyTo)
, _confirmed(false) { , _confirmed(false) {
connect(&_send, SIGNAL(clicked()), this, SLOT(onSend())); connect(&_send, SIGNAL(clicked()), this, SLOT(onSend()));
@ -79,30 +79,23 @@ PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxW
_thumb.setDevicePixelRatio(cRetinaFactor()); _thumb.setDevicePixelRatio(cRetinaFactor());
} else { } else {
_compressed.hide(); _compressed.hide();
if (!_file->thumb.isNull()) { if (_file->thumb.isNull()) {
_thumbw = 0;
} else {
_thumb = _file->thumb; _thumb = _file->thumb;
int32 tw = _thumb.width(), th = _thumb.height(); int32 tw = _thumb.width(), th = _thumb.height();
if (_thumb.isNull() || !tw || !th) { if (tw > th) {
_thumbw = _thumbx = _thumby = 0; _thumbw = (tw * st::msgFileThumbSize) / th;
} else if (tw > th) {
_thumbw = (tw * st::mediaThumbSize) / th;
_thumbx = (_thumbw - st::mediaThumbSize) / 2;
_thumby = 0;
} else { } else {
_thumbw = st::mediaThumbSize; _thumbw = st::msgFileThumbSize;
_thumbx = 0;
_thumby = ((th * _thumbw) / tw - st::mediaThumbSize) / 2;
} }
} _thumb = imagePix(_thumb.toImage(), _thumbw, 0, true, false, true, st::msgFileThumbSize, st::msgFileThumbSize);
if (_thumbw) {
_thumb = QPixmap::fromImage(_thumb.toImage().scaledToWidth(_thumbw * cIntRetinaFactor(), Qt::SmoothTransformation), Qt::ColorOnly);
_thumb.setDevicePixelRatio(cRetinaFactor());
} }
_name = _file->filename; _name.setText(st::semiboldFont, _file->filename, _textNameOptions);
_namew = st::normalFont->width(_name); _status = formatSizeText(_file->filesize);
_size = formatSizeText(_file->filesize); _statusw = qMax(_name.maxWidth(), st::normalFont->width(_status));
_textw = qMax(_namew, st::normalFont->width(_size)); _isImage = fileIsImage(_file->filename, _file->filemime);
} }
updateBoxSize(); updateBoxSize();
_caption.setMaxLength(MaxPhotoCaption); _caption.setMaxLength(MaxPhotoCaption);
@ -115,16 +108,16 @@ PhotoSendBox::PhotoSendBox(const FileLoadResultPtr &file) : AbstractBox(st::boxW
} }
PhotoSendBox::PhotoSendBox(const QString &phone, const QString &fname, const QString &lname, MsgId replyTo) : AbstractBox(st::boxWideWidth) PhotoSendBox::PhotoSendBox(const QString &phone, const QString &fname, const QString &lname, MsgId replyTo) : AbstractBox(st::boxWideWidth)
, _thumbx(0)
, _thumby(0)
, _thumbw(0)
, _thumbh(0)
, _namew(0)
, _textw(0)
, _caption(this, st::confirmCaptionArea, lang(lng_photo_caption)) , _caption(this, st::confirmCaptionArea, lang(lng_photo_caption))
, _compressed(this, lang(lng_send_image_compressed), true) , _compressed(this, lang(lng_send_image_compressed), true)
, _send(this, lang(lng_send_button), st::defaultBoxButton) , _send(this, lang(lng_send_button), st::defaultBoxButton)
, _cancel(this, lang(lng_cancel), st::cancelBoxButton) , _cancel(this, lang(lng_cancel), st::cancelBoxButton)
, _thumbx(0)
, _thumby(0)
, _thumbw(0)
, _thumbh(0)
, _statusw(0)
, _isImage(false)
, _phone(phone) , _phone(phone)
, _fname(fname) , _fname(fname)
, _lname(lname) , _lname(lname)
@ -135,10 +128,9 @@ PhotoSendBox::PhotoSendBox(const QString &phone, const QString &fname, const QSt
_compressed.hide(); _compressed.hide();
_name = lng_full_name(lt_first_name, _fname, lt_last_name, _lname); _name.setText(st::semiboldFont, lng_full_name(lt_first_name, _fname, lt_last_name, _lname), _textNameOptions);
_namew = st::normalFont->width(_name); _status = _phone;
_size = _phone; _statusw = qMax(_name.maxWidth(), st::normalFont->width(_status));
_textw = qMax(_namew, st::normalFont->width(_size));
updateBoxSize(); updateBoxSize();
prepare(); prepare();
@ -165,8 +157,10 @@ void PhotoSendBox::onCaptionResized() {
void PhotoSendBox::updateBoxSize() { void PhotoSendBox::updateBoxSize() {
if (_file && _file->type == PreparePhoto) { if (_file && _file->type == PreparePhoto) {
setMaxHeight(st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxPhotoCompressedPadding.top() + _compressed.height() + (_compressed.checked() ? (st::boxPhotoCompressedPadding.bottom() + _caption.height()) : 0) + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom()); setMaxHeight(st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxPhotoCompressedPadding.top() + _compressed.height() + (_compressed.checked() ? (st::boxPhotoCompressedPadding.bottom() + _caption.height()) : 0) + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
} else if (_thumbw) {
setMaxHeight(st::boxPhotoPadding.top() + st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom() + st::boxPhotoPadding.bottom() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
} else { } else {
setMaxHeight(st::boxPhotoPadding.top() + st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom() + st::boxPhotoPadding.bottom() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom()); setMaxHeight(st::boxPhotoPadding.top() + st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom() + st::boxPhotoPadding.bottom() + st::boxButtonPadding.top() + _send.height() + st::boxButtonPadding.bottom());
} }
} }
@ -191,35 +185,54 @@ void PhotoSendBox::paintEvent(QPaintEvent *e) {
} }
p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), _thumb); p.drawPixmap(_thumbx, st::boxPhotoPadding.top(), _thumb);
} else { } else {
int32 w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right(), h = st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom(); int32 w = width() - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
int32 tleft = st::mediaPadding.left() + st::mediaThumbSize + st::mediaPadding.right(); int32 h = _thumbw ? (st::msgFileThumbPadding.top() + st::msgFileThumbSize + st::msgFileThumbPadding.bottom()) : (st::msgFilePadding.top() + st::msgFileSize + st::msgFilePadding.bottom());
int32 twidth = w - tleft - st::mediaPadding.right(); int32 nameleft = 0, nametop = 0, nameright = 0, statustop = 0, linktop = 0;
if (twidth > _textw) { if (_thumbw) {
w -= (twidth - _textw); nameleft = st::msgFileThumbPadding.left() + st::msgFileThumbSize + st::msgFileThumbPadding.right();
twidth = _textw; nametop = st::msgFileThumbNameTop;
nameright = st::msgFileThumbPadding.left();
statustop = st::msgFileThumbStatusTop;
linktop = st::msgFileThumbLinkTop;
} else {
nameleft = st::msgFilePadding.left() + st::msgFileSize + st::msgFilePadding.right();
nametop = st::msgFileNameTop;
nameright = st::msgFilePadding.left();
statustop = st::msgFileStatusTop;
}
int32 namewidth = w - nameleft - (_thumbw ? st::msgFileThumbPadding.left() : st::msgFilePadding.left());
if (namewidth > _statusw) {
w -= (namewidth - _statusw);
namewidth = _statusw;
} }
int32 x = (width() - w) / 2, y = st::boxPhotoPadding.top(); int32 x = (width() - w) / 2, y = st::boxPhotoPadding.top();
App::roundRect(p, x, y, w, h, st::msgOutBg, MessageOutCorners, &st::msgOutShadow); App::roundRect(p, x, y, w, h, st::msgOutBg, MessageOutCorners, &st::msgOutShadow);
if (_thumbw) { if (_thumbw) {
int32 rf(cIntRetinaFactor()); QRect rthumb(rtlrect(x + st::msgFileThumbPadding.left(), y + st::msgFileThumbPadding.top(), st::msgFileThumbSize, st::msgFileThumbSize, width()));
p.drawPixmap(QPoint(x + st::mediaPadding.left(), y + st::mediaPadding.top()), _thumb, QRect(_thumbx * rf, _thumby * rf, st::mediaThumbSize * rf, st::mediaThumbSize * rf)); p.drawPixmap(rthumb.topLeft(), _thumb);
} else if (_file) { } else if (_file) {
p.drawPixmap(QPoint(x + st::mediaPadding.left(), y + st::mediaPadding.top()), App::sprite(), st::mediaMusicOutImg); QRect inner(rtlrect(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), st::msgFileSize, st::msgFileSize, width()));
} else { p.setPen(Qt::NoPen);
p.drawPixmap(x + st::mediaPadding.left(), y + st::mediaPadding.top(), userDefPhoto(1)->pix(st::mediaThumbSize)); p.setBrush(st::msgFileOutBg);
}
p.setFont(st::normalFont); p.setRenderHint(QPainter::HighQualityAntialiasing);
p.drawEllipse(inner);
p.setRenderHint(QPainter::HighQualityAntialiasing, false);
p.drawSpriteCenter(inner, _isImage ? st::msgFileOutImage : st::msgFileOutFile);
} else {
p.drawPixmapLeft(x + st::msgFilePadding.left(), y + st::msgFilePadding.top(), width(), userDefPhoto(1)->pixRounded(st::msgFileSize));
}
p.setFont(st::semiboldFont);
p.setPen(st::black); p.setPen(st::black);
if (twidth < _namew) { _name.drawLeftElided(p, x + nameleft, y + nametop, namewidth, width());
p.drawText(x + tleft, y + st::mediaPadding.top() + st::mediaNameTop + st::normalFont->ascent, st::normalFont->elided(_name, twidth));
} else {
p.drawText(x + tleft, y + st::mediaPadding.top() + st::mediaNameTop + st::normalFont->ascent, _name);
}
p.setPen(st::mediaOutFg); style::color status(st::mediaOutFg);
p.drawText(x + tleft, y + st::mediaPadding.top() + st::mediaThumbSize - st::mediaDetailsShift - st::normalFont->descent, _size); p.setFont(st::normalFont);
p.setPen(status);
p.drawTextLeft(x + nameleft, y + statustop, width(), _status);
} }
} }

View File

@ -65,16 +65,22 @@ private:
void updateBoxSize(); void updateBoxSize();
FileLoadResultPtr _file; FileLoadResultPtr _file;
int32 _thumbx, _thumby, _thumbw, _thumbh;
QString _name, _size; QPixmap _thumb;
int32 _namew, _textw;
InputArea _caption; InputArea _caption;
bool _compressedFromSettings; bool _compressedFromSettings;
Checkbox _compressed; Checkbox _compressed;
BoxButton _send, _cancel; BoxButton _send, _cancel;
QPixmap _thumb;
int32 _thumbx, _thumby, _thumbw, _thumbh;
Text _name;
QString _status;
int32 _statusw;
bool _isImage;
QString _phone, _fname, _lname; QString _phone, _fname, _lname;
MsgId _replyTo; MsgId _replyTo;
bool _confirmed; bool _confirmed;

View File

@ -396,6 +396,35 @@ QImage imageColored(const style::color &add, QImage img) {
return img; return img;
} }
QPixmap imagePix(QImage img, int32 w, int32 h, bool smooth, bool blurred, bool rounded, int32 outerw, int32 outerh) {
if (blurred) img = imageBlur(img);
if (w <= 0 || (w == img.width() && (h <= 0 || h == img.height()))) {
} else if (h <= 0) {
img = img.scaledToWidth(w, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
} else {
img = img.scaled(w, h, Qt::IgnoreAspectRatio, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
}
if (outerw > 0 && outerh > 0) {
outerw *= cIntRetinaFactor();
outerh *= cIntRetinaFactor();
if (outerw != w || outerh != h) {
img.setDevicePixelRatio(cRetinaFactor());
QImage result(outerw, outerh, QImage::Format_ARGB32_Premultiplied);
result.setDevicePixelRatio(cRetinaFactor());
{
QPainter p(&result);
if (w < outerw || h < outerh) {
p.fillRect(0, 0, result.width(), result.height(), st::black->b);
}
p.drawImage((result.width() - img.width()) / (2 * cIntRetinaFactor()), (result.height() - img.height()) / (2 * cIntRetinaFactor()), img);
}
img = result;
}
}
if (rounded) imageRound(img);
return QPixmap::fromImage(img, Qt::ColorOnly);
}
QPixmap Image::pixNoCache(int32 w, int32 h, bool smooth, bool blurred, bool rounded, int32 outerw, int32 outerh) const { QPixmap Image::pixNoCache(int32 w, int32 h, bool smooth, bool blurred, bool rounded, int32 outerw, int32 outerh) const {
restore(); restore();
loaded(); loaded();
@ -403,41 +432,22 @@ QPixmap Image::pixNoCache(int32 w, int32 h, bool smooth, bool blurred, bool roun
const QPixmap &p(pixData()); const QPixmap &p(pixData());
if (p.isNull()) return blank()->pix(); if (p.isNull()) return blank()->pix();
bool n = isNull(); if (isNull() && outerw > 0 && outerh > 0) {
QImage img = p.toImage();
if (!n || !(outerw > 0 && outerh > 0)) {
if (blurred) img = imageBlur(img);
if (w <= 0 || !width() || !height() || (w == width() && (h <= 0 || h == height()))) {
} else if (h <= 0) {
img = img.scaledToWidth(w, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
} else {
img = img.scaled(w, h, Qt::IgnoreAspectRatio, smooth ? Qt::SmoothTransformation : Qt::FastTransformation);
}
}
if (outerw > 0 && outerh > 0) {
outerw *= cIntRetinaFactor(); outerw *= cIntRetinaFactor();
outerh *= cIntRetinaFactor(); outerh *= cIntRetinaFactor();
if (outerw != w || outerh != h || n) {
img.setDevicePixelRatio(cRetinaFactor()); QImage result(outerw, outerh, QImage::Format_ARGB32_Premultiplied);
QImage result(outerw, outerh, QImage::Format_ARGB32_Premultiplied); result.setDevicePixelRatio(cRetinaFactor());
result.setDevicePixelRatio(cRetinaFactor());
if (n) { {
QPainter p(&result); QPainter p(&result);
p.fillRect(0, 0, result.width(), result.height(), st::black->b); p.fillRect(0, 0, result.width(), result.height(), st::black);
} else {
QPainter p(&result);
if (w < outerw || h < outerh || n) {
p.fillRect(0, 0, result.width(), result.height(), st::black->b);
}
if (!n) {
p.drawImage((result.width() - img.width()) / (2 * cIntRetinaFactor()), (result.height() - img.height()) / (2 * cIntRetinaFactor()), img);
}
}
img = result;
} }
if (rounded) imageRound(result);
return QPixmap::fromImage(result, Qt::ColorOnly);
} }
if (rounded) imageRound(img); return imagePix(p.toImage(), w, h, smooth, blurred, rounded, outerw, outerh);
return QPixmap::fromImage(img, Qt::ColorOnly);
} }
QPixmap Image::pixColoredNoCache(const style::color &add, int32 w, int32 h, bool smooth) const { QPixmap Image::pixColoredNoCache(const style::color &add, int32 w, int32 h, bool smooth) const {

View File

@ -49,6 +49,8 @@ inline bool operator!=(const StorageImageLocation &a, const StorageImageLocation
return !(a == b); return !(a == b);
} }
QPixmap imagePix(QImage img, int32 w, int32 h, bool smooth, bool blurred, bool rounded, int32 outerw, int32 outerh);
class Image { class Image {
public: public:

View File

@ -4412,7 +4412,7 @@ void HistoryDocument::draw(Painter &p, const HistoryItem *parent, const QRect &r
p.setFont(st::semiboldFont); p.setFont(st::semiboldFont);
p.setPen(st::black); p.setPen(st::black);
if (namewidth < _namew) { if (namewidth < _namew) {
p.drawTextLeft(nameleft, nametop, width, st::normalFont->elided(_name, namewidth)); p.drawTextLeft(nameleft, nametop, width, st::semiboldFont->elided(_name, namewidth));
} else { } else {
p.drawTextLeft(nameleft, nametop, width, _name, _namew); p.drawTextLeft(nameleft, nametop, width, _name, _namew);
} }

View File

@ -393,6 +393,7 @@ void FileLoadTask::process() {
_result->content = _content; _result->content = _content;
_result->filename = filename; _result->filename = filename;
_result->filemime = filemime;
_result->setFileData(filedata); _result->setFileData(filedata);
_result->thumbId = thumbId; _result->thumbId = thumbId;

View File

@ -190,6 +190,7 @@ struct FileLoadResult {
QByteArray content; QByteArray content;
QString filename; QString filename;
QString filemime;
int32 filesize; int32 filesize;
UploadFileParts fileparts; UploadFileParts fileparts;
QByteArray filemd5; QByteArray filemd5;

View File

@ -1080,12 +1080,10 @@ const FileLocation &DocumentData::location(bool check) {
return _location; return _location;
} }
void DocumentData::recountIsImage() { bool fileIsImage(const QString &name, const QString &mime) {
_isImage = false;
QString lowermime = mime.toLower(), namelower = name.toLower(); QString lowermime = mime.toLower(), namelower = name.toLower();
if (lowermime.startsWith(qstr("image/"))) { if (lowermime.startsWith(qstr("image/"))) {
_isImage = true; return true;
} else if (namelower.endsWith(qstr(".bmp")) } else if (namelower.endsWith(qstr(".bmp"))
|| namelower.endsWith(qstr(".jpg")) || namelower.endsWith(qstr(".jpg"))
|| namelower.endsWith(qstr(".jpeg")) || namelower.endsWith(qstr(".jpeg"))
@ -1096,8 +1094,13 @@ void DocumentData::recountIsImage() {
|| namelower.endsWith(qstr(".tif")) || namelower.endsWith(qstr(".tif"))
|| namelower.endsWith(qstr(".psd")) || namelower.endsWith(qstr(".psd"))
|| namelower.endsWith(qstr(".png"))) { || namelower.endsWith(qstr(".png"))) {
_isImage = true; return true;
} }
return false;
}
void DocumentData::recountIsImage() {
_isImage = fileIsImage(name, mime);
} }
WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill) : id(id) WebPageData::WebPageData(const WebPageId &id, WebPageType type, const QString &url, const QString &displayUrl, const QString &siteName, const QString &title, const QString &description, PhotoData *photo, DocumentData *doc, int32 duration, const QString &author, int32 pendingTill) : id(id)

View File

@ -1070,6 +1070,8 @@ struct SongData : public DocumentAdditionalData {
QString title, performer; QString title, performer;
}; };
bool fileIsImage(const QString &name, const QString &mime);
struct DocumentData { struct DocumentData {
DocumentData(const DocumentId &id, const uint64 &access = 0, int32 date = 0, const QVector<MTPDocumentAttribute> &attributes = QVector<MTPDocumentAttribute>(), const QString &mime = QString(), const ImagePtr &thumb = ImagePtr(), int32 dc = 0, int32 size = 0); DocumentData(const DocumentId &id, const uint64 &access = 0, int32 date = 0, const QVector<MTPDocumentAttribute> &attributes = QVector<MTPDocumentAttribute>(), const QString &mime = QString(), const ImagePtr &thumb = ImagePtr(), int32 dc = 0, int32 size = 0);
void setattributes(const QVector<MTPDocumentAttribute> &attributes); void setattributes(const QVector<MTPDocumentAttribute> &attributes);