File indexing completed on 2024-12-22 04:17:35

0001 /***************************************************************************
0002  *                                                                         *
0003  *   copyright : (C) 2012  Barth Netterfield                               *
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 #include "linedimensionstab.h"
0013 #include "plotitem.h"
0014 #include <QDebug>
0015 
0016 namespace Kst {
0017 
0018 LineDimensionsTab::LineDimensionsTab(ViewItem* viewItem, QWidget *parent)
0019   : DialogTab(parent), _viewItem(viewItem) {
0020   setupUi(this);
0021 
0022   connect(_lockPosToData, SIGNAL(clicked(bool)), this, SLOT(fillDimensions(bool)));
0023 }
0024 
0025 void LineDimensionsTab::fillDimensions(bool lock_pos_to_data) {
0026   if (lock_pos_to_data) {
0027     _p1X->setRange(-1E308, 1E308);
0028     _p2X->setRange(-1E308, 1E308);
0029     _p1Y->setRange(-1E308, 1E308);
0030     _p2Y->setRange(-1E308, 1E308);
0031     QPointF P1 = _viewItem->dataRelativeRect().topLeft();
0032     QPointF P2 = _viewItem->dataRelativeRect().bottomRight();
0033     _p1X->setValue(P1.x());
0034     _p1Y->setValue(P1.y());
0035     _p2X->setValue(P2.x());
0036     _p2Y->setValue(P2.y());
0037   } else {
0038     _p1X->setRange(0, 1);
0039     _p1Y->setRange(0, 1);
0040     _p2X->setRange(0, 1);
0041     _p2Y->setRange(0, 1);
0042     QRectF pr = _viewItem->parentRect();
0043     QPointF P1 = _viewItem->mapToParent(QPoint(_viewItem->rect().left(), _viewItem->rect().center().y()));
0044     QPointF P2 = _viewItem->mapToParent(QPoint(_viewItem->rect().right(), _viewItem->rect().center().y()));
0045     //qDebug() << pr << P1 << P2;
0046     _p1X->setValue((P1.x()-pr.left())/pr.width());
0047     _p2X->setValue((P2.x()-pr.left())/pr.width());
0048     _p1Y->setValue((P1.y()-pr.top())/pr.height());
0049     _p2Y->setValue((P2.y()-pr.top())/pr.height());
0050   }
0051 }
0052 
0053 void LineDimensionsTab::setupDimensions() {
0054 
0055   fillDimensions(_viewItem->dataPosLockable() && _viewItem->lockPosToData());
0056 
0057   _lockPosToData->setChecked(_viewItem->lockPosToData());
0058   if (_viewItem->dataPosLockable()) {
0059       _lockPosToData->show();
0060   } else {
0061       _lockPosToData->hide();
0062   }
0063 }
0064 
0065 
0066 void LineDimensionsTab::modified() {
0067   emit tabModified();
0068 }
0069 
0070 
0071 void LineDimensionsTab::clearTabValues() {
0072   _lockPosToData->setCheckState(Qt::PartiallyChecked);
0073 }
0074 
0075 
0076 void LineDimensionsTab::enableSingleEditOptions(bool enabled) {
0077   //_x->setEnabled(enabled);
0078   //_y->setEnabled(enabled);
0079 }
0080 
0081 
0082 bool LineDimensionsTab::lockPosToDataDirty() const {
0083   return _lockPosToData->checkState() != Qt::PartiallyChecked;
0084 }
0085 
0086 }