author | nemo |
Sun, 26 Feb 2012 12:56:53 -0500 | |
changeset 6744 | 7a4db08d291d |
parent 6700 | e04da46ee43c |
child 6952 | 7f70f37bbf08 |
permissions | -rw-r--r-- |
579 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
6700 | 3 |
* Copyright (c) 2006-2012 Andrey Korotaev <unC0Rr@gmail.com> |
579 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
19 |
#include <QFont> |
|
20 |
#include <QGridLayout> |
|
21 |
#include <QPushButton> |
|
22 |
#include <QListWidget> |
|
627 | 23 |
#include <QListWidgetItem> |
24 |
#include <QFileInfo> |
|
25 |
#include <QMessageBox> |
|
26 |
#include <QInputDialog> |
|
579 | 27 |
|
28 |
#include "hwconsts.h" |
|
5205
78138ae93820
some headers cleanup and rename of stats and playrecord pages for consistency
koda
parents:
4976
diff
changeset
|
29 |
#include "pageplayrecord.h" |
579 | 30 |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
31 |
QLayout * PagePlayDemo::bodyLayoutDefinition() |
579 | 32 |
{ |
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
33 |
QGridLayout * pageLayout = new QGridLayout(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
34 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
35 |
pageLayout->setColumnStretch(0, 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
36 |
pageLayout->setColumnStretch(1, 2); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
37 |
pageLayout->setColumnStretch(2, 1); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
38 |
pageLayout->setRowStretch(2, 100); |
579 | 39 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
40 |
BtnPlayDemo = new QPushButton(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
41 |
BtnPlayDemo->setFont(*font14); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
42 |
BtnPlayDemo->setText(QPushButton::tr("Play demo")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
43 |
pageLayout->addWidget(BtnPlayDemo, 3, 2); |
579 | 44 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
45 |
BtnRenameRecord = new QPushButton(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
46 |
BtnRenameRecord->setText(QPushButton::tr("Rename")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
47 |
pageLayout->addWidget(BtnRenameRecord, 0, 2); |
627 | 48 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
49 |
BtnRemoveRecord = new QPushButton(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
50 |
BtnRemoveRecord->setText(QPushButton::tr("Delete")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
51 |
pageLayout->addWidget(BtnRemoveRecord, 1, 2); |
720 | 52 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
53 |
DemosList = new QListWidget(this); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
54 |
DemosList->setGeometry(QRect(170, 10, 311, 311)); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
55 |
pageLayout->addWidget(DemosList, 0, 1, 3, 1); |
627 | 56 |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
57 |
return pageLayout; |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
58 |
} |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
59 |
|
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
60 |
void PagePlayDemo::connectSignals() |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
61 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
62 |
connect(BtnRenameRecord, SIGNAL(clicked()), this, SLOT(renameRecord())); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
63 |
connect(BtnRemoveRecord, SIGNAL(clicked()), this, SLOT(removeRecord())); |
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
64 |
} |
6009 | 65 |
|
6042
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
66 |
PagePlayDemo::PagePlayDemo(QWidget* parent) : AbstractPage(parent) |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
67 |
{ |
8b5345758f62
some more cleanups/refactoring/blahblah, some button positions may are a bit off atm. also I added a new picture for one of the buttons
sheepluva
parents:
6009
diff
changeset
|
68 |
initPage(); |
579 | 69 |
} |
70 |
||
581 | 71 |
void PagePlayDemo::FillFromDir(RecordType rectype) |
579 | 72 |
{ |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
73 |
QDir dir; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
74 |
QString extension; |
581 | 75 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
76 |
recType = rectype; |
627 | 77 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
78 |
dir.cd(cfgdir->absolutePath()); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
79 |
if (rectype == RT_Demo) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
80 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
81 |
dir.cd("Demos"); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
82 |
extension = "hwd"; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
83 |
BtnPlayDemo->setText(QPushButton::tr("Play demo")); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
84 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
85 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
86 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
87 |
dir.cd("Saves"); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
88 |
extension = "hws"; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
89 |
BtnPlayDemo->setText(QPushButton::tr("Load")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
90 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
91 |
dir.setFilter(QDir::Files); |
580 | 92 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
93 |
QStringList sl = dir.entryList(QStringList(QString("*.%2.%1").arg(extension, *cProtoVer))); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
94 |
sl.replaceInStrings(QRegExp(QString("^(.*)\\.%2\\.%1$").arg(extension, *cProtoVer)), "\\1"); |
580 | 95 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
96 |
DemosList->clear(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
97 |
DemosList->addItems(sl); |
579 | 98 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
99 |
for (int i = 0; i < DemosList->count(); ++i) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
100 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
101 |
DemosList->item(i)->setData(Qt::UserRole, dir.absoluteFilePath(QString("%1.%3.%2").arg(sl[i], extension, *cProtoVer))); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
102 |
DemosList->item(i)->setIcon(recType == RT_Demo ? QIcon(":/res/file_demo.png") : QIcon(":/res/file_save.png")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
103 |
} |
579 | 104 |
} |
105 |
||
627 | 106 |
void PagePlayDemo::renameRecord() |
107 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
108 |
QListWidgetItem * curritem = DemosList->currentItem(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
109 |
if (!curritem) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
110 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
111 |
QMessageBox::critical(this, |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
112 |
tr("Error"), |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
113 |
tr("Please select record from the list"), |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
114 |
tr("OK")); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
115 |
return ; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
116 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
117 |
QFile rfile(curritem->data(Qt::UserRole).toString()); |
627 | 118 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
119 |
QFileInfo finfo(rfile); |
627 | 120 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
121 |
bool ok; |
627 | 122 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
123 |
QString newname = QInputDialog::getText(this, tr("Rename dialog"), tr("Enter new file name:"), QLineEdit::Normal, finfo.completeBaseName().replace("." + *cProtoVer, ""), &ok); |
627 | 124 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
125 |
if(ok && newname.size()) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
126 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
127 |
QString newfullname = QString("%1/%2.%3.%4") |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
128 |
.arg(finfo.absolutePath()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
129 |
.arg(newname) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
130 |
.arg(*cProtoVer) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
131 |
.arg(finfo.suffix()); |
627 | 132 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
133 |
ok = rfile.rename(newfullname); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
134 |
if(!ok) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
135 |
QMessageBox::critical(this, tr("Error"), tr("Cannot rename to") + newfullname); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
136 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
137 |
FillFromDir(recType); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
138 |
} |
627 | 139 |
} |
720 | 140 |
|
141 |
void PagePlayDemo::removeRecord() |
|
142 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
143 |
QListWidgetItem * curritem = DemosList->currentItem(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
144 |
if (!curritem) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
145 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
146 |
QMessageBox::critical(this, |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
147 |
tr("Error"), |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
148 |
tr("Please select record from the list"), |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
149 |
tr("OK")); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
150 |
return ; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
151 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
152 |
QFile rfile(curritem->data(Qt::UserRole).toString()); |
720 | 153 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
154 |
bool ok; |
720 | 155 |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
156 |
ok = rfile.remove(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
157 |
if(!ok) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
158 |
QMessageBox::critical(this, tr("Error"), tr("Cannot delete file")); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
159 |
else |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
2742
diff
changeset
|
160 |
FillFromDir(recType); |
720 | 161 |
} |
5865 | 162 |
|
163 |
bool PagePlayDemo::isSave() |
|
164 |
{ |
|
165 |
return recType == RT_Save; |
|
166 |
} |