next steps skinning implementation (config for game table style works)

This commit is contained in:
doitux
2009-03-30 09:08:11 +00:00
parent 2c7b18962f
commit a2827fb4bc
7 changed files with 180 additions and 172 deletions
+6 -6
View File
@@ -409,9 +409,9 @@ p, li { white-space: pre-wrap; }
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="pushButton_selectGameTableStyle">
<widget class="QPushButton" name="pushButton_activateGameTableStyle">
<property name="text">
<string>Select</string>
<string>Activate</string>
</property>
</widget>
</item>
@@ -436,7 +436,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_delGameTableStyle">
<widget class="QPushButton" name="pushButton_removeGameTableStyle">
<property name="text">
<string>Remove</string>
</property>
@@ -487,9 +487,9 @@ p, li { white-space: pre-wrap; }
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QPushButton" name="pushButton_selectCardDeck">
<widget class="QPushButton" name="pushButton_activateCardDeck">
<property name="text">
<string>Select</string>
<string>Activate</string>
</property>
</widget>
</item>
@@ -514,7 +514,7 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_delCardDeck">
<widget class="QPushButton" name="pushButton_removeCardDeck">
<property name="text">
<string>Remove</string>
</property>
+149 -14
View File
@@ -24,6 +24,7 @@
#include "configfile.h"
#include <net/socket_startup.h>
#define POKERTH_DISTRIBUTED_GAME_TABLE_STYLES 1
using namespace std;
@@ -104,6 +105,13 @@ settingsDialogImpl::settingsDialogImpl(QWidget *parent, ConfigFile *c, selectAva
connect(groupBox_automaticServerConfig, SIGNAL(toggled(bool)), this, SLOT(toggleGroupBoxAutomaticServerConfig(bool)));
connect(groupBox_manualServerConfig, SIGNAL(toggled(bool)), this, SLOT(toggleGroupBoxManualServerConfig(bool)));
connect( listWidget_gameTableStyles, SIGNAL( currentItemChanged(QListWidgetItem*, QListWidgetItem*) ), this, SLOT ( showCurrentGameTableStylePreview() ));
connect( pushButton_activateGameTableStyle, SIGNAL( clicked() ), this, SLOT( setSelectedGameTableStyleActivated()) );
connect( pushButton_addGameTableStyle, SIGNAL( clicked() ), this, SLOT( addGameTableStyle()) );
connect( pushButton_removeGameTableStyle, SIGNAL( clicked() ), this, SLOT( removeGameTableStyle()) );
}
void settingsDialogImpl::exec() {
@@ -228,21 +236,49 @@ void settingsDialogImpl::exec() {
//S t y l e
// define PokerTH default GameTableStyle
// GameTableStyleReader defaultStyle(myConfig);
// defaultStyle.readStyleFile(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/table/default/defaulttablestyle.xml");
//
// QListWidgetItem *defaultItem = new QListWidgetItem(defaultStyle.getStyleDescription(),listWidget_gameTableStyles);
// defaultItem->setData(15, QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/table/default/defaulttablestyle.xml");
// defaultItem->setIcon(QIcon(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/misc/rating.png"));
//load secondary styles into list
listWidget_gameTableStyles->clear();
//show selected gametablestyles preview
// QFileInfo info(defaultGameTableStyleFile);
// QPixmap preview(info.absolutePath()+"/"+defaultStyle.getPreview());
// if(preview.height() > 160 || preview.width() > 120) label_gameTableStylePreview->setPixmap(preview.scaled(160,120,Qt::KeepAspectRatio,Qt::SmoothTransformation));
// else label_gameTableStylePreview->setPixmap(preview);
GameTableStyleReader defaultStyle(myConfig);
defaultStyle.readStyleFile(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/table/default/defaulttablestyle.xml");
QListWidgetItem *defaultItem = new QListWidgetItem(defaultStyle.getStyleDescription(),listWidget_gameTableStyles);
defaultItem->setData(15, QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/table/default/defaulttablestyle.xml");
//load secondary styles into list (if fallback no entry)
myGameTableStylesList = myConfig->readConfigStringList("GameTableStylesList");
list<std::string>::iterator it1;
for(it1= myGameTableStylesList.begin(); it1 != myGameTableStylesList.end(); it1++) {
GameTableStyleReader nextStyle(myConfig);
nextStyle.readStyleFile(QString::fromUtf8(it1->c_str()));
if(!nextStyle.getFallBack()) {
QListWidgetItem *nextItem = new QListWidgetItem(nextStyle.getStyleDescription());
nextItem->setData(15,QString::fromUtf8(it1->c_str()));
listWidget_gameTableStyles->addItem(nextItem);
}
}
//set current Game Table Style from config file
GameTableStyleReader currentGameTableStyle(myConfig);
currentGameTableStyle.readStyleFile(QString::fromUtf8(myConfig->readConfigString("CurrentGameTableStyle").c_str()));
int i;
bool currentFound(FALSE);
for(i=0; i < listWidget_gameTableStyles->count(); i++) {
QListWidgetItem *item = listWidget_gameTableStyles->item(i);
if(item->data(15) == currentGameTableStyle.getCurrentFileName()) {
item->setIcon(QIcon(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/misc/rating.png"));
listWidget_gameTableStyles->setCurrentItem(item);
currentFound=TRUE;
}
else item->setIcon(QIcon());
}
if(!currentFound) {
qDebug() << "Config ERROR: current game table style file not found in List. Mark default as selected.";
QListWidgetItem *item = listWidget_gameTableStyles->item(0);
item->setIcon(QIcon(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/misc/rating.png"));
listWidget_gameTableStyles->setCurrentItem(item);
}
//refresh Game Table Style Preview
showCurrentGameTableStylePreview();
//define PokerTH default CardDeck
@@ -432,6 +468,22 @@ void settingsDialogImpl::isAccepted() {
}
}
//S T Y L E
//save game table styles list
myGameTableStylesList.clear();
int i;
for(i=POKERTH_DISTRIBUTED_GAME_TABLE_STYLES; i < listWidget_gameTableStyles->count(); i++) {
QListWidgetItem *item = listWidget_gameTableStyles->item(i);
myGameTableStylesList.push_back(item->data(15).toString().toUtf8().constData());
}
myConfig->writeConfigStringList("GameTableStylesList", myGameTableStylesList);
//save current game table style
for(i=0; i < listWidget_gameTableStyles->count(); i++) {
QListWidgetItem *item = listWidget_gameTableStyles->item(i);
if(!item->icon().isNull())
myConfig->writeConfigString("CurrentGameTableStyle", item->data(15).toString().toUtf8().constData());
}
//Sound
myConfig->writeConfigInt("PlaySoundEffects", groupBox_playSoundEffects->isChecked());
myConfig->writeConfigInt("SoundVolume", horizontalSlider_soundVolume->value());
@@ -730,3 +782,86 @@ void settingsDialogImpl::toggleGroupBoxManualServerConfig(bool toggleState) {
else groupBox_automaticServerConfig->setChecked(TRUE);
}
void settingsDialogImpl::showCurrentGameTableStylePreview()
{
QListWidgetItem* item = listWidget_gameTableStyles->currentItem();
if(item) {
GameTableStyleReader style(myConfig);
style.readStyleFile(item->data(15).toString());
QPixmap preview(style.getPreview());
if(preview.height() > 160 || preview.width() > 120) label_gameTableStylePreview->setPixmap(preview.scaled(160,120,Qt::KeepAspectRatio,Qt::SmoothTransformation));
else label_gameTableStylePreview->setPixmap(preview);
}
}
void settingsDialogImpl::setSelectedGameTableStyleActivated()
{
QListWidgetItem* selectedItem = listWidget_gameTableStyles->currentItem();
if(selectedItem) {
int i;
for(i=0; i < listWidget_gameTableStyles->count(); i++) {
QListWidgetItem *item = listWidget_gameTableStyles->item(i);
if(item == selectedItem) {
item->setIcon(QIcon(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/misc/rating.png"));
}
else item->setIcon(QIcon());
}
}
}
void settingsDialogImpl::addGameTableStyle()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Please select your game table style"),
QDir::home().absolutePath(),
tr("PokerTH game table styles (*.xml)"));
if (!fileName.isEmpty()) {
int i;
bool fileNameAlreadyFound(FALSE);
for(i=0; i < listWidget_gameTableStyles->count(); i++) {
QListWidgetItem *item = listWidget_gameTableStyles->item(i);
if(item->data(15).toString() == fileName)
fileNameAlreadyFound = TRUE;
}
if(fileNameAlreadyFound) {
QMessageBox::warning(this, tr("Game Table Style Error"),
tr("Selected game table style file is already in the list. \nPlease select another one to add!"),
QMessageBox::Ok);
}
else {
GameTableStyleReader newStyle(myConfig);
newStyle.readStyleFile(fileName);
if(!newStyle.getFallBack()) {
QListWidgetItem *newItem = new QListWidgetItem(newStyle.getStyleDescription());
newItem->setData(15,fileName);
listWidget_gameTableStyles->addItem(newItem);
}
else {
QMessageBox::warning(this, tr("Game Table Style File Error"),
tr("Could not read game table style file. \nStyle will not be placed into list!"),
QMessageBox::Ok);
}
}
}
}
void settingsDialogImpl::removeGameTableStyle()
{
//never delete PokerTH defaullt Styles
if(listWidget_gameTableStyles->currentRow() >= POKERTH_DISTRIBUTED_GAME_TABLE_STYLES) {
QListWidgetItem* selectedItem = listWidget_gameTableStyles->currentItem();
if(selectedItem) {
// if selected is activated --> swith activation to first default
if(!selectedItem->icon().isNull()) {
QListWidgetItem* firstItem = listWidget_gameTableStyles->item(0);
firstItem->setIcon(QIcon(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/misc/rating.png"));
}
//remove from List
listWidget_gameTableStyles->takeItem(listWidget_gameTableStyles->currentRow());
}
}
}
@@ -79,7 +79,12 @@ public slots:
void toggleGroupBoxAutomaticServerConfig(bool /*toggleState*/);
void toggleGroupBoxManualServerConfig(bool /*toggleState*/);
void setSelectedGameTableStyleActivated();
void showCurrentGameTableStylePreview();
void addGameTableStyle();
void removeGameTableStyle();
private:
bool playerNickIsChanged;
@@ -95,6 +100,8 @@ private:
int myNetAfterMBAlwaysRaiseValue;
std::list<int> myManualBlindsList;
std::list<int> myNetManualBlindsList;
std::list<std::string> myGameTableStylesList;
std::list<std::string> myCardDecksList;
ConfigFile* myConfig;
boost::shared_ptr<selectAvatarDialogImpl> mySelectAvatarDialogImpl;
+10 -15
View File
@@ -26,7 +26,7 @@
using namespace std;
GameTableStyleReader::GameTableStyleReader(ConfigFile *c, gameTableImpl *w) : myConfig(c), myW(w)
GameTableStyleReader::GameTableStyleReader(ConfigFile *c, gameTableImpl *w) : myConfig(c), myW(w), fallBack(0)
{
}
@@ -40,26 +40,15 @@ void GameTableStyleReader::readStyleFile(QString file) {
string tinyFileName;
QMessageBox::warning(myW, tr("FILE"),
file,
QMessageBox::Ok);
//if style file failed --> default style fallback
if(QFile(file).exists()) {
currentFileName = QFile(file).fileName();
tinyFileName = currentFileName.toStdString();
QMessageBox::warning(myW, tr("WORKS"),
currentFileName,
QMessageBox::Ok);
tinyFileName = currentFileName.toUtf8().constData();
}
else {
currentFileName = QFile(QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str())+"/gfx/gui/table/default/defaulttablestyle.xml").fileName();
tinyFileName = currentFileName.toStdString();
QMessageBox::warning(myW, tr("FALLBACK"),
currentFileName,
QMessageBox::Ok);
tinyFileName = currentFileName.toUtf8().constData();
fallBack = 1;
}
QFileInfo info(currentFileName);
currentFileDir = info.absolutePath();
@@ -170,6 +159,7 @@ void GameTableStyleReader::readStyleFile(QString file) {
//if one or more items are wrong or left show detailed error message
if(!wrongItems.isEmpty() && myW != 0) showErrorMessage(StyleDescription, wrongItems, StyleMaintainerEMail);
}
else { qDebug() << "could not load game table style file: " << tinyFileName.c_str(); }
}
void GameTableStyleReader::showErrorMessage(QString style, QStringList failedItems, QString email)
@@ -181,3 +171,8 @@ void GameTableStyleReader::showErrorMessage(QString style, QStringList failedIte
QMessageBox::Ok);
}
QString GameTableStyleReader::getPreview()
{
return QString(currentFileDir+"/"+Preview);
}
+7 -2
View File
@@ -38,8 +38,11 @@ public:
void showErrorMessage(QString, QStringList, QString);
QString getStyleDescription() const { return StyleDescription; }
QString getPreview() const { return Preview; }
QString getCurrentFileName() const { return currentFileName; }
QString getPreview();
bool getFallBack() const { return fallBack; }
@@ -96,6 +99,8 @@ private:
ConfigFile *myConfig;
gameTableImpl *myW;
bool fallBack;
};
#endif
@@ -1,79 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by Felix Hammer *
* f.hammer@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "stylesheetreader.h"
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <fstream>
using namespace std;
StyleSheetReader::StyleSheetReader(std::string f) : styleSheetFileName(f)
{
fillBuffer();
}
StyleSheetReader::~StyleSheetReader()
{
}
void StyleSheetReader::fillBuffer() {
boost::recursive_mutex::scoped_lock lock(m_configMutex);
string tempString1("");
TiXmlDocument doc(styleSheetFileName);
if(doc.LoadFile()) {
TiXmlHandle docHandle( &doc );
TiXmlElement* colorList = docHandle.FirstChild( "PokerTH" ).FirstChild( "Table" ).FirstChild( "Colors" ).FirstChild().ToElement();
for( ; colorList; colorList=colorList->NextSiblingElement()) {
const char *tmpStr1 = colorList->Attribute("value");
if (tmpStr1) {
tempString1 = tmpStr1;
colorsBufferList.push_back(Colors(colorList->ValueStr(), tempString1));
// cout << colorList->ValueStr() << " : " << tempString1 << endl;
}
}
}
}
string StyleSheetReader::readColorString(string varName) const
{
boost::recursive_mutex::scoped_lock lock(m_configMutex);
size_t i;
string tempString("");
for (i=0; i<colorsBufferList.size(); i++) {
if (colorsBufferList[i].name == varName) {
tempString = colorsBufferList[i].value;
}
}
return tempString;
}
@@ -1,55 +0,0 @@
/***************************************************************************
* Copyright (C) 2006 by Felix Hammer *
* f.hammer@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef STYLESHEETREADER_H
#define STYLESHEETREADER_H
#include "tinyxml.h"
#include <vector>
#include <string>
#include <boost/thread.hpp>
class StyleSheetReader{
public:
StyleSheetReader(std::string f);
~StyleSheetReader();
void fillBuffer();
std::string readColorString(std::string varName) const;
private:
mutable boost::recursive_mutex m_configMutex;
struct Colors
{
Colors(const std::string &n, const std::string &v) : name(n), value(v) {}
std::string name;
std::string value;
};
std::vector<Colors> colorsBufferList;
std::string styleSheetFileName;
};
#endif