00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kis_grid_manager.h"
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026
00027 #ifdef HAVE_GL
00028 #include <qgl.h>
00029 #endif
00030
00031 #include <qradiobutton.h>
00032
00033 #include <kaction.h>
00034 #include <kdialogbase.h>
00035 #include <klocale.h>
00036
00037
00038 #include "kis_config.h"
00039 #include "kis_grid_drawer.h"
00040 #include "kis_image.h"
00041 #include "kis_view.h"
00042
00043 KisGridManager::KisGridManager(KisView * parent)
00044 : QObject(parent), m_view(parent)
00045 {
00046
00047 }
00048
00049 KisGridManager::~KisGridManager()
00050 {
00051
00052 }
00053
00054 void KisGridManager::setup(KActionCollection * collection)
00055 {
00056 m_toggleGrid = new KToggleAction(i18n("Show Grid"), "", this, SLOT(toggleGrid()), collection, "view_toggle_grid");
00057 m_toggleGrid->setCheckedState(KGuiItem(i18n("Hide Grid")));
00058 m_toggleGrid->setChecked(false);
00059
00060
00061 m_gridFastConfig1x1 = new KAction(i18n("1x1"), 0, "", this, SLOT(fastConfig1x1()), collection, "view_fast_grid_1x1");
00062 m_gridFastConfig2x2 = new KAction(i18n("2x2"), 0, "", this, SLOT(fastConfig2x2()), collection, "view_fast_grid_2x2");
00063 m_gridFastConfig5x5 = new KAction(i18n("5x5"), 0, "", this, SLOT(fastConfig5x5()), collection, "view_fast_grid_5x5");
00064 m_gridFastConfig10x10 = new KAction(i18n("10x10"), 0, "", this, SLOT(fastConfig10x10()), collection, "view_fast_grid_10x10");
00065 m_gridFastConfig20x20 = new KAction(i18n("20x20"), 0, "", this, SLOT(fastConfig20x20()), collection, "view_fast_grid_20x20");
00066 m_gridFastConfig40x40 = new KAction(i18n("40x40"), 0, "", this, SLOT(fastConfig40x40()), collection, "view_fast_grid_40x40");
00067 }
00068
00069 void KisGridManager::updateGUI()
00070 {
00071
00072 }
00073
00074 void KisGridManager::toggleGrid()
00075 {
00076 m_view->updateCanvas();
00077 }
00078
00079 void KisGridManager::fastConfig1x1()
00080 {
00081 KisConfig cfg;
00082 cfg.setGridHSpacing(1);
00083 cfg.setGridVSpacing(1);
00084 m_view->updateCanvas();
00085 }
00086
00087 void KisGridManager::fastConfig2x2()
00088 {
00089 KisConfig cfg;
00090 cfg.setGridHSpacing(2);
00091 cfg.setGridVSpacing(2);
00092 m_view->updateCanvas();
00093 }
00094
00095 void KisGridManager::fastConfig5x5()
00096 {
00097 KisConfig cfg;
00098 cfg.setGridHSpacing(5);
00099 cfg.setGridVSpacing(5);
00100 m_view->updateCanvas();
00101 }
00102
00103 void KisGridManager::fastConfig10x10()
00104 {
00105 KisConfig cfg;
00106 cfg.setGridHSpacing(10);
00107 cfg.setGridVSpacing(10);
00108 m_view->updateCanvas();
00109 }
00110
00111 void KisGridManager::fastConfig20x20()
00112 {
00113 KisConfig cfg;
00114 cfg.setGridHSpacing(20);
00115 cfg.setGridVSpacing(20);
00116 m_view->updateCanvas();
00117 }
00118
00119 void KisGridManager::fastConfig40x40()
00120 {
00121 KisConfig cfg;
00122 cfg.setGridHSpacing(40);
00123 cfg.setGridVSpacing(40);
00124 m_view->updateCanvas();
00125 }
00126
00127 void KisGridManager::drawGrid(QRect wr, QPainter *p, bool openGL)
00128 {
00129 KisImageSP image = m_view->canvasSubject()->currentImg();
00130
00131 if (image) {
00132 if (m_toggleGrid->isChecked())
00133 {
00134 GridDrawer *gridDrawer = 0;
00135
00136 if (openGL) {
00137 gridDrawer = new OpenGLGridDrawer();
00138 } else {
00139 Q_ASSERT(p);
00140
00141 if (p) {
00142 gridDrawer = new QPainterGridDrawer(p);
00143 }
00144 }
00145
00146 Q_ASSERT(gridDrawer != 0);
00147
00148 if (gridDrawer) {
00149 gridDrawer->drawGrid(image, wr);
00150 delete gridDrawer;
00151 }
00152 }
00153 }
00154 }
00155
00156 #include "kis_grid_manager.moc"