QTfrontend/ui/widget/mapContainer.cpp
changeset 13256 edb2f654f8f6
parent 13255 0cc068e8a391
child 13258 dd054edd56df
equal deleted inserted replaced
13255:0cc068e8a391 13256:edb2f654f8f6
   190 
   190 
   191     missionMapList = new QListView(this);
   191     missionMapList = new QListView(this);
   192     rightLayout->addWidget(missionMapList, 1);
   192     rightLayout->addWidget(missionMapList, 1);
   193     m_childWidgets << missionMapList;
   193     m_childWidgets << missionMapList;
   194 
   194 
   195     /* Map name label (when not room master) */
   195     /* Map name (when not room master) */
   196 
   196     /* We use a QTextEdit instead of QLabel because it is able
   197     lblMapName = new QLabel(this);
   197        to wrap at any character. */
   198     lblMapName->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
   198     teMapName = new QTextEdit(this);
   199     lblMapName->setAlignment(Qt::AlignTop | Qt::AlignLeft);
   199     teMapName->setObjectName("mapName");
   200     lblMapName->setTextFormat(Qt::PlainText);
   200     teMapName->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum);
   201     lblMapName->setWordWrap(true),
   201     teMapName->setAlignment(Qt::AlignTop | Qt::AlignLeft);
   202     rightLayout->addWidget(lblMapName, 1);
   202 
   203     m_childWidgets << lblMapName;
   203     /* Boilerplate to emulate a QLabel */
       
   204     teMapName->setReadOnly(true);
       
   205     teMapName->setAcceptRichText(false);
       
   206     teMapName->setFrameStyle(QFrame::NoFrame);
       
   207     QPalette pal = QPalette(qApp->palette());
       
   208     pal.setColor(QPalette::Base, Qt::transparent);
       
   209     teMapName->setPalette(pal);
       
   210 
       
   211     teMapName->setLineWrapMode(QTextEdit::WidgetWidth);
       
   212     teMapName->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
       
   213 
       
   214     rightLayout->addWidget(teMapName, 1);
       
   215     m_childWidgets << teMapName;
   204 
   216 
   205     /* Map load and edit buttons */
   217     /* Map load and edit buttons */
   206 
   218 
   207     drawnControls->addStretch(1);
   219     drawnControls->addStretch(1);
   208 
   220 
   521         changeMapType(MapModel::MissionMap, m_missionMapModel->index(m_missionMapModel->findMap(map), 0));
   533         changeMapType(MapModel::MissionMap, m_missionMapModel->index(m_missionMapModel->findMap(map), 0));
   522     } else
   534     } else
   523     {
   535     {
   524         qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map;
   536         qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map;
   525         m_missingMap = true;
   537         m_missingMap = true;
   526         lblMapName->setText(map);
   538         setMapNameLabel(map);
   527         if (m_mapInfo.type != MapModel::StaticMap && m_mapInfo.type != MapModel::MissionMap)
   539         if (m_mapInfo.type != MapModel::StaticMap && m_mapInfo.type != MapModel::MissionMap)
   528         {
   540         {
   529             m_mapInfo.type = MapModel::StaticMap;
   541             m_mapInfo.type = MapModel::StaticMap;
   530             changeMapType(MapModel::StaticMap, QModelIndex());
   542             changeMapType(MapModel::StaticMap, QModelIndex());
   531         }
   543         }
   892 
   904 
   893 void HWMapContainer::changeMapType(MapModel::MapType type, const QModelIndex & newMap)
   905 void HWMapContainer::changeMapType(MapModel::MapType type, const QModelIndex & newMap)
   894 {
   906 {
   895     staticMapList->hide();
   907     staticMapList->hide();
   896     missionMapList->hide();
   908     missionMapList->hide();
   897     lblMapName->hide();
   909     teMapName->hide();
   898     lblMapList->hide();
   910     lblMapList->hide();
   899     generationStyles->hide();
   911     generationStyles->hide();
   900     mazeStyles->hide();
   912     mazeStyles->hide();
   901     lblDesc->hide();
   913     lblDesc->hide();
   902     btnLoadMap->hide();
   914     btnLoadMap->hide();
   937             setupMissionMapsView();
   949             setupMissionMapsView();
   938             mapgen = MAPGEN_MAP;
   950             mapgen = MAPGEN_MAP;
   939             missionMapChanged(newMap.isValid() ? newMap : missionMapList->currentIndex());
   951             missionMapChanged(newMap.isValid() ? newMap : missionMapList->currentIndex());
   940             lblMapList->setText(tr("Mission:"));
   952             lblMapList->setText(tr("Mission:"));
   941             lblMapList->show();
   953             lblMapList->show();
   942             lblMapName->setText(m_curMap);
   954             setMapNameLabel(m_curMap);
   943             if(m_master)
   955             if(m_master)
   944             {
   956             {
   945                 missionMapList->show();
   957                 missionMapList->show();
   946             }
   958             }
   947             else
   959             else
   948             {
   960             {
   949                 lblMapName->show();
   961                 teMapName->show();
   950             }
   962             }
   951             mapFeatureSize->hide();
   963             mapFeatureSize->hide();
   952             lblDesc->setText(m_mapInfo.desc);
   964             lblDesc->setText(m_mapInfo.desc);
   953             lblDesc->show();
   965             lblDesc->show();
   954             emit mapChanged(m_curMap);
   966             emit mapChanged(m_curMap);
   957             setupStaticMapsView();
   969             setupStaticMapsView();
   958             mapgen = MAPGEN_MAP;
   970             mapgen = MAPGEN_MAP;
   959             staticMapChanged(newMap.isValid() ? newMap : staticMapList->currentIndex());
   971             staticMapChanged(newMap.isValid() ? newMap : staticMapList->currentIndex());
   960             lblMapList->setText(tr("Map:"));
   972             lblMapList->setText(tr("Map:"));
   961             lblMapList->show();
   973             lblMapList->show();
   962             lblMapName->setText(m_curMap);
   974             setMapNameLabel(m_curMap);
   963             if(m_master)
   975             if(m_master)
   964             {
   976             {
   965                 staticMapList->show();
   977                 staticMapList->show();
   966             }
   978             }
   967             else
   979             else
   968             {
   980             {
   969                 lblMapName->show();
   981                 teMapName->show();
   970             }
   982             }
   971             mapFeatureSize->hide();
   983             mapFeatureSize->hide();
   972             emit mapChanged(m_curMap);
   984             emit mapChanged(m_curMap);
   973             break;
   985             break;
   974         case MapModel::FortsMap:
   986         case MapModel::FortsMap:
  1184     foreach (QWidget *widget, m_childWidgets)
  1196     foreach (QWidget *widget, m_childWidgets)
  1185         widget->setEnabled(master);
  1197         widget->setEnabled(master);
  1186 
  1198 
  1187     if(m_mapInfo.type == MapModel::StaticMap)
  1199     if(m_mapInfo.type == MapModel::StaticMap)
  1188     {
  1200     {
  1189         lblMapName->setHidden(master);
  1201         teMapName->setHidden(master);
  1190         staticMapList->setVisible(master);
  1202         staticMapList->setVisible(master);
  1191     }
  1203     }
  1192     else if(m_mapInfo.type == MapModel::MissionMap)
  1204     else if(m_mapInfo.type == MapModel::MissionMap)
  1193     {
  1205     {
  1194         lblMapName->setHidden(master);
  1206         teMapName->setHidden(master);
  1195         missionMapList->setVisible(master);
  1207         missionMapList->setVisible(master);
  1196     }
  1208     }
  1197 
  1209 
  1198     if(m_missingMap)
  1210     if(m_missingMap)
  1199     {
  1211     {
  1246             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
  1258             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
  1247             this,
  1259             this,
  1248             SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
  1260             SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
  1249     staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
  1261     staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
  1250 }
  1262 }
       
  1263 
       
  1264 // Call this function instead of setting the text of the map name label
       
  1265 // directly.
       
  1266 void HWMapContainer::setMapNameLabel(QString mapName)
       
  1267 {
       
  1268     // Cut off insanely long names to be displayed
       
  1269     if(mapName.length() >= 90)
       
  1270     {
       
  1271         mapName.truncate(84);
       
  1272         mapName.append(" (...)");
       
  1273     }
       
  1274     teMapName->setPlainText(mapName);
       
  1275 }