icon_button_with_text.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "ui/widgets/icon_button_with_text.h"
  8. namespace Ui {
  9. IconButtonWithText::IconButtonWithText(
  10. not_null<RpWidget*> parent,
  11. const style::IconButtonWithText &st)
  12. : IconButton(parent, st.iconButton)
  13. , _st(st) {
  14. }
  15. void IconButtonWithText::paintEvent(QPaintEvent *e) {
  16. IconButton::paintEvent(e);
  17. const auto r = rect() - _st.textPadding;
  18. const auto overIconOpacity = IconButton::iconOverOpacity();
  19. auto p = QPainter(this);
  20. p.setFont(_st.font);
  21. p.setPen((overIconOpacity == 1.) ? _st.textFgOver : _st.textFg);
  22. p.drawText(r, _text, _st.textAlign);
  23. if (overIconOpacity > 0. && overIconOpacity < 1.) {
  24. p.setPen(_st.textFgOver);
  25. p.setOpacity(overIconOpacity);
  26. p.drawText(r, _text, _st.textAlign);
  27. }
  28. }
  29. void IconButtonWithText::setText(const QString &text) {
  30. if (_text != text) {
  31. _text = text;
  32. update();
  33. }
  34. }
  35. } // namespace Ui