From kde-commits Fri Nov 25 11:40:09 2011 From: Khudyakov Alexey Date: Fri, 25 Nov 2011 11:40:09 +0000 To: kde-commits Subject: [kstars/KDE/4.7] kstars/widgets: Backport fix for 258182 to 4.7 Message-Id: <20111125114009.4AE73A60A9 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=132222129702694 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/mo= onphasecalendarwidget.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 #include @@ -32,30 +33,21 @@ #include #include #include -#include = #include = -MoonPhaseCalendar::MoonPhaseCalendar( KSMoon &moon, QWidget *parent ) : KD= ateTable(parent), m_Moon(moon) { - = +MoonPhaseCalendar::MoonPhaseCalendar( KSMoon &moon, QWidget *parent ) : + KDateTable(parent), + m_Moon(moon) +{ // Populate moon images from disk into the hash numDayColumns =3D calendar()->daysInWeek( QDate::currentDate() ); numWeekRows =3D 7; imagesLoaded =3D false; - - for( int i =3D 0; i < 36; ++i ) - m_Images[i] =3D NULL; - // TODO: Set geometry. - } = MoonPhaseCalendar::~MoonPhaseCalendar() { - // Free up the moon image pixmaps - if( imagesLoaded ) { - for( int i =3D 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 =3D " << MoonImageSize; for( int i =3D 0; i < 36; ++i ) { - QString imName =3D QString().sprintf("moon%02d.png", i); - QFile imFile; - if( m_Images[i] ) - delete m_Images[i]; - m_Images[i] =3D NULL; - if( KSUtils::openDataFile( imFile, imName ) ) { - imFile.close(); - m_Images[i] =3D new QPixmap( QPixmap( imFile.fileName() ).scal= ed( MoonImageSize, MoonImageSize, Qt::KeepAspectRatio, Qt::SmoothTransforma= tion ) ); - } + QString imName =3D QString().sprintf("moon%02d", i); + m_Images[i] =3D + QPixmap::fromImage( TextureManager::getImage( imName ) ). + scaled( MoonImageSize, MoonImageSize, Qt::KeepAspectRatio, Qt:= :SmoothTransformation ); } imagesLoaded =3D true; } @@ -280,7 +267,12 @@ void MoonPhaseCalendar::paintCell( QPainter *painter, = int row, int col, const KC if( calendar()->isValid( cellDate ) ) { int iPhase =3D computeMoonPhase( KStarsDateTime( cellDate, QTi= me(0, 0, 0) ) ); QRect drawRect =3D cell.toRect(); - painter->drawPixmap( ( drawRect.width() - MoonImageSize )/2, 1= 2 + (( drawRect.height() - 12 ) - MoonImageSize)/2, *m_Images[ iPhase ] ); = // FIXME: Using hard coded fontsize + painter->drawPixmap( ( drawRect.width() - MoonImageSize )/2, 1= 2 + (( drawRect.height() - 12 ) - MoonImageSize)/2, m_Images[ iPhase ] ); /= / FIXME: Using hard coded fon +// + painter + // painter->drawPixmap( ( drawRect.width() - MoonImageSize )/2, + // 12 + (( drawRect.height() - 12 ) - Moo= nImageSize)/2, + // m_Images[ iPhase ] ); + // FIXME: Using hard coded fontsize // kDebug() << "Drew moon image " << iPhase; } } diff --git a/kstars/widgets/moonphasecalendarwidget.h b/kstars/widgets/moon= phasecalendarwidget.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 ph= ase + QPixmap m_Images[36]; // Array storing moon images against integer pha= se = double cellWidth, cellHeight; int numWeekRows;