88 QWidget * topWidget = new QWidget(); |
89 QWidget * topWidget = new QWidget(); |
89 QHBoxLayout * topLayout = new QHBoxLayout(topWidget); |
90 QHBoxLayout * topLayout = new QHBoxLayout(topWidget); |
90 topWidget->setContentsMargins(0, 0, 0, 0); |
91 topWidget->setContentsMargins(0, 0, 0, 0); |
91 topLayout->setContentsMargins(0, 0, 0, 0); |
92 topLayout->setContentsMargins(0, 0, 0, 0); |
92 |
93 |
93 QHBoxLayout * twoColumnLayout = new QHBoxLayout(); |
94 twoColumnLayout = new QHBoxLayout(); |
94 QVBoxLayout * leftLayout = new QVBoxLayout(); |
95 QVBoxLayout * leftLayout = new QVBoxLayout(); |
|
96 leftLayout->setAlignment(Qt::AlignLeft); |
95 QVBoxLayout * rightLayout = new QVBoxLayout(); |
97 QVBoxLayout * rightLayout = new QVBoxLayout(); |
96 twoColumnLayout->addLayout(leftLayout, 0); |
98 twoColumnLayout->addLayout(leftLayout, 0); |
97 twoColumnLayout->addStretch(1); |
|
98 twoColumnLayout->addLayout(rightLayout, 0); |
99 twoColumnLayout->addLayout(rightLayout, 0); |
99 QVBoxLayout * drawnControls = new QVBoxLayout(); |
100 QVBoxLayout * drawnControls = new QVBoxLayout(); |
100 |
101 |
101 /* Map type label */ |
102 /* Map type label */ |
102 |
103 |
172 leftLayout->addLayout(bottomLeftLayout, 1); |
173 leftLayout->addLayout(bottomLeftLayout, 1); |
173 |
174 |
174 /* Map list label */ |
175 /* Map list label */ |
175 |
176 |
176 lblMapList = new QLabel(this); |
177 lblMapList = new QLabel(this); |
|
178 lblMapList->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); |
|
179 lblMapList->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
177 rightLayout->addWidget(lblMapList, 0); |
180 rightLayout->addWidget(lblMapList, 0); |
178 m_childWidgets << lblMapList; |
181 m_childWidgets << lblMapList; |
179 |
182 |
180 /* Static maps list */ |
183 /* Static maps list */ |
181 |
184 |
186 /* Mission maps list */ |
189 /* Mission maps list */ |
187 |
190 |
188 missionMapList = new QListView(this); |
191 missionMapList = new QListView(this); |
189 rightLayout->addWidget(missionMapList, 1); |
192 rightLayout->addWidget(missionMapList, 1); |
190 m_childWidgets << missionMapList; |
193 m_childWidgets << missionMapList; |
|
194 |
|
195 /* Map name label (when not room master) */ |
|
196 |
|
197 lblMapName = new QLabel(this); |
|
198 lblMapName->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); |
|
199 lblMapName->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
|
200 lblMapName->setTextFormat(Qt::PlainText); |
|
201 lblMapName->setWordWrap(true), |
|
202 rightLayout->addWidget(lblMapName, 1); |
|
203 m_childWidgets << lblMapName; |
191 |
204 |
192 /* Map load and edit buttons */ |
205 /* Map load and edit buttons */ |
193 |
206 |
194 drawnControls->addStretch(1); |
207 drawnControls->addStretch(1); |
195 |
208 |
240 //mapFeatureSize->setTickPosition(QSlider::TicksBelow); |
253 //mapFeatureSize->setTickPosition(QSlider::TicksBelow); |
241 mapFeatureSize->setMaximum(25); |
254 mapFeatureSize->setMaximum(25); |
242 mapFeatureSize->setMinimum(1); |
255 mapFeatureSize->setMinimum(1); |
243 //mapFeatureSize->setFixedWidth(259); |
256 //mapFeatureSize->setFixedWidth(259); |
244 mapFeatureSize->setValue(m_mapFeatureSize); |
257 mapFeatureSize->setValue(m_mapFeatureSize); |
245 mapFeatureSize->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
258 mapFeatureSize->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); |
246 bottomLeftLayout->addWidget(mapFeatureSize, 0); |
259 bottomLeftLayout->addWidget(mapFeatureSize, 0); |
247 connect(mapFeatureSize, SIGNAL(valueChanged(int)), this, SLOT(setFeatureSize(int))); |
260 connect(mapFeatureSize, SIGNAL(valueChanged(int)), this, SLOT(setFeatureSize(int))); |
248 m_childWidgets << mapFeatureSize; |
261 m_childWidgets << mapFeatureSize; |
249 |
262 |
250 /* Mission description */ |
263 /* Mission description */ |
251 |
264 |
252 lblDesc = new QLabel(); |
265 lblDesc = new QLabel(); |
253 lblDesc->setWordWrap(true); |
266 lblDesc->setWordWrap(true); |
254 lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
267 lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
255 lblDesc->setAlignment(Qt::AlignTop | Qt::AlignLeft); |
268 lblDesc->setAlignment(Qt::AlignBottom | Qt::AlignLeft); |
256 lblDesc->setStyleSheet("font: 10px;"); |
269 lblDesc->setStyleSheet("font: 10px;"); |
257 bottomLeftLayout->addWidget(lblDesc, 100); |
270 bottomLeftLayout->addWidget(lblDesc, 100); |
258 |
271 |
259 /* Add stretch above theme button */ |
272 /* Add stretch above theme button */ |
260 |
273 |
497 { |
510 { |
498 //nuffin |
511 //nuffin |
499 } |
512 } |
500 else if (m_staticMapModel->mapExists(map)) |
513 else if (m_staticMapModel->mapExists(map)) |
501 { |
514 { |
|
515 m_missingMap = false; |
502 changeMapType(MapModel::StaticMap, m_staticMapModel->index(m_staticMapModel->findMap(map), 0)); |
516 changeMapType(MapModel::StaticMap, m_staticMapModel->index(m_staticMapModel->findMap(map), 0)); |
503 } |
517 } |
504 else if (m_missionMapModel->mapExists(map)) |
518 else if (m_missionMapModel->mapExists(map)) |
505 { |
519 { |
|
520 m_missingMap = false; |
506 changeMapType(MapModel::MissionMap, m_missionMapModel->index(m_missionMapModel->findMap(map), 0)); |
521 changeMapType(MapModel::MissionMap, m_missionMapModel->index(m_missionMapModel->findMap(map), 0)); |
507 } else |
522 } else |
508 { |
523 { |
509 qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map; |
524 qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map; |
|
525 m_missingMap = true; |
|
526 lblMapName->setText(map); |
|
527 updatePreview(); |
510 } |
528 } |
511 } |
529 } |
512 |
530 |
513 void HWMapContainer::setMap(const QString & map) |
531 void HWMapContainer::setMap(const QString & map) |
514 { |
532 { |
515 if ((m_mapInfo.type == MapModel::Invalid) || (map != m_mapInfo.name)) |
533 if ((m_mapInfo.type == MapModel::Invalid) || (map != m_mapInfo.name) || m_missingMap) |
516 intSetMap(map); |
534 intSetMap(map); |
517 } |
535 } |
518 |
536 |
519 void HWMapContainer::setTheme(const QString & theme) |
537 void HWMapContainer::setTheme(const QString & theme) |
520 { |
538 { |
733 disconnect(pMap, 0, this, SLOT(setImage(const QPixmap))); |
751 disconnect(pMap, 0, this, SLOT(setImage(const QPixmap))); |
734 disconnect(pMap, 0, this, SLOT(setHHLimit(int))); |
752 disconnect(pMap, 0, this, SLOT(setHHLimit(int))); |
735 pMap = 0; |
753 pMap = 0; |
736 } |
754 } |
737 |
755 |
738 QPixmap failIcon; |
756 QPixmap failPixmap; |
|
757 QIcon failIcon; |
739 |
758 |
740 switch(m_mapInfo.type) |
759 switch(m_mapInfo.type) |
741 { |
760 { |
742 case MapModel::Invalid: |
761 case MapModel::Invalid: |
743 failIcon = QPixmap(":/res/btnDisabled.png"); |
762 failPixmap = QPixmap(":/res/missingMap.png"); |
744 mapPreview->setIcon(QIcon(failIcon)); |
763 failIcon = QIcon(); |
745 mapPreview->setIconSize(failIcon.size()); |
764 failIcon.addPixmap(failPixmap, QIcon::Normal); |
|
765 failIcon.addPixmap(failPixmap, QIcon::Disabled); |
|
766 mapPreview->setIcon(failIcon); |
|
767 mapPreview->setIconSize(failPixmap.size()); |
|
768 lblDesc->clear(); |
746 break; |
769 break; |
747 case MapModel::GeneratedMap: |
770 case MapModel::GeneratedMap: |
748 case MapModel::GeneratedMaze: |
771 case MapModel::GeneratedMaze: |
749 case MapModel::GeneratedPerlin: |
772 case MapModel::GeneratedPerlin: |
750 case MapModel::HandDrawnMap: |
773 case MapModel::HandDrawnMap: |
751 case MapModel::FortsMap: |
774 case MapModel::FortsMap: |
752 askForGeneratedPreview(); |
775 askForGeneratedPreview(); |
753 break; |
776 break; |
754 default: |
777 default: |
755 QPixmap mapImage; |
778 if(m_missingMap) |
756 bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png"); |
|
757 |
|
758 if(!success) |
|
759 { |
779 { |
760 mapPreview->setIcon(QIcon()); |
780 failPixmap = QPixmap(":/res/missingMap.png"); |
761 return; |
781 failIcon = QIcon(); |
|
782 failIcon.addPixmap(failPixmap, QIcon::Normal); |
|
783 failIcon.addPixmap(failPixmap, QIcon::Disabled); |
|
784 mapPreview->setIcon(failIcon); |
|
785 mapPreview->setIconSize(failPixmap.size()); |
|
786 lblDesc->clear(); |
|
787 break; |
762 } |
788 } |
763 |
789 else |
764 hhLimit = m_mapInfo.limit; |
790 { |
765 addInfoToPreview(mapImage); |
791 QPixmap mapImage; |
|
792 bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png"); |
|
793 |
|
794 if(!success) |
|
795 { |
|
796 mapPreview->setIcon(QIcon()); |
|
797 return; |
|
798 } |
|
799 |
|
800 hhLimit = m_mapInfo.limit; |
|
801 addInfoToPreview(mapImage); |
|
802 } |
766 } |
803 } |
767 } |
804 } |
768 |
805 |
769 void HWMapContainer::setAllMapParameters(const QString &map, MapGenerator m, int mazesize, const QString &seed, int tmpl, int featureSize) |
806 void HWMapContainer::setAllMapParameters(const QString &map, MapGenerator m, int mazesize, const QString &seed, int tmpl, int featureSize) |
770 { |
807 { |
894 setupMissionMapsView(); |
932 setupMissionMapsView(); |
895 mapgen = MAPGEN_MAP; |
933 mapgen = MAPGEN_MAP; |
896 missionMapChanged(newMap.isValid() ? newMap : missionMapList->currentIndex()); |
934 missionMapChanged(newMap.isValid() ? newMap : missionMapList->currentIndex()); |
897 lblMapList->setText(tr("Mission:")); |
935 lblMapList->setText(tr("Mission:")); |
898 lblMapList->show(); |
936 lblMapList->show(); |
899 missionMapList->show(); |
937 if(m_master) |
|
938 { |
|
939 missionMapList->show(); |
|
940 } |
|
941 else |
|
942 { |
|
943 lblMapName->show(); |
|
944 } |
900 mapFeatureSize->hide(); |
945 mapFeatureSize->hide(); |
901 lblDesc->setText(m_mapInfo.desc); |
946 lblDesc->setText(m_mapInfo.desc); |
902 lblDesc->show(); |
947 lblDesc->show(); |
903 emit mapChanged(m_curMap); |
948 emit mapChanged(m_curMap); |
904 break; |
949 break; |
906 setupStaticMapsView(); |
951 setupStaticMapsView(); |
907 mapgen = MAPGEN_MAP; |
952 mapgen = MAPGEN_MAP; |
908 staticMapChanged(newMap.isValid() ? newMap : staticMapList->currentIndex()); |
953 staticMapChanged(newMap.isValid() ? newMap : staticMapList->currentIndex()); |
909 lblMapList->setText(tr("Map:")); |
954 lblMapList->setText(tr("Map:")); |
910 lblMapList->show(); |
955 lblMapList->show(); |
|
956 if(m_master) |
|
957 { |
|
958 staticMapList->show(); |
|
959 } |
|
960 else |
|
961 { |
|
962 lblMapName->show(); |
|
963 } |
911 mapFeatureSize->hide(); |
964 mapFeatureSize->hide(); |
912 staticMapList->show(); |
|
913 emit mapChanged(m_curMap); |
965 emit mapChanged(m_curMap); |
914 break; |
966 break; |
915 case MapModel::FortsMap: |
967 case MapModel::FortsMap: |
916 mapgen = MAPGEN_FORTS; |
968 mapgen = MAPGEN_FORTS; |
917 setMapInfo(MapModel::MapInfoForts); |
969 setMapInfo(MapModel::MapInfoForts); |
996 void HWMapContainer::updateTheme(const QModelIndex & current) |
1048 void HWMapContainer::updateTheme(const QModelIndex & current) |
997 { |
1049 { |
998 m_theme = selectedTheme = current.data(ThemeModel::ActualNameRole).toString(); |
1050 m_theme = selectedTheme = current.data(ThemeModel::ActualNameRole).toString(); |
999 m_themeID = current.row(); |
1051 m_themeID = current.row(); |
1000 QIcon icon = current.data(Qt::DecorationRole).value<QIcon>(); |
1052 QIcon icon = current.data(Qt::DecorationRole).value<QIcon>(); |
1001 //QSize iconSize = icon.actualSize(QSize(65535, 65535)); |
|
1002 //btnTheme->setFixedHeight(64); |
|
1003 //btnTheme->setIconSize(iconSize); |
|
1004 btnTheme->setIcon(icon); |
1053 btnTheme->setIcon(icon); |
1005 btnTheme->setText(tr("Theme: %1").arg(current.data(Qt::DisplayRole).toString())); |
1054 QString themeLabel = tr("Theme: %1").arg(current.data(Qt::DisplayRole).toString()); |
|
1055 btnTheme->setText(themeLabel); |
1006 updateThemeButtonSize(); |
1056 updateThemeButtonSize(); |
1007 } |
1057 } |
1008 |
1058 |
1009 void HWMapContainer::staticMapChanged(const QModelIndex & map, const QModelIndex & old) |
1059 void HWMapContainer::staticMapChanged(const QModelIndex & map, const QModelIndex & old) |
1010 { |
1060 { |
1026 else return; |
1076 else return; |
1027 |
1077 |
1028 // Make sure it is a valid index |
1078 // Make sure it is a valid index |
1029 if (!map.isValid()) |
1079 if (!map.isValid()) |
1030 { |
1080 { |
|
1081 // Make sure there's always a valid selection in the map list |
1031 if (old.isValid()) |
1082 if (old.isValid()) |
1032 { |
1083 { |
1033 mapList->setCurrentIndex(old); |
1084 mapList->setCurrentIndex(old); |
1034 mapList->scrollTo(old); |
1085 mapList->scrollTo(old); |
1035 } |
1086 } |
1036 else |
1087 m_mapInfo.type = MapModel::Invalid; |
1037 { |
1088 m_missingMap = true; |
1038 m_mapInfo.type = MapModel::Invalid; |
1089 updatePreview(); |
1039 updatePreview(); |
|
1040 } |
|
1041 |
|
1042 return; |
1090 return; |
1043 } |
1091 } |
1044 |
1092 |
1045 // If map changed, update list selection |
1093 // If map changed, update list selection |
1046 if (mapList->currentIndex() != map) |
1094 if (mapList->currentIndex() != map) |
1047 { |
1095 { |
1048 mapList->setCurrentIndex(map); |
1096 mapList->setCurrentIndex(map); |
1049 mapList->scrollTo(map); |
1097 mapList->scrollTo(map); |
|
1098 } |
|
1099 if (m_missingMap) |
|
1100 { |
|
1101 m_missingMap = false; |
|
1102 updatePreview(); |
1050 } |
1103 } |
1051 |
1104 |
1052 Q_ASSERT(map.data(Qt::UserRole + 1).canConvert<MapModel::MapInfo>()); // Houston, we have a problem. |
1105 Q_ASSERT(map.data(Qt::UserRole + 1).canConvert<MapModel::MapInfo>()); // Houston, we have a problem. |
1053 setMapInfo(map.data(Qt::UserRole + 1).value<MapModel::MapInfo>()); |
1106 setMapInfo(map.data(Qt::UserRole + 1).value<MapModel::MapInfo>()); |
1054 } |
1107 } |
1121 if (master == m_master) return; |
1175 if (master == m_master) return; |
1122 m_master = master; |
1176 m_master = master; |
1123 |
1177 |
1124 foreach (QWidget *widget, m_childWidgets) |
1178 foreach (QWidget *widget, m_childWidgets) |
1125 widget->setEnabled(master); |
1179 widget->setEnabled(master); |
|
1180 |
|
1181 if(m_mapInfo.type == MapModel::StaticMap) |
|
1182 { |
|
1183 lblMapName->setHidden(master); |
|
1184 staticMapList->setVisible(master); |
|
1185 } |
|
1186 else if(m_mapInfo.type == MapModel::MissionMap) |
|
1187 { |
|
1188 lblMapName->setHidden(master); |
|
1189 missionMapList->setVisible(master); |
|
1190 } |
|
1191 |
|
1192 if(m_missingMap) |
|
1193 { |
|
1194 // Force map type reset if host provided missing map |
|
1195 m_missingMap = false; |
|
1196 changeMapType(MapModel::GeneratedMap); |
|
1197 } |
1126 } |
1198 } |
1127 |
1199 |
1128 void HWMapContainer::intSetIconlessTheme(const QString & name) |
1200 void HWMapContainer::intSetIconlessTheme(const QString & name) |
1129 { |
1201 { |
1130 if (name.isEmpty()) return; |
1202 if (name.isEmpty()) return; |