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.

kptoolflip.cpp 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 <kptoolflip.h>
  24. #include <tqapplication.h>
  25. #include <tqradiobutton.h>
  26. #include <tqvbox.h>
  27. #include <tqvbuttongroup.h>
  28. #include <kdebug.h>
  29. #include <tdelocale.h>
  30. #include <kpdefs.h>
  31. #include <kpdocument.h>
  32. #include <kppixmapfx.h>
  33. #include <kpselection.h>
  34. #include <kptool.h>
  35. #include <kpmainwindow.h>
  36. /*
  37. * kpToolFlipCommand
  38. */
  39. kpToolFlipCommand::kpToolFlipCommand (bool actOnSelection,
  40. bool horiz, bool vert,
  41. kpMainWindow *mainWindow)
  42. : kpCommand (mainWindow),
  43. m_actOnSelection (actOnSelection),
  44. m_horiz (horiz), m_vert (vert)
  45. {
  46. }
  47. kpToolFlipCommand::~kpToolFlipCommand ()
  48. {
  49. }
  50. // public virtual [base kpCommand]
  51. TQString kpToolFlipCommand::name () const
  52. {
  53. TQString opName;
  54. #if 1
  55. opName = i18n ("Flip");
  56. #else // re-enable when giving full descriptions for all actions
  57. if (m_horiz && m_vert)
  58. opName = i18n ("Flip horizontally and vertically");
  59. else if (m_horiz)
  60. opName = i18n ("Flip horizontally");
  61. else if (m_vert)
  62. opName = i18n ("Flip vertically");
  63. else
  64. {
  65. kdError () << "kpToolFlipCommand::name() not asked to flip" << endl;
  66. return TQString();
  67. }
  68. #endif
  69. if (m_actOnSelection)
  70. return i18n ("Selection: %1").arg (opName);
  71. else
  72. return opName;
  73. }
  74. // public virtual [base kpCommand]
  75. int kpToolFlipCommand::size () const
  76. {
  77. return 0;
  78. }
  79. // public virtual [base kpCommand]
  80. void kpToolFlipCommand::execute ()
  81. {
  82. flip ();
  83. }
  84. // public virtual [base kpCommand]
  85. void kpToolFlipCommand::unexecute ()
  86. {
  87. flip ();
  88. }
  89. // private
  90. void kpToolFlipCommand::flip ()
  91. {
  92. kpDocument *doc = document ();
  93. if (!doc)
  94. return;
  95. TQApplication::setOverrideCursor (TQt::waitCursor);
  96. if (m_actOnSelection)
  97. {
  98. doc->selection ()->flip (m_horiz, m_vert);
  99. if (m_mainWindow->tool ())
  100. m_mainWindow->tool ()->somethingBelowTheCursorChanged ();
  101. }
  102. else
  103. {
  104. TQPixmap newPixmap = kpPixmapFX::flip (*doc->pixmap (), m_horiz, m_vert);
  105. doc->setPixmap (newPixmap);
  106. }
  107. TQApplication::restoreOverrideCursor ();
  108. }
  109. /*
  110. * kpToolFlipDialog
  111. */
  112. // private static
  113. bool kpToolFlipDialog::s_lastIsVerticalFlip = true;
  114. kpToolFlipDialog::kpToolFlipDialog (bool actOnSelection, TQWidget *parent)
  115. : KDialogBase (parent, 0/*name*/, true/*modal*/,
  116. actOnSelection ? i18n ("Flip Selection") : i18n ("Flip Image"),
  117. KDialogBase::Ok | KDialogBase::Cancel)
  118. {
  119. TQVBox *vbox = makeVBoxMainWidget ();
  120. if (!vbox)
  121. {
  122. kdError () << "kpToolFlipDialog::kpToolFlipDialog() received NULL vbox" << endl;
  123. }
  124. else
  125. {
  126. TQVButtonGroup *buttonGroup = new TQVButtonGroup (i18n ("Direction"), vbox);
  127. // I'm sure vert flipping is much more common than horiz flipping so make it come first
  128. m_verticalFlipRadioButton = new TQRadioButton (i18n ("&Vertical (upside-down)"), buttonGroup);
  129. m_horizontalFlipRadioButton = new TQRadioButton (i18n ("&Horizontal"), buttonGroup);
  130. m_verticalFlipRadioButton->setChecked (s_lastIsVerticalFlip);
  131. m_horizontalFlipRadioButton->setChecked (!s_lastIsVerticalFlip);
  132. connect (m_verticalFlipRadioButton, TQT_SIGNAL (toggled (bool)),
  133. this, TQT_SLOT (slotIsVerticalFlipChanged ()));
  134. connect (m_horizontalFlipRadioButton, TQT_SIGNAL (toggled (bool)),
  135. this, TQT_SLOT (slotIsVerticalFlipChanged ()));
  136. }
  137. }
  138. kpToolFlipDialog::~kpToolFlipDialog ()
  139. {
  140. }
  141. // public slot
  142. void kpToolFlipDialog::slotIsVerticalFlipChanged ()
  143. {
  144. s_lastIsVerticalFlip = m_verticalFlipRadioButton->isChecked ();
  145. }
  146. // public
  147. bool kpToolFlipDialog::getHorizontalFlip () const
  148. {
  149. return m_horizontalFlipRadioButton->isChecked ();
  150. }
  151. // public
  152. bool kpToolFlipDialog::getVerticalFlip () const
  153. {
  154. return m_verticalFlipRadioButton->isChecked ();
  155. }
  156. // public
  157. bool kpToolFlipDialog::isNoOp () const
  158. {
  159. return !getHorizontalFlip () && !getVerticalFlip ();
  160. }
  161. #include <kptoolflip.moc>