23 #include <QPainter> |
23 #include <QPainter> |
24 #include <QLinearGradient> |
24 #include <QLinearGradient> |
25 #include <QColor> |
25 #include <QColor> |
26 #include <QTextStream> |
26 #include <QTextStream> |
27 #include <QLabel> |
27 #include <QLabel> |
28 #include <QListWidget> |
28 #include <QListView> |
29 #include <QVBoxLayout> |
29 #include <QVBoxLayout> |
30 #include <QIcon> |
30 #include <QIcon> |
31 #include <QLineEdit> |
31 #include <QLineEdit> |
32 #include <QMessageBox> |
32 #include <QMessageBox> |
|
33 #include <QStringListModel> |
33 |
34 |
34 #include "hwconsts.h" |
35 #include "hwconsts.h" |
35 #include "mapContainer.h" |
36 #include "mapContainer.h" |
36 #include "igbox.h" |
37 #include "igbox.h" |
37 #include "HWApplication.h" |
38 #include "HWApplication.h" |
198 mapLayout->addWidget(gbThemes, 0, 2, 3, 1); |
199 mapLayout->addWidget(gbThemes, 0, 2, 3, 1); |
199 |
200 |
200 QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes); |
201 QVBoxLayout * gbTLayout = new QVBoxLayout(gbThemes); |
201 gbTLayout->setContentsMargins(0, 0, 0 ,0); |
202 gbTLayout->setContentsMargins(0, 0, 0 ,0); |
202 gbTLayout->setSpacing(0); |
203 gbTLayout->setSpacing(0); |
203 lwThemes = new QListWidget(mapWidget); |
204 lvThemes = new QListView(mapWidget); |
204 lwThemes->setMinimumHeight(30); |
205 lvThemes->setMinimumHeight(30); |
205 lwThemes->setFixedWidth(140); |
206 lvThemes->setFixedWidth(140); |
206 QFile tmpfile; |
207 lvThemes->setModel(themesModel); |
207 for (int i = 0; i < Themes->size(); ++i) { |
208 lvThemes->setIconSize(QSize(16, 16)); |
208 QListWidgetItem * lwi = new QListWidgetItem(); |
209 lvThemes->setEditTriggers(QListView::NoEditTriggers); |
209 lwi->setText(Themes->at(i)); |
210 |
210 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon.png").arg(cfgdir->absolutePath()).arg(Themes->at(i))); |
211 connect(lvThemes->selectionModel(), SIGNAL(currentRowChanged( const QModelIndex &, const QModelIndex &)), this, SLOT(themeSelected( const QModelIndex &, const QModelIndex &))); |
211 if (tmpfile.exists()) lwi->setIcon(QIcon(QFileInfo(tmpfile).absoluteFilePath())); |
|
212 else lwi->setIcon(QIcon(QString("%1/Themes/%2/icon.png").arg(datadir->absolutePath()).arg(Themes->at(i)))); |
|
213 //lwi->setTextAlignment(Qt::AlignHCenter); |
|
214 lwThemes->addItem(lwi); |
|
215 } |
|
216 connect(lwThemes, SIGNAL(currentRowChanged(int)), this, SLOT(themeSelected(int))); |
|
217 |
212 |
218 // override default style to tighten up theme scroller |
213 // override default style to tighten up theme scroller |
219 lwThemes->setStyleSheet(QString( |
214 lvThemes->setStyleSheet(QString( |
220 "QListWidget{" |
215 "QListView{" |
221 "border: solid;" |
216 "border: solid;" |
222 "border-width: 0px;" |
217 "border-width: 0px;" |
223 "border-radius: 0px;" |
218 "border-radius: 0px;" |
224 "border-color: transparent;" |
219 "border-color: transparent;" |
225 "background-color: #0d0544;" |
220 "background-color: #0d0544;" |
227 "font: bold 13px;" |
222 "font: bold 13px;" |
228 "}" |
223 "}" |
229 ) |
224 ) |
230 ); |
225 ); |
231 |
226 |
232 gbTLayout->addWidget(lwThemes); |
227 gbTLayout->addWidget(lvThemes); |
233 lwThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); |
228 lvThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); |
234 |
229 |
235 mapLayout->setSizeConstraint(QLayout::SetFixedSize); |
230 mapLayout->setSizeConstraint(QLayout::SetFixedSize); |
236 |
231 |
237 QWidget* seedWidget = new QWidget(this); |
232 QWidget* seedWidget = new QWidget(this); |
238 mainLayout.addWidget(seedWidget, 1, 0); |
233 mainLayout.addWidget(seedWidget, 1, 0); |
374 getMazeSize(), |
369 getMazeSize(), |
375 getDrawnMapData() |
370 getDrawnMapData() |
376 ); |
371 ); |
377 } |
372 } |
378 |
373 |
379 void HWMapContainer::themeSelected(int currentRow) |
374 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &) |
380 { |
375 { |
381 QString theme = Themes->at(currentRow); |
376 QString theme = current.data().toString(); |
382 QList<QVariant> mapInfo; |
377 QList<QVariant> mapInfo; |
383 mapInfo.push_back(QString("+rnd+")); |
378 mapInfo.push_back(QString("+rnd+")); |
384 mapInfo.push_back(theme); |
379 mapInfo.push_back(theme); |
385 mapInfo.push_back(18); |
380 mapInfo.push_back(18); |
386 mapInfo.push_back(false); |
381 mapInfo.push_back(false); |
387 chooseMap->setItemData(0, mapInfo); |
382 chooseMap->setItemData(0, mapInfo); |
388 mapInfo[0] = QString("+maze+"); |
383 mapInfo[0] = QString("+maze+"); |
389 chooseMap->setItemData(1, mapInfo); |
384 chooseMap->setItemData(1, mapInfo); |
390 mapInfo[0] = QString("+drawn+"); |
385 mapInfo[0] = QString("+drawn+"); |
391 chooseMap->setItemData(2, mapInfo); |
386 chooseMap->setItemData(2, mapInfo); |
392 QFile tmpfile; |
387 |
393 tmpfile.setFileName(QString("%1/Data/Themes/%2/icon@2x.png").arg(cfgdir->absolutePath()).arg(theme)); |
388 gbThemes->setIcon(qVariantValue<QIcon>(current.data(Qt::UserRole))); |
394 if (tmpfile.exists()) gbThemes->setIcon(QIcon(QFileInfo(tmpfile).absoluteFilePath())); |
|
395 else gbThemes->setIcon(QIcon(QString("%1/Themes/%2/icon@2x.png").arg(datadir->absolutePath()).arg(theme))); |
|
396 emit themeChanged(theme); |
389 emit themeChanged(theme); |
397 } |
390 } |
398 |
391 |
399 QString HWMapContainer::getCurrentSeed() const |
392 QString HWMapContainer::getCurrentSeed() const |
400 { |
393 { |
537 updatePreview(); |
531 updatePreview(); |
538 } |
532 } |
539 |
533 |
540 void HWMapContainer::setRandomTheme() |
534 void HWMapContainer::setRandomTheme() |
541 { |
535 { |
542 if(!Themes->size()) return; |
536 if(!themesModel->rowCount()) return; |
543 quint32 themeNum = rand() % Themes->size(); |
537 quint32 themeNum = rand() % themesModel->rowCount(); |
544 lwThemes->setCurrentRow(themeNum); |
538 lvThemes->setCurrentIndex(themesModel->index(themeNum)); |
545 } |
539 } |
546 |
540 |
547 void HWMapContainer::intSetTemplateFilter(int filter) |
541 void HWMapContainer::intSetTemplateFilter(int filter) |
548 { |
542 { |
549 cbTemplateFilter->setCurrentIndex(filter); |
543 cbTemplateFilter->setCurrentIndex(filter); |