Exemple #1
0
void PhotoCropBox::init(const QImage &img, PeerData *peer) {
	if (peerIsChat(_peerId) || (peer && peer->isMegagroup())) {
		_title = lang(lng_create_group_crop);
	} else if (peerIsChannel(_peerId)) {
		_title = lang(lng_create_channel_crop);
	} else {
		_title = lang(lng_settings_crop_profile);
	}

	connect(&_done, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
	if (peerToBareInt(_peerId)) {
		connect(this, SIGNAL(ready(const QImage&)), this, SLOT(onReady(const QImage&)));
	}

	int32 s = st::boxWideWidth - st::boxPhotoPadding.left() - st::boxPhotoPadding.right();
	_thumb = QPixmap::fromImage(img.scaled(s, s, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
	_thumbw = _thumb.width();
	_thumbh = _thumb.height();
	if (_thumbw > _thumbh) {
		_cropw = _thumbh - 20;
	} else {
		_cropw = _thumbw - 20;
	}
	_cropx = (_thumbw - _cropw) / 2;
	_cropy = (_thumbh - _cropw) / 2;

	_thumbx = (st::boxWideWidth - _thumbw) / 2;
	_thumby = st::boxPhotoPadding.top();
	setMouseTracking(true);

	resizeMaxHeight(st::boxWideWidth, st::boxPhotoPadding.top() + _thumbh + st::boxPhotoPadding.bottom() + st::boxTextFont->height + st::cropSkip + st::boxButtonPadding.top() + _done.height() + st::boxButtonPadding.bottom());
}
Exemple #2
0
PhotoCropBox::PhotoCropBox(const QImage &img, const PeerId &peer, bool upload) : AbstractBox()
, _downState(0)
, _done(this, lang(lng_settings_save), st::defaultBoxButton)
, _cancel(this, lang(lng_cancel), st::cancelBoxButton)
, _img(img)
, _peerId(peer) {
	if (peerIsChannel(_peerId)) {
		_title = lang(lng_create_channel_crop);
	} else if (peerIsChat(_peerId)) {
		_title = lang(lng_create_group_crop);
	} else {
		_title = lang(lng_settings_crop_profile);
	}

	connect(&_done, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
	if (_peerId && upload) {
		connect(this, SIGNAL(ready(const QImage&)), this, SLOT(onReady(const QImage&)));
	}