[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    [PATCH] [KPresenter] Really keep the aspect ratio of a frame if the check box is selected
From:       Marc Mutz <mutz () kde ! org>
Date:       2002-07-21 0:23:28
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi!

This patch gets rid of the annoying behaviour that the style dialog 
doesn't enforce a constant aspect ratio, even though the corresponding 
check box is selected.

Please review. It's quite small.


OTOH, while writing this patch, I came across the thought of adding
  setReferencePoint( int/double )
  setRelativeValue( double ) [slot]
  valueChangedRelative( double ) [signal]
methods to K{Int,Double}NumInput that would allow an arbitrary number of 
KNumInputs to sync themselves in exactly this way just by 
cross-connecting the above signals and slots.

The reference point of each class'd be a non-zero value in the valid 
range that corresponds to 100% (1.0). In addition to emitting the 
absolute value, the numinput would emit the value in units of the 
reference point.

What do you think?

Marc,
who thinks that the new fractional number spin box looks good on KOffice 
;-)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)

iD8DBQE9Of8I3oWD+L2/6DgRAt+uAKClb3TeVH7RVxzS7fsUe1uQvNji1wCdG9qs
idCoTzyT370f5BKJ59ts9hU=
=fCFW
-----END PGP SIGNATURE-----

["kpresenter-keep-aspect-ratio.diff" (text/x-diff)]

Index: styledia.cc
===================================================================
RCS file: /home/kde/koffice/kpresenter/styledia.cc,v
retrieving revision 1.92
diff -u -3 -p -r1.92 styledia.cc
--- styledia.cc	2002/07/15 16:24:37	1.92
+++ styledia.cc	2002/07/21 00:23:02
@@ -961,6 +961,8 @@ void StyleDia::setupTabGeometry()
 
     keepRatio= new QCheckBox( i18n("Keep ratio"), tab);
     layout->addWidget(keepRatio);
+    connect( keepRatio, SIGNAL(toggled(bool)),
+	     this, SLOT(slotKeepRatioToggled(bool)));
 
     if ( allTextObj )
     {
@@ -991,6 +993,8 @@ void StyleDia::setupTabGeometry()
 
     m_lineWidth= new KDoubleNumInput( grp1 );
     m_lineWidth->setRange ( 0, 9999, 1, false);
+    connect( m_lineWidth, SIGNAL(valueChanged(double)),
+	     this, SLOT(slotUpdateHeightForWidth(double)) );
 
     pGrid->addWidget( m_lineWidth, 4, 0 );
 
@@ -1009,6 +1013,9 @@ void StyleDia::setupTabGeometry()
 
     m_lineHeight= new KDoubleNumInput( grp1 );
     m_lineHeight->setRange ( 0, 9999, 1, false);
+    connect( m_lineHeight, SIGNAL(valueChanged(double)),
+	     this, SLOT(slotUpdateWidthForHeight(double)) );
+
     pGrid->addWidget( m_lineHeight, 4, 1 );
 
 
@@ -1153,6 +1160,27 @@ void StyleDia::slotMarginsChanged( doubl
 }
 
 
+void StyleDia::slotUpdateWidthForHeight( double height )
+{
+    if ( !isKeepRatio() ) return;
+    if ( heightByWidthRatio == 0 ) return; // avoid DBZ
+    m_lineWidth->setValue( height / heightByWidthRatio );
+}
+
+void StyleDia::slotUpdateHeightForWidth( double width )
+{
+    if ( !isKeepRatio() ) return;
+    m_lineHeight->setValue( width * heightByWidthRatio );
+}
+
+void StyleDia::slotKeepRatioToggled( bool on ) {
+    if ( !on ) return;
+    if ( m_lineWidth->value() == 0 )
+        heightByWidthRatio = 1.0; // arbitrary
+    else
+        heightByWidthRatio = m_lineHeight->value() / m_lineWidth->value();
+}
+
 void StyleDia::protectChanged()
 {
     if ( lockUpdate )
@@ -1329,6 +1357,7 @@ void StyleDia::setSize(const KoRect & _r
     m_lineLeft->setValue(KoUnit::ptToUnit( QMAX(0.00, _rect.left()), m_doc->getUnit() ));
     m_lineWidth->setValue(KoUnit::ptToUnit( QMAX(0.00, _rect.width()), m_doc->getUnit() ));
     m_lineHeight->setValue(KoUnit::ptToUnit( QMAX(0.00, _rect.height()), m_doc->getUnit() ));
+    heightByWidthRatio = m_lineHeight->value() / m_lineWidth->value();
 }
 
 void StyleDia::setProtectContent( bool p )
Index: styledia.h
===================================================================
RCS file: /home/kde/koffice/kpresenter/styledia.h,v
retrieving revision 1.42
diff -u -3 -p -r1.42 styledia.h
--- styledia.h	2002/07/15 16:24:37	1.42
+++ styledia.h	2002/07/21 00:23:02
@@ -285,6 +285,7 @@ private:
     double oldTop;
     double oldBottom;
     double oldRight;
+    double heightByWidthRatio;
 
 private slots:
     void slotReset();
@@ -292,6 +293,9 @@ private slots:
     void protectChanged();
     void slotMarginsChanged( double );
     void slotProtectContentChanged( bool );
+    void slotUpdateWidthForHeight( double );
+    void slotUpdateHeightForWidth( double );
+    void slotKeepRatioToggled( bool );
 signals:
     void styleOk();
 };

_______________________________________________
koffice-devel mailing list
koffice-devel@mail.kde.org
http://mail.kde.org/mailman/listinfo/koffice-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic