File indexing completed on 2024-12-22 04:17:26
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2008 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "circleitemdialog.h" 0014 0015 #include "circledimensionstab.h" 0016 #include "circleitem.h" 0017 #include "dialogpage.h" 0018 #include "application.h" 0019 #include "objectstore.h" 0020 #include "mainwindow.h" 0021 #include "document.h" 0022 0023 namespace Kst { 0024 0025 CircleItemDialog::CircleItemDialog(CircleItem *item, QWidget *parent) 0026 : ViewItemDialog(item, parent), _viewItem(item) { 0027 0028 _circleDimensionsTab = new CircleDimensionsTab(item, this); 0029 0030 DialogPage *circleDimensionsPage = new DialogPage(this); 0031 circleDimensionsPage->setPageTitle(tr("Size/Position")); 0032 circleDimensionsPage->addDialogTab(_circleDimensionsTab); 0033 addDialogPage(circleDimensionsPage); 0034 selectDialogPage(circleDimensionsPage); 0035 0036 connect(_circleDimensionsTab, SIGNAL(apply()), this, SLOT(dimensionsChanged())); 0037 0038 setupDimensions(); 0039 0040 connect(_circleDimensionsTab, SIGNAL(tabModified()), this, SLOT(modified())); 0041 0042 } 0043 0044 0045 void CircleItemDialog::setupDimensions() { 0046 _circleDimensionsTab->enableSingleEditOptions(true); 0047 _circleDimensionsTab->setupDimensions(); 0048 } 0049 0050 void CircleItemDialog::saveDimensions(ViewItem *item) { 0051 Q_ASSERT(item); 0052 0053 if (editMode() == Multiple) { // saving dimensions not supported for edit multiple mode 0054 return; 0055 } 0056 0057 if (_circleDimensionsTab->lockPosToData() && item->dataPosLockable()) { 0058 QRectF dr; 0059 dr.setWidth(2*_circleDimensionsTab->radius()); 0060 dr.setHeight(2*_circleDimensionsTab->radius()); 0061 dr.moveCenter(QPointF(_circleDimensionsTab->x(), _circleDimensionsTab->y())); 0062 0063 item->setDataRelativeRect(dr); 0064 bool lockPosToData = _circleDimensionsTab->lockPosToDataDirty() ? _circleDimensionsTab->lockPosToData() : item->lockPosToData(); 0065 item->setLockPosToData(lockPosToData); 0066 0067 item->applyDataLockedDimensions(); 0068 } else { 0069 0070 QRectF parentRect = item->parentRect(); 0071 qreal parentWidth = parentRect.width(); 0072 qreal parentHeight = parentRect.height(); 0073 qreal parentX = parentRect.x(); 0074 qreal parentY = parentRect.y(); 0075 0076 qreal relativeRadius = _circleDimensionsTab->radiusDirty() ? _circleDimensionsTab->radius() :item->relativeWidth()*0.5; 0077 bool lockPosToData = _circleDimensionsTab->lockPosToDataDirty() ? _circleDimensionsTab->lockPosToData() : item->lockPosToData(); 0078 0079 qreal radius = relativeRadius * parentWidth; 0080 item->setLockPosToData(lockPosToData); 0081 0082 item->setPos(parentX + _circleDimensionsTab->x()*parentWidth, parentY + _circleDimensionsTab->y()*parentHeight); 0083 item->setViewRect(-radius, -radius, radius*2.0, radius*2.0); 0084 0085 QTransform transform; 0086 0087 item->setTransform(transform); 0088 item->updateRelativeSize(); 0089 } 0090 } 0091 }