[Kst] kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Sat Apr 10 22:44:10 CEST 2004


CVS commit by staikos: 

preserve aspect ratio during resize to keep with current Kst behaviour
(also keeps relative sizing and positioning - basically the entire geometry
aspect is preserved)


  M +36 -4     kstviewobject.cpp   1.19
  M +10 -0     kstviewobject.h   1.15


--- kdeextragear-2/kst/kst/kstviewobject.cpp  #1.18:1.19
@@ -29,4 +29,5 @@
 KstViewObject::KstViewObject() : KstObject(), _geom(0, 0, 1, 1), _focus(false) {
   _standardActions = 0;
+  updateAspect();
 }
 
@@ -35,4 +36,5 @@ KstViewObject::KstViewObject(QDomElement
   Q_UNUSED(e)
   _standardActions = 0;
+  updateAspect();
 }
 
@@ -105,4 +107,5 @@ void KstViewObject::appendChild(KstViewO
   obj->_parent = this;
   _children.append(obj);
+  obj->updateAspect();
 }
 
@@ -111,4 +114,5 @@ void KstViewObject::prependChild(KstView
   obj->_parent = this;
   _children.prepend(obj);
+  obj->updateAspect();
 }
 
@@ -138,4 +142,5 @@ void KstViewObject::insertChildAfter(con
   }
   obj->_parent = this;
+  obj->updateAspect();
 }
 
@@ -163,4 +168,5 @@ void KstViewObject::resize(const QSize& 
   QSize old = _geom.size();
   _geom.setSize(size);
+  updateAspect();
   for (KstViewObjectList::Iterator i = _children.begin(); i != _children.end(); ++i) {
     (*i)->parentResized(old, size);
@@ -175,8 +181,7 @@ QSize KstViewObject::size() const {
 
 void KstViewObject::parentResized(const QSize& old, const QSize& size) {
-  //kdDebug() << "Resizing [" << tagName() << "] due to parent resize. args are " << old << " " << size << endl;
-  resize(QSize(size.width() * _geom.width() / old.width(),
-               size.height() * _geom.height() / old.height()));
-//  move(QPoint(int(_geom.x() * xScale), int(_geom.y() * yScale)));
+  Q_UNUSED(old)
+  Q_UNUSED(size)
+  updateFromAspect();
 }
 
@@ -253,4 +258,5 @@ void KstViewObject::move(const QPoint& p
   //kdDebug() << "Moving [" << tagName() << "] " << pos << endl;
   _geom.moveTopLeft(pos);
+  updateAspect();
 }
 
@@ -387,4 +393,30 @@ void KstViewObject::lower() {
 
 
+void KstViewObject::updateFromAspect() {
+  if (!_parent) {
+    return;
+  }
+  _geom.setX(_aspect.x * _parent->geometry().width());
+  _geom.setY(_aspect.y * _parent->geometry().height());
+  _geom.setRight(_geom.x() + _aspect.w * _parent->geometry().width());
+  _geom.setBottom(_geom.y() + _aspect.h * _parent->geometry().height());
+}
+
+
+void KstViewObject::updateAspect() {
+  if (!_parent) {
+    _aspect.x = 0.0;
+    _aspect.y = 0.0;
+    _aspect.w = 0.0;
+    _aspect.h = 0.0;
+    return;
+  }
+  _aspect.x = double(_geom.x()) / double(_parent->geometry().width());
+  _aspect.y = double(_geom.y()) / double(_parent->geometry().height());
+  _aspect.w = double(_geom.width()) / double(_parent->geometry().width());
+  _aspect.h = double(_geom.height()) / double(_parent->geometry().height());
+}
+
+
 #include "kstviewobject.moc"
 // vim: ts=2 sw=2 et

--- kdeextragear-2/kst/kst/kstviewobject.h  #1.14:1.15
@@ -21,4 +21,5 @@
 #include "kstobject.h"
 
+#include <assert.h>
 #include <qcolor.h>
 #include <qdom.h>
@@ -32,4 +33,9 @@ typedef KstSharedPtr<KstViewObject> KstV
 typedef KstObjectList<KstViewObjectPtr> KstViewObjectList;
 
+struct KstAspectRatio {
+  KstAspectRatio() : x(0.0), y(0.0), w(0.0), h(0.0) {}
+  double x, y, w, h;
+};
+
 class KstViewObject : public KstObject {
   Q_OBJECT
@@ -101,4 +107,6 @@ class KstViewObject : public KstObject {
   protected slots:
     virtual void parentResized(const QSize& old, const QSize& size);
+    virtual void updateFromAspect();
+    virtual void updateAspect();
 
     /***********  Actions ************/
@@ -117,4 +125,5 @@ class KstViewObject : public KstObject {
     KstViewObjectPtr _parent;
     int _standardActions;
+    KstAspectRatio _aspect;
 };
 
@@ -132,4 +141,5 @@ template<class T>
 KstViewObjectPtr KstViewObject::findChildType(const QPoint& pos) {
   // FIXME
+  abort();
   return KstViewObjectPtr();
 }





More information about the Kst mailing list