[Kstars-devel] KDE/kdeedu/kstars/kstars

Alexey Khudyakov alexey.skladnoy at gmail.com
Sat Dec 5 22:24:47 CET 2009


SVN commit 1059135 by khudyakov:

Finally close regression in infoboxes

Infoboxes appears in right place and stickyness is save into options

CCMAIL: kstars-devel at kde.org

 M  +3 -1      skymap.cpp  
 M  +51 -40    widgets/infoboxwidget.cpp  
 M  +6 -3      widgets/infoboxwidget.h  


--- trunk/KDE/kdeedu/kstars/kstars/skymap.cpp #1059134:1059135
@@ -230,14 +230,17 @@
     // Time box
     Options::setPositionTimeBox( m_timeBox->pos() );
     Options::setShadeTimeBox(    m_timeBox->shaded() );
+    Options::setStickyTimeBox(   m_timeBox->sticky() );
     Options::setShowTimeBox(     m_timeBox->isVisibleTo(m_iboxes) );
     // Geo box
     Options::setPositionGeoBox( m_geoBox->pos() );
     Options::setShadeGeoBox(    m_geoBox->shaded() );
+    Options::setStickyGeoBox(   m_geoBox->sticky() );
     Options::setShowGeoBox(     m_geoBox->isVisibleTo(m_iboxes) );
     // Obj box
     Options::setPositionFocusBox( m_objBox->pos() );
     Options::setShadeFocusBox(    m_objBox->shaded() );
+    Options::setStickyFocusBox(   m_objBox->sticky() );
     Options::setShowFocusBox(     m_objBox->isVisibleTo(m_iboxes) );
     
     //store focus values in Options
@@ -269,7 +272,6 @@
 
 
 void SkyMap::showFocusCoords() {
-    kDebug() << "--";
     if( focusObject() && Options::isTracking() )
         emit objectChanged( focusObject() );
     else
--- trunk/KDE/kdeedu/kstars/kstars/widgets/infoboxwidget.cpp #1059134:1059135
@@ -19,40 +19,16 @@
 #include <QMouseEvent>
 #include <QFontMetrics>
 
-#include <kdebug.h>
-
 #include "kstarsdata.h"
 #include "colorscheme.h"
+#include "ksutils.h"
 
 #include "widgets/infoboxwidget.h"
 
 
-namespace {
-    // Padding
-    const int padX = 6;
-    const int padY = 2;
+const int InfoBoxWidget::padX = 6;
+const int InfoBoxWidget::padY = 2;
 
-    int repositionX(int x, int lo, int hi, int& align, bool xaxis) {
-        if( x <= lo )
-            return lo;
-        if( x >= hi ) {
-            align |= xaxis ? InfoBoxWidget::AnchorRight : InfoBoxWidget::AnchorBottom;
-            kDebug() << "HI " << align;
-            return hi;
-        }
-        align &= ~( xaxis ? InfoBoxWidget::AnchorRight : InfoBoxWidget::AnchorBottom );
-        kDebug() << "DD " << align;
-        return x;
-    }
-
-    int adjustX(int x, int lo, int hi, int& align, bool xaxis) {
-        if( (xaxis && (align & InfoBoxWidget::AnchorRight)) || (!xaxis && (align & InfoBoxWidget::AnchorBottom)) )
-            return hi;
-        return repositionX(x, lo, hi, align, xaxis);
-    }
-}
-
-
 InfoBoxes::~InfoBoxes()
 {}
 
@@ -62,7 +38,7 @@
     m_boxes.append(ibox);
 }
 
-void InfoBoxes::resizeEvent(QResizeEvent * event) {
+void InfoBoxes::resizeEvent(QResizeEvent*) {
     foreach(InfoBoxWidget* w, m_boxes)
         w->adjust();
 }
@@ -76,8 +52,8 @@
     m_shaded(shade),
     m_anchor(anchor)
 {
+    move(pos);
     updateSize();
-    adjust();
 }
 
 InfoBoxWidget::~InfoBoxWidget()
@@ -91,6 +67,7 @@
     int h = fm.height() * (m_shaded ? 1 : m_strings.size());
     // Add padding
     resize(w + 2*padX, h + 2*padY + 2);
+    adjust();
 }
 
 void InfoBoxWidget::slotTimeChanged() {
@@ -155,18 +132,31 @@
 }
 
 void InfoBoxWidget::adjust() {
-    int newX = adjustX(x(), 0, parentWidget()->width()  - width(),  m_anchor, true);
-    int newY = adjustX(y(), 0, parentWidget()->height() - height(), m_anchor, false);
+    // X axis
+    int newX = x();
+    int maxX = parentWidget()->width() - width();
+    if( m_anchor & AnchorRight ) {
+        newX = maxX;
+    } else {
+        newX = KSUtils::clamp(newX, 0, maxX);
+        if( newX == maxX )
+            m_anchor |= AnchorRight;
+    }
+    // Y axis
+    int newY = y();
+    int maxY = parentWidget()->height() - height();
+    if( m_anchor & AnchorBottom ) {
+        newY = maxY;
+    } else {
+        newY = KSUtils::clamp(newY, 0, maxY);
+        if( newY == maxY )
+            m_anchor |= AnchorBottom;
+    }
+    // Do move
     move(newX, newY);
 }
 
-void InfoBoxWidget::reposition(int newX, int newY) {
-    newX = repositionX(newX, 0, parentWidget()->width()  - width(),  m_anchor, true);
-    newY = repositionX(newY, 0, parentWidget()->height() - height(), m_anchor, false);
-    move(newX, newY);
-}
-
-void InfoBoxWidget::paintEvent(QPaintEvent* e)
+void InfoBoxWidget::paintEvent(QPaintEvent*)
 {
     // If widget contain no strings return
     if( m_strings.empty() )
@@ -199,8 +189,29 @@
 
 void InfoBoxWidget::mouseMoveEvent(QMouseEvent * event) {
     m_grabbed = true;
-    int newX = repositionX(x() + event->x(), 0, parentWidget()->width()  - width(),  m_anchor, true);
-    int newY = repositionX(y() + event->y(), 0, parentWidget()->height() - height(), m_anchor, false);
+    // X axis
+    int newX = x() + event->x();
+    int maxX = parentWidget()->width() - width();
+    if( newX > maxX ) {
+        newX = maxX;
+        m_anchor |= AnchorRight;
+    } else {
+        if( newX < 0 )
+            newX = 0;
+        m_anchor &= ~AnchorRight;
+    }
+    // Y axis
+    int newY = y() + event->y();
+    int maxY = parentWidget()->height() - height();
+    if( newY > maxY ) {
+        newY = maxY;
+        m_anchor |= AnchorBottom;
+    } else {
+        if( newY < 0 )
+            newY = 0;
+        m_anchor &= ~AnchorBottom;
+    }
+    // Do move
     move(newX, newY);
 }
 
--- trunk/KDE/kdeedu/kstars/kstars/widgets/infoboxwidget.h #1059134:1059135
@@ -64,10 +64,10 @@
 
     /** Check whether box is shaded. In this case only one line is shown. */
     bool shaded() const { return m_shaded; }
-
+    /** Get stickyness status of */
+    int sticky() const { return m_anchor; }
+    
     /** Adjust widget's postion */
-    void reposition(int newX, int newY);
-    /** Adjust widget's postion */
     void adjust();
 
 public slots:
@@ -94,6 +94,9 @@
     bool m_grabbed;         // True if widget is dragged around
     bool m_shaded;          // True if widget if shaded
     int  m_anchor;          // Vertical alignment of widget
+
+    static const int padX;
+    static const int padY;
 };
 
 #endif /* INFOBOXWIDGET_H_ */


More information about the Kstars-devel mailing list