passport_form_row.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "passport/passport_form_row.h"
  8. #include "ui/wrap/fade_wrap.h"
  9. #include "ui/text_options.h"
  10. #include "styles/style_boxes.h"
  11. #include "styles/style_passport.h"
  12. namespace Passport {
  13. FormRow::FormRow(
  14. QWidget *parent,
  15. const QString &title,
  16. const QString &description)
  17. : RippleButton(parent, st::passportRowRipple)
  18. , _title(
  19. st::semiboldTextStyle,
  20. title,
  21. Ui::NameTextOptions(),
  22. st::boxWideWidth / 2)
  23. , _description(
  24. st::defaultTextStyle,
  25. description,
  26. Ui::NameTextOptions(),
  27. st::boxWideWidth / 2) {
  28. }
  29. void FormRow::setReady(bool ready) {
  30. _ready = ready;
  31. resizeToWidth(width());
  32. update();
  33. }
  34. int FormRow::resizeGetHeight(int newWidth) {
  35. const auto availableWidth = countAvailableWidth(newWidth);
  36. _titleHeight = _title.countHeight(availableWidth);
  37. _descriptionHeight = _description.countHeight(availableWidth);
  38. const auto result = st::passportRowPadding.top()
  39. + _titleHeight
  40. + st::passportRowSkip
  41. + _descriptionHeight
  42. + st::passportRowPadding.bottom();
  43. return result;
  44. }
  45. int FormRow::countAvailableWidth(int newWidth) const {
  46. return newWidth
  47. - st::passportRowPadding.left()
  48. - st::passportRowPadding.right()
  49. - (_ready ? st::passportRowReadyIcon : st::passportRowEmptyIcon).width();
  50. }
  51. int FormRow::countAvailableWidth() const {
  52. return countAvailableWidth(width());
  53. }
  54. void FormRow::paintEvent(QPaintEvent *e) {
  55. Painter p(this);
  56. const auto ms = getms();
  57. paintRipple(p, 0, 0, ms);
  58. const auto left = st::passportRowPadding.left();
  59. const auto availableWidth = countAvailableWidth();
  60. auto top = st::passportRowPadding.top();
  61. p.setPen(st::passportRowTitleFg);
  62. _title.drawLeft(p, left, top, availableWidth, width());
  63. top += _titleHeight + st::passportRowSkip;
  64. p.setPen(st::passportRowDescriptionFg);
  65. _description.drawLeft(p, left, top, availableWidth, width());
  66. top += _descriptionHeight + st::passportRowPadding.bottom();
  67. const auto &icon = _ready
  68. ? st::passportRowReadyIcon
  69. : st::passportRowEmptyIcon;
  70. icon.paint(
  71. p,
  72. width() - st::passportRowPadding.right() - icon.width(),
  73. (height() - icon.height()) / 2,
  74. width());
  75. }
  76. } // namespace Passport