libs/flake

SnapGuideConfigWidget.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "SnapGuideConfigWidget.h"
00021 #include "KoSnapGuide.h"
00022 #include "KoSnapStrategy.h"
00023 
00024 SnapGuideConfigWidget::SnapGuideConfigWidget(KoSnapGuide * snapGuide, QWidget * parent)
00025         : QWidget(parent), m_snapGuide(snapGuide)
00026 {
00027     widget.setupUi(this);
00028 
00029     widget.orthogonalSnapGuide->setIcon(KIcon("snap-orto"));
00030     widget.nodeSnapGuide->setIcon(KIcon("snap-node"));
00031     widget.extensionSnapGuide->setIcon(KIcon("snap-extension"));
00032     widget.intersectionSnapGuide->setIcon(KIcon("snap-intersection"));
00033     widget.boundingBoxSnapGuide->setIcon(KIcon("snap-boundingbox"));
00034     widget.lineGuideSnapGuide->setIcon(KIcon("snap-guideline"));
00035 
00036     updateControls();
00037 
00038     connect(widget.useSnapGuides, SIGNAL(stateChanged(int)), this, SLOT(snappingEnabled(int)));
00039     connect(widget.orthogonalSnapGuide, SIGNAL(stateChanged(int)), this, SLOT(strategyChanged()));
00040     connect(widget.nodeSnapGuide, SIGNAL(stateChanged(int)), this, SLOT(strategyChanged()));
00041     connect(widget.extensionSnapGuide, SIGNAL(stateChanged(int)), this, SLOT(strategyChanged()));
00042     connect(widget.intersectionSnapGuide, SIGNAL(stateChanged(int)), this, SLOT(strategyChanged()));
00043     connect(widget.boundingBoxSnapGuide, SIGNAL(stateChanged(int)), this, SLOT(strategyChanged()));
00044     connect(widget.lineGuideSnapGuide, SIGNAL(stateChanged(int)), this, SLOT(strategyChanged()));
00045     connect(widget.snapDistance, SIGNAL(valueChanged(int)), this, SLOT(distanceChanged(int)));
00046 
00047     widget.useSnapGuides->setCheckState(snapGuide->isSnapping() ? Qt::Checked : Qt::Unchecked);
00048 }
00049 
00050 SnapGuideConfigWidget::~SnapGuideConfigWidget()
00051 {
00052 }
00053 
00054 void SnapGuideConfigWidget::snappingEnabled(int state)
00055 {
00056     widget.orthogonalSnapGuide->setEnabled(state == Qt::Checked);
00057     widget.nodeSnapGuide->setEnabled(state == Qt::Checked);
00058     widget.extensionSnapGuide->setEnabled(state == Qt::Checked);
00059     widget.intersectionSnapGuide->setEnabled(state == Qt::Checked);
00060     widget.boundingBoxSnapGuide->setEnabled(state == Qt::Checked);
00061     widget.lineGuideSnapGuide->setEnabled(state == Qt::Checked);
00062     widget.snapDistance->setEnabled(state == Qt::Checked);
00063 
00064     m_snapGuide->enableSnapping(state == Qt::Checked);
00065 }
00066 
00067 void SnapGuideConfigWidget::strategyChanged()
00068 {
00069     int strategies = 0;
00070     if (widget.orthogonalSnapGuide->checkState() == Qt::Checked)
00071         strategies |= KoSnapStrategy::Orthogonal;
00072     if (widget.nodeSnapGuide->checkState() == Qt::Checked)
00073         strategies |= KoSnapStrategy::Node;
00074     if (widget.extensionSnapGuide->checkState() == Qt::Checked)
00075         strategies |= KoSnapStrategy::Extension;
00076     if (widget.intersectionSnapGuide->checkState() == Qt::Checked)
00077         strategies |= KoSnapStrategy::Intersection;
00078     if (widget.boundingBoxSnapGuide->checkState() == Qt::Checked)
00079         strategies |= KoSnapStrategy::BoundingBox;
00080     if (widget.lineGuideSnapGuide->checkState() == Qt::Checked)
00081         strategies |= KoSnapStrategy::GuideLine;
00082 
00083     m_snapGuide->enableSnapStrategies(strategies);
00084 }
00085 
00086 void SnapGuideConfigWidget::distanceChanged(int distance)
00087 {
00088     m_snapGuide->setSnapDistance(distance);
00089 }
00090 
00091 void SnapGuideConfigWidget::updateControls()
00092 {
00093     if (m_snapGuide->enabledSnapStrategies() & KoSnapStrategy::Orthogonal)
00094         widget.orthogonalSnapGuide->setCheckState(Qt::Checked);
00095     else
00096         widget.orthogonalSnapGuide->setCheckState(Qt::Unchecked);
00097     if (m_snapGuide->enabledSnapStrategies() & KoSnapStrategy::Node)
00098         widget.nodeSnapGuide->setCheckState(Qt::Checked);
00099     else
00100         widget.nodeSnapGuide->setCheckState(Qt::Unchecked);
00101     if (m_snapGuide->enabledSnapStrategies() & KoSnapStrategy::Extension)
00102         widget.extensionSnapGuide->setCheckState(Qt::Checked);
00103     else
00104         widget.extensionSnapGuide->setCheckState(Qt::Unchecked);
00105     if (m_snapGuide->enabledSnapStrategies() & KoSnapStrategy::Intersection)
00106         widget.intersectionSnapGuide->setCheckState(Qt::Checked);
00107     else
00108         widget.intersectionSnapGuide->setCheckState(Qt::Unchecked);
00109     if (m_snapGuide->enabledSnapStrategies() & KoSnapStrategy::BoundingBox)
00110         widget.boundingBoxSnapGuide->setCheckState(Qt::Checked);
00111     else
00112         widget.boundingBoxSnapGuide->setCheckState(Qt::Unchecked);
00113     if (m_snapGuide->enabledSnapStrategies() & KoSnapStrategy::GuideLine)
00114         widget.lineGuideSnapGuide->setCheckState(Qt::Checked);
00115     else
00116         widget.lineGuideSnapGuide->setCheckState(Qt::Unchecked);
00117 
00118     widget.snapDistance->setValue(m_snapGuide->snapDistance());
00119 }
00120 
00121 void SnapGuideConfigWidget::showEvent(QShowEvent * event)
00122 {
00123     Q_UNUSED(event);
00124     updateControls();
00125 }
00126 
00127 #include "SnapGuideConfigWidget.moc"