You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tdegames/konquest/planet_info.cc

162 lines
3.8 KiB

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqpalette.h>
#include <tqcolor.h>
#include <kapplication.h>
#include <klocale.h>
#include "planet_info.h"
#include <kglobal.h>
#include "planet_info.moc"
PlanetInfo::PlanetInfo( TQWidget *parent, TQPalette palette )
: TQFrame( parent )
{
setPalette( palette );
name = new TQLabel( this );
name->setMinimumWidth( 100 );
owner = new TQLabel( this );
owner->setMinimumWidth( 100 );
ships = new TQLabel( this );
ships->setMinimumWidth( 100 );
production = new TQLabel( this );
production->setMinimumWidth( 100 );
kill_percent = new TQLabel( this );
kill_percent->setMinimumWidth( 100 );
clearDisplay();
TQVBoxLayout *tqlayout1 = new TQVBoxLayout( this );
tqlayout1->addWidget( name );
tqlayout1->addWidget( owner );
tqlayout1->addWidget( ships );
tqlayout1->addWidget( production );
tqlayout1->addWidget( kill_percent );
tqlayout1->addStretch(1);
setMouseTracking( true );
setMinimumSize( tqsizeHint() );
setMaximumHeight( tqsizeHint().height() );
}
PlanetInfo::~PlanetInfo()
{
emptyPlanetInfoList();
}
TQSize PlanetInfo::tqsizeHint() const
{
int height;
height = name->tqsizeHint().height() +
owner->tqsizeHint().height() +
ships->tqsizeHint().height() +
production->tqsizeHint().height()+
kill_percent->tqsizeHint().height();
return TQSize( 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()
{
TQString temp;
temp = "<qt>" + i18n("Planet name: ");
name->setText( temp );
temp = "<qt>" + i18n("Owner: ");
owner->setText( temp );
temp = "<qt>" + i18n("Ships: ");
ships->setText( temp );
temp = "<qt>" + i18n("Production: ");
production->setText( temp );
temp = "<qt>" + 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();
TQString temp;
temp = "<qt>" + i18n("Planet name: %1").tqarg(planet->getName());
name->setText( temp );
return;
}
TQString nameToShow = planet->getName();
PlanetInfoListIterator itr( planet_stats );
planet_info_buffer *p;
while( (p = itr()) ) {
if( p->planet == planet ) {
TQString temp;
temp = "<qt>" + i18n("Planet name: %1").tqarg(p->planet->getName());
name->setText( temp );
temp = "<qt>" + i18n("Owner: %1").tqarg(p->planet->getPlayer()->getColoredName());
owner->setText( temp );
temp = "<qt>" + i18n("Ships: %1").tqarg( KGlobal::locale()->formatNumber(p->ships, 0) );
ships->setText( temp );
temp = "<qt>" + i18n("Production: %1").tqarg( KGlobal::locale()->formatNumber(p->production, 0) );
production->setText( temp );
temp = "<qt>" + i18n("Kill percent: %1").tqarg( KGlobal::locale()->formatNumber(p->killRate, 3) );
kill_percent->setText( temp );
}
}
}