summaryrefslogtreecommitdiffstats
path: root/krita/ui/kis_perspective_grid_manager.cpp
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-01-20 01:29:50 +0000
commit8362bf63dea22bbf6736609b0f49c152f975eb63 (patch)
tree0eea3928e39e50fae91d4e68b21b1e6cbae25604 /krita/ui/kis_perspective_grid_manager.cpp
downloadkoffice-8362bf63dea22bbf6736609b0f49c152f975eb63.tar.gz
koffice-8362bf63dea22bbf6736609b0f49c152f975eb63.zip
Added old abandoned KDE3 version of koffice
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1077364 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krita/ui/kis_perspective_grid_manager.cpp')
-rw-r--r--krita/ui/kis_perspective_grid_manager.cpp159
1 files changed, 159 insertions, 0 deletions
diff --git a/krita/ui/kis_perspective_grid_manager.cpp b/krita/ui/kis_perspective_grid_manager.cpp
new file mode 100644
index 00000000..13c5cb13
--- /dev/null
+++ b/krita/ui/kis_perspective_grid_manager.cpp
@@ -0,0 +1,159 @@
+/*
+ * This file is part of Krita
+ *
+ * Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
+ *
+ * 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 <kaction.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include "kis_image.h"
+#include "kis_grid_drawer.h"
+#include "kis_perspective_grid.h"
+#include "kis_view.h"
+
+KisPerspectiveGridManager::KisPerspectiveGridManager(KisView * parent)
+ : QObject()
+ , 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(KActionCollection * collection)
+{
+ kdDebug() << "KisPerspectiveGridManager::setup(KActionCollection * collection)" << endl;
+ m_toggleGrid = new KToggleAction(i18n("Show Perspective Grid"), "", this, SLOT(toggleGrid()), collection, "view_toggle_perspective_grid");
+ m_toggleGrid->setCheckedState(KGuiItem(i18n("Hide Perspective Grid")));
+ m_toggleGrid->setChecked(false);
+ m_gridClear = new KAction(i18n("Clear Perspective Grid"), 0, "", this, 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(QRect wr, QPainter *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 QPainterGridDrawer(p);
+ }
+ }
+
+ Q_ASSERT(gridDrawer != 0);
+
+ for( QValueList<KisSubPerspectiveGrid*>::const_iterator it = pGrid->begin(); it != pGrid->end(); ++it)
+ {
+ gridDrawer->drawPerspectiveGrid(image, wr, *it );
+ }
+ delete gridDrawer;
+ }
+}
+
+
+#include "kis_perspective_grid_manager.moc"