mirror of https://github.com/procxx/kepka.git
				
				
				
			Check solution length in CreatePollBox.
This commit is contained in:
		
							parent
							
								
									76d81ff197
								
							
						
					
					
						commit
						b34d5b8306
					
				|  | @ -39,6 +39,7 @@ constexpr auto kOptionLimit = 100; | ||||||
| constexpr auto kWarnQuestionLimit = 80; | constexpr auto kWarnQuestionLimit = 80; | ||||||
| constexpr auto kWarnOptionLimit = 30; | constexpr auto kWarnOptionLimit = 30; | ||||||
| constexpr auto kSolutionLimit = 200; | constexpr auto kSolutionLimit = 200; | ||||||
|  | constexpr auto kWarnSolutionLimit = 60; | ||||||
| constexpr auto kErrorLimit = 99; | constexpr auto kErrorLimit = 99; | ||||||
| 
 | 
 | ||||||
| class Options { | class Options { | ||||||
|  | @ -825,6 +826,28 @@ not_null<Ui::InputField*> CreatePollBox::setupSolution( | ||||||
| 	solution->setEditLinkCallback( | 	solution->setEditLinkCallback( | ||||||
| 		DefaultEditLinkCallback(_session, solution)); | 		DefaultEditLinkCallback(_session, solution)); | ||||||
| 
 | 
 | ||||||
|  | 	const auto warning = CreateWarningLabel( | ||||||
|  | 		inner, | ||||||
|  | 		solution, | ||||||
|  | 		kSolutionLimit, | ||||||
|  | 		kWarnSolutionLimit); | ||||||
|  | 	rpl::combine( | ||||||
|  | 		solution->geometryValue(), | ||||||
|  | 		warning->sizeValue() | ||||||
|  | 	) | rpl::start_with_next([=](QRect geometry, QSize label) { | ||||||
|  | 		warning->moveToLeft( | ||||||
|  | 			(inner->width() | ||||||
|  | 				- label.width() | ||||||
|  | 				- st::createPollWarningPosition.x()), | ||||||
|  | 			(geometry.y() | ||||||
|  | 				- st::createPollFieldPadding.top() | ||||||
|  | 				- st::settingsSubsectionTitlePadding.bottom() | ||||||
|  | 				- st::settingsSubsectionTitle.style.font->height | ||||||
|  | 				+ st::settingsSubsectionTitle.style.font->ascent | ||||||
|  | 				- st::createPollWarning.style.font->ascent), | ||||||
|  | 			geometry.width()); | ||||||
|  | 	}, warning->lifetime()); | ||||||
|  | 
 | ||||||
| 	inner->add( | 	inner->add( | ||||||
| 		object_ptr<Ui::FlatLabel>( | 		object_ptr<Ui::FlatLabel>( | ||||||
| 			inner, | 			inner, | ||||||
|  | @ -990,6 +1013,12 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() { | ||||||
| 		} else { | 		} else { | ||||||
| 			*error &= ~Error::Correct; | 			*error &= ~Error::Correct; | ||||||
| 		} | 		} | ||||||
|  | 		if (quiz->checked() | ||||||
|  | 			&& solution->getLastText().trimmed().size() > kSolutionLimit) { | ||||||
|  | 			*error |= Error::Solution; | ||||||
|  | 		} else { | ||||||
|  | 			*error &= ~Error::Solution; | ||||||
|  | 		} | ||||||
| 	}; | 	}; | ||||||
| 	const auto showError = [=](const QString &text) { | 	const auto showError = [=](const QString &text) { | ||||||
| 		Ui::Toast::Show(text); | 		Ui::Toast::Show(text); | ||||||
|  | @ -1004,6 +1033,8 @@ object_ptr<Ui::RpWidget> CreatePollBox::setupContent() { | ||||||
| 			options->focusFirst(); | 			options->focusFirst(); | ||||||
| 		} else if (*error & Error::Correct) { | 		} else if (*error & Error::Correct) { | ||||||
| 			showError(tr::lng_polls_choose_correct(tr::now)); | 			showError(tr::lng_polls_choose_correct(tr::now)); | ||||||
|  | 		} else if (*error & Error::Solution) { | ||||||
|  | 			solution->showError(); | ||||||
| 		} else if (!*error) { | 		} else if (!*error) { | ||||||
| 			_submitRequests.fire({ collectResult(), sendOptions }); | 			_submitRequests.fire({ collectResult(), sendOptions }); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
|  | @ -50,6 +50,7 @@ private: | ||||||
| 		Options  = 0x02, | 		Options  = 0x02, | ||||||
| 		Correct  = 0x04, | 		Correct  = 0x04, | ||||||
| 		Other    = 0x08, | 		Other    = 0x08, | ||||||
|  | 		Solution = 0x10, | ||||||
| 	}; | 	}; | ||||||
| 	friend constexpr inline bool is_flag_type(Error) { return true; } | 	friend constexpr inline bool is_flag_type(Error) { return true; } | ||||||
| 	using Errors = base::flags<Error>; | 	using Errors = base::flags<Error>; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue