chalk

kis_selected_transaction.cpp
1/*
2 * Copyright (c) 2002 Patrick Julien <freak@codepimps.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18#include "kis_types.h"
19#include "kis_global.h"
20#include "kis_selected_transaction.h"
21#include "kis_selection.h"
22
23KisSelectedTransaction::KisSelectedTransaction(const TQString& name, KisPaintDeviceSP device) :
24 KisTransaction(name, device),
25 m_device(device),
26 m_hadSelection(device->hasSelection())
27{
28 m_selTransaction = new KisTransaction(name, device->selection().data());
29 if(! m_hadSelection) {
30 m_device->deselect(); // let us not be the cause of select
31 }
32}
33
34KisSelectedTransaction::~KisSelectedTransaction()
35{
36 delete m_selTransaction;
37}
38
39void KisSelectedTransaction::execute()
40{
41 super::execute();
42 m_selTransaction->execute();
43 if(m_redoHasSelection)
44 m_device->selection();
45 else
46 m_device->deselect();
47 m_device->emitSelectionChanged();
48}
49
50void KisSelectedTransaction::unexecute()
51{
52 m_redoHasSelection = m_device->hasSelection();
53
54 super::unexecute();
55 m_selTransaction->unexecute();
56 if(m_hadSelection)
57 m_device->selection();
58 else
59 m_device->deselect();
60 m_device->emitSelectionChanged();
61}
62
63void KisSelectedTransaction::unexecuteNoUpdate()
64{
65 m_redoHasSelection = m_device->hasSelection();
66
67 super::unexecuteNoUpdate();
68 m_selTransaction->unexecuteNoUpdate();
69 if(m_hadSelection)
70 m_device->selection();
71 else
72 m_device->deselect();
73}