From c90c389a8a8d9d8661e9772ec4144c5cf2039f23 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- konquest/planet_info.cc | 161 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 konquest/planet_info.cc (limited to 'konquest/planet_info.cc') diff --git a/konquest/planet_info.cc b/konquest/planet_info.cc new file mode 100644 index 00000000..4c1d4be1 --- /dev/null +++ b/konquest/planet_info.cc @@ -0,0 +1,161 @@ +#include +#include +#include +#include +#include +#include + +#include "planet_info.h" +#include +#include "planet_info.moc" + +PlanetInfo::PlanetInfo( QWidget *parent, QPalette palette ) + : QFrame( parent ) +{ + setPalette( palette ); + + name = new QLabel( this ); + name->setMinimumWidth( 100 ); + owner = new QLabel( this ); + owner->setMinimumWidth( 100 ); + ships = new QLabel( this ); + ships->setMinimumWidth( 100 ); + production = new QLabel( this ); + production->setMinimumWidth( 100 ); + kill_percent = new QLabel( this ); + kill_percent->setMinimumWidth( 100 ); + + clearDisplay(); + + QVBoxLayout *layout1 = new QVBoxLayout( this ); + + layout1->addWidget( name ); + layout1->addWidget( owner ); + layout1->addWidget( ships ); + layout1->addWidget( production ); + layout1->addWidget( kill_percent ); + layout1->addStretch(1); + + setMouseTracking( true ); + + setMinimumSize( sizeHint() ); + setMaximumHeight( sizeHint().height() ); +} + +PlanetInfo::~PlanetInfo() +{ + emptyPlanetInfoList(); +} + +QSize PlanetInfo::sizeHint() const +{ + int height; + + height = name->sizeHint().height() + + owner->sizeHint().height() + + ships->sizeHint().height() + + production->sizeHint().height()+ + kill_percent->sizeHint().height(); + + return QSize( 100, height ); +} + +void PlanetInfo::setPlanetList( PlanetList &newPlanets ) +{ + emptyPlanetInfoList(); + + PlanetListIterator itr( newPlanets ); + + Planet *p; + while( (p = itr()) ) { + planet_info_buffer *stats = new planet_info_buffer; + stats->planet = p; + planet_stats.append( stats ); + } + + rescanPlanets(); +} + +void PlanetInfo::rescanPlanets() +{ + PlanetInfoListIterator itr( planet_stats ); + planet_info_buffer *p; + + while( (p = itr()) ) { + p->production = p->planet->getProduction(); + p->ships = p->planet->getFleet().getShipCount(); + p->killRate = p->planet->getKillPercentage(); + } +} + +void PlanetInfo::clearDisplay() +{ + QString temp; + + temp = "" + i18n("Planet name: "); + name->setText( temp ); + + temp = "" + i18n("Owner: "); + owner->setText( temp ); + + temp = "" + i18n("Ships: "); + ships->setText( temp ); + + temp = "" + i18n("Production: "); + production->setText( temp ); + + temp = "" + i18n("Kill percent: "); + kill_percent->setText( temp ); +} + +void PlanetInfo::emptyPlanetInfoList() +{ + planet_stats.first(); + + planet_info_buffer *p; + while( (p = planet_stats.take()) ) { + delete p; + } + +} + +void PlanetInfo::showPlanet( Planet *planet ) +{ + if( planet->getPlayer()->isNeutral() ) { + clearDisplay(); + + QString temp; + + temp = "" + i18n("Planet name: %1").arg(planet->getName()); + name->setText( temp ); + return; + } + + QString nameToShow = planet->getName(); + + PlanetInfoListIterator itr( planet_stats ); + planet_info_buffer *p; + + while( (p = itr()) ) { + if( p->planet == planet ) { + + QString temp; + + temp = "" + i18n("Planet name: %1").arg(p->planet->getName()); + name->setText( temp ); + + temp = "" + i18n("Owner: %1").arg(p->planet->getPlayer()->getColoredName()); + owner->setText( temp ); + + temp = "" + i18n("Ships: %1").arg( KGlobal::locale()->formatNumber(p->ships, 0) ); + ships->setText( temp ); + + temp = "" + i18n("Production: %1").arg( KGlobal::locale()->formatNumber(p->production, 0) ); + production->setText( temp ); + + temp = "" + i18n("Kill percent: %1").arg( KGlobal::locale()->formatNumber(p->killRate, 3) ); + kill_percent->setText( temp ); + } + } +} + -- cgit v1.2.1