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
|
/*
* This file is part of Chalk
*
* Copyright (c) 2006 Cyrille Berger <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kis_perspective_grid_manager.h"
#include <tdeaction.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include "kis_image.h"
#include "kis_grid_drawer.h"
#include "kis_perspective_grid.h"
#include "kis_view.h"
KisPerspectiveGridManager::KisPerspectiveGridManager(KisView * parent)
: TQObject()
, m_toggleEdition(false)
, m_view(parent)
{
}
KisPerspectiveGridManager::~KisPerspectiveGridManager()
{
}
void KisPerspectiveGridManager::updateGUI()
{
KisImageSP image = m_view->canvasSubject()->currentImg();
if (image ) {
KisPerspectiveGrid* pGrid = image->perspectiveGrid();
m_toggleGrid->setEnabled( pGrid->hasSubGrids());
}
}
void KisPerspectiveGridManager::setup(TDEActionCollection * collection)
{
kdDebug() << "KisPerspectiveGridManager::setup(TDEActionCollection * collection)" << endl;
m_toggleGrid = new TDEToggleAction(i18n("Show Perspective Grid"), "", this, TQT_SLOT(toggleGrid()), collection, "view_toggle_perspective_grid");
m_toggleGrid->setCheckedState(KGuiItem(i18n("Hide Perspective Grid")));
m_toggleGrid->setChecked(false);
m_gridClear = new TDEAction(i18n("Clear Perspective Grid"), 0, "", this, TQT_SLOT(clearPerspectiveGrid()), collection, "view_clear_perspective_grid");
}
void KisPerspectiveGridManager::setGridVisible(bool t)
{
KisImageSP image = m_view->canvasSubject()->currentImg();
if (t && image ) {
KisPerspectiveGrid* pGrid = image->perspectiveGrid();
if( pGrid->hasSubGrids())
{
m_toggleGrid->setChecked(true);
}
} else {
m_toggleGrid->setChecked(false);
}
m_view->refreshKisCanvas();
}
void KisPerspectiveGridManager::toggleGrid()
{
KisImageSP image = m_view->canvasSubject()->currentImg();
if (image && m_toggleGrid->isChecked()) {
KisPerspectiveGrid* pGrid = image->perspectiveGrid();
if(!pGrid->hasSubGrids())
{
KMessageBox::error(0, i18n("Before displaying the perspective grid, you need to initialize it with the perspective grid tool"), i18n("No Perspective Grid to Display") );
m_toggleGrid->setChecked(false);
}
}
m_view->updateCanvas();
}
void KisPerspectiveGridManager::clearPerspectiveGrid()
{
KisImageSP image = m_view->canvasSubject()->currentImg();
if (image ) {
image->perspectiveGrid()->clearSubGrids();
m_view->updateCanvas();
m_toggleGrid->setChecked(false);
m_toggleGrid->setEnabled(false);
}
}
void KisPerspectiveGridManager::startEdition()
{
m_toggleEdition = true;
m_toggleGrid->setEnabled( false );
if( m_toggleGrid->isChecked() )
m_view->updateCanvas();
}
void KisPerspectiveGridManager::stopEdition()
{
m_toggleEdition = false;
m_toggleGrid->setEnabled( true );
if( m_toggleGrid->isChecked() )
m_view->updateCanvas();
}
void KisPerspectiveGridManager::drawGrid(TQRect wr, TQPainter *p, bool openGL )
{
KisImageSP image = m_view->canvasSubject()->currentImg();
if (image && m_toggleGrid->isChecked() && !m_toggleEdition) {
KisPerspectiveGrid* pGrid = image->perspectiveGrid();
GridDrawer *gridDrawer = 0;
if (openGL) {
gridDrawer = new OpenGLGridDrawer();
} else {
Q_ASSERT(p);
if (p) {
gridDrawer = new TQPainterGridDrawer(p);
}
}
Q_ASSERT(gridDrawer != 0);
for( TQValueList<KisSubPerspectiveGrid*>::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it)
{
gridDrawer->drawPerspectiveGrid(image, wr, *it );
}
delete gridDrawer;
}
}
#include "kis_perspective_grid_manager.moc"
|