summaryrefslogtreecommitdiffstats
path: root/konquest/fleetdlg.cc
blob: ebe230c38a58d4e8530ff2062bac3fc269af258a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <tqlayout.h>
#include <kapplication.h>
#include <klocale.h>
#include <math.h>
#include <kglobal.h>
#include <kpushbutton.h>
#include <kstdguiitem.h>

#include "fleetdlg.h"

FleetDlgListViewItem::FleetDlgListViewItem(TQListView *parent, TQString s1, TQString s2, TQString s3, TQString s4, TQString s5) : TQListViewItem(parent, s1, s2, s3, s4, s5)
{
}

int FleetDlgListViewItem::compare(TQListViewItem *i, int col, bool) const
{
	if (col == 1)
	{
		if (text(col) > i -> text(col)) return 1;
		else if (text(col) < i -> text(col)) return -1;
		else return compare(i, 0, true);
	}
	else if (col == 3)
	{
		if (text(col).toDouble() > i -> text(col).toDouble()) return 1;
		else if (text(col).toDouble() < i -> text(col).toDouble()) return -1;
		else return compare(i, 0, true);
	}
	else
	{
		if (text(col).toInt() > i -> text(col).toInt()) return 1;
		else if (text(col).toInt() < i -> text(col).toInt()) return -1;
		else return compare(i, 0, true);
	}
}


FleetDlg::FleetDlg( TQWidget *parent, AttackFleetList *fleets )
    : TQDialog(parent, "FleetDlg", true ), fleetList(fleets)
{
    setCaption( kapp->makeStdCaption(i18n("Fleet Overview")) );

    fleetTable = new TDEListView( this, 0 );
    fleetTable->addColumn(i18n("Fleet No."));
    fleetTable->addColumn(i18n("Destination"));
    fleetTable->addColumn(i18n("Ships"));
    fleetTable->addColumn(i18n("Kill Percentage"));
    fleetTable->addColumn(i18n("Arrival Turn"));
    fleetTable->setMinimumSize( fleetTable->sizeHint() );

    KPushButton *okButton = new KPushButton( KStdGuiItem::ok(), this );
    okButton->setMinimumSize( okButton->sizeHint() );
    okButton->setDefault(true);

    TQVBoxLayout *layout1 = new TQVBoxLayout( this );
    TQHBoxLayout *layout2 = new TQHBoxLayout;

    layout1->addWidget( fleetTable, 1 );
    layout1->addLayout( layout2 );

    layout2->addStretch( 2 );
    layout2->addWidget( okButton );
    layout2->addStretch( 2 );

    connect( okButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(accept()) );

    init();

    resize( 580, 140  );
}

void
FleetDlg::init()
{
    AttackFleet *curFleet;
    AttackFleetListIterator nextFleet( *fleetList );
    int fleetNumber = 0;
    
    while( (curFleet = nextFleet())) {
        fleetNumber++;
        new FleetDlgListViewItem(fleetTable,
                                 TQString("%1").arg(fleetNumber),
                                 curFleet->destination->getName(),
                                 TQString("%1").arg(curFleet->getShipCount()),
                                 TQString("%1").arg(TDEGlobal::locale()->formatNumber(curFleet->killPercentage, 3)),
                                 TQString("%1").arg((int)ceil(curFleet->arrivalTurn)));
    }
}