IconPair.C 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
  3. *
  4. * See the LICENSE file for terms of use.
  5. */
  6. #include <Wt/WCssDecorationStyle>
  7. #include <Wt/WContainerWidget>
  8. #include <Wt/WImage>
  9. #include "IconPair.h"
  10. IconPair::IconPair(const std::string icon1URI, const std::string icon2URI,
  11. bool clickIsSwitch, Wt::WContainerWidget *parent)
  12. : Wt::WCompositeWidget(parent),
  13. impl_(new Wt::WContainerWidget()),
  14. icon1_(new Wt::WImage(icon1URI, impl_)),
  15. icon2_(new Wt::WImage(icon2URI, impl_)),
  16. icon1Clicked(icon1_->clicked()),
  17. icon2Clicked(icon2_->clicked())
  18. {
  19. setImplementation(impl_);
  20. implementStateless(&IconPair::showIcon1, &IconPair::undoShowIcon1);
  21. implementStateless(&IconPair::showIcon2, &IconPair::undoShowIcon2);
  22. setInline(true);
  23. icon2_->hide();
  24. if (clickIsSwitch) {
  25. icon1_->clicked().connect(icon1_, &Wt::WImage::hide);
  26. icon1_->clicked().connect(icon2_, &Wt::WImage::show);
  27. icon2_->clicked().connect(icon2_, &Wt::WImage::hide);
  28. icon2_->clicked().connect(icon1_, &Wt::WImage::show); //
  29. decorationStyle().setCursor(Wt::PointingHandCursor);
  30. }
  31. } //
  32. void IconPair::setState(int num)
  33. {
  34. if (num == 0) {
  35. icon1_->show();
  36. icon2_->hide();
  37. } else {
  38. icon1_->hide();
  39. icon2_->show();
  40. }
  41. }
  42. int IconPair::state() const
  43. {
  44. return (icon1_->isHidden() ? 1 : 0);
  45. }
  46. void IconPair::showIcon1()
  47. {
  48. previousState_ = (icon1_->isHidden() ? 1 : 0);
  49. setState(0);
  50. }
  51. void IconPair::showIcon2()
  52. {
  53. previousState_ = (icon1_->isHidden() ? 1 : 0);
  54. setState(1);
  55. }
  56. void IconPair::undoShowIcon1()
  57. {
  58. setState(previousState_);
  59. }
  60. void IconPair::undoShowIcon2()
  61. {
  62. setState(previousState_);
  63. } //