- Some style changes by nemo
authorunc0rr
Mon, 16 Mar 2009 19:55:56 +0000
changeset 1897 e9dcb47013c7
parent 1896 fdacad5d0acc
child 1898 f0ab0c77946d
- Some style changes by nemo - Add ability for schemes save and load
QTfrontend/about.cpp
QTfrontend/ammoSchemeModel.cpp
QTfrontend/ammoSchemeModel.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/main.cpp
--- a/QTfrontend/about.cpp	Mon Mar 16 14:43:15 2009 +0000
+++ b/QTfrontend/about.cpp	Mon Mar 16 19:55:56 2009 +0000
@@ -35,6 +35,10 @@
 
 	lbl1->setOpenExternalLinks(true);
 	lbl1->setText(
+            "<style type=\"text/css\">"
+            "a { color: #ffcc00; }"
+//            "a:hover { color: yellow; }"
+            "</style>" 
 			"<div align=\"center\"><h1>Hedgewars</h1>"
 			"<h3>" + QLabel::tr("Version") + " " + *cVersionString + "</h3>"
 			"<p><a href=\"http://www.hedgewars.org/\">http://www.hedgewars.org/</a></p><br>" +
@@ -47,7 +51,12 @@
 	QTextBrowser *lbl2 = new QTextBrowser(this);
 
 	lbl2->setOpenExternalLinks(true);
-	lbl2->setText(  QString("<h2>") +
+	lbl2->setText(
+            "<style type=\"text/css\">"
+            "a { color: #ffcc00; }"
+//            "a:hover { color: yellow; }"
+            "</style>" +
+            QString("<h2>") +
 			QLabel::tr("Developers:") +
 			"</h2><p>"
 			"Engine, frontend, net server: Andrey Korotaev &lt;<a href=\"mailto:unC0Rr@gmail.com\">unC0Rr@gmail.com</a>&gt;<br>"
--- a/QTfrontend/ammoSchemeModel.cpp	Mon Mar 16 14:43:15 2009 +0000
+++ b/QTfrontend/ammoSchemeModel.cpp	Mon Mar 16 19:55:56 2009 +0000
@@ -18,11 +18,37 @@
 
 #include <QDebug>
 #include <QModelIndex>
+
 #include "ammoSchemeModel.h"
+#include "hwconsts.h"
 
-AmmoSchemeModel::AmmoSchemeModel(QObject* parent) :
-  QAbstractTableModel(parent)
+AmmoSchemeModel::AmmoSchemeModel(QObject* parent, const QString & fileName) :
+	QAbstractTableModel(parent),
+	fileConfig(fileName, QSettings::IniFormat)
 {
+	spNames
+		<< "name"             //  0
+		<< "fortsmode"        //  1
+		<< "divteams"         //  2
+		<< "solidland"        //  3
+		<< "border"           //  4
+		<< "lowgrav"          //  5
+		<< "laser"            //  6
+		<< "invulnerability"  //  7
+		<< "mines"            //  8
+		<< "damagefactor"     //  9
+		<< "turntime"         // 10
+		<< "health"           // 11
+		<< "suddendeath"      // 12
+		<< "caseprobability"  // 13
+		;
+
+
+	QStringList predefSchemesNames;
+	predefSchemesNames
+		<< tr("Default")
+		<< tr("Pro mode");
+	
 	defaultScheme
 		<< QVariant(tr("Default")) // name           0
 		<< QVariant(false)         // fortsmode      1
@@ -40,7 +66,43 @@
 		<< QVariant(5)             // case prob      13
 		;
 
+	QList<QVariant> proMode;
+	proMode
+		<< QVariant(tr("Pro mode"))// name           0
+		<< QVariant(false)         // fortsmode      1
+		<< QVariant(false)         // team divide    2
+		<< QVariant(false)         // solid land     3
+		<< QVariant(false)         // border         4
+		<< QVariant(false)         // low gravity    5
+		<< QVariant(false)         // laser sight    6
+		<< QVariant(false)         // invulnerable   7
+		<< QVariant(false)         // add mines      8
+		<< QVariant(100)           // damage modfier 9
+		<< QVariant(15)            // turn time      10
+		<< QVariant(100)           // init health    11
+		<< QVariant(15)            // sudden death   12
+		<< QVariant(0)             // case prob      13
+		;
+
 	schemes.append(defaultScheme);
+	schemes.append(proMode);
+
+
+	int size = fileConfig.beginReadArray("schemes");
+	for (int i = 0; i < size; ++i) {
+		fileConfig.setArrayIndex(i);
+
+		if (!predefSchemesNames.contains(fileConfig.value(spNames[0]).toString()))
+		{
+			QList<QVariant> scheme;
+
+			for (int k = 0; k < spNames.size(); ++k)
+				scheme << fileConfig.value(spNames[k], defaultScheme[k]);
+
+			schemes.append(scheme);
+		}
+	}
+	fileConfig.endArray();
 }
 
 QVariant AmmoSchemeModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -102,6 +164,7 @@
 {
 	beginRemoveRows(parent, row, row);
 
+	fileConfig.remove(schemes[row][0].toString());
 	schemes.removeAt(row);
 
 	endRemoveRows();
@@ -118,3 +181,17 @@
 
 	return schemes[index.row()][index.column()];
 }
+
+void AmmoSchemeModel::Save()
+{
+	fileConfig.beginWriteArray("schemes");
+	for (int i = 0; i < schemes.size(); ++i) {
+		fileConfig.setArrayIndex(i);
+
+		QList<QVariant> scheme = schemes[i];
+
+		for (int k = 0; k < spNames.size(); ++k)
+			fileConfig.setValue(spNames[k], scheme[k]);
+	}
+	fileConfig.endArray();
+}
--- a/QTfrontend/ammoSchemeModel.h	Mon Mar 16 14:43:15 2009 +0000
+++ b/QTfrontend/ammoSchemeModel.h	Mon Mar 16 19:55:56 2009 +0000
@@ -19,7 +19,9 @@
 #ifndef _AMMO_SCHEME_MODEL_INCLUDED
 #define _AMMO_SCHEME_MODEL_INCLUDED
 
+#include <QSettings>
 #include <QAbstractTableModel>
+#include <QStringList>
 #include <QList>
 
 class AmmoSchemeModel : public QAbstractTableModel
@@ -27,7 +29,7 @@
 	Q_OBJECT
 
 public:
-	AmmoSchemeModel(QObject *parent = 0);
+	AmmoSchemeModel(QObject * parent, const QString & fileName);
 
 	QVariant headerData(int section, Qt::Orientation orientation, int role) const;
 	int rowCount(const QModelIndex & parent) const;
@@ -38,6 +40,9 @@
 	bool removeRows(int row, int count, const QModelIndex & parent = QModelIndex());
 	QVariant data(const QModelIndex &index, int role) const;
 
+public slots:
+	void Save();
+
 signals:
 	void dataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
 
@@ -46,6 +51,10 @@
 
 private:
 	QList<QVariant> defaultScheme;
+
+	QSettings fileConfig;
+
+	QStringList spNames;
 };
 
 #endif // _AMMO_SCHEME_MODEL_INCLUDED
--- a/QTfrontend/hwform.cpp	Mon Mar 16 14:43:15 2009 +0000
+++ b/QTfrontend/hwform.cpp	Mon Mar 16 19:55:56 2009 +0000
@@ -150,7 +150,7 @@
 	connect(ui.pageScheme->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
 
 
-	AmmoSchemeModel * ammoSchemeModel = new AmmoSchemeModel(this);
+	ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
 	ui.pageScheme->setModel(ammoSchemeModel);
 	ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel);
 
@@ -365,6 +365,8 @@
 
 void HWForm::btnExitClicked()
 {
+	ammoSchemeModel->Save();
+	
 	if (eggTimer.elapsed() < 3000)
 		close();
 	else
--- a/QTfrontend/hwform.h	Mon Mar 16 14:43:15 2009 +0000
+++ b/QTfrontend/hwform.h	Mon Mar 16 19:55:56 2009 +0000
@@ -34,6 +34,7 @@
 class GameUIConfig;
 class HWNetRegisterServer;
 class QCloseEvent;
+class AmmoSchemeModel;
 
 class HWForm : public QMainWindow
 {
@@ -123,6 +124,7 @@
 	HWTeam * editedTeam;
 	HWNewNet * hwnet;
 	GameUIConfig * config;
+	AmmoSchemeModel * ammoSchemeModel;
 	QStack<quint8> PagesStack;
 	HWNetServer* pnetserver;
 	HWNetRegisterServer* pRegisterServer;
--- a/QTfrontend/main.cpp	Mon Mar 16 14:43:15 2009 +0000
+++ b/QTfrontend/main.cpp	Mon Mar 16 19:55:56 2009 +0000
@@ -62,12 +62,7 @@
 				"background-color: #870c8f;"
 				"}"
 
-			"QPushButton, QLineEdit, QLabel, QHeaderView, "
-			"QListWidget, QTableView, QTextBrowser, QSpinBox, "
-			"QToolBox::tab, QToolBox::tab QWidget, QComboBox, "
-			"QComboBox QAbstractItemView, IconedGroupBox, .QGroupBox, "
-            "GameCFGWidget, TeamSelWidget, SelWeaponWidget, "
-			"QCheckBox, QRadioButton, QMenu::item, QTabBar::tab:selected {"
+			"* {"
 				"color: #ffcc00;"
 			"}"
 
@@ -79,7 +74,8 @@
 			"QPushButton, QListWidget, QTableView, QLineEdit, QHeaderView, "
 			"QTextBrowser, QSpinBox, QToolBox, QComboBox, "
             "QComboBox QAbstractItemView, IconedGroupBox, "
-			".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, QTabWidget::pane {"
+			".QGroupBox, GameCFGWidget, TeamSelWidget, SelWeaponWidget, "
+            "QTabWidget::pane, QTabBar::tab {"
 				"border: solid;"
 				"border-width: 3px;"
 				"border-color: #ffcc00;"
@@ -138,14 +134,10 @@
 			"}"
 
             "QTabBar::tab {"
-                 "border-top: solid;"
-                 "border-left: solid;"
-                 "border-right: solid;"
-                 "border-width: 3px;"
+                 "border-bottom-width: 0;"
                  "border-radius: 0;"
                  "border-top-left-radius: 6px;"
                  "border-top-right-radius: 6px;"
-                 "border-color: #ffcc00;"
                  "padding: 3px;"
             "}"
             "QTabBar::tab:!selected {"