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 #if QT_VERSION >= 0x040300 |
42 mainLayout.setContentsMargins(QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
43 mainLayout.setContentsMargins(QApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
43 1, |
44 1, |
44 QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
45 QApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
45 QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
46 QApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
46 imageButt = new QPushButton(this); |
47 #endif |
47 imageButt->setObjectName("imageButt"); |
48 imageButt = new QPushButton(this); |
48 imageButt->setFixedSize(256 + 6, 128 + 6); |
49 imageButt->setObjectName("imageButt"); |
49 imageButt->setFlat(true); |
50 imageButt->setFixedSize(256 + 6, 128 + 6); |
50 imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum); |
51 imageButt->setFlat(true); |
51 mainLayout.addWidget(imageButt, 0, 0, 1, 2); |
52 imageButt->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);//QSizePolicy::Minimum, QSizePolicy::Minimum); |
52 connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed())); |
53 mainLayout.addWidget(imageButt, 0, 0, 1, 2); |
53 connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme())); |
54 connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed())); |
54 |
55 connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomTheme())); |
55 chooseMap = new QComboBox(this); |
56 |
56 chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
57 chooseMap = new QComboBox(this); |
57 chooseMap->addItem(QComboBox::tr("generated map...")); |
58 chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
58 for (int i = 0; i < mapList->size(); ++i) { |
59 chooseMap->addItem(QComboBox::tr("generated map...")); |
59 QString map = (*mapList)[i]; |
60 chooseMap->addItems(*mapList); |
60 QFile mapCfgFile( |
61 connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int))); |
61 QString("%1/Maps/%2/map.cfg") |
62 mainLayout.addWidget(chooseMap, 1, 1); |
62 .arg(datadir->absolutePath()) |
63 |
63 .arg(map)); |
64 QLabel * lblMap = new QLabel(tr("Map"), this); |
64 if (mapCfgFile.open(QFile::ReadOnly)) { |
65 mainLayout.addWidget(lblMap, 1, 0); |
65 QString theme; |
|
66 QTextStream input(&mapCfgFile); |
|
67 input >> theme; |
|
68 chooseMap->addItem(map, theme); |
|
69 mapCfgFile.close(); |
|
70 } |
|
71 } |
|
72 |
|
73 connect(chooseMap, SIGNAL(currentIndexChanged(int)), this, SLOT(mapChanged(int))); |
|
74 mainLayout.addWidget(chooseMap, 1, 1); |
|
75 |
|
76 QLabel * lblMap = new QLabel(tr("Map"), this); |
|
77 mainLayout.addWidget(lblMap, 1, 0); |
66 |
78 |
67 gbThemes = new IconedGroupBox(this); |
79 gbThemes = new IconedGroupBox(this); |
68 gbThemes->setTitleTextPadding(60); |
80 gbThemes->setTitleTextPadding(60); |
69 gbThemes->setTitle(tr("Themes")); |
81 gbThemes->setTitle(tr("Themes")); |
70 |
82 |
86 connect(lwThemes, SIGNAL(currentRowChanged(int)), this, SLOT(themeSelected(int))); |
98 connect(lwThemes, SIGNAL(currentRowChanged(int)), this, SLOT(themeSelected(int))); |
87 |
99 |
88 gbTLayout->addWidget(lwThemes); |
100 gbTLayout->addWidget(lwThemes); |
89 lwThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); |
101 lwThemes->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum); |
90 |
102 |
91 mainLayout.setSizeConstraint(QLayout::SetFixedSize);//SetMinimumSize |
103 mainLayout.setSizeConstraint(QLayout::SetFixedSize);//SetMinimumSize |
92 |
104 |
93 setRandomSeed(); |
105 setRandomSeed(); |
94 setRandomTheme(); |
106 setRandomTheme(); |
95 } |
107 } |
96 |
108 |
97 void HWMapContainer::setImage(const QImage newImage) |
109 void HWMapContainer::setImage(const QImage newImage) |
98 { |
110 { |
99 QPixmap px(256, 128); |
111 QPixmap px(256, 128); |
100 QPixmap pxres(256, 128); |
112 QPixmap pxres(256, 128); |
101 QPainter p(&pxres); |
113 QPainter p(&pxres); |
102 |
114 |
103 px.fill(Qt::yellow); |
115 px.fill(Qt::yellow); |
104 QBitmap bm = QBitmap::fromImage(newImage); |
116 QBitmap bm = QBitmap::fromImage(newImage); |
105 px.setMask(bm); |
117 px.setMask(bm); |
106 |
118 |
107 QLinearGradient linearGrad(QPoint(128, 0), QPoint(128, 128)); |
119 QLinearGradient linearGrad(QPoint(128, 0), QPoint(128, 128)); |
108 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
120 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
109 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
121 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
110 p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
122 p.fillRect(QRect(0, 0, 256, 128), linearGrad); |
111 p.drawPixmap(QPoint(0, 0), px); |
123 p.drawPixmap(QPoint(0, 0), px); |
112 |
124 |
113 imageButt->setIcon(pxres); |
125 imageButt->setIcon(pxres); |
114 imageButt->setIconSize(QSize(256, 128)); |
126 imageButt->setIconSize(QSize(256, 128)); |
115 chooseMap->setCurrentIndex(0); |
127 chooseMap->setCurrentIndex(0); |
116 pMap = 0; |
128 pMap = 0; |
117 } |
129 } |
118 |
130 |
119 void HWMapContainer::mapChanged(int index) |
131 void HWMapContainer::mapChanged(int index) |
120 { |
132 { |
121 if(!index) { |
133 if(!index) { |
122 changeImage(); |
134 changeImage(); |
123 emit mapChanged("+rnd+"); |
135 gbThemes->show(); |
124 return; |
136 emit mapChanged("+rnd+"); |
125 } |
137 emit themeChanged(chooseMap->itemData(0).toString()); |
126 |
138 } else |
127 loadMap(index); |
139 { |
128 |
140 loadMap(index); |
129 emit mapChanged(chooseMap->currentText()); |
141 gbThemes->hide(); |
|
142 emit mapChanged(chooseMap->currentText()); |
|
143 } |
130 } |
144 } |
131 |
145 |
132 void HWMapContainer::loadMap(int index) |
146 void HWMapContainer::loadMap(int index) |
133 { |
147 { |
134 QPixmap mapImage; |
148 QPixmap mapImage; |
135 if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/preview.png")) { |
149 if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/preview.png")) { |
136 changeImage(); |
150 changeImage(); |
137 chooseMap->setCurrentIndex(0); |
151 chooseMap->setCurrentIndex(0); |
138 return; |
152 return; |
139 } |
153 } |
140 imageButt->setIcon(mapImage); |
154 imageButt->setIcon(mapImage); |
141 QFile mapCfgFile(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/map.cfg"); |
|
142 if (mapCfgFile.open(QFile::ReadOnly)) { |
|
143 QTextStream input(&mapCfgFile); |
|
144 input >> theme; |
|
145 mapCfgFile.close(); |
|
146 } |
|
147 } |
155 } |
148 |
156 |
149 void HWMapContainer::changeImage() |
157 void HWMapContainer::changeImage() |
150 { |
158 { |
151 pMap = new HWMap(); |
159 pMap = new HWMap(); |