diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-26 00:41:16 +0000 |
commit | 698569f8428ca088f764d704034a1330517b98c0 (patch) | |
tree | bf45be6946ebbbee9cce5a5bcf838f4c952d87e6 /chalk/ui/kis_perspective_grid_manager.cpp | |
parent | 2785103a6bd4de55bd26d79e34d0fdd4b329a73a (diff) | |
download | koffice-698569f8428ca088f764d704034a1330517b98c0.tar.gz koffice-698569f8428ca088f764d704034a1330517b98c0.zip |
Finish rebranding of Krita as Chalk
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/koffice@1238363 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'chalk/ui/kis_perspective_grid_manager.cpp')
-rw-r--r-- | chalk/ui/kis_perspective_grid_manager.cpp | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/chalk/ui/kis_perspective_grid_manager.cpp b/chalk/ui/kis_perspective_grid_manager.cpp new file mode 100644 index 00000000..c454af80 --- /dev/null +++ b/chalk/ui/kis_perspective_grid_manager.cpp @@ -0,0 +1,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 <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 * tqparent) + : TQObject() + , m_toggleEdition(false) + , m_view(tqparent) +{ + +} + + +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, TQT_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, 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" |