QTfrontend/ui/widget/mapContainer.cpp
changeset 8377 869f80966a77
parent 8070 66bc20d089fc
child 8393 85bd6c7b2641
--- a/QTfrontend/ui/widget/mapContainer.cpp	Mon Jan 14 12:07:06 2013 +0400
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Mon Jan 14 11:19:59 2013 +0100
@@ -30,13 +30,24 @@
 #include <QIcon>
 #include <QLineEdit>
 #include <QStringListModel>
+#include <QListWidget>
+#include <QListWidgetItem>
+#include <QDebug>
+#include <QFile>
+#include <QFileDialog>
+#include <QInputDialog>
+#include <QMessageBox>
 
 #include "hwconsts.h"
 #include "mapContainer.h"
+#include "themeprompt.h"
+#include "seedprompt.h"
 #include "igbox.h"
 #include "HWApplication.h"
 #include "ThemeModel.h"
 
+
+
 HWMapContainer::HWMapContainer(QWidget * parent) :
     QWidget(parent),
     mainLayout(this),
@@ -47,6 +58,7 @@
     hhSmall.load(":/res/hh_small.png");
     hhLimit = 18;
     templateFilter = 0;
+    m_master = true;
 
     linearGrad = QLinearGradient(QPoint(128, 0), QPoint(128, 128));
     linearGrad.setColorAt(1, QColor(0, 0, 192));
@@ -57,135 +69,192 @@
                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin),
                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
 
-    QWidget* mapWidget = new QWidget(this);
-    mainLayout.addWidget(mapWidget, 0, 0, Qt::AlignHCenter);
-
-    QGridLayout* mapLayout = new QGridLayout(mapWidget);
-    mapLayout->setMargin(0);
+    m_staticMapModel = DataManager::instance().staticMapModel();
+    m_missionMapModel = DataManager::instance().missionMapModel();
+    m_themeModel = DataManager::instance().themeModel();
 
-    imageButt = new QPushButton(mapWidget);
-    imageButt->setObjectName("imageButt");
-    imageButt->setFixedSize(256 + 6, 128 + 6);
-    imageButt->setFlat(true);
-    imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum);
-    mapLayout->addWidget(imageButt, 0, 0, 1, 2);
-    connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap()));
+    /* Layouts */
 
-    chooseMap = new QComboBox(mapWidget);
-    chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
-    m_mapModel = DataManager::instance().mapModel();
-    chooseMap->setEditable(false);
-    chooseMap->setModel(m_mapModel);
+    QHBoxLayout * typeLayout = new QHBoxLayout();
+    QHBoxLayout * seedLayout = new QHBoxLayout();
+    QHBoxLayout * twoColumnLayout = new QHBoxLayout();
+    QVBoxLayout * leftLayout = new QVBoxLayout();
+    QVBoxLayout * rightLayout = new QVBoxLayout();
+    twoColumnLayout->addLayout(leftLayout, 0);
+    twoColumnLayout->addStretch(1);
+    twoColumnLayout->addLayout(rightLayout, 0);
+    QVBoxLayout * drawnControls = new QVBoxLayout();
+    leftLayout->addLayout(typeLayout, 0);
+    rightLayout->addLayout(seedLayout, 0);
+
+    /* Map type combobox */
 
-    mapLayout->addWidget(chooseMap, 1, 1);
+    typeLayout->setSpacing(10);
+    typeLayout->addWidget(new QLabel(tr("Map type:")), 0);
+    cType = new QComboBox(this);
+    typeLayout->addWidget(cType, 1);
+    cType->insertItem(0, tr("Image map"), MapModel::StaticMap);
+    cType->insertItem(1, tr("Mission map"), MapModel::MissionMap);
+    cType->insertItem(2, tr("Hand-drawn"), MapModel::HandDrawnMap);
+    cType->insertItem(3, tr("Randomly generated"), MapModel::GeneratedMap);
+    cType->insertItem(4, tr("Random maze"), MapModel::GeneratedMaze);
+    connect(cType, SIGNAL(currentIndexChanged(int)), this, SLOT(mapTypeChanged(int)));
+    m_childWidgets << cType;
 
-    QLabel * lblMap = new QLabel(tr("Map"), mapWidget);
-    mapLayout->addWidget(lblMap, 1, 0);
-
-    lblFilter = new QLabel(tr("Filter"), mapWidget);
-    mapLayout->addWidget(lblFilter, 2, 0);
+    /* Randomize button */
 
-    cbTemplateFilter = new QComboBox(mapWidget);
-    cbTemplateFilter->addItem(tr("All"), 0);
-    cbTemplateFilter->addItem(tr("Small"), 1);
-    cbTemplateFilter->addItem(tr("Medium"), 2);
-    cbTemplateFilter->addItem(tr("Large"), 3);
-    cbTemplateFilter->addItem(tr("Cavern"), 4);
-    cbTemplateFilter->addItem(tr("Wacky"), 5);
-    mapLayout->addWidget(cbTemplateFilter, 2, 1);
+    seedLayout->addStretch(1);
+    const QIcon& lp = QIcon(":/res/dice.png");
+    QSize sz = lp.actualSize(QSize(65535, 65535));
+    btnRandomize = new QPushButton();
+    btnRandomize->setText(tr("Random"));
+    btnRandomize->setIcon(lp);
+    btnRandomize->setFixedHeight(30);
+    btnRandomize->setIconSize(sz);
+    btnRandomize->setFlat(true);
+    btnRandomize->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+    connect(btnRandomize, SIGNAL(clicked()), this, SLOT(setRandomMap()));
+    m_childWidgets << btnRandomize;
+    btnRandomize->setStyleSheet("padding: 5px;");
+    btnRandomize->setFixedHeight(cType->height());
+    seedLayout->addWidget(btnRandomize, 1);
 
-    connect(cbTemplateFilter, SIGNAL(activated(int)), this, SLOT(setTemplateFilter(int)));
+    /* Seed button */
+    btnSeed = new QPushButton(parentWidget()->parentWidget());
+    btnSeed->setText(tr("Seed"));
+    btnSeed->setStyleSheet("padding: 5px;");
+    btnSeed->setFixedHeight(cType->height());
+    connect(btnSeed, SIGNAL(clicked()), this, SLOT(showSeedPrompt()));
+    seedLayout->addWidget(btnSeed, 0);
 
-    maze_size_label = new QLabel(tr("Type"), mapWidget);
-    mapLayout->addWidget(maze_size_label, 2, 0);
-    maze_size_label->hide();
-    cbMazeSize = new QComboBox(mapWidget);
-    cbMazeSize->addItem(tr("Small tunnels"), 0);
-    cbMazeSize->addItem(tr("Medium tunnels"), 1);
-    cbMazeSize->addItem(tr("Large tunnels"), 2);
-    cbMazeSize->addItem(tr("Small floating islands"), 3);
-    cbMazeSize->addItem(tr("Medium floating islands"), 4);
-    cbMazeSize->addItem(tr("Large floating islands"), 5);
-    cbMazeSize->setCurrentIndex(1);
+    /* Map preview label */
+
+    QLabel * lblMapPreviewText = new QLabel(this);
+    lblMapPreviewText->setText(tr("Map preview:"));
+    leftLayout->addWidget(lblMapPreviewText, 0, Qt::AlignLeft);
+
+    /* Map Preview */
 
-    mapLayout->addWidget(cbMazeSize, 2, 1);
-    cbMazeSize->hide();
-    connect(cbMazeSize, SIGNAL(activated(int)), this, SLOT(setMazeSize(int)));
+    mapPreview = new QLabel(this);
+    mapPreview->setObjectName("mapPreview");
+    mapPreview->setFixedSize(256, 128);
+    leftLayout->addWidget(mapPreview, 0);
+
+    /* Bottom-Left layout */
 
-    gbThemes = new IconedGroupBox(mapWidget);
-    gbThemes->setTitleTextPadding(80);
-    gbThemes->setContentTopPadding(15);
-    gbThemes->setTitle(tr("Themes"));
+    QVBoxLayout * bottomLeftLayout = new QVBoxLayout();
+    leftLayout->addLayout(bottomLeftLayout, 1);
+
+    /* Map list label */
+
+    lblMapList = new QLabel();
+    rightLayout->addWidget(lblMapList, 0);
+
+    /* Static maps list */
 
-    //gbThemes->setStyleSheet("padding: 0px"); // doesn't work - stylesheet is set with icon
-    mapLayout->addWidget(gbThemes, 0, 2, 3, 1);
-    // disallow row to be collapsed (so it can't get ignored when Qt applies rowSpan of gbThemes)
-    mapLayout->setRowMinimumHeight(2, 13);
-    QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes);
-    gbTLayout->setContentsMargins(0, 0, 0 ,0);
-    gbTLayout->setSpacing(0);
-    lvThemes = new QListView(mapWidget);
-    lvThemes->setMinimumHeight(30);
-    lvThemes->setFixedWidth(140);
-    m_themeModel = DataManager::instance().themeModel();
-    lvThemes->setModel(m_themeModel);
-    lvThemes->setIconSize(QSize(16, 16));
-    lvThemes->setEditTriggers(QListView::NoEditTriggers);
+    staticMapList = new QListView;
+    staticMapList->setModel(m_staticMapModel);
+    rightLayout->addWidget(staticMapList, 1);
+    staticMapList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    m_childWidgets << staticMapList;
+    QItemSelectionModel * staticSelectionModel = staticMapList->selectionModel();
+    connect(staticSelectionModel,
+            SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
+            this,
+            SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
 
-    connect(lvThemes->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT(themeSelected( const QModelIndex &, const QModelIndex &)));
+    /* Mission maps list */
 
-    // override default style to tighten up theme scroller
-    lvThemes->setStyleSheet(QString(
-                                "QListView{"
-                                "border: solid;"
-                                "border-width: 0px;"
-                                "border-radius: 0px;"
-                                "border-color: transparent;"
-                                "background-color: #0d0544;"
-                                "color: #ffcc00;"
-                                "font: bold 13px;"
-                                "}"
-                            )
-                           );
+    missionMapList = new QListView;
+    missionMapList->setModel(m_missionMapModel);
+    missionMapList->setEditTriggers(QAbstractItemView::NoEditTriggers);
+    rightLayout->addWidget(missionMapList, 1);
+    m_childWidgets << missionMapList;
+    QItemSelectionModel * missionSelectionModel = missionMapList->selectionModel();
+    connect(missionSelectionModel,
+            SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
+            this,
+            SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &)));
+
+    /* Map load and edit buttons */
+
+    drawnControls->addStretch(1);
 
-    gbTLayout->addWidget(lvThemes);
-    lvThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
+    btnLoadMap = new QPushButton(tr("Load map drawing"));
+    btnLoadMap->setStyleSheet("padding: 20px;");
+    drawnControls->addWidget(btnLoadMap, 0);
+    m_childWidgets << btnLoadMap;
+    connect(btnLoadMap, SIGNAL(clicked()), this, SLOT(loadDrawing()));
+
+    btnEditMap = new QPushButton(tr("Edit map drawing"));
+    btnEditMap->setStyleSheet("padding: 20px;");
+    drawnControls->addWidget(btnEditMap, 0);
+    m_childWidgets << btnEditMap;
+    connect(btnEditMap, SIGNAL(clicked()), this, SIGNAL(drawMapRequested()));
+
+    drawnControls->addStretch(1);
+
+    rightLayout->addLayout(drawnControls);
+
+    /* Generator style list */
 
-    mapLayout->setSizeConstraint(QLayout::SetFixedSize);
+    generationStyles = new QListWidget();
+    new QListWidgetItem(tr("All"), generationStyles);
+    new QListWidgetItem(tr("Small"), generationStyles);
+    new QListWidgetItem(tr("Medium"), generationStyles);
+    new QListWidgetItem(tr("Large"), generationStyles);
+    new QListWidgetItem(tr("Cavern"), generationStyles);
+    new QListWidgetItem(tr("Wacky"), generationStyles);
+    connect(generationStyles, SIGNAL(currentRowChanged(int)), this, SLOT(setTemplateFilter(int)));
+    m_childWidgets << generationStyles;
+    rightLayout->addWidget(generationStyles, 1);
+
+    /* Maze style list */
 
-    QWidget* seedWidget = new QWidget(this);
-    mainLayout.addWidget(seedWidget, 1, 0);
+    mazeStyles = new QListWidget();
+    new QListWidgetItem(tr("Small tunnels"), mazeStyles);
+    new QListWidgetItem(tr("Medium tunnels"), mazeStyles);
+    new QListWidgetItem(tr("Largetunnels"), mazeStyles);
+    new QListWidgetItem(tr("Small islands"), mazeStyles);
+    new QListWidgetItem(tr("Medium islands"), mazeStyles);
+    new QListWidgetItem(tr("Large islands"), mazeStyles);
+    connect(mazeStyles, SIGNAL(currentRowChanged(int)), this, SLOT(setMazeSize(int)));
+    m_childWidgets << mazeStyles;
+    rightLayout->addWidget(mazeStyles, 1);
 
-    QGridLayout* seedLayout = new QGridLayout(seedWidget);
-    seedLayout->setMargin(0);
+    /* Mission description */
 
-    seedLabel = new QLabel(tr("Seed"), seedWidget);
-    seedLayout->addWidget(seedLabel, 3, 0);
-    seedEdit = new QLineEdit(seedWidget);
-    seedEdit->setMaxLength(54);
-    connect(seedEdit, SIGNAL(returnPressed()), this, SLOT(seedEdited()));
-    seedLayout->addWidget(seedEdit, 3, 1);
-    seedLayout->setColumnStretch(1, 5);
-    seedSet = new QPushButton(seedWidget);
-    seedSet->setText(QPushButton::tr("more"));
-    connect(seedSet, SIGNAL(clicked()), this, SLOT(seedEdited()));
-    seedLayout->setColumnStretch(2, 1);
-    seedLayout->addWidget(seedSet, 3, 2);
+    lblDesc = new QLabel();
+    lblDesc->setWordWrap(true);
+    lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
+    lblDesc->setAlignment(Qt::AlignTop | Qt::AlignLeft);
+    bottomLeftLayout->addWidget(lblDesc, 100);
+
+    /* Spacing above theme chooser */
+
+    bottomLeftLayout->addStretch(1);
+
+    /* Theme chooser */
 
-    seedLabel->setVisible(false);
-    seedEdit->setVisible(false);
+    btnTheme = new QPushButton();
+    connect(btnTheme, SIGNAL(clicked()), this, SLOT(showThemePrompt()));
+    m_childWidgets << btnTheme;
+    bottomLeftLayout->addWidget(btnTheme, 1);
 
-    setRandomSeed();
-    setRandomTheme();
+    /* Add everything to main layout */
+
+    mainLayout.addLayout(twoColumnLayout, 0);
 
-    chooseMap->setCurrentIndex(0);
-    mapChanged(0);
-    // use signal "activated" rather than currentIndexChanged
-    // because index is somtimes changed a few times in a row programmatically
-    connect(chooseMap, SIGNAL(activated(int)), this, SLOT(mapChanged(int)));
+    /* Set defaults */
 
-    // update model views after model changes (to e.g. re-adjust separators)
-    connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews()));
+    setRandomTheme();
+    setRandomSeed();
+    setMazeSize(0);
+    setTemplateFilter(0);
+    staticMapChanged(m_staticMapModel->index(0, 0));
+    missionMapChanged(m_missionMapModel->index(0, 0));
+    updateTheme(m_themeModel->index(0, 0));
+    mapTypeChanged(0);
 }
 
 void HWMapContainer::setImage(const QImage newImage)
@@ -202,8 +271,9 @@
     p.drawPixmap(QPoint(0, 0), px);
 
     addInfoToPreview(pxres);
-    //chooseMap->setCurrentIndex(mapgen);
     pMap = 0;
+
+    cType->setEnabled(isMaster());
 }
 
 void HWMapContainer::setHHLimit(int newHHLimit)
@@ -211,70 +281,6 @@
     hhLimit = newHHLimit;
 }
 
-void HWMapContainer::mapChanged(int index)
-{
-    if (chooseMap->currentIndex() != index)
-        chooseMap->setCurrentIndex(index);
-
-    if (index < 0)
-    {
-        m_mapInfo.type = MapModel::Invalid;
-        updatePreview();
-        return;
-    }
-
-    Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
-    m_mapInfo = chooseMap->itemData(index, Qt::UserRole + 1).value<MapModel::MapInfo>();
-    m_curMap = m_mapInfo.name;
-
-    switch(m_mapInfo.type)
-    {
-        case MapModel::GeneratedMap:
-            mapgen = MAPGEN_REGULAR;
-            gbThemes->show();
-            lblFilter->show();
-            cbTemplateFilter->show();
-            maze_size_label->hide();
-            cbMazeSize->hide();
-            break;
-        case MapModel::GeneratedMaze:
-            mapgen = MAPGEN_MAZE;
-            gbThemes->show();
-            lblFilter->hide();
-            cbTemplateFilter->hide();
-            maze_size_label->show();
-            cbMazeSize->show();
-            break;
-        case MapModel::HandDrawnMap:
-            mapgen = MAPGEN_DRAWN;
-            gbThemes->show();
-            lblFilter->hide();
-            cbTemplateFilter->hide();
-            maze_size_label->hide();
-            cbMazeSize->hide();
-            break;
-        default:
-            mapgen = MAPGEN_MAP;
-            gbThemes->hide();
-            lblFilter->hide();
-            cbTemplateFilter->hide();
-            maze_size_label->hide();
-            cbMazeSize->hide();
-            m_theme = m_mapInfo.theme;
-    }
-
-    // the map has no pre-defined theme, so let's use the selected one
-    if (m_mapInfo.theme.isEmpty())
-    {
-        m_theme = lvThemes->currentIndex().data().toString();
-        emit themeChanged(m_theme);
-    }
-
-    updatePreview();
-    emit mapChanged(m_curMap);
-    emit mapgenChanged(mapgen);
-}
-
 // Should this add text to identify map size?
 void HWMapContainer::addInfoToPreview(QPixmap image)
 {
@@ -292,8 +298,7 @@
     p.drawText(image.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text);
     p.drawPixmap(image.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall);
 
-    imageButt->setIcon(finalImage);
-    imageButt->setIconSize(image.size());
+    mapPreview->setPixmap(finalImage);
 }
 
 void HWMapContainer::askForGeneratedPreview()
@@ -322,14 +327,8 @@
     p.drawPixmap(QPoint(x, y), waitIcon);
 
     addInfoToPreview(waitImage);
-}
 
-void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &)
-{
-    m_theme = current.data().toString();
-
-    gbThemes->setIcon(qVariantValue<QIcon>(current.data(Qt::UserRole)));
-    emit themeChanged(m_theme);
+    cType->setEnabled(false);
 }
 
 QString HWMapContainer::getCurrentSeed() const
@@ -339,8 +338,14 @@
 
 QString HWMapContainer::getCurrentMap() const
 {
-    if(chooseMap->currentIndex() < MAPGEN_MAP) return QString();
-    return(m_curMap);
+    switch (m_mapInfo.type)
+    {
+        case MapModel::StaticMap:
+        case MapModel::MissionMap:
+            return m_curMap;
+        default:
+            return QString();
+    }
 }
 
 QString HWMapContainer::getCurrentTheme() const
@@ -370,20 +375,17 @@
 
 quint32 HWMapContainer::getTemplateFilter() const
 {
-    return cbTemplateFilter->itemData(cbTemplateFilter->currentIndex()).toInt();
+    return generationStyles->currentRow();
 }
 
 void HWMapContainer::resizeEvent ( QResizeEvent * event )
 {
     Q_UNUSED(event);
-    //imageButt->setIconSize(imageButt->size());
 }
 
 void HWMapContainer::intSetSeed(const QString & seed)
 {
     m_seed = seed;
-    if (seed != seedEdit->text())
-        seedEdit->setText(seed);
 }
 
 void HWMapContainer::setSeed(const QString & seed)
@@ -395,11 +397,29 @@
 
 void HWMapContainer::intSetMap(const QString & map)
 {
-    m_curMap = map;
-
-    int id = m_mapModel->indexOf(map);
-
-    mapChanged(id);
+    if (map == "+rnd+")
+    {
+        changeMapType(MapModel::GeneratedMap);
+    }
+    else if (map == "+maze+")
+    {
+        changeMapType(MapModel::GeneratedMaze);
+    }
+    else if (map == "+drawn+")
+    {
+        changeMapType(MapModel::HandDrawnMap);
+    }
+    else if (m_staticMapModel->mapExists(map))
+    {
+        changeMapType(MapModel::StaticMap, m_staticMapModel->index(m_staticMapModel->findMap(map), 0));
+    }
+    else if (m_missionMapModel->mapExists(map))
+    {
+        changeMapType(MapModel::MissionMap, m_missionMapModel->index(m_missionMapModel->findMap(map), 0));
+    } else
+    {
+        qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map;
+    }
 }
 
 void HWMapContainer::setMap(const QString & map)
@@ -413,13 +433,11 @@
     QModelIndexList mdl = m_themeModel->match(m_themeModel->index(0), Qt::DisplayRole, theme);
 
     if(mdl.size())
-        lvThemes->setCurrentIndex(mdl.at(0));
+        updateTheme(mdl.at(0));
 }
 
 void HWMapContainer::setRandomMap()
 {
-    int idx;
-
     setRandomSeed();
     switch(m_mapInfo.type)
     {
@@ -427,17 +445,14 @@
         case MapModel::GeneratedMaze:
             setRandomTheme();
             break;
-        case MapModel::HandDrawnMap:
-            emit drawMapRequested();
+        case MapModel::MissionMap:
+            missionMapChanged(m_missionMapModel->index(rand() % m_missionMapModel->rowCount(), 0));
             break;
-        case MapModel::MissionMap:
         case MapModel::StaticMap:
-            // get random map of same type
-            idx = m_mapModel->randomMap(m_mapInfo.type);
-            mapChanged(idx);
+            staticMapChanged(m_staticMapModel->index(rand() % m_staticMapModel->rowCount(), 0));
             break;
-        case MapModel::Invalid:
-            mapChanged(0);
+        default:
+            break;
     }
 }
 
@@ -452,12 +467,12 @@
 {
     if(!m_themeModel->rowCount()) return;
     quint32 themeNum = rand() % m_themeModel->rowCount();
-    lvThemes->setCurrentIndex(m_themeModel->index(themeNum));
+    updateTheme(m_themeModel->index(themeNum));
 }
 
 void HWMapContainer::intSetTemplateFilter(int filter)
 {
-    cbTemplateFilter->setCurrentIndex(filter);
+    generationStyles->setCurrentRow(filter);
     emit newTemplateFilter(filter);
 }
 
@@ -475,12 +490,12 @@
 
 int HWMapContainer::getMazeSize(void) const
 {
-    return cbMazeSize->currentIndex();
+    return mazeStyles->currentRow();
 }
 
 void HWMapContainer::intSetMazeSize(int size)
 {
-    cbMazeSize->setCurrentIndex(size);
+    mazeStyles->setCurrentRow(size);
     emit mazeSizeChanged(size);
 }
 
@@ -521,9 +536,6 @@
                 break;
         }
 
-        if(m != MAPGEN_MAP)
-            chooseMap->setCurrentIndex(m);
-
         emit mapgenChanged(m);
     }
 }
@@ -546,23 +558,10 @@
     return drawMapScene.encode();
 }
 
-void HWMapContainer::seedEdited()
+void HWMapContainer::setNewSeed(const QString & newSeed)
 {
-    if (seedLabel->isVisible() == false )
-    {
-        seedLabel->setVisible(true);
-        seedEdit->setVisible(true);
-        seedSet->setText(tr("Set"));
-        return;
-    }
-
-    if (seedEdit->text().isEmpty())
-        seedEdit->setText(m_seed);
-    else
-    {
-        setSeed(seedEdit->text());
-        emit seedChanged(seedEdit->text());
-    }
+    setSeed(newSeed);
+    emit seedChanged(newSeed);
 }
 
 DrawMapScene * HWMapContainer::getDrawMapScene()
@@ -592,8 +591,7 @@
     {
         case MapModel::Invalid:
             failIcon = QPixmap(":/res/btnDisabled.png");
-            imageButt->setIcon(failIcon);
-            imageButt->setIconSize(failIcon.size());
+            mapPreview->setPixmap(failIcon);
             break;
         case MapModel::GeneratedMap:
             askForGeneratedPreview();
@@ -610,7 +608,7 @@
 
             if(!success)
             {
-                imageButt->setIcon(QIcon());
+                mapPreview->setPixmap(QPixmap());
                 return;
             }
 
@@ -638,13 +636,13 @@
     {
         QModelIndexList mdl = m_themeModel->match(m_themeModel->index(0), Qt::DisplayRole, m_theme);
         if (mdl.size() > 0)
-            lvThemes->setCurrentIndex(mdl.at(0));
+            updateTheme(mdl.at(0));
         else
             setRandomTheme();
     }
 
     // restore map selection
-    if ((!m_curMap.isEmpty()) && (chooseMap->currentIndex() < 0))
+    if (!m_curMap.isEmpty())
         intSetMap(m_curMap);
     else
         updatePreview();
@@ -656,3 +654,227 @@
     if (map == pMap)
         pMap = 0;
 }
+
+void HWMapContainer::mapTypeChanged(int index)
+{
+    changeMapType((MapModel::MapType)cType->itemData(index).toInt());
+}
+
+void HWMapContainer::changeMapType(MapModel::MapType type, const QModelIndex & newMap)
+{
+    staticMapList->hide();
+    missionMapList->hide();
+    lblMapList->hide();
+    generationStyles->hide();
+    mazeStyles->hide();
+    lblDesc->hide();
+    btnTheme->hide();
+    btnLoadMap->hide();
+    btnEditMap->hide();
+    btnRandomize->hide();
+
+    switch (type)
+    {
+        case MapModel::GeneratedMap:
+            mapgen = MAPGEN_REGULAR;
+            setMapInfo(MapModel::MapInfoRandom);
+            lblMapList->setText(tr("Map size:"));
+            lblMapList->show();
+            generationStyles->show();
+            btnRandomize->show();
+            btnTheme->show();
+            break;
+        case MapModel::GeneratedMaze:
+            mapgen = MAPGEN_MAZE;
+            setMapInfo(MapModel::MapInfoMaze);
+            lblMapList->setText(tr("Maze style:"));
+            lblMapList->show();
+            mazeStyles->show();
+            btnRandomize->show();
+            btnTheme->show();
+            break;
+        case MapModel::HandDrawnMap:
+            mapgen = MAPGEN_DRAWN;
+            setMapInfo(MapModel::MapInfoDrawn);
+            btnTheme->show();
+            btnLoadMap->show();
+            btnEditMap->show();
+            break;
+        case MapModel::MissionMap:
+            mapgen = MAPGEN_MAP;
+            missionMapChanged(newMap.isValid() ? newMap : missionMapList->currentIndex());
+            lblMapList->setText(tr("Mission:"));
+            lblMapList->show();
+            missionMapList->show();
+            lblDesc->setText(m_mapInfo.desc);
+            lblDesc->show();
+            btnRandomize->show();
+            emit mapChanged(m_curMap);
+            break;
+        case MapModel::StaticMap:
+            mapgen = MAPGEN_MAP;
+            staticMapChanged(newMap.isValid() ? newMap : staticMapList->currentIndex());
+            lblMapList->setText(tr("Map:"));
+            lblMapList->show();
+            staticMapList->show();
+            btnRandomize->show();
+            emit mapChanged(m_curMap);
+            break;
+        default:
+            break;
+    }
+
+    // Update cType combobox
+    for (int i = 0; i < cType->count(); i++)
+    {
+        if ((MapModel::MapType)cType->itemData(i).toInt() == type)
+        {
+            cType->setCurrentIndex(i);
+            break;
+        }
+    }
+
+    emit mapgenChanged(mapgen);
+}
+
+void HWMapContainer::showThemePrompt()
+{
+    ThemePrompt prompt(this);
+    int theme = prompt.exec() - 1; // Since 0 means canceled, so all indexes are +1'd
+    if (theme < 0) return;
+
+    QModelIndex current = m_themeModel->index(theme, 0);
+    updateTheme(current);
+    
+    emit themeChanged(m_theme);
+}
+
+void HWMapContainer::updateTheme(const QModelIndex & current)
+{
+    m_theme = selectedTheme = current.data().toString();
+    QIcon icon = qVariantValue<QIcon>(current.data(Qt::UserRole));
+    QSize iconSize = icon.actualSize(QSize(65535, 65535));
+    btnTheme->setFixedHeight(iconSize.height());
+    btnTheme->setIconSize(iconSize);
+    btnTheme->setIcon(icon);
+    btnTheme->setText(tr("Theme: ") + current.data(Qt::DisplayRole).toString());
+    emit themeChanged(m_theme);
+}
+
+void HWMapContainer::staticMapChanged(const QModelIndex & map, const QModelIndex & old)
+{
+    mapChanged(map, 0, old);
+}
+
+void HWMapContainer::missionMapChanged(const QModelIndex & map, const QModelIndex & old)
+{
+    mapChanged(map, 1, old);
+}
+
+// Type: 0 = static, 1 = mission
+void HWMapContainer::mapChanged(const QModelIndex & map, int type, const QModelIndex & old)
+{
+    QListView * mapList;
+
+    if (type == 0)      mapList = staticMapList;
+    else if (type == 1) mapList = missionMapList;
+    else                return;
+
+    // Make sure it is a valid index
+    if (!map.isValid())
+    {
+        if (old.isValid())
+        {
+            mapList->setCurrentIndex(old);
+            mapList->scrollTo(old);
+        }
+        else
+        {
+            m_mapInfo.type = MapModel::Invalid;
+            updatePreview();
+        }
+
+        return;
+    }
+
+    // If map changed, update list selection
+    if (mapList->currentIndex() != map)
+    {
+        mapList->setCurrentIndex(map);
+        mapList->scrollTo(map);
+    }
+
+    if (map.data(Qt::UserRole + 1).canConvert<MapModel::MapInfo>())
+        setMapInfo(map.data(Qt::UserRole + 1).value<MapModel::MapInfo>());
+    else
+        Q_ASSERT(false); // Houston, we have a problem.
+
+}
+
+void HWMapContainer::setMapInfo(MapModel::MapInfo mapInfo)
+{
+    m_mapInfo = mapInfo;
+    m_curMap = m_mapInfo.name;
+    m_theme = m_mapInfo.theme;
+
+    // the map has no pre-defined theme, so let's use the selected one
+    if (m_mapInfo.theme.isEmpty())
+    {
+        m_theme = selectedTheme;
+        emit themeChanged(m_theme);
+    }
+
+    lblDesc->setText(mapInfo.desc);
+
+    updatePreview();
+    emit mapChanged(m_curMap);
+}
+
+void HWMapContainer::loadDrawing()
+{
+
+
+    QString fileName = QFileDialog::getOpenFileName(NULL, tr("Load drawn map"), ".", tr("Drawn Maps") + " (*.hwmap);;" + tr("All files") + " (*)");
+
+    if(fileName.isEmpty()) return;
+
+
+
+    QFile f(fileName);
+
+    if(!f.open(QIODevice::ReadOnly))
+    {
+        QMessageBox errorMsg(parentWidget());
+        errorMsg.setIcon(QMessageBox::Warning);
+        errorMsg.setWindowTitle(QMessageBox::tr("File error"));
+        errorMsg.setText(QMessageBox::tr("Cannot open '%1' for reading").arg(fileName));
+        errorMsg.setWindowModality(Qt::WindowModal);
+        errorMsg.exec();
+    }
+    else
+    {
+        drawMapScene.decode(qUncompress(QByteArray::fromBase64(f.readAll())));
+        mapDrawingFinished();
+    }
+}
+
+void HWMapContainer::showSeedPrompt()
+{
+    SeedPrompt prompt(parentWidget()->parentWidget(), getCurrentSeed(), isMaster());
+    connect(&prompt, SIGNAL(seedSelected(const QString &)), this, SLOT(setNewSeed(const QString &)));
+    prompt.exec();
+}
+
+bool HWMapContainer::isMaster()
+{
+    return m_master;
+}
+
+void HWMapContainer::setMaster(bool master)
+{
+    if (master == m_master) return;
+    m_master = master;
+    
+    foreach (QWidget *widget, m_childWidgets)
+        widget->setEnabled(master);
+}