[kde-doc-english] [konquest] /: Make "current standings" dialogue dockable.

Alexander Schuch aschuch247 at gmail.com
Sun Nov 24 18:35:41 UTC 2013


Git commit 6e75b6b27923d8adbc1dc65c20ec65b9679d1617 by Alexander Schuch.
Committed on 10/11/2013 at 03:27.
Pushed by aschuch into branch 'master'.

Make "current standings" dialogue dockable.

The dialogue "current standings" is replaced by a dockable widget. This way
the player is able to see the standings all the time without the need to
open/close the dialogue at the beginning of each turn.

The dockable widget can also be made floating, so it can be used almost the
same as the modal dialogue before.

REVIEW: 113782
GUI:

M  +2    -0    CMakeLists.txt
M  +4    -60   dialogs/scoredlg.cc
M  +3    -5    dialogs/scoredlg.h
M  +47   -13   gameview.cc
M  +8    -5    gameview.h
M  +3    -3    konquestui.rc
M  +33   -9    mainwin.cc
M  +3    -1    mainwin.h
C  +92   -37   view/standingswidget.cpp [from: dialogs/scoredlg.cc - 055% similarity]
C  +17   -13   view/standingswidget.h [from: dialogs/scoredlg.h - 067% similarity]     [License: GPL]

http://commits.kde.org/konquest/6e75b6b27923d8adbc1dc65c20ec65b9679d1617

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b321ad..a20ce0b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,6 +56,8 @@ set(konquest_SRCS
     players/player_gui.cpp
     players/spectatorplayer.cpp
     players/spectatorplayer_gui.cpp
+
+    view/standingswidget.cpp
 )
 
 kde4_add_ui_files(konquest_SRCS dialogs/newGameDialog.ui )
diff --git a/dialogs/scoredlg.cc b/dialogs/scoredlg.cc
index 5e66cd4..e0f05a7 100644
--- a/dialogs/scoredlg.cc
+++ b/dialogs/scoredlg.cc
@@ -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.
  */
+
 #include "scoredlg.h"
 
 #include <klocale.h>
@@ -29,77 +30,20 @@
 #include <QHeaderView>
 
 ScoreDlg::ScoreDlg( QWidget *parent, const QString& title, QList<Player *> players )
-    : KDialog(parent), m_players(players)
+    : KDialog(parent)
 {
     setObjectName( QLatin1String( "ScoreDlg" ) );
     setModal( true );
     setCaption(title);
     setButtons( KDialog::Ok );
 
-    // Create the table.
-    m_scoreTable = new QTableWidget( this );
-    m_scoreTable->setColumnCount(6);
-    QStringList headers;
-    headers << i18nc("The player name", "Player") << i18n("Ships\nBuilt") 
-	    << i18n("Planets\nConquered") << i18n("Fleets\nLaunched")
-	    << i18n("Fleets\nDestroyed") << i18n("Ships\nDestroyed");
-    m_scoreTable->setHorizontalHeaderLabels(headers);
-    m_scoreTable->verticalHeader()->hide();
-    init();
+    m_scoreTable = new StandingsWidget(this, players);
 
-    m_scoreTable->setMinimumSize( m_scoreTable->sizeHint() );
-    m_scoreTable->setSelectionMode( QAbstractItemView::NoSelection );
-    m_scoreTable->setSortingEnabled(true);
-    
     setMainWidget( m_scoreTable );
     connect( this, SIGNAL(okClicked()), this, SLOT(accept()) );
-
-    resize( 580, 140  );
-}
-
-ScoreDlg::~ScoreDlg()
-{
 }
 
 
-void
-ScoreDlg::init()
+ScoreDlg::~ScoreDlg()
 {
-    m_scoreTable->setRowCount(m_players.count());
-    int row = 0;
-    
-    QTableWidgetItem *item;
-    foreach (Player *curPlayer, m_players) {
-        item = new QTableWidgetItem(curPlayer->name());
-        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-        m_scoreTable->setItem(row, 0, item);
-        
-        item = new QTableWidgetItem();
-        item->setData(Qt::DisplayRole, curPlayer->shipsBuilt());
-        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-        m_scoreTable->setItem(row, 1, item);
-        
-        item = new QTableWidgetItem();
-        item->setData(Qt::DisplayRole, curPlayer->planetsConquered());
-        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-        m_scoreTable->setItem(row, 2, item);
-        
-        item = new QTableWidgetItem();
-        item->setData(Qt::DisplayRole, curPlayer->fleetsLaunched());
-        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-        m_scoreTable->setItem(row, 3, item);
-        
-        item = new QTableWidgetItem();
-        item->setData(Qt::DisplayRole, curPlayer->enemyFleetsDestroyed());
-        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-        m_scoreTable->setItem(row, 4, item);
-        
-        item = new QTableWidgetItem();
-        item->setData(Qt::DisplayRole, curPlayer->enemyShipsDestroyed());
-        item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
-        m_scoreTable->setItem(row, 5, item);
-        
-        row++;
-    }
 }
-
diff --git a/dialogs/scoredlg.h b/dialogs/scoredlg.h
index bda18a5..1495d46 100644
--- a/dialogs/scoredlg.h
+++ b/dialogs/scoredlg.h
@@ -19,14 +19,15 @@
     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_SCOREDLG_H
 #define KONQUEST_SCOREDLG_H
 
-
 #include <QTableWidget>
 #include <KDialog>
 
 #include "../players/player.h"
+#include "../view/standingswidget.h"
 
 
 class ScoreDlg : public KDialog
@@ -38,10 +39,7 @@ public:
     ~ScoreDlg();
 
 private:
-    void init();
-
-    QList<Player *>  m_players;
-    QTableWidget     *m_scoreTable;
+    StandingsWidget *m_scoreTable;
 
 };
 
diff --git a/gameview.cc b/gameview.cc
index f67d570..c68e988 100644
--- a/gameview.cc
+++ b/gameview.cc
@@ -46,15 +46,18 @@
 #include "dialogs/scoredlg.h"
 #include "dialogs/fleetdlg.h"
 
+#include "view/standingswidget.h"
+
 #include <cmath>
 
 /*********************************************************************
  Game Board
 *********************************************************************/
 
-GameView::GameView(QWidget *parent, Game *game, QDockWidget *messagesDock)
+GameView::GameView(QWidget *parent, Game *game, QDockWidget *messagesDock, QDockWidget *standingsDock)
   : QWidget( parent ),
     m_messagesDock(messagesDock),
+    m_standingsDock(standingsDock),
     m_game( game ),
     m_queueMessages(false),
     m_messageQueue(), 
@@ -106,6 +109,9 @@ GameView::GameView(QWidget *parent, Game *game, QDockWidget *messagesDock)
 
     m_messagesDock->setWidget(m_msgWidget);
 
+    m_standingsWidget = new StandingsWidget(0);
+    m_standingsDock->setWidget(m_standingsWidget);
+
     m_gameMessage = new QLabel( this );
     m_gameMessage->setPalette( palette );
 
@@ -249,6 +255,20 @@ GameView::keyPressEvent( QKeyEvent *e )
 //************************************************************************
 // Game engine/state machine
 //************************************************************************
+
+/**
+ * Prepare the turn for a local player by updating the informational widgets.
+ */
+
+void
+GameView::turnPreparation()
+{
+    m_standingsWidget->update(m_game->players());
+
+    turn();
+}
+
+
 void
 GameView::turn()
 {
@@ -474,7 +494,7 @@ GameView::startNewGame()
 
         LocalPlayer *local = qobject_cast<LocalPlayer*>(player);
         if (local)
-            connect(local, SIGNAL(canPlay()), this, SLOT(turn()));
+            connect(local, SIGNAL(canPlay()), this, SLOT(turnPreparation()));
     }
 
     connect(m_game, SIGNAL(finished()), this, SLOT(gameOver()));
@@ -523,11 +543,23 @@ GameView::shutdownGame()
 void
 GameView::gameOver()
 {
-    if(m_initCompleted){
+    if (m_initCompleted) {
         kDebug() << "Game over";
-        ScoreDlg *scoreDlg = new ScoreDlg( this, i18n("Final Standings"),
-                                            m_game->players() );
+
+        /**
+         * @todo This is an attempt to remove duplicate information from screen.
+         * It is not a final solution, but only the best we came up with. The
+         * problem is that the messages cannot be seen anymore, so the player
+         * cannot check what happened last. Furthermore, this sudden change of
+         * the GUI setup can be confusing for players.
+         */
+
+        m_messagesDock->hide();
+        m_standingsDock->hide();
+
+        ScoreDlg *scoreDlg = new ScoreDlg(this, i18n("Final Standings"), m_game->players());
         scoreDlg->exec();
+        scoreDlg->deleteLater();
 
         cleanupGame();
     }
@@ -535,6 +567,7 @@ GameView::gameOver()
         m_cleanupNeeded = true;
 }
 
+
 void
 GameView::cleanupGame()
 {
@@ -632,6 +665,15 @@ GameView::changeGameView()
     kDebug() << "Calling GameView::changeGameView" << isRunning;
 
     m_messagesDock->setVisible(isRunning);
+
+    if (!isRunning) {
+
+        // Only hide the standings dock if the game is not running, but do not
+        // automatically show it as soon as the game is running.
+
+        m_standingsDock->hide();
+    }
+
     m_mapWidget->setVisible(isRunning);
     m_gameMessage->setVisible(isRunning);
     m_standingOrder->setVisible(isRunning);
@@ -678,14 +720,6 @@ GameView::measureDistance()
     }
 }
 
-void
-GameView::showScores()
-{
-    ScoreDlg *scoreDlg = new ScoreDlg( this, i18n("Current Standings"),
-                                       m_game->players() );
-    scoreDlg->exec();
-    scoreDlg->deleteLater();
-}
 
 void
 GameView::showFleets()
diff --git a/gameview.h b/gameview.h
index 7d8700e..3678226 100644
--- a/gameview.h
+++ b/gameview.h
@@ -29,7 +29,6 @@
 #include "players/player.h"
 #include "game.h"
 
-
 //************************************************************************
 // forward declarations
 //************************************************************************
@@ -48,6 +47,7 @@ class Player;
 class MapView;
 class MapScene;
 class GameLogic;
+class StandingsWidget;
 
 
 struct GameMessage {
@@ -77,7 +77,7 @@ class GameView : public QWidget
     Q_OBJECT
 
 public:
-    explicit  GameView(QWidget *parent, Game *game, QDockWidget *messagesDock);
+    explicit  GameView(QWidget *parent, Game *game, QDockWidget *messagesDock, QDockWidget *standingsDock);
     virtual  ~GameView();
     bool  confirmNewGame();
 
@@ -92,14 +92,13 @@ protected slots:
     // Toolbar items
     //***************************************************************
     void  measureDistance();
-    void  showScores();
     void  showFleets();
 
 public slots:
     void  startNewGame();
     void  gameMsg(const KLocalizedString &msg, Player *player = 0,
 		  Planet *planet = 0, Player *planetPlayer = 0);
-    void  turn();
+    void  turnPreparation();
 
 signals:
     void  newGUIState( GUIState newState );
@@ -117,7 +116,8 @@ private slots:
 private:
     void  changeGameView();
     void  cleanupGame();
-    
+
+    void  turn();
 
     //***************************************************************
     // Display Widgets
@@ -133,7 +133,10 @@ private:
     QLabel        *m_splashScreen;
     QTextEdit     *m_msgWidget;
 
+    StandingsWidget *m_standingsWidget;
+
     QDockWidget   *m_messagesDock;
+    QDockWidget   *m_standingsDock;
 
     //***************************************************************
     // Game objects
diff --git a/konquestui.rc b/konquestui.rc
index 683cd11..baee7c1 100644
--- a/konquestui.rc
+++ b/konquestui.rc
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gui name="konquest"
-     version="3"
+     version="4"
      xmlns="http://www.kde.org/standards/kxmlgui/1.0"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0
@@ -9,11 +9,11 @@
 <MenuBar>
   <Menu name="game"><text>&Game</text>
   <Action name="game_measure"/>
-  <Action name="game_scores"/>
   <Action name="game_fleets"/>
   </Menu>
   <Menu name="view"><text>&View</text>
   <Action name="view_messages"/>
+  <Action name="view_standings"/>
   </Menu>
 </MenuBar>
 
@@ -24,7 +24,7 @@
   <Action name="move_end_turn"/>
   <Separator/>
   <Action name="game_measure"/>
-  <Action name="game_scores"/>
+  <Action name="view_standings"/>
   <Action name="game_fleets"/>
 </ToolBar>
 
diff --git a/mainwin.cc b/mainwin.cc
index 2b4cece..296a30e 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -91,12 +91,6 @@ MainWindow::setupActions()
     m_measureAction->setText( i18n("&Measure Distance") );
     m_measureAction->setEnabled(false);
 
-    // Show standings
-    m_standingAction = actionCollection()->addAction( QLatin1String(  "game_scores" ) );
-    m_standingAction->setIcon( KIcon( QLatin1String( "help-contents" )) );
-    m_standingAction->setText( i18n("&Show Standings") );
-    m_standingAction->setEnabled(false);
-
     // Show fleet overview
     m_fleetAction = actionCollection()->addAction( QLatin1String(  "game_fleets" ) );
     m_fleetAction->setIcon( KIcon( QLatin1String( "fork" )) );
@@ -119,6 +113,10 @@ MainWindow::setupActions()
     m_messagesAction->setCheckable(true);
     m_messagesAction->setChecked(m_messagesDock->isVisible());
 
+    // The action signal "toggled" is fired even in case the state is changed
+    // via code using setChecked(). "triggered" however is only fired if the
+    // user actually triggered the change.
+
     // The dock signal "visibilityChanged" is fired if the dock is shown or
     // hidden. But this includes hidden in a tab as well. The action should not
     // represent the visibility state, but if the dock is present somewhere in
@@ -127,6 +125,22 @@ MainWindow::setupActions()
 
     connect(m_messagesAction, SIGNAL(triggered(bool)), m_messagesDock, SLOT(setVisible(bool)));
     connect(m_messagesDock, SIGNAL(visibilityChanged(bool)), this, SLOT(updateMessagesActionSlot()));
+
+    // docking area - standings
+
+    m_standingsDock = new QDockWidget(i18n("Standings"), this);
+    m_standingsDock->setObjectName("dock-standings");
+
+    tabifyDockWidget(m_messagesDock, m_standingsDock);
+
+    m_standingsAction = actionCollection()->addAction(QLatin1String("view_standings"));
+    m_standingsAction->setIcon(KIcon(QLatin1String("help-contents")));
+    m_standingsAction->setText(i18n("Show &Standings"));
+    m_standingsAction->setCheckable(true);
+    m_standingsAction->setChecked(m_standingsDock->isVisible());
+
+    connect(m_standingsAction, SIGNAL(triggered(bool)), m_standingsDock, SLOT(setVisible(bool)));
+    connect(m_standingsDock, SIGNAL(visibilityChanged(bool)), this, SLOT(updateStandingsActionSlot()));
 }
 
 
@@ -134,7 +148,7 @@ void
 MainWindow::setupGameView()
 {
     m_game      = new LocalGame( this );
-    m_gameView  = new GameView(this, m_game, m_messagesDock);
+    m_gameView  = new GameView(this, m_game, m_messagesDock, m_standingsDock);
     setCentralWidget( m_gameView );
 
     connect ( m_game,    SIGNAL( gameMsg(const KLocalizedString &,
@@ -147,7 +161,6 @@ MainWindow::setupGameView()
 	     this,       SLOT( guiStateChange( GUIState ) ) );
 
     connect(m_measureAction,  SIGNAL(triggered(bool)), m_gameView, SLOT( measureDistance() ));
-    connect(m_standingAction, SIGNAL(triggered(bool)), m_gameView, SLOT( showScores() ));
     connect(m_fleetAction,    SIGNAL(triggered(bool)), m_gameView, SLOT( showFleets() ));
     connect(m_endTurnAction,  SIGNAL(triggered()),     m_gameView, SLOT(nextPlayer()));
     connect(m_endGameAction,  SIGNAL(triggered()),     m_gameView, SLOT(shutdownGame()));
@@ -169,10 +182,13 @@ MainWindow::setupGUI()
      */
 
     m_messagesAction->setEnabled(false);
+    m_standingsAction->setEnabled(false);
 
     m_messagesDock->toggleViewAction()->setEnabled(false);
+    m_standingsDock->toggleViewAction()->setEnabled(false);
 
     m_messagesDock->hide();
+    m_standingsDock->hide();
 }
 
 
@@ -211,12 +227,13 @@ MainWindow::guiStateChange( GUIState newState )
     m_endTurnAction ->setEnabled( m_game->isRunning() && (newState == SOURCE_PLANET) );
     m_endGameAction ->setEnabled( m_game->isRunning() );
     m_measureAction ->setEnabled( newState == SOURCE_PLANET );
-    m_standingAction->setEnabled( newState == SOURCE_PLANET );
     m_fleetAction   ->setEnabled( newState == SOURCE_PLANET );
 
     m_messagesAction->setEnabled(m_game->isRunning());
+    m_standingsAction->setEnabled(m_game->isRunning());
 
     m_messagesDock->toggleViewAction()->setEnabled(m_game->isRunning());
+    m_standingsDock->toggleViewAction()->setEnabled(m_game->isRunning());
 
     m_statusBarText->setText(i18n("Turn # %1", m_game->turnCounter()));
 }
@@ -227,3 +244,10 @@ MainWindow::updateMessagesActionSlot()
 {
     m_messagesAction->setChecked(m_messagesDock->toggleViewAction()->isChecked());
 }
+
+
+void
+MainWindow::updateStandingsActionSlot()
+{
+    m_standingsAction->setChecked(m_standingsDock->toggleViewAction()->isChecked());
+}
diff --git a/mainwin.h b/mainwin.h
index 663177b..1bc67e6 100644
--- a/mainwin.h
+++ b/mainwin.h
@@ -52,6 +52,7 @@ private slots:
     void guiStateChange( GUIState );
     void startNewGame();
     void updateMessagesActionSlot();
+    void updateStandingsActionSlot();
 
 private:
     // Widgets
@@ -62,13 +63,14 @@ private:
     // Actions
     KAction  *m_endTurnAction;
     KAction  *m_messagesAction;
+    KAction  *m_standingsAction;
 
     QAction  *m_endGameAction;
     QAction  *m_measureAction;
-    QAction  *m_standingAction;
     QAction  *m_fleetAction;
 
     QDockWidget *m_messagesDock;
+    QDockWidget *m_standingsDock;
 };
 
 #endif // KONQUEST_MAINWIN_H
diff --git a/dialogs/scoredlg.cc b/view/standingswidget.cpp
similarity index 55%
copy from dialogs/scoredlg.cc
copy to view/standingswidget.cpp
index 5e66cd4..0063292 100644
--- a/dialogs/scoredlg.cc
+++ b/view/standingswidget.cpp
@@ -4,6 +4,7 @@
     Copyright 2006 Dmitry Suzdalev <dimsuz at gmail.com>
     Copyright 2006 Inge Wallin <inge at lysator.liu.se>
     Copyright 2006 Pierre Ducroquet <pinaraf at gmail.com>
+    Copyright 2013 Alexander Schuch <aschuch247 at gmail.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -19,87 +20,141 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
-#include "scoredlg.h"
+
+#include "standingswidget.h"
+
+#include <QHeaderView>
+#include <QTableWidget>
+#include <QVBoxLayout>
 
 #include <klocale.h>
 #include <kcomponentdata.h>
 #include <KStandardGuiItem>
 #include <kguiitem.h>
 
-#include <QHeaderView>
 
-ScoreDlg::ScoreDlg( QWidget *parent, const QString& title, QList<Player *> players )
-    : KDialog(parent), m_players(players)
+StandingsWidget::StandingsWidget(QWidget *parent) :
+    QWidget(parent)
 {
-    setObjectName( QLatin1String( "ScoreDlg" ) );
-    setModal( true );
-    setCaption(title);
-    setButtons( KDialog::Ok );
+    setupTable();
+}
 
-    // Create the table.
-    m_scoreTable = new QTableWidget( this );
-    m_scoreTable->setColumnCount(6);
-    QStringList headers;
-    headers << i18nc("The player name", "Player") << i18n("Ships\nBuilt") 
-	    << i18n("Planets\nConquered") << i18n("Fleets\nLaunched")
-	    << i18n("Fleets\nDestroyed") << i18n("Ships\nDestroyed");
-    m_scoreTable->setHorizontalHeaderLabels(headers);
-    m_scoreTable->verticalHeader()->hide();
-    init();
 
-    m_scoreTable->setMinimumSize( m_scoreTable->sizeHint() );
-    m_scoreTable->setSelectionMode( QAbstractItemView::NoSelection );
-    m_scoreTable->setSortingEnabled(true);
-    
-    setMainWidget( m_scoreTable );
-    connect( this, SIGNAL(okClicked()), this, SLOT(accept()) );
+/**
+ * @note Use "delegating constructor" once C++11 is required by KDE.
+ */
+
+StandingsWidget::StandingsWidget(QWidget *parent, const QList<Player *> players) :
+    // StandingsWidget(parent)
+    QWidget(parent)
+{
+    setupTable();
+    update(players);
+}
+
 
-    resize( 580, 140  );
+StandingsWidget::~StandingsWidget()
+{
 }
 
-ScoreDlg::~ScoreDlg()
+
+QSize
+StandingsWidget::sizeHint() const
 {
+    int w = m_scoreTable->verticalHeader()->width();
+    int h = m_scoreTable->horizontalHeader()->height();
+
+    for (int col = 0; col < m_scoreTable->columnCount(); ++col) {
+        w += m_scoreTable->columnWidth(col);
+    }
+
+    for (int row = 0; row < m_scoreTable->rowCount(); ++row ) {
+        h += m_scoreTable->rowHeight(row);
+    }
+
+    /**
+     * @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!
+     */
+
+    return QSize(w, h) + QSize(20, 40);
 }
 
 
 void
-ScoreDlg::init()
+StandingsWidget::update(const QList<Player *> players )
 {
-    m_scoreTable->setRowCount(m_players.count());
+    m_scoreTable->setRowCount(players.count());
+    m_scoreTable->clearContents();
+
+    m_scoreTable->setSortingEnabled(false);
+
     int row = 0;
-    
+
     QTableWidgetItem *item;
-    foreach (Player *curPlayer, m_players) {
+
+    foreach (Player *curPlayer, players) {
         item = new QTableWidgetItem(curPlayer->name());
         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
         m_scoreTable->setItem(row, 0, item);
-        
+
         item = new QTableWidgetItem();
         item->setData(Qt::DisplayRole, curPlayer->shipsBuilt());
         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
         m_scoreTable->setItem(row, 1, item);
-        
+
         item = new QTableWidgetItem();
         item->setData(Qt::DisplayRole, curPlayer->planetsConquered());
         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
         m_scoreTable->setItem(row, 2, item);
-        
+
         item = new QTableWidgetItem();
         item->setData(Qt::DisplayRole, curPlayer->fleetsLaunched());
         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
         m_scoreTable->setItem(row, 3, item);
-        
+
         item = new QTableWidgetItem();
         item->setData(Qt::DisplayRole, curPlayer->enemyFleetsDestroyed());
         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
         m_scoreTable->setItem(row, 4, item);
-        
+
         item = new QTableWidgetItem();
         item->setData(Qt::DisplayRole, curPlayer->enemyShipsDestroyed());
         item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable);
         m_scoreTable->setItem(row, 5, item);
-        
-        row++;
+
+        ++row;
     }
+
+    m_scoreTable->setSortingEnabled(true);
+    m_scoreTable->resizeColumnsToContents();
 }
 
+
+void
+StandingsWidget::setupTable()
+{
+    setObjectName(QLatin1String("widget-standings"));
+
+    QVBoxLayout *main = new QVBoxLayout(this);
+
+    m_scoreTable = new QTableWidget();
+    m_scoreTable->setColumnCount(6);
+    m_scoreTable->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
+    m_scoreTable->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
+    m_scoreTable->setSelectionMode(QAbstractItemView::NoSelection);
+
+    QStringList headers;
+    headers
+        << i18nc("The player name", "Player")
+        << i18n("Ships\nBuilt")
+        << i18n("Planets\nConquered")
+        << i18n("Fleets\nLaunched")
+        << i18n("Fleets\nDestroyed")
+        << i18n("Ships\nDestroyed");
+    m_scoreTable->setHorizontalHeaderLabels(headers);
+    m_scoreTable->verticalHeader()->hide();
+
+    main->addWidget(m_scoreTable);
+}
diff --git a/dialogs/scoredlg.h b/view/standingswidget.h
similarity index 67%
copy from dialogs/scoredlg.h
copy to view/standingswidget.h
index bda18a5..e0b6687 100644
--- a/dialogs/scoredlg.h
+++ b/view/standingswidget.h
@@ -4,6 +4,7 @@
     Copyright 2006 Dmitry Suzdalev <dimsuz at gmail.com>
     Copyright 2006 Inge Wallin <inge at lysator.liu.se>
     Copyright 2006 Pierre Ducroquet <pinaraf at gmail.com>
+    Copyright 2013 Alexander Schuch <aschuch247 at gmail.com>
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -19,30 +20,33 @@
     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_SCOREDLG_H
-#define KONQUEST_SCOREDLG_H
 
+#ifndef KONQUEST_STANDINGSWIDGET_H
+#define KONQUEST_STANDINGSWIDGET_H
 
-#include <QTableWidget>
-#include <KDialog>
+#include <QWidget>
 
 #include "../players/player.h"
 
 
-class ScoreDlg : public KDialog
+class QTableWidget;
+
+
+class StandingsWidget : public QWidget
 {
 
 public:
-    ScoreDlg( QWidget *parent, const QString& title, 
-              QList<Player *> players );
-    ~ScoreDlg();
+    explicit StandingsWidget(QWidget *parent);
+    explicit StandingsWidget(QWidget *parent, const QList<Player *> players);
+    ~StandingsWidget();
 
-private:
-    void init();
+    QSize sizeHint() const;
+    void update(const QList<Player *> players);
 
-    QList<Player *>  m_players;
-    QTableWidget     *m_scoreTable;
+private:
+    void setupTable();
 
+    QTableWidget *m_scoreTable;
 };
 
-#endif // KONQUEST_SCOREDLG_H
+#endif // KONQUEST_STANDINGSWIDGET_H


More information about the kde-doc-english mailing list