| 
									
										
										
										
											2018-03-19 20:22:27 +04:00
										 |  |  | /*
 | 
					
						
							|  |  |  | This file is part of Telegram Desktop, | 
					
						
							|  |  |  | the official desktop application for the Telegram messaging service. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | For license and copyright information please follow this link: | 
					
						
							|  |  |  | https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | #include "passport/passport_form_row.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ui/wrap/fade_wrap.h"
 | 
					
						
							|  |  |  | #include "ui/text_options.h"
 | 
					
						
							|  |  |  | #include "styles/style_boxes.h"
 | 
					
						
							|  |  |  | #include "styles/style_passport.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Passport { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | FormRow::FormRow( | 
					
						
							|  |  |  | 	QWidget *parent, | 
					
						
							|  |  |  | 	const QString &title, | 
					
						
							|  |  |  | 	const QString &description) | 
					
						
							|  |  |  | : RippleButton(parent, st::passportRowRipple) | 
					
						
							|  |  |  | , _title( | 
					
						
							|  |  |  | 	st::semiboldTextStyle, | 
					
						
							|  |  |  | 	title, | 
					
						
							|  |  |  | 	Ui::NameTextOptions(), | 
					
						
							|  |  |  | 	st::boxWideWidth / 2) | 
					
						
							|  |  |  | , _description( | 
					
						
							|  |  |  | 	st::defaultTextStyle, | 
					
						
							|  |  |  | 	description, | 
					
						
							|  |  |  | 	Ui::NameTextOptions(), | 
					
						
							|  |  |  | 	st::boxWideWidth / 2) { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FormRow::setReady(bool ready) { | 
					
						
							| 
									
										
										
										
											2018-03-31 05:45:40 +04:00
										 |  |  | 	_ready = ready; | 
					
						
							| 
									
										
										
										
											2018-03-19 20:22:27 +04:00
										 |  |  | 	resizeToWidth(width()); | 
					
						
							| 
									
										
										
										
											2018-03-31 05:45:40 +04:00
										 |  |  | 	update(); | 
					
						
							| 
									
										
										
										
											2018-03-19 20:22:27 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int FormRow::resizeGetHeight(int newWidth) { | 
					
						
							|  |  |  | 	const auto availableWidth = countAvailableWidth(newWidth); | 
					
						
							|  |  |  | 	_titleHeight = _title.countHeight(availableWidth); | 
					
						
							|  |  |  | 	_descriptionHeight = _description.countHeight(availableWidth); | 
					
						
							|  |  |  | 	const auto result = st::passportRowPadding.top() | 
					
						
							|  |  |  | 		+ _titleHeight | 
					
						
							|  |  |  | 		+ st::passportRowSkip | 
					
						
							|  |  |  | 		+ _descriptionHeight | 
					
						
							|  |  |  | 		+ st::passportRowPadding.bottom(); | 
					
						
							|  |  |  | 	return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int FormRow::countAvailableWidth(int newWidth) const { | 
					
						
							|  |  |  | 	return newWidth | 
					
						
							|  |  |  | 		- st::passportRowPadding.left() | 
					
						
							|  |  |  | 		- st::passportRowPadding.right() | 
					
						
							| 
									
										
										
										
											2018-03-31 05:45:40 +04:00
										 |  |  | 		- (_ready ? st::passportRowReadyIcon : st::passportRowEmptyIcon).width(); | 
					
						
							| 
									
										
										
										
											2018-03-19 20:22:27 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int FormRow::countAvailableWidth() const { | 
					
						
							|  |  |  | 	return countAvailableWidth(width()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FormRow::paintEvent(QPaintEvent *e) { | 
					
						
							|  |  |  | 	Painter p(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const auto ms = getms(); | 
					
						
							|  |  |  | 	paintRipple(p, 0, 0, ms); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const auto left = st::passportRowPadding.left(); | 
					
						
							|  |  |  | 	const auto availableWidth = countAvailableWidth(); | 
					
						
							|  |  |  | 	auto top = st::passportRowPadding.top(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 05:45:40 +04:00
										 |  |  | 	p.setPen(st::passportRowTitleFg); | 
					
						
							| 
									
										
										
										
											2018-03-19 20:22:27 +04:00
										 |  |  | 	_title.drawLeft(p, left, top, availableWidth, width()); | 
					
						
							|  |  |  | 	top += _titleHeight + st::passportRowSkip; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-31 05:45:40 +04:00
										 |  |  | 	p.setPen(st::passportRowDescriptionFg); | 
					
						
							| 
									
										
										
										
											2018-03-19 20:22:27 +04:00
										 |  |  | 	_description.drawLeft(p, left, top, availableWidth, width()); | 
					
						
							|  |  |  | 	top += _descriptionHeight + st::passportRowPadding.bottom(); | 
					
						
							| 
									
										
										
										
											2018-03-31 05:45:40 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	const auto &icon = _ready | 
					
						
							|  |  |  | 		? st::passportRowReadyIcon | 
					
						
							|  |  |  | 		: st::passportRowEmptyIcon; | 
					
						
							|  |  |  | 	icon.paint( | 
					
						
							|  |  |  | 		p, | 
					
						
							|  |  |  | 		width() - st::passportRowPadding.right() - icon.width(), | 
					
						
							|  |  |  | 		(height() - icon.height()) / 2, | 
					
						
							|  |  |  | 		width()); | 
					
						
							| 
									
										
										
										
											2018-03-19 20:22:27 +04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // namespace Passport
 |