Warning, file /office/calligra/libs/flake/SnapGuideConfigWidget.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Library General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2 of the License, or (at your option) any later version. 0008 * 0009 * This library is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 * Library General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU Library General Public License 0015 * along with this library; see the file COPYING.LIB. If not, write to 0016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #include "SnapGuideConfigWidget.h" 0021 #include "KoSnapGuide.h" 0022 0023 #include <KoIcon.h> 0024 0025 SnapGuideConfigWidget::SnapGuideConfigWidget(KoSnapGuide * snapGuide, QWidget * parent) 0026 : QWidget(parent), m_snapGuide(snapGuide) 0027 { 0028 widget.setupUi(this); 0029 0030 widget.orthogonalSnapGuide->setIcon(koIcon("snap-orthogonal")); 0031 widget.nodeSnapGuide->setIcon(koIcon("snap-node")); 0032 widget.extensionSnapGuide->setIcon(koIcon("snap-extension")); 0033 widget.intersectionSnapGuide->setIcon(koIcon("snap-intersection")); 0034 widget.boundingBoxSnapGuide->setIcon(koIcon("snap-bounding-box")); 0035 widget.lineGuideSnapGuide->setIcon(koIcon("snap-guideline")); 0036 0037 updateControls(); 0038 0039 connect(widget.useSnapGuides, SIGNAL(toggled(bool)), this, SLOT(snappingEnabled(bool))); 0040 connect(widget.orthogonalSnapGuide, SIGNAL(toggled(bool)), this, SLOT(strategyChanged())); 0041 connect(widget.nodeSnapGuide, SIGNAL(toggled(bool)), this, SLOT(strategyChanged())); 0042 connect(widget.extensionSnapGuide, SIGNAL(toggled(bool)), this, SLOT(strategyChanged())); 0043 connect(widget.intersectionSnapGuide, SIGNAL(toggled(bool)), this, SLOT(strategyChanged())); 0044 connect(widget.boundingBoxSnapGuide, SIGNAL(toggled(bool)), this, SLOT(strategyChanged())); 0045 connect(widget.lineGuideSnapGuide, SIGNAL(toggled(bool)), this, SLOT(strategyChanged())); 0046 connect(widget.snapDistance, SIGNAL(valueChanged(int)), this, SLOT(distanceChanged(int))); 0047 0048 widget.useSnapGuides->setChecked(snapGuide->isSnapping()); 0049 } 0050 0051 SnapGuideConfigWidget::~SnapGuideConfigWidget() 0052 { 0053 } 0054 0055 void SnapGuideConfigWidget::snappingEnabled(bool isEnabled) 0056 { 0057 widget.orthogonalSnapGuide->setEnabled(isEnabled); 0058 widget.nodeSnapGuide->setEnabled(isEnabled); 0059 widget.extensionSnapGuide->setEnabled(isEnabled); 0060 widget.intersectionSnapGuide->setEnabled(isEnabled); 0061 widget.boundingBoxSnapGuide->setEnabled(isEnabled); 0062 widget.lineGuideSnapGuide->setEnabled(isEnabled); 0063 widget.snapDistance->setEnabled(isEnabled); 0064 0065 m_snapGuide->enableSnapping(isEnabled); 0066 } 0067 0068 void SnapGuideConfigWidget::strategyChanged() 0069 { 0070 KoSnapGuide::Strategies strategies; 0071 if (widget.orthogonalSnapGuide->isChecked()) 0072 strategies |= KoSnapGuide::OrthogonalSnapping; 0073 if (widget.nodeSnapGuide->isChecked()) 0074 strategies |= KoSnapGuide::NodeSnapping; 0075 if (widget.extensionSnapGuide->isChecked()) 0076 strategies |= KoSnapGuide::ExtensionSnapping; 0077 if (widget.intersectionSnapGuide->isChecked()) 0078 strategies |= KoSnapGuide::IntersectionSnapping; 0079 if (widget.boundingBoxSnapGuide->isChecked()) 0080 strategies |= KoSnapGuide::BoundingBoxSnapping; 0081 if (widget.lineGuideSnapGuide->isChecked()) 0082 strategies |= KoSnapGuide::GuideLineSnapping; 0083 0084 m_snapGuide->enableSnapStrategies(strategies); 0085 } 0086 0087 void SnapGuideConfigWidget::distanceChanged(int distance) 0088 { 0089 m_snapGuide->setSnapDistance(distance); 0090 } 0091 0092 void SnapGuideConfigWidget::updateControls() 0093 { 0094 const KoSnapGuide::Strategies enabledSnapStrategies = m_snapGuide->enabledSnapStrategies(); 0095 0096 widget.orthogonalSnapGuide->setChecked(enabledSnapStrategies & KoSnapGuide::OrthogonalSnapping); 0097 widget.nodeSnapGuide->setChecked(enabledSnapStrategies & KoSnapGuide::NodeSnapping); 0098 widget.extensionSnapGuide->setChecked(enabledSnapStrategies & KoSnapGuide::ExtensionSnapping); 0099 widget.intersectionSnapGuide->setChecked(enabledSnapStrategies & KoSnapGuide::IntersectionSnapping); 0100 widget.boundingBoxSnapGuide->setChecked(enabledSnapStrategies & KoSnapGuide::BoundingBoxSnapping); 0101 widget.lineGuideSnapGuide->setChecked(enabledSnapStrategies & KoSnapGuide::GuideLineSnapping); 0102 0103 widget.snapDistance->setValue(m_snapGuide->snapDistance()); 0104 } 0105 0106 void SnapGuideConfigWidget::showEvent(QShowEvent * event) 0107 { 0108 Q_UNUSED(event); 0109 updateControls(); 0110 }