Commit 8e48e525 authored by Alexander Schuch's avatar Alexander Schuch
Browse files

Update fleet overview dialogue.

The fleet overview dialogue is not resized to a constant size anymore, and
automatically adopts to the number of (own) attack fleets. Numbers shown in
that dialogue are handled as numbers now rather than as strings so that
they are sorted properly (1, 2, 10, 20 instead of 1, 10, 2, 20). They are
as well aligned to the right so that they are nicer to read. The source and
destination planet fields show the player colour of the owner now.

The structure resembles the one of the standings widget and this indeed
is a first step of converting the dialogue into a dockable widget.

REVIEW: 114735
GUI:
parent 2ba94f6c
......@@ -22,8 +22,8 @@
#include "fleetdlg.h"
#include <QTableWidget>
#include <QHeaderView>
#include <QTableWidget>
#include <kcomponentdata.h>
#include <kglobal.h>
......@@ -33,6 +33,8 @@
#include <klocale.h>
#include "planet.h"
#include "../players/player.h"
FleetDlg::FleetDlg( QWidget *parent,
const AttackFleetList &fleets,
......@@ -45,6 +47,59 @@ FleetDlg::FleetDlg( QWidget *parent,
setCaption( i18n("Fleet Overview") );
setButtons( KDialog::Ok );
setupTable();
update();
setMainWidget( m_fleetTable );
connect( this, SIGNAL(okClicked()), this, SLOT(accept()) );
}
QSize
FleetDlg::sizeHint() const
{
int w = m_fleetTable->verticalHeader()->width();
int h = m_fleetTable->horizontalHeader()->height();
for (int col = 0; col < m_fleetTable->columnCount(); ++col) {
w += m_fleetTable->columnWidth(col);
}
for (int row = 0; row < m_fleetTable->rowCount(); ++row) {
h += m_fleetTable->rowHeight(row);
}
/**
* @todo The created dialogue should not be larger than the screen, and
* ideally, it should not be larger than the main application window.
* As the vertical main application window size is not (yet) known here,
* simply use a hard-coded limit right now.
*/
if (h > 480) {
// As the height of the widget is reduced, a vertical scrollbar is
// shown. Add the width of that scrollbar to the width of the widget to
// prevent a horizontal scrollbar from appearing.
h = 480;
w += m_fleetTable->style()->pixelMetric(QStyle::PM_ScrollBarExtent);
}
/**
* @todo The size calculated here does not yet prevent scrollbars to be
* shown for the table. Figure out the offsets needed to be added and remove
* the hard-coded numbers below! One reason here is that this size hint is
* for the whole dialogue and not just for the table.
*/
return QSize(w, h) + QSize(40, 80);
}
void
FleetDlg::setupTable()
{
m_fleetTable = new QTableWidget(this);
m_fleetTable->setColumnCount(7);
m_fleetTable->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
......@@ -60,76 +115,87 @@ FleetDlg::FleetDlg( QWidget *parent,
<< i18n("Ships")
<< i18n("Kill Percentage")
<< i18n("Arrival Turn");
m_fleetTable->setHorizontalHeaderLabels(headerLabels);
m_fleetTable->verticalHeader()->hide();
m_fleetTable->setMinimumSize( m_fleetTable->sizeHint() );
setMainWidget( m_fleetTable );
connect( this, SIGNAL(okClicked()), this, SLOT(accept()) );
init();
resize( 580, 140 );
m_fleetTable->setSortingEnabled(true);
m_fleetTable->sortItems( 1, Qt::AscendingOrder );
}
void
FleetDlg::init()
FleetDlg::update()
{
AttackFleet *curFleet=0;
AttackFleetList fleets = m_standingOrders + m_newFleetList + m_fleetList;
const int standingOrders = m_standingOrders.count();
const int newFleets = standingOrders + m_newFleetList.count();
m_fleetTable->setRowCount( fleets.count() );
QTableWidgetItem *item;
for( int f = 0; f < fleets.count(); ++f) {
curFleet = fleets.at(f);
int row = 0;
QTableWidgetItem *item;
foreach (AttackFleet *curFleet, fleets) {
item = new QTableWidgetItem();
if( f < newFleets) {
if( row < newFleets) {
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
item->setCheckState(Qt::Checked);
if( f < standingOrders )
if( row < standingOrders )
item->setText(i18n("Standing order"));
} else {
item->setFlags(Qt::ItemIsEnabled);
}
m_fleetTable->setItem( f, 0, item );
m_fleetTable->setItem(row, 0, item);
item = new QTableWidgetItem(QString::number(f + 1));
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, row + 1);
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled);
m_fleetTable->setItem( f, 1, item );
m_fleetTable->setItem(row, 1, item);
item = new QTableWidgetItem(curFleet->source->name());
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curFleet->source->name());
item->setData(Qt::DecorationRole, curFleet->source->player()->color());
item->setFlags(Qt::ItemIsEnabled);
m_fleetTable->setItem( f, 2, item );
m_fleetTable->setItem(row, 2, item);
item = new QTableWidgetItem(curFleet->destination->name());
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curFleet->destination->name());
item->setData(Qt::DecorationRole, curFleet->destination->player()->color());
item->setFlags(Qt::ItemIsEnabled);
m_fleetTable->setItem( f, 3, item );
m_fleetTable->setItem(row, 3, item);
item = new QTableWidgetItem(QString::number(curFleet->shipCount()));
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curFleet->shipCount());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled);
m_fleetTable->setItem( f, 4, item );
m_fleetTable->setItem(row, 4, item);
// The number is formatted and added as a string. Sorting by this
// column sorts by string comparison rather than by floating point
// number comparison. But as all values have the same amount of
// characters/digits, sorting by string actually works.
item = new QTableWidgetItem(QString("%1") .arg(KGlobal::locale()->formatNumber(curFleet->source->killPercentage(), 3)));
item = new QTableWidgetItem(QString("%1").arg(KGlobal::locale()->formatNumber(curFleet->source->killPercentage(), 3)));
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled);
m_fleetTable->setItem( f, 5, item );
m_fleetTable->setItem(row, 5, item);
item = new QTableWidgetItem(QString::number(curFleet->arrivalTurn));
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curFleet->arrivalTurn);
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled);
m_fleetTable->setItem( f, 6, item );
m_fleetTable->setItem(row, 6, item);
++row;
}
m_fleetTable->setSortingEnabled(true);
m_fleetTable->resizeColumnsToContents();
}
AttackFleetList *FleetDlg::uncheckedFleets() {
AttackFleetList*
FleetDlg::uncheckedFleets()
{
AttackFleetList *fleets = new AttackFleetList();
QTableWidgetItem *item;
int count = m_fleetTable->rowCount();
......
......@@ -19,6 +19,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KONQUEST_FLEETDLG_H
#define KONQUEST_FLEETDLG_H
......@@ -28,6 +29,7 @@
class QTableWidget;
class FleetDlg : public KDialog
{
public:
......@@ -37,8 +39,11 @@ public:
const AttackFleetList &standingOrders );
AttackFleetList *uncheckedFleets();
QSize sizeHint() const;
private:
void init();
void update();
void setupTable();
AttackFleetList m_newFleetList;
AttackFleetList m_standingOrders;
......@@ -46,5 +51,4 @@ private:
QTableWidget *m_fleetTable;
};
#endif // KONQUEST_FLEETDLG_H
......@@ -68,7 +68,7 @@ StandingsWidget::sizeHint() const
w += m_standingsTable->columnWidth(col);
}
for (int row = 0; row < m_standingsTable->rowCount(); ++row ) {
for (int row = 0; row < m_standingsTable->rowCount(); ++row) {
h += m_standingsTable->rowHeight(row);
}
......@@ -78,7 +78,7 @@ StandingsWidget::sizeHint() const
* the hard-coded numbers below!
*/
return QSize(w, h) + QSize(20, 40);
return QSize(w, h) + QSize(m_standingsTable->columnCount() - 1, 40);
}
......@@ -87,60 +87,58 @@ StandingsWidget::update(const QList<Player *> players )
{
m_standingsTable->setRowCount(players.count());
m_standingsTable->clearContents();
m_standingsTable->setSortingEnabled(false);
int row = 0;
QTableWidgetItem *item;
foreach (Player *curPlayer, players) {
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->name());
item->setData(Qt::DecorationRole, curPlayer->color());
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 0, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->shipsBuilt());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 1, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->planetsConquered());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 2, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->fleetsLaunched());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 3, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->enemyFleetsDestroyed());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 4, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->enemyShipsDestroyed());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 5, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->turnProduction());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 6, item);
item = new QTableWidgetItem();
item->setData(Qt::DisplayRole, curPlayer->turnShips());
item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
item->setFlags(Qt::ItemIsEnabled);
m_standingsTable->setItem(row, 7, item);
++row;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment