IconPair.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // This may look like C code, but it's really -*- C++ -*-
  2. /*
  3. * Copyright (C) 2008 Emweb bvba, Kessel-Lo, Belgium.
  4. *
  5. * See the LICENSE file for terms of use.
  6. */
  7. #ifndef ICONPAIR_H_
  8. #define ICONPAIR_H_
  9. #include <Wt/WCompositeWidget>
  10. namespace Wt {
  11. class WImage;
  12. }
  13. /**
  14. * @addtogroup treelist
  15. */
  16. /*@{*/
  17. /*! \brief An icon pair (identical to WIconPair)
  18. *
  19. * This widget manages two images, only one of which is shown at a single
  20. * time.
  21. *
  22. * The widget may also react to click events, by changing state.
  23. *
  24. * This widget is part of the %Wt treelist example, where it is used
  25. * to represent the expand/collapse icons, and the corresponding
  26. * map open/close icon.
  27. *
  28. * \sa TreeNode
  29. */
  30. class IconPair : public Wt::WCompositeWidget
  31. {
  32. public:
  33. /*! \brief Construct a two-state icon widget.
  34. *
  35. * The constructor takes the URI of the two icons. When clickIsSwitch
  36. * is set true, clicking on the icon will switch state.
  37. */
  38. IconPair(const std::string icon1URI, const std::string icon2URI,
  39. bool clickIsSwitch = true, Wt::WContainerWidget *parent = 0);
  40. /*! \brief Set which icon should be visible.
  41. *
  42. * The first icon has number 0, and the second icon has number 1.
  43. *
  44. * \sa state()
  45. */
  46. void setState(int num);
  47. /*! \brief Get the current state.
  48. *
  49. * \sa setState()
  50. */
  51. int state() const;
  52. /*! \brief Get the first icon image
  53. */
  54. Wt::WImage *icon1() const { return icon1_; }
  55. /*! \brief Get the second icon image
  56. */
  57. Wt::WImage *icon2() const { return icon2_; }
  58. /*! \brief Set state to 0 (show icon 1).
  59. */
  60. void showIcon1();
  61. /*! \brief Set state to 1 (show icon 2).
  62. */
  63. void showIcon2();
  64. private:
  65. Wt::WContainerWidget *impl_;
  66. //! First icon.
  67. Wt::WImage *icon1_;
  68. //! Second icon.
  69. Wt::WImage *icon2_;
  70. public:
  71. /*! \brief Signal emitted when clicked while in state 0 (icon 1 is
  72. * shown).
  73. */
  74. Wt::EventSignal<Wt::WMouseEvent>& icon1Clicked;
  75. /*! \brief Signal emitted when clicked while in state 1 (icon 2 is
  76. * shown).
  77. */
  78. Wt::EventSignal<Wt::WMouseEvent>& icon2Clicked;
  79. private:
  80. //! Undo state for prelearning stateless showIcon1() and showIcon2() slots
  81. int previousState_;
  82. //! Undo function for prelearning showIcon1()
  83. void undoShowIcon1();
  84. //! Undo function for prelearning showIcon2()
  85. void undoShowIcon2();
  86. };
  87. /*@}*/
  88. #endif // ICONPAIR_H_