Example #1
0
LanguageBox::LanguageBox() :
_close(this, lang(lng_box_ok), st::defaultBoxButton) {

	bool haveTestLang = (cLang() == languageTest);

	int32 y = st::boxTitleHeight + st::boxOptionListPadding.top();
	_langs.reserve(languageCount + (haveTestLang ? 1 : 0));
	if (haveTestLang) {
		_langs.push_back(new Radiobutton(this, qsl("lang"), languageTest, qsl("Custom Lang"), (cLang() == languageTest), st::langsButton));
		_langs.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y);
		y += _langs.back()->height() + st::boxOptionListPadding.top();
		connect(_langs.back(), SIGNAL(changed()), this, SLOT(onChange()));
	}
	for (int32 i = 0; i < languageCount; ++i) {
		LangLoaderResult result;
		if (i) {
			LangLoaderPlain loader(qsl(":/langs/lang_") + LanguageCodes[i] + qsl(".strings"), LangLoaderRequest(lng_language_name));
			result = loader.found();
		} else {
			result.insert(lng_language_name, langOriginal(lng_language_name));
		}
		_langs.push_back(new Radiobutton(this, qsl("lang"), i, result.value(lng_language_name, LanguageCodes[i] + qsl(" language")), (cLang() == i), st::langsButton));
		_langs.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y);
		y += _langs.back()->height() + st::boxOptionListPadding.top();
		connect(_langs.back(), SIGNAL(changed()), this, SLOT(onChange()));
	}

	resizeMaxHeight(st::langsWidth, st::boxTitleHeight + (languageCount + (haveTestLang ? 1 : 0)) * (st::boxOptionListPadding.top() + st::langsButton.height) + st::boxOptionListPadding.bottom() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _close.height() + st::boxButtonPadding.bottom());

	connect(&_close, SIGNAL(clicked()), this, SLOT(onClose()));

	_close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height());
	prepare();
}
Example #2
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());
}
Example #3
0
UsernameBox::UsernameBox() : AbstractBox(st::boxWidth),
_save(this, lang(lng_settings_save), st::defaultBoxButton),
_cancel(this, lang(lng_cancel), st::cancelBoxButton),
_username(this, st::defaultInputField, qsl("@username"), App::self()->username, false),
_link(this, QString(), st::defaultBoxLinkButton),
_saveRequestId(0), _checkRequestId(0),
_about(st::boxWidth - st::usernamePadding.left()) {
	setBlueTitle(true);

	_goodText = App::self()->username.isEmpty() ? QString() : lang(lng_username_available);

	textstyleSet(&st::usernameTextStyle);
	_about.setRichText(st::boxTextFont, lang(lng_username_about));
	resizeMaxHeight(st::boxWidth, st::boxTitleHeight + st::usernamePadding.top() + _username.height() + st::usernameSkip + _about.countHeight(st::boxWidth - st::usernamePadding.left()) + 3 * st::usernameTextStyle.lineHeight + st::usernamePadding.bottom() + st::boxButtonPadding.top() + _save.height() + st::boxButtonPadding.bottom());
	textstyleRestore();

	connect(&_save, SIGNAL(clicked()), this, SLOT(onSave()));
	connect(&_cancel, SIGNAL(clicked()), this, SLOT(onClose()));
	connect(&_username, SIGNAL(changed()), this, SLOT(onChanged()));
	connect(&_username, SIGNAL(submitted(bool)), this, SLOT(onSave()));

	connect(&_link, SIGNAL(clicked()), this, SLOT(onLinkClick()));

	_checkTimer.setSingleShot(true);
	connect(&_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck()));

	prepare();
}
Example #4
0
void UsernameBox::initBox() {
	resizeMaxHeight(st::usernameWidth, st::boxTitleHeight + st::addContactPadding.top() + _usernameInput.height() + st::addContactPadding.bottom() + _about.countHeight(st::usernameWidth - 2 * st::boxTitlePos.x()) + st::usernameSkip + _saveButton.height());

	connect(&_saveButton, SIGNAL(clicked()), this, SLOT(onSave()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose()));
	connect(&_usernameInput, SIGNAL(changed()), this, SLOT(onChanged()));

	_checkTimer.setSingleShot(true);
	connect(&_checkTimer, SIGNAL(timeout()), this, SLOT(onCheck()));

	prepare();
}
Example #5
0
AboutBox::AboutBox() :
_done(this, lang(lng_about_done), st::aboutCloseButton),
_version(this, qsl("[a href=\"https://desktop.telegram.org/#changelog\"]") + textClean(lng_about_version(lt_version, QString::fromWCharArray(AppVersionStr) + (DevChannel ? " dev" : ""))) + qsl("[/a]"), st::aboutVersion, st::defaultTextStyle),
_text(this, lang(lng_about_text), st::aboutLabel, st::aboutTextStyle) {
	
	resizeMaxHeight(st::aboutWidth, st::aboutHeight);

	_version.move(0, st::aboutVersionTop);
	_text.move(0, st::aboutTextTop);

	_headerWidth = st::aboutHeaderFont->m.width(qsl("Telegram "));
	_subheaderWidth = st::aboutSubheaderFont->m.width(qsl("Desktop"));

	_done.move(0, height() - _done.height());

	connect(&_done, SIGNAL(clicked()), this, SLOT(onClose()));

	prepare();
}
Example #6
0
PhotoSendBox::PhotoSendBox(const QString &phone, const QString &fname, const QString &lname, MsgId replyTo) : _img(0),
_thumbx(0), _thumby(0), _thumbw(0), _thumbh(0), _namew(0), _textw(0),
_compressed(this, lang(lng_send_image_compressed), true),
_sendButton(this, lang(lng_send_button), st::btnSelectDone),
_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
_phone(phone), _fname(fname), _lname(lname), _replyTo(replyTo) {
	connect(&_sendButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose()));

	_compressed.hide();

	_name = lng_full_name(lt_first_name, _fname, lt_last_name, _lname);
	_namew = st::mediaFont->width(_name);
	_size = _phone;
	_textw = qMax(_namew, st::mediaFont->width(_size));

	resizeMaxHeight(st::boxWideWidth, st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom() + st::boxPadding.bottom() + _sendButton.height());
	prepare();
}
Example #7
0
AutoLockBox::AutoLockBox() :
_done(this, lang(lng_about_done), st::langsCloseButton) {

	bool haveTestLang = (cLang() == languageTest);

	int32 opts[] = { 60, 300, 3600, 18000 }, cnt = sizeof(opts) / sizeof(opts[0]);

	resizeMaxHeight(st::langsWidth, st::boxTitleHeight + st::langsPadding.top() + st::langsPadding.bottom() + cnt * (st::langPadding.top() + st::rbDefFlat.height + st::langPadding.bottom()) + _done.height());

	int32 y = st::boxTitleHeight + st::langsPadding.top();
	_options.reserve(cnt);
	for (int32 i = 0; i < cnt; ++i) {
		int32 v = opts[i];
		_options.push_back(new FlatRadiobutton(this, qsl("autolock"), v, (v % 3600) ? lng_passcode_autolock_minutes(lt_count, v / 60) : lng_passcode_autolock_hours(lt_count, v / 3600), (cAutoLock() == v), st::langButton));
		_options.back()->move(st::langsPadding.left() + st::langPadding.left(), y + st::langPadding.top());
		y += st::langPadding.top() + _options.back()->height() + st::langPadding.bottom();
		connect(_options.back(), SIGNAL(changed()), this, SLOT(onChange()));
	}

	connect(&_done, SIGNAL(clicked()), this, SLOT(onClose()));

	_done.move(0, height() - _done.height());
	prepare();
}
Example #8
0
AutoLockBox::AutoLockBox() :
_close(this, lang(lng_box_ok), st::defaultBoxButton) {

	bool haveTestLang = (cLang() == languageTest);

	int32 opts[] = { 60, 300, 3600, 18000 }, cnt = sizeof(opts) / sizeof(opts[0]);

	resizeMaxHeight(st::langsWidth, st::boxTitleHeight + cnt * (st::boxOptionListPadding.top() + st::langsButton.height) + st::boxOptionListPadding.bottom() + st::boxPadding.bottom() + st::boxButtonPadding.top() + _close.height() + st::boxButtonPadding.bottom());

	int32 y = st::boxTitleHeight + st::boxOptionListPadding.top();
	_options.reserve(cnt);
	for (int32 i = 0; i < cnt; ++i) {
		int32 v = opts[i];
		_options.push_back(new Radiobutton(this, qsl("autolock"), v, (v % 3600) ? lng_passcode_autolock_minutes(lt_count, v / 60) : lng_passcode_autolock_hours(lt_count, v / 3600), (Global::AutoLock() == v), st::langsButton));
		_options.back()->move(st::boxPadding.left() + st::boxOptionListPadding.left(), y);
		y += _options.back()->height() + st::boxOptionListPadding.top();
		connect(_options.back(), SIGNAL(changed()), this, SLOT(onChange()));
	}

	connect(&_close, SIGNAL(clicked()), this, SLOT(onClose()));

	_close.moveToRight(st::boxButtonPadding.right(), height() - st::boxButtonPadding.bottom() - _close.height());
	prepare();
}
Example #9
0
PhotoSendBox::PhotoSendBox(const ReadyLocalMedia &img) : _img(new ReadyLocalMedia(img)),
	_thumbx(0), _thumby(0), _thumbw(0), _thumbh(0), _namew(0), _textw(0),
	_compressed(this, lang(lng_send_image_compressed), cCompressPastedImage()),
	_sendButton(this, lang(lng_send_button), st::btnSelectDone),
	_cancelButton(this, lang(lng_cancel), st::btnSelectCancel),
	_replyTo(img.replyTo) {
	connect(&_sendButton, SIGNAL(clicked()), this, SLOT(onSend()));
	connect(&_cancelButton, SIGNAL(clicked()), this, SLOT(onClose()));

	if (_img->type == ToPreparePhoto) {
		int32 maxW = 0, maxH = 0;
		for (PreparedPhotoThumbs::const_iterator i = _img->photoThumbs.cbegin(), e = _img->photoThumbs.cend(); i != e; ++i) {
			if (i->width() >= maxW && i->height() >= maxH) {
				_thumb = *i;
				maxW = _thumb.width();
				maxH = _thumb.height();
			}
		}
		int32 tw = _thumb.width(), th = _thumb.height();
		if (!tw || !th) {
			tw = th = 1;
		}
		_thumbw = width() - st::boxPadding.left() - st::boxPadding.right();
		if (_thumb.width() < _thumbw) {
			_thumbw = (_thumb.width() > 20) ? _thumb.width() : 20;
		}
		int32 maxthumbh = qMin(qRound(1.5 * _thumbw), int(st::confirmMaxHeight));
		_thumbh = qRound(th * float64(_thumbw) / tw);
		if (_thumbh > maxthumbh) {
			_thumbw = qRound(_thumbw * float64(maxthumbh) / _thumbh);
			_thumbh = maxthumbh;
			if (_thumbw < 10) {
				_thumbw = 10;
			}
		}
		resizeMaxHeight(st::boxWideWidth, _thumbh + st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::boxPadding.bottom() + _compressed.height() + _sendButton.height());

		_thumb = QPixmap::fromImage(_thumb.toImage().scaled(_thumbw * cIntRetinaFactor(), _thumbh * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly);
		_thumb.setDevicePixelRatio(cRetinaFactor());
	} else {
		_compressed.hide();
		if (!_img->photoThumbs.isEmpty()) {
			_thumb = _img->photoThumbs.cbegin().value();
			int32 tw = _thumb.width(), th = _thumb.height();
			if (_thumb.isNull() || !tw || !th) {
				_thumbw = _thumbx = _thumby = 0;
			} else if (tw > th) {
				_thumbw = (tw * st::mediaThumbSize) / th;
				_thumbx = (_thumbw - st::mediaThumbSize) / 2;
				_thumby = 0;
			} else {
				_thumbw = st::mediaThumbSize;
				_thumbx = 0;
				_thumby = ((th * _thumbw) / tw - st::mediaThumbSize) / 2;
			}
		}
		if (_thumbw) {
			_thumb = QPixmap::fromImage(_thumb.toImage().scaledToWidth(_thumbw * cIntRetinaFactor(), Qt::SmoothTransformation), Qt::ColorOnly);
			_thumb.setDevicePixelRatio(cRetinaFactor());
		}
		resizeMaxHeight(st::boxWideWidth, st::boxPadding.top() + st::boxFont->height + st::boxPadding.bottom() + st::mediaPadding.top() + st::mediaThumbSize + st::mediaPadding.bottom() + st::boxPadding.bottom() + _sendButton.height());

		_name = _img->filename;
		_namew = st::mediaFont->width(_name);
		_size = formatSizeText(_img->filesize);
		_textw = qMax(_namew, st::mediaFont->width(_size));
	}
	prepare();
}
Example #10
0
void AbstractBox::setMaxHeight(int32 maxHeight) {
	resizeMaxHeight(width(), maxHeight);
}