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

List:       kde-commits
Subject:    [kstars/KDE/4.7] kstars/widgets: Backport fix for 258182 to 4.7
From:       Khudyakov Alexey <alexey.skladnoy () gmail ! com>
Date:       2011-11-25 11:40:09
Message-ID: 20111125114009.4AE73A60A9 () git ! kde ! org
[Download RAW message or body]

Git commit 32d656d205a5ba917efb4199dc337623447f5f5b by Khudyakov Alexey.
Committed on 17/11/2011 at 18:46.
Pushed by khudyakov into branch 'KDE/4.7'.

Backport fix for 258182 to 4.7

Fix crash in moon phase almanach

1. Read Moon images from texture manager
2. Store array of pixmaps instead of array of pointers to pixmap
   and avoid manual memory management entirely.

CCBUG: 258182

M  +15   -23   kstars/widgets/moonphasecalendarwidget.cpp
M  +1    -1    kstars/widgets/moonphasecalendarwidget.h

http://commits.kde.org/kstars/32d656d205a5ba917efb4199dc337623447f5f5b

diff --git a/kstars/widgets/moonphasecalendarwidget.cpp \
b/kstars/widgets/moonphasecalendarwidget.cpp index e19248a..841c650 100644
--- a/kstars/widgets/moonphasecalendarwidget.cpp
+++ b/kstars/widgets/moonphasecalendarwidget.cpp
@@ -21,6 +21,7 @@
 #include "ksnumbers.h"
 #include "kstarsdatetime.h"
 #include "ksutils.h"
+#include "texturemanager.h"
 
 #include <kcolorscheme.h>
 #include <kglobal.h>
@@ -32,30 +33,21 @@
 #include <QPainter>
 #include <QStyle>
 #include <QtGui/QStyleOptionViewItem>
-#include <QFile>
 
 #include <cmath>
 
-MoonPhaseCalendar::MoonPhaseCalendar( KSMoon &moon, QWidget *parent ) : \
                KDateTable(parent), m_Moon(moon) {
-    
+MoonPhaseCalendar::MoonPhaseCalendar( KSMoon &moon, QWidget *parent ) :
+    KDateTable(parent),
+    m_Moon(moon)
+{
     // Populate moon images from disk into the hash
     numDayColumns = calendar()->daysInWeek( QDate::currentDate() );
     numWeekRows = 7;
     imagesLoaded = false;
-
-    for( int i = 0; i < 36; ++i )
-        m_Images[i] = NULL;
-
     // TODO: Set geometry.
-
 }
 
 MoonPhaseCalendar::~MoonPhaseCalendar() {
-    // Free up the moon image pixmaps
-    if( imagesLoaded ) {
-        for( int i = 0; i < 36; ++i )
-            delete m_Images[i];
-    }
 }
 
 QSize MoonPhaseCalendar::sizeHint() const {
@@ -68,15 +60,10 @@ void MoonPhaseCalendar::loadImages() {
     computeMoonImageSize();
     kDebug() << "Loading moon images. MoonImageSize = " << MoonImageSize;
     for( int i = 0; i < 36; ++i ) {
-        QString imName = QString().sprintf("moon%02d.png", i);
-        QFile imFile;
-        if( m_Images[i] )
-            delete m_Images[i];
-        m_Images[i] = NULL;
-        if( KSUtils::openDataFile( imFile, imName ) ) {
-            imFile.close();
-            m_Images[i] = new QPixmap( QPixmap( imFile.fileName() ).scaled( \
                MoonImageSize, MoonImageSize, Qt::KeepAspectRatio, \
                Qt::SmoothTransformation ) );
-        }
+        QString imName = QString().sprintf("moon%02d", i);
+        m_Images[i] =
+            QPixmap::fromImage( TextureManager::getImage( imName ) ).
+            scaled( MoonImageSize, MoonImageSize, Qt::KeepAspectRatio, \
Qt::SmoothTransformation );  }
     imagesLoaded = true;
 }
@@ -280,7 +267,12 @@ void MoonPhaseCalendar::paintCell( QPainter *painter, int row, \
int col, const KC  if( calendar()->isValid( cellDate ) ) {
             int iPhase = computeMoonPhase( KStarsDateTime( cellDate, QTime(0, 0, 0) \
) );  QRect drawRect = cell.toRect();
-            painter->drawPixmap( ( drawRect.width() - MoonImageSize )/2, 12 + (( \
drawRect.height() - 12 ) - MoonImageSize)/2, *m_Images[ iPhase ] ); // FIXME: Using \
hard coded fontsize +            painter->drawPixmap( ( drawRect.width() - \
MoonImageSize )/2, 12 + (( drawRect.height() - 12 ) - MoonImageSize)/2, m_Images[ \
iPhase ] ); // FIXME: Using hard coded fon +// +            painter
+            // painter->drawPixmap( ( drawRect.width() - MoonImageSize )/2,
+                                 // 12 + (( drawRect.height() - 12 ) - \
MoonImageSize)/2, +                                 // m_Images[ iPhase ] );
+            // FIXME: Using hard coded fontsize
             //            kDebug() << "Drew moon image " << iPhase;
         }
     }
diff --git a/kstars/widgets/moonphasecalendarwidget.h \
b/kstars/widgets/moonphasecalendarwidget.h index 6108edf..99e83a7 100644
--- a/kstars/widgets/moonphasecalendarwidget.h
+++ b/kstars/widgets/moonphasecalendarwidget.h
@@ -91,7 +91,7 @@ class MoonPhaseCalendar : public KDateTable {
      */
     unsigned short computeMoonPhase( const KStarsDateTime &date );
 
-    QPixmap *m_Images[36]; // Array storing moon images against integer phase
+    QPixmap m_Images[36]; // Array storing moon images against integer phase
 
     double cellWidth, cellHeight;
     int numWeekRows;


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

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