summaryrefslogtreecommitdiffstats
path: root/kolourpaint/tools/kptoolflip.cpp
blob: 146b639fa41774fe18143e0193f08d3c2b929fd7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213

/*
   Copyright (c) 2003,2004,2005 Clarence Dang <[email protected]>
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

   1. Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
   2. Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
   IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
   IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/


#include <kptoolflip.h>

#include <tqapplication.h>
#include <tqradiobutton.h>
#include <tqvbox.h>
#include <tqvbuttongroup.h>

#include <kdebug.h>
#include <klocale.h>

#include <kpdefs.h>
#include <kpdocument.h>
#include <kppixmapfx.h>
#include <kpselection.h>
#include <kptool.h>
#include <kpmainwindow.h>


/*
 * kpToolFlipCommand
 */

kpToolFlipCommand::kpToolFlipCommand (bool actOnSelection,
                                      bool horiz, bool vert,
                                      kpMainWindow *mainWindow)
    : kpCommand (mainWindow),
      m_actOnSelection (actOnSelection),
      m_horiz (horiz), m_vert (vert)
{
}

kpToolFlipCommand::~kpToolFlipCommand ()
{
}


// public virtual [base kpCommand]
TQString kpToolFlipCommand::name () const
{
    TQString opName;

    
#if 1
    opName = i18n ("Flip");
#else  // re-enable when giving full descriptions for all actions
    if (m_horiz && m_vert)
        opName = i18n ("Flip horizontally and vertically");
    else if (m_horiz)
        opName = i18n ("Flip horizontally");
    else if (m_vert)
        opName = i18n ("Flip vertically");
    else
    {
        kdError () << "kpToolFlipCommand::name() not asked to flip" << endl;
        return TQString::null;
    }
#endif


    if (m_actOnSelection)
        return i18n ("Selection: %1").arg (opName);
    else
        return opName;
}


// public virtual [base kpCommand]
int kpToolFlipCommand::size () const
{
    return 0;
}


// public virtual [base kpCommand]
void kpToolFlipCommand::execute ()
{
    flip ();
}

// public virtual [base kpCommand]
void kpToolFlipCommand::unexecute ()
{
    flip ();
}


// private
void kpToolFlipCommand::flip ()
{
    kpDocument *doc = document ();
    if (!doc)
        return;


    TQApplication::setOverrideCursor (Qt::waitCursor);

    
    if (m_actOnSelection)
    {
        doc->selection ()->flip (m_horiz, m_vert);
        if (m_mainWindow->tool ())
            m_mainWindow->tool ()->somethingBelowTheCursorChanged ();
    }
    else
    {
        TQPixmap newPixmap = kpPixmapFX::flip (*doc->pixmap (), m_horiz, m_vert);

        doc->setPixmap (newPixmap);
    }


    TQApplication::restoreOverrideCursor ();
}


/*
 * kpToolFlipDialog
 */

// private static
bool kpToolFlipDialog::s_lastIsVerticalFlip = true;


kpToolFlipDialog::kpToolFlipDialog (bool actOnSelection, TQWidget *parent)
    : KDialogBase (parent, 0/*name*/, true/*modal*/,
                   actOnSelection ? i18n ("Flip Selection") : i18n ("Flip Image"),
                   KDialogBase::Ok | KDialogBase::Cancel)
{
    TQVBox *vbox = makeVBoxMainWidget ();

    if (!vbox)
    {
        kdError () << "kpToolFlipDialog::kpToolFlipDialog() received NULL vbox" << endl;
    }
    else
    {
        TQVButtonGroup *buttonGroup = new TQVButtonGroup (i18n ("Direction"), vbox);

        // I'm sure vert flipping is much more common than horiz flipping so make it come first
        m_verticalFlipRadioButton = new TQRadioButton (i18n ("&Vertical (upside-down)"), buttonGroup);
        m_horizontalFlipRadioButton = new TQRadioButton (i18n ("&Horizontal"), buttonGroup);

        m_verticalFlipRadioButton->setChecked (s_lastIsVerticalFlip);
        m_horizontalFlipRadioButton->setChecked (!s_lastIsVerticalFlip);

        connect (m_verticalFlipRadioButton, TQT_SIGNAL (toggled (bool)),
                 this, TQT_SLOT (slotIsVerticalFlipChanged ()));
        connect (m_horizontalFlipRadioButton, TQT_SIGNAL (toggled (bool)),
                 this, TQT_SLOT (slotIsVerticalFlipChanged ()));
    }
}

kpToolFlipDialog::~kpToolFlipDialog ()
{
}


// public slot
void kpToolFlipDialog::slotIsVerticalFlipChanged ()
{
    s_lastIsVerticalFlip = m_verticalFlipRadioButton->isChecked ();
}


// public
bool kpToolFlipDialog::getHorizontalFlip () const
{
    return m_horizontalFlipRadioButton->isChecked ();
}

// public
bool kpToolFlipDialog::getVerticalFlip () const
{
    return m_verticalFlipRadioButton->isChecked ();
}

// public
bool kpToolFlipDialog::isNoOp () const
{
    return !getHorizontalFlip () && !getVerticalFlip ();
}


#include <kptoolflip.moc>