ctkCheckBoxPixmaps.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. /*=========================================================================
  15. Program: ParaView
  16. Module: pqCheckBoxPixMaps.h
  17. Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
  18. All rights reserved.
  19. ParaView is a free software; you can redistribute it and/or modify it
  20. under the terms of the ParaView license version 1.2.
  21. See http://www.paraview.org/paraview/project/license.html for the full ParaView license.
  22. A copy of this license can be obtained by contacting
  23. Kitware Inc.
  24. 28 Corporate Drive
  25. Clifton Park, NY 12065
  26. USA
  27. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. ========================================================================*/
  39. #ifndef __ctkCheckBoxPixmaps_h
  40. #define __ctkCheckBoxPixmaps_h
  41. /// Qt includes
  42. #include <QObject>
  43. #include <QPixmap>
  44. /// CTK includes
  45. #include "ctkPimpl.h"
  46. #include "ctkWidgetsExport.h"
  47. class QPixmap;
  48. class QWidget;
  49. class ctkCheckBoxPixmapsPrivate;
  50. /// \ingroup Widgets
  51. ///
  52. /// ctkCheckBoxPixmaps is a helper class that can used to create pixmaps for
  53. /// checkboxs in various states. This is useful for showing checkboxes in qt-views.
  54. class CTK_WIDGETS_EXPORT ctkCheckBoxPixmaps : public QObject
  55. {
  56. Q_OBJECT
  57. typedef QObject Superclass;
  58. public:
  59. ///
  60. /// The widget is used to retrieve the style of the checkboxes
  61. /// If the widget is 0 (not recommended) use the QApplication style.
  62. ctkCheckBoxPixmaps(QWidget* parent = 0);
  63. virtual ~ctkCheckBoxPixmaps();
  64. ///
  65. /// Returns a pixmap for the given state .
  66. /// The pixmaps have been cached so the cost of the function is minimum.
  67. const QPixmap& pixmap(Qt::CheckState state, bool active) const;
  68. ///
  69. /// Utility function that can take an int for the state.
  70. /// Best to be avoided.
  71. inline const QPixmap& pixmap(int state, bool active) const;
  72. protected:
  73. QScopedPointer<ctkCheckBoxPixmapsPrivate> d_ptr;
  74. private:
  75. Q_DECLARE_PRIVATE(ctkCheckBoxPixmaps);
  76. Q_DISABLE_COPY(ctkCheckBoxPixmaps);
  77. };
  78. const QPixmap& ctkCheckBoxPixmaps::pixmap(int state, bool active) const
  79. {
  80. return this->pixmap(static_cast<Qt::CheckState>(state), active);
  81. }
  82. #endif