[Kst] branches/work/kst/portto4/kst/src/libkstapp

Barth Netterfield netterfield at astro.utoronto.ca
Tue Dec 9 18:42:43 CET 2008


SVN commit 894967 by netterfield:

Add a dimensions tab to view object dialogs, to allow
location, size, and orientation of view objects to be set manually.

Add defaults to changedatasamplesdialog.



 M  +26 -10    changedatasampledialog.cpp  
 M  +1 -1      changedatasampledialog.h  
 A             dimensionstab.cpp   [License: GPL (v2+)]
 A             dimensionstab.h   [License: GPL (v2+)]
 A             dimensionstab.ui  
 M  +3 -0      libkstapp.pro  
 M  +0 -1      view.cpp  
 M  +54 -18    viewitem.cpp  
 M  +10 -2     viewitem.h  
 M  +74 -0     viewitemdialog.cpp  
 M  +4 -1      viewitemdialog.h  


--- branches/work/kst/portto4/kst/src/libkstapp/changedatasampledialog.cpp #894966:894967
@@ -16,11 +16,12 @@
 #include "objectstore.h"
 #include "document.h"
 #include "mainwindow.h"
+#include "dialogdefaults.h"
 
 namespace Kst {
 
 ChangeDataSampleDialog::ChangeDataSampleDialog(QWidget *parent)
-  : QDialog(parent), _modified(false) {
+  : QDialog(parent) {
    setupUi(this);
 
   if (MainWindow *mw = qobject_cast<MainWindow*>(parent)) {
@@ -32,7 +33,7 @@
 
   connect(_clear, SIGNAL(clicked()), _curveList, SLOT(clearSelection()));
   connect(_selectAll, SIGNAL(clicked()), this, SLOT(selectAll()));
-  connect(_curveList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateDefaults(QListWidgetItem*)));
+  //connect(_curveList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(updateDefaults(QListWidgetItem*)));
   connect(_curveList, SIGNAL(itemSelectionChanged()), this, SLOT(updateButtons()));
 
   connect(_dataRange, SIGNAL(modified()), this, SLOT(modified()));
@@ -41,6 +42,7 @@
   connect(_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(OKClicked()));
   connect(_buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(reject()));
 
+  initialzeEntries();
   updateButtons();
 }
 
@@ -56,12 +58,12 @@
 
 
 void ChangeDataSampleDialog::updateButtons() {
-  _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(_curveList->selectedItems().count() > 0 && (_modified || _curveList->selectedItems().count() > 1));
+  bool ok = (_curveList->selectedItems().count() > 0);
+  _buttonBox->button(QDialogButtonBox::Apply)->setEnabled(ok);
 }
 
 
 void ChangeDataSampleDialog::modified() {
-  _modified = true;
   updateButtons();
 }
 
@@ -80,8 +82,8 @@
     _curveList->addItem(wi);
   }
 
+  _curveList->blockSignals(false);
   _curveList->selectAll();
-  _curveList->blockSignals(false);
 }
 
 
@@ -90,6 +92,16 @@
 }
 
 
+void ChangeDataSampleDialog::initialzeEntries() {
+    _dataRange->setCountFromEnd(_dialogDefaults->value("vector/countFromEnd",false).toBool());
+    _dataRange->setStart(_dialogDefaults->value("vector/start", 0).toInt());
+    _dataRange->setReadToEnd(_dialogDefaults->value("vector/readToEnd",true).toBool());
+    _dataRange->setRange(_dialogDefaults->value("vector/range", 1).toInt());
+    _dataRange->setSkip(_dialogDefaults->value("vector/skip", 0).toInt());
+    _dataRange->setDoSkip(_dialogDefaults->value("vector/doSkip", false).toBool());
+    _dataRange->setDoFilter(_dialogDefaults->value("vector/doAve",false).toBool());
+}
+
 void ChangeDataSampleDialog::updateDefaults(QListWidgetItem* item) {
   if (!item) {
     return;
@@ -108,15 +120,11 @@
 
     vector->unlock();
   }
-
-  _modified = false;
 }
 
 
 void ChangeDataSampleDialog::OKClicked() {
-  if (_buttonBox->button(QDialogButtonBox::Apply)->isEnabled()) {
-    apply();
-  }
+  apply();
   accept();
 }
 
@@ -135,6 +143,14 @@
       vector->unlock();
     }
   }
+  _dialogDefaults->setValue("vector/range", _dataRange->range());
+  _dialogDefaults->setValue("vector/start", _dataRange->start());
+  _dialogDefaults->setValue("vector/countFromEnd", _dataRange->countFromEnd());
+  _dialogDefaults->setValue("vector/readToEnd", _dataRange->readToEnd());
+  _dialogDefaults->setValue("vector/skip", _dataRange->skip());
+  _dialogDefaults->setValue("vector/doSkip", _dataRange->doSkip());
+  _dialogDefaults->setValue("vector/doAve", _dataRange->doFilter());
+
   updateCurveListDialog();
 }
 
--- branches/work/kst/portto4/kst/src/libkstapp/changedatasampledialog.h #894966:894967
@@ -38,11 +38,11 @@
     void apply();
     void updateButtons();
     void modified();
+    void initialzeEntries();
 
   private:
     void updateCurveListDialog();
 
-    bool _modified;
     ObjectStore *_store;
 
 };
--- branches/work/kst/portto4/kst/src/libkstapp/libkstapp.pro #894966:894967
@@ -56,6 +56,7 @@
     dialogpage.cpp \
     dialogtab.cpp \
     differentiatecurvesdialog.cpp \
+    dimensionstab.cpp \
     document.cpp \
     editmultiplewidget.cpp \
     ellipseitem.cpp \
@@ -156,6 +157,7 @@
     dialogpage.h \
     dialogtab.h \
     differentiatecurvesdialog.h \
+    dimensionstab.h \
     document.h \
     editmultiplewidget.h \
     ellipseitem.h \
@@ -240,6 +242,7 @@
     debugdialog.ui \
     dialog.ui \
     differentiatecurvesdialog.ui \
+    dimensionstab.ui \
     editmultiplewidget.ui \
     equationtab.ui \
     eventmonitortab.ui \
--- branches/work/kst/portto4/kst/src/libkstapp/view.cpp #894966:894967
@@ -200,7 +200,6 @@
 
 
 bool View::event(QEvent *event) {
-
   if (event->type() == QEvent::Shortcut) {
     QShortcutEvent *e = static_cast<QShortcutEvent*>(event);
 
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.cpp #894966:894967
@@ -66,6 +66,32 @@
           this, SLOT(viewMouseModeChanged(View::MouseMode)));
   connect(parent, SIGNAL(viewModeChanged(View::ViewMode)),
           this, SLOT(updateView()));
+
+  // Add actions common to all view objects
+  // create them here in the constructor so we
+  // can register shortcuts.
+  _editAction = new QAction(tr("Edit"), this);
+  _editAction->setShortcut(Qt::Key_E);
+  registerShortcut(_editAction);
+  connect(_editAction, SIGNAL(triggered()), this, SLOT(edit()));
+
+  _deleteAction = new QAction(tr("Delete"), this);
+  _deleteAction->setShortcut(Qt::Key_Delete);
+  registerShortcut(_deleteAction);
+  connect(_deleteAction, SIGNAL(triggered()), this, SLOT(remove()));
+
+  _raiseAction = new QAction(tr("Raise"), this);
+  connect(_raiseAction, SIGNAL(triggered()), this, SLOT(raise()));
+
+  _lowerAction = new QAction(tr("Lower"), this);
+  connect(_lowerAction, SIGNAL(triggered()), this, SLOT(lower()));
+
+  _autoLayoutAction = new QAction(tr("Automatic"), this);
+  connect(_autoLayoutAction, SIGNAL(triggered()), this, SLOT(createAutoLayout()));
+
+  _customLayoutAction = new QAction(tr("Custom"), this);
+  connect(_customLayoutAction, SIGNAL(triggered()), this, SLOT(createCustomLayout()));
+
 }
 
 
@@ -747,28 +773,19 @@
 
   addTitle(&menu);
 
-  QAction *editAction = menu.addAction(tr("Edit"));
-  connect(editAction, SIGNAL(triggered()), this, SLOT(edit()));
+  menu.addAction(_editAction);
+  menu.addAction(_raiseAction);
+  menu.addAction(_lowerAction);
 
-  QAction *raiseAction = menu.addAction(tr("Raise"));
-  connect(raiseAction, SIGNAL(triggered()), this, SLOT(raise()));
-
-  QAction *lowerAction = menu.addAction(tr("Lower"));
-  connect(lowerAction, SIGNAL(triggered()), this, SLOT(lower()));
-
   QMenu layoutMenu;
   layoutMenu.setTitle(tr("Cleanup Layout"));
 
-  QAction *autoLayoutAction = layoutMenu.addAction(tr("Automatic"));
-  connect(autoLayoutAction, SIGNAL(triggered()), this, SLOT(createAutoLayout()));
+  layoutMenu.addAction(_autoLayoutAction);
+  layoutMenu.addAction(_customLayoutAction);
 
-  QAction *customLayoutAction = layoutMenu.addAction(tr("Custom"));
-  connect(customLayoutAction, SIGNAL(triggered()), this, SLOT(createCustomLayout()));
-
   menu.addMenu(&layoutMenu);
 
-  QAction *removeAction = menu.addAction(tr("Remove"));
-  connect(removeAction, SIGNAL(triggered()), this, SLOT(remove()));
+  menu.addAction(_deleteAction);
 
   addToMenuForContextEvent(menu);
 
@@ -1290,8 +1307,9 @@
              << endl;
 #endif
 
-    if (!topLevel) /*bring the old parent's transform with us*/
+    if (!topLevel) { /*bring the old parent's transform with us*/
       setTransform(parentItem()->transform(), true);
+    }
 
     /*cancel out the new parent's initial transform*/
     setTransform(viewItem->transform().inverted(), true);
@@ -1361,7 +1379,7 @@
     _parentRelativeWidth = (width() / parentViewItem()->width());
     _parentRelativeCenter =  mapToParent(rect().center()) - parentViewItem()->rect().topLeft();
     _parentRelativeCenter =  QPointF(_parentRelativeCenter.x() / parentViewItem()->width(), _parentRelativeCenter.y() / parentViewItem()->height());
-  } else if (parentView()) {
+   } else if (parentView()) {
     _parentRelativeHeight = (height() / parentView()->height());
     _parentRelativeWidth = (width() / parentView()->width());
     _parentRelativeCenter =  mapToParent(rect().center()) - parentView()->rect().topLeft();
@@ -1370,10 +1388,23 @@
     _parentRelativeHeight = 0;
     _parentRelativeWidth = 0;
     _parentRelativeCenter = QPointF(0, 0);
+   }
+}
+
+QPointF ViewItem::relativeCenter() const {
+  QPointF c;
+  if (parentViewItem()) {
+    c =  mapToParent(rect().center()) - parentViewItem()->rect().topLeft();
+    c =  QPointF(c.x() / parentViewItem()->width(), c.y() / parentViewItem()->height());
+  } else if (parentView()) {
+    c =  mapToParent(rect().center()) - parentView()->rect().topLeft();
+    c =  QPointF(c.x() / parentView()->width(), c.y() / parentView()->height());
+  } else {
+    c = QPointF(0, 0);
   }
+  return c;
 }
 
-
 void ViewItem::updateChildGeometry(const QRectF &oldParentRect, const QRectF &newParentRect) {
 //   qDebug() << "ViewItem::updateChildGeometry" << oldParentRect << newParentRect << endl;
 
@@ -1677,6 +1708,7 @@
     new MoveCommand(this, _originalPosition, pos());
 
     maybeReparent();
+    updateRelativeSize();
     ViewGridLayout::resetSharedPlots(this);
   } else if (oldMode == View::Resize && _originalRect != rect()) {
     new ResizeCommand(this, _originalRect, rect());
@@ -1721,7 +1753,11 @@
   update();
 }
 
+qreal ViewItem::rotationAngle() const {
+  return 180.0/M_PI * atan2(transform().m12(), transform().m11());
+}
 
+
 #ifndef QT_NO_DEBUG_STREAM
 QDebug operator<<(QDebug dbg, ViewItem *viewItem) {
     dbg.nospace() << viewItem->name();
--- branches/work/kst/portto4/kst/src/libkstapp/viewitem.h #894966:894967
@@ -67,7 +67,8 @@
     virtual void updateRelativeSize();
     qreal relativeHeight() const { return _parentRelativeHeight; }
     qreal relativeWidth() const { return _parentRelativeWidth; }
-    QPointF relativeCenter() const { return _parentRelativeCenter; }
+    QPointF relativeCenter() const;
+    qreal rotationAngle() const;
 
     GripMode gripMode() const;
     void setGripMode(GripMode mode);
@@ -199,6 +200,13 @@
     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
     virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);
 
+    QAction *_editAction;
+    QAction *_deleteAction;
+    QAction *_raiseAction;
+    QAction *_lowerAction;
+    QAction *_autoLayoutAction;
+    QAction *_customLayoutAction;
+
   private Q_SLOTS:
     void viewMouseModeChanged(View::MouseMode oldMode);
     void updateView();
@@ -218,6 +226,7 @@
     bool _acceptsChildItems;
     bool _acceptsContextMenuEvents;
     QPointF _originalPosition;
+    QPointF _parentRelativeCenter;
     QRectF _originalRect;
     QTransform _originalTransform;
     QLineF _normalLine;
@@ -227,7 +236,6 @@
     QTransform _rotationTransform;
     QHash<QString, QAction*> _shortcutMap;
     qreal _parentRelativeHeight, _parentRelativeWidth;
-    QPointF _parentRelativeCenter;
 
     friend class View;
     friend class Scene;
--- branches/work/kst/portto4/kst/src/libkstapp/viewitemdialog.cpp #894966:894967
@@ -15,12 +15,14 @@
 #include "filltab.h"
 #include "stroketab.h"
 #include "layouttab.h"
+#include "dimensionstab.h"
 #include "dialogpage.h"
 #include "viewgridlayout.h"
 
 #include <QPen>
 #include <QBrush>
 #include <QDebug>
+#include <QtGlobal>
 
 namespace Kst {
 
@@ -43,6 +45,13 @@
   page->addDialogTab(_layoutTab);
   addDialogPage(page);
 
+  _dimensionsTab = new DimensionsTab(_item, this);
+  DialogPage *dimensionsPage = new DialogPage(this);
+  dimensionsPage->setPageTitle(tr("Dimensions"));
+  dimensionsPage->addDialogTab(_dimensionsTab);
+  addDialogPage(dimensionsPage);
+  connect(_dimensionsTab, SIGNAL(apply()), this, SLOT(dimensionsChanged()));
+
   QList<DialogPage*> dialogPages = _item->dialogPages();
   foreach (DialogPage *dialogPage, dialogPages)
     addDialogPage(dialogPage);
@@ -50,6 +59,9 @@
   setupFill();
   setupStroke();
   setupLayout();
+  setupDimensions();
+
+  connect(_dimensionsTab, SIGNAL(tabModified()), this, SLOT(modified()));
 }
 
 
@@ -105,6 +117,11 @@
 }
 
 
+void ViewItemDialog::setupDimensions() {
+  _dimensionsTab->setupDimensions();
+}
+
+
 void ViewItemDialog::fillChanged() {
   Q_ASSERT(_item);
 
@@ -158,7 +175,64 @@
   layout->update();*/
 }
 
+void ViewItemDialog::dimensionsChanged() {
+  Q_ASSERT(_item);
 
+  double pw; // parent width
+  double ph; // parent height
+  double ptlx; // parent top left x
+  double ptly; // parent top left y
+  double r; // rotation
+  double w; // width
+  double h; // height
+  double x;
+  double y;
+
+  if (_item->parentViewItem()) {
+    pw = _item->parentViewItem()->width();
+    ph = _item->parentViewItem()->height();
+    ptlx = _item->parentViewItem()->rect().topLeft().x();
+    ptly = _item->parentViewItem()->rect().topLeft().y();
+  } else if (_item->parentView()) {
+    pw = _item->parentView()->width();
+    ph = _item->parentView()->height();
+    ptlx = _item->parentView()->rect().topLeft().x();
+    ptly = _item->parentView()->rect().topLeft().y();
+  } else {
+    Q_ASSERT_X(false,"parent test", "item has no parentview item");
+    pw = ph = ptlx = ptly = 1.0;
+  }
+
+  if (rect().width()>0) {
+    r = double(_item->rect().height()) / double(_item->rect().width());
+  } else {
+    r = 10000.0;
+  }
+
+  w = _dimensionsTab->w() * pw;
+  if (_dimensionsTab->fixedAspect()) {
+    h = w*r;
+    _item->setLockAspectRatio(true);
+  } else {
+    h = _dimensionsTab->h() * ph;
+    _item->setLockAspectRatio(false);
+  }
+  x = _dimensionsTab->x() * pw + ptlx - w/2.0;
+  y = _dimensionsTab->y() * ph + ptly - h/2.0;
+
+  _item->setViewRect(0,0,w,h);
+  _item->setPos(x,y);
+
+  QTransform t;
+  QPointF origin = _item->centerOfRotation();
+  t.translate(origin.x(), origin.y());
+  t.rotate(_dimensionsTab->r());
+  t.translate(-origin.x(), -origin.y());
+
+  _item->setTransform(t);
+  _item->updateRelativeSize();
 }
 
+}
+
 // vim: ts=2 sw=2 et
--- branches/work/kst/portto4/kst/src/libkstapp/viewitemdialog.h #894966:894967
@@ -24,6 +24,7 @@
 class FillTab;
 class StrokeTab;
 class LayoutTab;
+class DimensionsTab;
 
 class KST_EXPORT ViewItemDialog : public Dialog
 {
@@ -36,17 +37,19 @@
     void fillChanged();
     void strokeChanged();
     void layoutChanged();
+    void dimensionsChanged();
 
   private:
     void setupFill();
     void setupStroke();
     void setupLayout();
-
+    void setupDimensions();
   private:
     QPointer<ViewItem> _item;
     FillTab *_fillTab;
     StrokeTab *_strokeTab;
     LayoutTab *_layoutTab;
+    DimensionsTab *_dimensionsTab;
 };
 
 }


More information about the Kst mailing list