RoundedWidget.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 ROUNDED_WIDGET_H_
  8. #define ROUNDED_WIDGET_H_
  9. #include <Wt/WCompositeWidget>
  10. #include "CornerImage.h"
  11. namespace Wt {
  12. class WContainerWidget;
  13. }
  14. /**
  15. * @addtogroup styleexample
  16. */
  17. /*@{*/
  18. /*! \brief A widget with rounded corners.
  19. *
  20. * This widgets represents a widget for which any combination of its four
  21. * corners may be rounded. Although rounded corners is not a standard part
  22. * of the CSS specification, this widget will be rendered identical on
  23. * all platforms.
  24. *
  25. * The contents of the widget is managed inside a WContainerWidget, which
  26. * is accessed using the contents() method.
  27. *
  28. * The radius of the rounded corners, the background color of the image,
  29. * and the surrounding color may be changed at all times.
  30. *
  31. * The RoundedWidget is part of the %Wt style example.
  32. *
  33. * \sa CornerImage.
  34. */
  35. class RoundedWidget : public WCompositeWidget
  36. {
  37. public:
  38. /*! \brief One of the four corners of a widget.
  39. */
  40. enum Corner { TopLeft = CornerImage::TopLeft, //!< Top left
  41. TopRight = CornerImage::TopRight, //!< Top right
  42. BottomLeft = CornerImage::BottomLeft, //!< Bottom left
  43. BottomRight = CornerImage::BottomRight, //!< Bottom right
  44. All = 0xF}; //!< All
  45. /*! \brief Construct a widget with any combination of its corners
  46. * rounded.
  47. */
  48. RoundedWidget(int corners = All, WContainerWidget *parent = 0);
  49. /*! \brief Destruct a RoundedWidget
  50. */
  51. ~RoundedWidget();
  52. /*! \brief Set the widget background color.
  53. *
  54. * Because the background color also affects the color of the
  55. * corner images, the background color cannot be set using the
  56. * WCssDecorationStyle() of the widget.
  57. */
  58. void setBackgroundColor(WColor color);
  59. /*! \brief Get the widget background color.
  60. */
  61. WColor backgroundColor() const { return backgroundColor_; }
  62. /*! \brief Show or hide rounded corners.
  63. */
  64. void enableRoundedCorners(bool how);
  65. /*! \brief Set the corner radius of the widget.
  66. */
  67. void setCornerRadius(int radius);
  68. /*! \brief Get the corner radius of the widget.
  69. */
  70. int cornerRadius() const { return radius_; }
  71. /*! \brief Set the surrounding color of the widget.
  72. *
  73. * This color will be used "outside" the corner, in each of the
  74. * corner images.
  75. */
  76. void setSurroundingColor(WColor color);
  77. /*! \brief Get the surrounding color of the widget.
  78. */
  79. WColor surroundingColor() const { return surroundingColor_; }
  80. /*! \brief Access the contents container.
  81. *
  82. * The contents WContainerWidget represents the contents inside
  83. * the rounded widget.
  84. */
  85. WContainerWidget *contents() const { return contents_; }
  86. private:
  87. //! Background color
  88. WColor backgroundColor_;
  89. //! "Surrounding" color -- maybe we can use a transparent color ?
  90. WColor surroundingColor_;
  91. //! Radius
  92. int radius_;
  93. //! OR'ed specification of the corners which are to be rounded.
  94. int corners_;
  95. //! The container widget in which to store the contents.
  96. WContainerWidget *contents_;
  97. //! This composite widget is implemented as a WContainerWidget
  98. WContainerWidget *impl_;
  99. //! A container at the top which renders the top rounding
  100. WContainerWidget *top_;
  101. //! A container at the bottom renders the bottom rounding
  102. WContainerWidget *bottom_;
  103. //! Up to four CornerImages for each corner.
  104. CornerImage *images_[4];
  105. //! Create the implementation.
  106. void create();
  107. //! Adjust the image (colors and radius).
  108. void adjust();
  109. };
  110. /*@}*/
  111. #endif // ROUNDED_WIDGET_H_