TDE graphics utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

179 lines
4.8 KiB

  1. /*
  2. Copyright (c) 2003,2004,2005 Clarence Dang <dang@kde.org>
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in the
  11. documentation and/or other materials provided with the distribution.
  12. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  13. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  14. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  15. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  16. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  17. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  18. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  19. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  20. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  21. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22. */
  23. #define DEBUG_KP_SELECTION_TRANSPARENCY 0
  24. #include <kpselectiontransparency.h>
  25. #include <kdebug.h>
  26. #include <kpcolor.h>
  27. #include <kpcolorsimilaritydialog.h>
  28. kpSelectionTransparency::kpSelectionTransparency ()
  29. : m_isOpaque (true)
  30. {
  31. setColorSimilarity (0);
  32. }
  33. kpSelectionTransparency::kpSelectionTransparency (const kpColor &transparentColor, double colorSimilarity)
  34. : m_isOpaque (false),
  35. m_transparentColor (transparentColor)
  36. {
  37. setColorSimilarity (colorSimilarity);
  38. }
  39. kpSelectionTransparency::kpSelectionTransparency (bool isOpaque, const kpColor &transparentColor,
  40. double colorSimilarity)
  41. : m_isOpaque (isOpaque),
  42. m_transparentColor (transparentColor)
  43. {
  44. setColorSimilarity (colorSimilarity);
  45. }
  46. bool kpSelectionTransparency::operator== (const kpSelectionTransparency &rhs) const
  47. {
  48. #if DEBUG_KP_SELECTION_TRANSPARENCY && 0
  49. kdDebug () << "kpSelectionTransparency::operator==()" << endl;
  50. #endif
  51. if (m_isOpaque != rhs.m_isOpaque)
  52. {
  53. #if DEBUG_KP_SELECTION_TRANSPARENCY && 0
  54. kdDebug () << "\tdifferent opacity: lhs=" << m_isOpaque
  55. << " rhs=" << rhs.m_isOpaque
  56. << endl;
  57. #endif
  58. return false;
  59. }
  60. if (m_isOpaque)
  61. {
  62. #if DEBUG_KP_SELECTION_TRANSPARENCY && 0
  63. kdDebug () << "\tboth opaque - eq" << endl;
  64. #endif
  65. return true;
  66. }
  67. #if DEBUG_KP_SELECTION_TRANSPARENCY && 0
  68. kdDebug () << "\tcolours: lhs=" << (int *) m_transparentColor.toTQRgb ()
  69. << " rhs=" << (int *) rhs.m_transparentColor.toTQRgb ()
  70. << endl;
  71. kdDebug () << "\tcolour similarity: lhs=" << m_colorSimilarity
  72. << " rhs=" << rhs.m_colorSimilarity
  73. << endl;
  74. #endif
  75. return (m_transparentColor == rhs.m_transparentColor &&
  76. m_colorSimilarity == rhs.m_colorSimilarity);
  77. }
  78. bool kpSelectionTransparency::operator!= (const kpSelectionTransparency &rhs) const
  79. {
  80. return !(*this == rhs);
  81. }
  82. kpSelectionTransparency::~kpSelectionTransparency ()
  83. {
  84. }
  85. // public
  86. bool kpSelectionTransparency::isOpaque () const
  87. {
  88. return m_isOpaque;
  89. }
  90. // public
  91. bool kpSelectionTransparency::isTransparent () const
  92. {
  93. return !isOpaque ();
  94. }
  95. // public
  96. void kpSelectionTransparency::setOpaque (bool yes)
  97. {
  98. m_isOpaque = yes;
  99. }
  100. // public
  101. void kpSelectionTransparency::setTransparent (bool yes)
  102. {
  103. setOpaque (!yes);
  104. }
  105. // public
  106. kpColor kpSelectionTransparency::transparentColor () const
  107. {
  108. if (m_isOpaque)
  109. {
  110. // There are legitimate uses for this so no kdError()
  111. kdDebug () << "kpSelectionTransparency::transparentColor() "
  112. "getting transparent color even though opaque" << endl;
  113. }
  114. return m_transparentColor;
  115. }
  116. // public
  117. void kpSelectionTransparency::setTransparentColor (const kpColor &transparentColor)
  118. {
  119. m_transparentColor = transparentColor;
  120. }
  121. // public
  122. double kpSelectionTransparency::colorSimilarity () const
  123. {
  124. if (m_colorSimilarity < 0 ||
  125. m_colorSimilarity > kpColorSimilarityDialog::maximumColorSimilarity)
  126. {
  127. kdError () << "kpSelectionTransparency::colorSimilarity() invalid colorSimilarity" << endl;
  128. return 0;
  129. }
  130. return m_colorSimilarity;
  131. }
  132. // pubulic
  133. void kpSelectionTransparency::setColorSimilarity (double colorSimilarity)
  134. {
  135. m_colorSimilarity = colorSimilarity;
  136. m_processedColorSimilarity = kpColor::processSimilarity (colorSimilarity);
  137. }
  138. // public
  139. int kpSelectionTransparency::processedColorSimilarity () const
  140. {
  141. return m_processedColorSimilarity;
  142. }