chalk

kis_grid_manager.cpp
1/*
2 * This file is part of Chalk
3 *
4 * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 */
20
21#include "kis_grid_manager.h"
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#ifdef HAVE_GL
28#include <tqgl.h>
29#endif
30
31#include <tqradiobutton.h>
32
33#include <tdeaction.h>
34#include <kdialogbase.h>
35#include <tdelocale.h>
36
37
38#include "kis_config.h"
39#include "kis_grid_drawer.h"
40#include "kis_image.h"
41#include "kis_view.h"
42
43KisGridManager::KisGridManager(KisView * parent)
44 : TQObject(parent), m_view(parent)
45{
46
47}
48
49KisGridManager::~KisGridManager()
50{
51
52}
53
54void KisGridManager::setup(TDEActionCollection * collection)
55{
56 m_toggleGrid = new TDEToggleAction(i18n("Show Grid"), "", this, TQ_SLOT(toggleGrid()), collection, "view_toggle_grid");
57 m_toggleGrid->setCheckedState(KGuiItem(i18n("Hide Grid")));
58 m_toggleGrid->setChecked(false);
59
60 // Fast grid config
61 m_gridFastConfig1x1 = new TDEAction(i18n("1x1"), 0, "", this, TQ_SLOT(fastConfig1x1()), collection, "view_fast_grid_1x1");
62 m_gridFastConfig2x2 = new TDEAction(i18n("2x2"), 0, "", this, TQ_SLOT(fastConfig2x2()), collection, "view_fast_grid_2x2");
63 m_gridFastConfig5x5 = new TDEAction(i18n("5x5"), 0, "", this, TQ_SLOT(fastConfig5x5()), collection, "view_fast_grid_5x5");
64 m_gridFastConfig10x10 = new TDEAction(i18n("10x10"), 0, "", this, TQ_SLOT(fastConfig10x10()), collection, "view_fast_grid_10x10");
65 m_gridFastConfig20x20 = new TDEAction(i18n("20x20"), 0, "", this, TQ_SLOT(fastConfig20x20()), collection, "view_fast_grid_20x20");
66 m_gridFastConfig40x40 = new TDEAction(i18n("40x40"), 0, "", this, TQ_SLOT(fastConfig40x40()), collection, "view_fast_grid_40x40");
67}
68
69void KisGridManager::updateGUI()
70{
71
72}
73
74void KisGridManager::toggleGrid()
75{
76 m_view->updateCanvas();
77}
78
79void KisGridManager::fastConfig1x1()
80{
81 KisConfig cfg;
82 cfg.setGridHSpacing(1);
83 cfg.setGridVSpacing(1);
84 m_view->updateCanvas();
85}
86
87void KisGridManager::fastConfig2x2()
88{
89 KisConfig cfg;
90 cfg.setGridHSpacing(2);
91 cfg.setGridVSpacing(2);
92 m_view->updateCanvas();
93}
94
95void KisGridManager::fastConfig5x5()
96{
97 KisConfig cfg;
98 cfg.setGridHSpacing(5);
99 cfg.setGridVSpacing(5);
100 m_view->updateCanvas();
101}
102
103void KisGridManager::fastConfig10x10()
104{
105 KisConfig cfg;
106 cfg.setGridHSpacing(10);
107 cfg.setGridVSpacing(10);
108 m_view->updateCanvas();
109}
110
111void KisGridManager::fastConfig20x20()
112{
113 KisConfig cfg;
114 cfg.setGridHSpacing(20);
115 cfg.setGridVSpacing(20);
116 m_view->updateCanvas();
117}
118
119void KisGridManager::fastConfig40x40()
120{
121 KisConfig cfg;
122 cfg.setGridHSpacing(40);
123 cfg.setGridVSpacing(40);
124 m_view->updateCanvas();
125}
126
127void KisGridManager::drawGrid(TQRect wr, TQPainter *p, bool openGL)
128{
129 KisImageSP image = m_view->canvasSubject()->currentImg();
130
131 if (image) {
132 if (m_toggleGrid->isChecked())
133 {
134 GridDrawer *gridDrawer = 0;
135
136 if (openGL) {
137 gridDrawer = new OpenGLGridDrawer();
138 } else {
139 Q_ASSERT(p);
140
141 if (p) {
142 gridDrawer = new TQPainterGridDrawer(p);
143 }
144 }
145
146 Q_ASSERT(gridDrawer != 0);
147
148 if (gridDrawer) {
149 gridDrawer->drawGrid(image, wr);
150 delete gridDrawer;
151 }
152 }
153 }
154}
155
156#include "kis_grid_manager.moc"