[kde-doc-english] [konquest] /: Make messages list dockable.

Alexander Schuch aschuch247 at gmail.com
Sat Nov 16 00:12:32 UTC 2013


Git commit 7b70db8425ef6df8b11098526709547a5cfbda28 by Alexander Schuch.
Committed on 03/11/2013 at 20:29.
Pushed by aschuch into branch 'master'.

Make messages list dockable.

The messages list was always visible and always at the bottom of the game
view. It now is a dockable widget which can be moved to any edge of the
window or even made floating, or closed altogether.

REVIEW: 113596
GUI:

M  +1    -0    Konquest.cc
M  +7    -6    gameview.cc
M  +4    -2    gameview.h
M  +4    -1    konquestui.rc
M  +67   -5    mainwin.cc
M  +10   -0    mainwin.h

http://commits.kde.org/konquest/7b70db8425ef6df8b11098526709547a5cfbda28

diff --git a/Konquest.cc b/Konquest.cc
index fdabc5b..89f9e2f 100644
--- a/Konquest.cc
+++ b/Konquest.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 <kapplication.h>
 #include <klocale.h>
 #include <kcmdlineargs.h>
diff --git a/gameview.cc b/gameview.cc
index 2505994..f67d570 100644
--- a/gameview.cc
+++ b/gameview.cc
@@ -24,6 +24,7 @@
 #include "gameview.h"
 
 #include <QCheckBox>
+#include <QDockWidget>
 #include <QLabel>
 #include <QPushButton>
 #include <QLineEdit>
@@ -51,8 +52,9 @@
  Game Board
 *********************************************************************/
 
-GameView::GameView( QWidget *parent, Game *game )
+GameView::GameView(QWidget *parent, Game *game, QDockWidget *messagesDock)
   : QWidget( parent ),
+    m_messagesDock(messagesDock),
     m_game( game ),
     m_queueMessages(false),
     m_messageQueue(), 
@@ -96,13 +98,13 @@ GameView::GameView( QWidget *parent, Game *game )
     m_mapWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
     m_mapWidget->setFrameShape(QFrame::NoFrame);
 
-    m_msgWidget = new QTextEdit( this );
-    m_msgWidget->setMaximumHeight(75);
+    m_msgWidget = new QTextEdit();
     m_msgWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
     m_msgWidget->setReadOnly(true);
     m_msgWidget->setPalette( blackPal );
     m_msgWidget->setAutoFillBackground( true );
-    m_msgWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+
+    m_messagesDock->setWidget(m_msgWidget);
 
     m_gameMessage = new QLabel( this );
     m_gameMessage->setPalette( palette );
@@ -147,7 +149,6 @@ GameView::GameView( QWidget *parent, Game *game )
 
     mainLayout->addLayout( topLineLayout );
     mainLayout->addWidget( m_mapWidget );
-    mainLayout->addWidget( m_msgWidget );
 
     //**********************************************************************
     // Set up signal/slot connections
@@ -630,7 +631,7 @@ GameView::changeGameView()
 
     kDebug() << "Calling GameView::changeGameView" << isRunning;
 
-    m_msgWidget->setVisible(isRunning);
+    m_messagesDock->setVisible(isRunning);
     m_mapWidget->setVisible(isRunning);
     m_gameMessage->setVisible(isRunning);
     m_standingOrder->setVisible(isRunning);
diff --git a/gameview.h b/gameview.h
index 47b9463..7d8700e 100644
--- a/gameview.h
+++ b/gameview.h
@@ -23,7 +23,6 @@
 #ifndef KONQUEST_GAMEVIEW_H
 #define KONQUEST_GAMEVIEW_H
 
-
 #include <QWidget>
 
 #include "planet.h"
@@ -36,6 +35,7 @@
 //************************************************************************
 
 class QCheckBox;
+class QDockWidget;
 class QLabel;
 class QPushButton;
 class QLineEdit;
@@ -77,7 +77,7 @@ class GameView : public QWidget
     Q_OBJECT
 
 public:
-    explicit  GameView( QWidget *parent, Game *game );
+    explicit  GameView(QWidget *parent, Game *game, QDockWidget *messagesDock);
     virtual  ~GameView();
     bool  confirmNewGame();
 
@@ -133,6 +133,8 @@ private:
     QLabel        *m_splashScreen;
     QTextEdit     *m_msgWidget;
 
+    QDockWidget   *m_messagesDock;
+
     //***************************************************************
     // Game objects
     //***************************************************************
diff --git a/konquestui.rc b/konquestui.rc
index a99d39d..683cd11 100644
--- a/konquestui.rc
+++ b/konquestui.rc
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <gui name="konquest"
-     version="2"
+     version="3"
      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
@@ -12,6 +12,9 @@
   <Action name="game_scores"/>
   <Action name="game_fleets"/>
   </Menu>
+  <Menu name="view"><text>&View</text>
+  <Action name="view_messages"/>
+  </Menu>
 </MenuBar>
 
 <ToolBar name="mainToolBar"><text>Main Toolbar</text>
diff --git a/mainwin.cc b/mainwin.cc
index 6f2a70d..2b4cece 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -19,8 +19,10 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
+
 #include "mainwin.h"
 
+#include <QDockWidget>
 #include <QPushButton>
 #include <QLabel>
 #include <QDebug>
@@ -54,15 +56,21 @@ MainWindow::MainWindow()
     // The status bar.
     m_statusBarText = new QLabel(i18n("Galactic Conquest"));
     statusBar()->addWidget(m_statusBarText);
-
-    resize(600, 650);
 }
 
+
 MainWindow::~MainWindow()
 {
 }
 
 
+QSize
+MainWindow::sizeHint() const
+{
+    return KXmlGuiWindow::sizeHint().expandedTo(QSize(600, 650));
+}
+
+
 void
 MainWindow::setupActions()
 {
@@ -98,6 +106,27 @@ MainWindow::setupActions()
     // Toolbar
     addToolBar ( Qt::LeftToolBarArea, toolBar() );
     toolBar()->setMovable(false);
+
+    // docking area - messages
+
+    m_messagesDock = new QDockWidget(i18n("Messages"), this);
+    m_messagesDock->setObjectName("dock-messages");
+
+    addDockWidget(Qt::BottomDockWidgetArea, m_messagesDock);
+
+    m_messagesAction = actionCollection()->addAction(QLatin1String("view_messages"));
+    m_messagesAction->setText(i18n("Show &Messages"));
+    m_messagesAction->setCheckable(true);
+    m_messagesAction->setChecked(m_messagesDock->isVisible());
+
+    // 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
+    // the GUI, regardless of currently visible in an active tab or invisible
+    // in a not currently active tab.
+
+    connect(m_messagesAction, SIGNAL(triggered(bool)), m_messagesDock, SLOT(setVisible(bool)));
+    connect(m_messagesDock, SIGNAL(visibilityChanged(bool)), this, SLOT(updateMessagesActionSlot()));
 }
 
 
@@ -105,7 +134,7 @@ void
 MainWindow::setupGameView()
 {
     m_game      = new LocalGame( this );
-    m_gameView  = new GameView( this, m_game );
+    m_gameView  = new GameView(this, m_game, m_messagesDock);
     setCentralWidget( m_gameView );
 
     connect ( m_game,    SIGNAL( gameMsg(const KLocalizedString &,
@@ -124,6 +153,29 @@ MainWindow::setupGameView()
     connect(m_endGameAction,  SIGNAL(triggered()),     m_gameView, SLOT(shutdownGame()));
 }
 
+
+void
+MainWindow::setupGUI()
+{
+    KXmlGuiWindow::setupGUI();
+
+    /**
+     * @todo The docks should not be visible on the main screen, and neither
+     * should it be possible to open the docks. During the game and later on,
+     * this is handled by GameView::changeGameView() and by
+     * MainWindow::guiStateChange(). Just the initial setup does not work that
+     * way. - Rework the GUI setup sequence so that the following hack is not
+     * required.
+     */
+
+    m_messagesAction->setEnabled(false);
+
+    m_messagesDock->toggleViewAction()->setEnabled(false);
+
+    m_messagesDock->hide();
+}
+
+
 void
 MainWindow::startNewGame()
 {
@@ -139,8 +191,7 @@ MainWindow::startNewGame()
 void
 MainWindow::guiStateChange( GUIState newState )
 {
-    if (newState == NONE)
-    {
+    if (newState == NONE) {
         m_gameView->deleteLater();
         m_game->deleteLater();
         this->setupGameView();
@@ -163,5 +214,16 @@ MainWindow::guiStateChange( GUIState newState )
     m_standingAction->setEnabled( newState == SOURCE_PLANET );
     m_fleetAction   ->setEnabled( newState == SOURCE_PLANET );
 
+    m_messagesAction->setEnabled(m_game->isRunning());
+
+    m_messagesDock->toggleViewAction()->setEnabled(m_game->isRunning());
+
     m_statusBarText->setText(i18n("Turn # %1", m_game->turnCounter()));
 }
+
+
+void
+MainWindow::updateMessagesActionSlot()
+{
+    m_messagesAction->setChecked(m_messagesDock->toggleViewAction()->isChecked());
+}
diff --git a/mainwin.h b/mainwin.h
index c50ea80..663177b 100644
--- a/mainwin.h
+++ b/mainwin.h
@@ -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_MAINWIN_H
 #define KONQUEST_MAINWIN_H
 
@@ -29,6 +30,8 @@
 #include "gameview.h"
 
 class QAction;
+class QDockWidget;
+
 
 class MainWindow : public KXmlGuiWindow
 {
@@ -38,13 +41,17 @@ public:
     MainWindow();
     ~MainWindow();
 
+    QSize sizeHint() const;
+
 private:
     void setupActions();
     void setupGameView();
+    void setupGUI();
 
 private slots:
     void guiStateChange( GUIState );
     void startNewGame();
+    void updateMessagesActionSlot();
 
 private:
     // Widgets
@@ -54,11 +61,14 @@ private:
 
     // Actions
     KAction  *m_endTurnAction;
+    KAction  *m_messagesAction;
 
     QAction  *m_endGameAction;
     QAction  *m_measureAction;
     QAction  *m_standingAction;
     QAction  *m_fleetAction;
+
+    QDockWidget *m_messagesDock;
 };
 
 #endif // KONQUEST_MAINWIN_H


More information about the kde-doc-english mailing list