37 HWMapContainer::HWMapContainer(QWidget * parent) : |
37 HWMapContainer::HWMapContainer(QWidget * parent) : |
38 QWidget(parent), |
38 QWidget(parent), |
39 mainLayout(this), |
39 mainLayout(this), |
40 pMap(0) |
40 pMap(0) |
41 { |
41 { |
|
42 hhSmall.load(":/res/hh_small.png"); |
|
43 hhLimit = 18; |
|
44 |
42 mainLayout.setContentsMargins(QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
45 mainLayout.setContentsMargins(QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
43 1, |
46 1, |
44 QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
47 QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
45 QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
48 QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
|
49 |
46 imageButt = new QPushButton(this); |
50 imageButt = new QPushButton(this); |
47 imageButt->setObjectName("imageButt"); |
51 imageButt->setObjectName("imageButt"); |
48 imageButt->setFixedSize(256 + 6, 128 + 6); |
52 imageButt->setFixedSize(256 + 6, 128 + 6); |
49 imageButt->setFlat(true); |
53 imageButt->setFlat(true); |
50 imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum); |
54 imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum); |
59 QString map = (*mapList)[i]; |
63 QString map = (*mapList)[i]; |
60 QFile mapCfgFile( |
64 QFile mapCfgFile( |
61 QString("%1/Maps/%2/map.cfg") |
65 QString("%1/Maps/%2/map.cfg") |
62 .arg(datadir->absolutePath()) |
66 .arg(datadir->absolutePath()) |
63 .arg(map)); |
67 .arg(map)); |
|
68 |
64 if (mapCfgFile.open(QFile::ReadOnly)) { |
69 if (mapCfgFile.open(QFile::ReadOnly)) { |
65 QString theme; |
70 QString theme; |
|
71 quint32 limit = 0; |
|
72 QList<QVariant> mapInfo; |
66 QTextStream input(&mapCfgFile); |
73 QTextStream input(&mapCfgFile); |
67 input >> theme; |
74 input >> theme; |
68 chooseMap->addItem(map, theme); |
75 input >> limit; |
|
76 mapInfo.push_back(theme); |
|
77 if (limit) |
|
78 mapInfo.push_back(limit); |
|
79 else |
|
80 mapInfo.push_back(18); |
|
81 chooseMap->addItem(map, mapInfo); |
69 mapCfgFile.close(); |
82 mapCfgFile.close(); |
70 } |
83 } |
71 } |
84 } |
72 |
85 |
73 connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int))); |
86 connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int))); |
120 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
133 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
121 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
134 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
122 p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
135 p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
123 p.drawPixmap(QPoint(0, 0), px); |
136 p.drawPixmap(QPoint(0, 0), px); |
124 |
137 |
125 imageButt->setIcon(pxres); |
138 addInfoToPreview(pxres); |
126 imageButt->setIconSize(QSize(256, 128)); |
|
127 chooseMap->setCurrentIndex(0); |
139 chooseMap->setCurrentIndex(0); |
128 pMap = 0; |
140 pMap = 0; |
|
141 } |
|
142 |
|
143 void HWMapContainer::setHHLimit(int newHHLimit) |
|
144 { |
|
145 hhLimit = newHHLimit; |
129 } |
146 } |
130 |
147 |
131 void HWMapContainer::mapChanged(int index) |
148 void HWMapContainer::mapChanged(int index) |
132 { |
149 { |
133 if(!index) { |
150 if(!index) { |
149 if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/preview.png")) { |
166 if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/preview.png")) { |
150 changeImage(); |
167 changeImage(); |
151 chooseMap->setCurrentIndex(0); |
168 chooseMap->setCurrentIndex(0); |
152 return; |
169 return; |
153 } |
170 } |
154 imageButt->setIcon(mapImage); |
171 |
|
172 hhLimit = chooseMap->itemData(index).toList()[1].toInt(); |
|
173 addInfoToPreview(mapImage); |
|
174 } |
|
175 |
|
176 // Should this add text to identify map size? |
|
177 void HWMapContainer::addInfoToPreview(QPixmap image) |
|
178 { |
|
179 QPixmap finalImage = QPixmap(image.size()); |
|
180 finalImage.fill(QColor(0, 0, 0, 0)); |
|
181 |
|
182 QPainter p(&finalImage); |
|
183 p.drawPixmap(image.rect(), image); |
|
184 //p.setPen(QColor(0xf4,0x9e,0xe9)); |
|
185 p.setPen(QColor(0xff,0xcc,0x00)); |
|
186 p.setBrush(QColor(0, 0, 0)); |
|
187 p.drawRect(image.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20); |
|
188 p.setFont(QFont("MS Shell Dlg", 10)); |
|
189 p.drawText(image.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, QString::number(hhLimit)); |
|
190 p.drawPixmap(image.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall); |
|
191 |
|
192 imageButt->setIcon(finalImage); |
|
193 imageButt->setIconSize(image.size()); |
155 } |
194 } |
156 |
195 |
157 void HWMapContainer::changeImage() |
196 void HWMapContainer::changeImage() |
158 { |
197 { |
159 pMap = new HWMap(); |
198 pMap = new HWMap(); |
160 connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage))); |
199 connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage))); |
|
200 connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int))); |
161 pMap->getImage(m_seed.toStdString()); |
201 pMap->getImage(m_seed.toStdString()); |
162 } |
202 } |
163 |
203 |
164 void HWMapContainer::themeSelected(int currentRow) |
204 void HWMapContainer::themeSelected(int currentRow) |
165 { |
205 { |
166 QString theme = Themes->at(currentRow); |
206 QString theme = Themes->at(currentRow); |
167 chooseMap->setItemData(0, theme); |
207 QList<QVariant> mapInfo; |
|
208 mapInfo.push_back(theme); |
|
209 mapInfo.push_back(18); |
|
210 chooseMap->setItemData(0, mapInfo); |
168 gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(theme))); |
211 gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(theme))); |
169 emit themeChanged(theme); |
212 emit themeChanged(theme); |
170 } |
213 } |
171 |
214 |
172 QString HWMapContainer::getCurrentSeed() const |
215 QString HWMapContainer::getCurrentSeed() const |