QTfrontend/pagetraining.cpp
changeset 6052 5e3e7d19bdb5
parent 6050 07561ade87ca
child 6054 d3751a18cecb
--- a/QTfrontend/pagetraining.cpp	Tue Sep 27 05:08:23 2011 +0200
+++ b/QTfrontend/pagetraining.cpp	Tue Sep 27 16:14:35 2011 +0200
@@ -17,6 +17,7 @@
  */
 
 #include <QGridLayout>
+#include <QVBoxLayout>
 #include <QLabel>
 #include <QListWidget>
 #include <QListWidgetItem>
@@ -32,44 +33,72 @@
 // left column
 
     // declare start button, caption and description
-    btnStart = formattedButton(":/res/Trainings.png", true);
-    btnStart->setToolTip(QPushButton::tr("Go!"));
-    lblCaption = new QLabel(this);
-    lblDescription = new QLabel(this);
-    lblDescription->setWordWrap(true);
+    btnPreview = formattedButton(":/res/Trainings.png", true);
+    btnPreview->setToolTip(QPushButton::tr("Go!"));
+
+    // make both rows equal height
+    pageLayout->setRowStretch(0, 1);
+    pageLayout->setRowStretch(1, 1);
 
     // add start button, caption and description to 3 different rows
-    pageLayout->addWidget(btnStart, 0, 0);
-    pageLayout->addWidget(lblCaption, 1, 0);
-    pageLayout->addWidget(lblDescription, 2, 0);
-
-    // make first and last row stretch vertically
-    pageLayout->setRowStretch(0, 1);
-    pageLayout->setRowStretch(1, 0);
-    pageLayout->setRowStretch(2, 1);
+    pageLayout->addWidget(btnPreview, 0, 0);
 
-    // make both columns equal width
-    pageLayout->setColumnStretch(0, 1);
-    pageLayout->setColumnStretch(1, 1);
+    // center preview
+    pageLayout->setAlignment(btnPreview, Qt::AlignRight | Qt::AlignVCenter);
 
-    // center widgets within their grid cells
-    pageLayout->setAlignment(btnStart, Qt::AlignHCenter | Qt::AlignVCenter);
-    pageLayout->setAlignment(lblCaption, Qt::AlignHCenter | Qt::AlignVCenter);
-    pageLayout->setAlignment(lblDescription, Qt::AlignHCenter | Qt::AlignVCenter);
 
 // right column
 
+    // info area (caption on top, description below)
+    QVBoxLayout * infoLayout = new QVBoxLayout();
+
+    lblCaption = new QLabel();
+    lblCaption->setMinimumWidth(360);
+    lblCaption->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
+    lblCaption->setWordWrap(true);
+    lblDescription = new QLabel();
+    lblDescription->setMinimumWidth(360);
+    lblDescription->setAlignment(Qt::AlignHCenter | Qt::AlignTop);
+    lblDescription->setWordWrap(true);
+
+    infoLayout->addWidget(lblCaption);
+    infoLayout->addWidget(lblDescription);
+
+    pageLayout->addLayout(infoLayout, 0, 1);
+    pageLayout->setAlignment(infoLayout, Qt::AlignLeft);
+
+
+    // mission list
     lstMissions = new QListWidget(this);
-    pageLayout->addWidget(lstMissions, 0, 1, 3, 1); // spans over 3 rows
+    pageLayout->addWidget(lstMissions, 1, 0, 1, 2); // span 2 columns
+
+    // let's not make the list use more space than needed
+    lstMissions->setFixedWidth(360);
+    pageLayout->setAlignment(lstMissions, Qt::AlignHCenter);
 
     return pageLayout;
 }
 
+QLayout * PageTraining::footerLayoutDefinition()
+{
+    QBoxLayout * bottomLayout = new QVBoxLayout();
+
+    btnStart = formattedButton(QPushButton::tr("Go!"));
+    btnStart->setFixedWidth(140);
+
+    bottomLayout->addWidget(btnStart);
+
+    bottomLayout->setAlignment(btnStart, Qt::AlignRight | Qt::AlignVCenter);
+
+    return bottomLayout;
+}
+
 
 void PageTraining::connectSignals()
 {
     connect(lstMissions, SIGNAL(itemSelectionChanged()), this, SLOT(updateInfo()));
     connect(lstMissions, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(startSelected()));
+    connect(btnPreview, SIGNAL(clicked()), this, SLOT(startSelected()));
     connect(btnStart, SIGNAL(clicked()), this, SLOT(startSelected()));
 }
 
@@ -78,6 +107,7 @@
 {
     initPage();
 
+//  TODO -> this should be done in a tool "DataDir" class
     QDir tmpdir;
     tmpdir.cd(cfgdir->absolutePath());
     tmpdir.cd("Data/Missions/Training");
@@ -89,7 +119,12 @@
     QStringList defaultList = scriptList(tmpdir);
     defaultList.sort();
 
-    missionList << defaultList;
+    // add non-duplicate default scripts to the list
+    foreach (const QString & mission, defaultList)
+    {
+        if (!missionList.contains(mission))
+            missionList.append(mission);
+    }
 
     // add only default scripts that have names different from detected user scripts
     foreach (const QString & mission, missionList)
@@ -106,6 +141,10 @@
     }
 
     updateInfo();
+
+    // pre-select first mission
+    if (lstMissions->count() > 0)
+        lstMissions->setCurrentRow(0);
 }
 
 QStringList PageTraining::scriptList(const QDir & scriptDir) const
@@ -132,19 +171,19 @@
         // TODO also use .pngs in userdata folder
         QString thumbFile = datadir->absolutePath() + "/Graphics/Missions/Training/" + lstMissions->currentItem()->data(Qt::UserRole).toString() + ".png";
         if (QFile::exists(thumbFile))
-            btnStart->setIcon(QIcon(thumbFile));
+            btnPreview->setIcon(QIcon(thumbFile));
         else
-            btnStart->setIcon(QIcon(":/res/Trainings.png"));
+            btnPreview->setIcon(QIcon(":/res/Trainings.png"));
 
-        lblCaption->setText(lstMissions->currentItem()->text());
+        lblCaption->setText("<h2>" + lstMissions->currentItem()->text()+"</h2>");
         // TODO load mission description from file
-        lblDescription->setText("< Imagine\nMission\nDescription\nhere >\n\nThank you.");
+        lblDescription->setText("< Imagine Mission Description here >\n\nThank you.");
     }
     else
     {
-        btnStart->setIcon(QIcon(":/res/Trainings.png"));
-        lblCaption->setText(tr("Select a mission on the right -->"));
+        btnPreview->setIcon(QIcon(":/res/Trainings.png"));
+        lblCaption->setText(tr("Select a mission!"));
         // TODO better text and tr()
-        lblDescription->setText("Welcome to the Training screen.\n\n\n...\nWHAT?\nIt's not finished yet...");
+        lblDescription->setText("");
     }
 }