TDE graphics utilities
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

107 rindas
3.0KB

  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. #include <tqapplication.h>
  24. #include <tqpixmap.h>
  25. #include <tdelocale.h>
  26. #include <kpdefs.h>
  27. #include <kpdocument.h>
  28. #include <kpmainwindow.h>
  29. #include <kppixmapfx.h>
  30. #include <kpselection.h>
  31. #include <kptoolconverttograyscale.h>
  32. kpToolConvertToGrayscaleCommand::kpToolConvertToGrayscaleCommand (bool actOnSelection,
  33. kpMainWindow *mainWindow)
  34. : kpCommand (mainWindow),
  35. m_actOnSelection (actOnSelection),
  36. m_oldPixmapPtr (0)
  37. {
  38. }
  39. kpToolConvertToGrayscaleCommand::~kpToolConvertToGrayscaleCommand ()
  40. {
  41. delete m_oldPixmapPtr;
  42. }
  43. // public virtual [base kpCommand]
  44. TQString kpToolConvertToGrayscaleCommand::name () const
  45. {
  46. TQString opName = i18n ("Reduce to Grayscale");
  47. if (m_actOnSelection)
  48. return i18n ("Selection: %1").arg (opName);
  49. else
  50. return opName;
  51. }
  52. // public virtual [base kpCommand]
  53. int kpToolConvertToGrayscaleCommand::size () const
  54. {
  55. return kpPixmapFX::pixmapSize (m_oldPixmapPtr);
  56. }
  57. // public virtual [base kpCommand]
  58. void kpToolConvertToGrayscaleCommand::execute ()
  59. {
  60. kpDocument *doc = document ();
  61. if (!doc)
  62. return;
  63. TQApplication::setOverrideCursor (TQt::waitCursor);
  64. m_oldPixmapPtr = new TQPixmap ();
  65. *m_oldPixmapPtr = *doc->pixmap (m_actOnSelection);
  66. TQPixmap newPixmap = kpPixmapFX::convertToGrayscale (*doc->pixmap (m_actOnSelection));
  67. doc->setPixmap (m_actOnSelection, newPixmap);
  68. TQApplication::restoreOverrideCursor ();
  69. }
  70. // public virtual [base kpCommand]
  71. void kpToolConvertToGrayscaleCommand::unexecute ()
  72. {
  73. kpDocument *doc = document ();
  74. if (!doc)
  75. return;
  76. doc->setPixmap (m_actOnSelection, *m_oldPixmapPtr);
  77. delete m_oldPixmapPtr;
  78. m_oldPixmapPtr = 0;
  79. }