Commit 332503dc authored by Johannes Bergmeier's avatar Johannes Bergmeier

- Changed the value-list on the left to use the symbols from the theme instead...

- Changed the value-list on the left to use the symbols from the theme instead of old hardcoded symbols
- Removed old code for symbols as it will not be used anymore and had bad usability

I consider the old behavior as a showstopper-bug, as it may result in completely different symbols in the game and the list
If this fix results in new problems, please undo this commit

svn path=/trunk/KDE/kdegames/ksudoku/; revision=894750
parent 680e6135
......@@ -29,61 +29,6 @@
namespace ksudoku {
SymbolConfigListWidget::SymbolConfigListWidget(const QList<SymbolTable*>& tables, QWidget* parent) : QListWidget(parent) {
for(int i = 0; i < tables.size(); ++i) {
SymbolTable* table = tables[i];
QString chars;
for(int j = 1; j <= table->maxValue(); ++j)
chars += table->symbolForValue(j) + ' ';
QListWidgetItem* li = new QListWidgetItem(table->text(), this);
li->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
QString tooltip = i18ncp("list arg2 consists of arg1 symbols: arg3", "<html><h4>%2</h4>consists of 1 symbol:<br/>%3</html>", "<html><h4>%2</h4>consists of %1 symbols:<br/>%3</html>", table->maxValue(), table->text(), chars);
li->setData(Qt::ToolTipRole, tooltip);
li->setData(Qt::UserRole, table->name());
li->setCheckState(Qt::Unchecked);
}
}
SymbolConfigListWidget::~SymbolConfigListWidget() {
}
QStringList SymbolConfigListWidget::enabledTables() const {
QStringList list;
for(int i = 0; i < count(); ++i) {
QListWidgetItem* li = item(i);
if(li->checkState() == Qt::Checked)
list << li->data(Qt::UserRole).toString();
}
return list;
}
void SymbolConfigListWidget::setEnabledTables(const QStringList& tables) {
for(int i = 0; i < count(); ++i) {
QListWidgetItem* li = item(i);
if(tables.contains(li->data(Qt::UserRole).toString()))
li->setCheckState(Qt::Checked);
else
li->setCheckState(Qt::Unchecked);
}
}
SymbolConfig::SymbolConfig(Symbols* symbols) : m_symbols(symbols) {
QVBoxLayout* layout = new QVBoxLayout(this);
m_symbolTableView = new SymbolConfigListWidget(symbols->possibleTables(), this);
m_symbolTableView->setObjectName("kcfg_Symbols");
layout->addWidget(m_symbolTableView);
}
SymbolConfig::~SymbolConfig() {
}
GameConfig::GameConfig(QWidget* parent)
: QWidget(parent)
{
......
......@@ -31,30 +31,6 @@ namespace ksudoku {
class Symbols;
struct SymbolTable;
class SymbolConfigListWidget : public QListWidget {
Q_OBJECT
Q_PROPERTY(QStringList enabledTables READ enabledTables WRITE setEnabledTables USER true)
public:
SymbolConfigListWidget(const QList<SymbolTable*>& tables, QWidget* parent = 0);
~SymbolConfigListWidget();
public:
QStringList enabledTables() const;
void setEnabledTables(const QStringList& tables);
};
class SymbolConfig : public QWidget {
Q_OBJECT
public:
SymbolConfig(Symbols* symbols);
~SymbolConfig();
private:
SymbolConfigListWidget* m_symbolTableView;
Symbols* m_symbols;
};
class GameConfig : public QWidget, private Ui::ConfigGame {
Q_OBJECT
public:
......
......@@ -147,8 +147,6 @@ KSudoku::KSudoku()
updateShapesList();
m_symbols.setEnabledTables(Settings::symbols());
QTimer *timer = new QTimer( this );
connect( timer, SIGNAL(timeout()), this, SLOT(updateStatusBar()) );
......@@ -220,7 +218,6 @@ void KSudoku::startGame(const Game& game) {
view->setValueListWidget(m_valueListWidget);
view->createView();
view->setSymbolTable(m_symbols.selectTable(view->game().order()));
connect(view, SIGNAL(valueSelected(int)), m_valueListWidget, SLOT(selectValue(int)));
connect(m_valueListWidget, SIGNAL(valueSelected(int)), view, SLOT(selectValue(int)));
......@@ -242,7 +239,7 @@ void KSudoku::startGame(const Game& game) {
policy.setVerticalStretch(1);
widget->setSizePolicy(policy);
m_valueListWidget->setCurrentTable(m_symbols.selectTable(view->game(). order()), view->game().order());
m_valueListWidget->setMaxValue(view->game().order());
m_valueListWidget->selectValue(1);
m_valueListWidget->show();
}
......@@ -583,24 +580,18 @@ void KSudoku::optionsPreferences()
dialog->addPage(gameConfig, i18nc("Game Section in Config", "Game"), "games-config-options");
dialog->addPage(new KGameThemeSelector(dialog, Settings::self(), KGameThemeSelector::NewStuffDisableDownload), i18n("Theme"), "games-config-theme");
SymbolConfig* symbolConfig = new SymbolConfig(&m_symbols);
dialog->addPage(symbolConfig, i18n("Symbol Themes"), "games-config-theme");
dialog->setHelp(QString(),"ksudoku");
dialog->setHelp(QString(),"ksudoku");
connect(dialog, SIGNAL(settingsChanged(const QString&)), SLOT(updateSettings()));
dialog->show();
}
void KSudoku::updateSettings() {
m_symbols.setEnabledTables(Settings::symbols());
Renderer::instance()->loadTheme(Settings::theme());
KsView* view = currentView();
if(view) {
int order = view->game().order();
SymbolTable* table = m_symbols.selectTable(order);
view->setSymbolTable(table);
m_valueListWidget->setCurrentTable(table, order);
m_valueListWidget->setMaxValue(order);
view->settingsChanged();
}
......
......@@ -27,8 +27,6 @@
#include <knewstuff/knewstuff.h>
#endif
#include "symbols.h"
class KUrl;
namespace ksudoku {
......@@ -153,8 +151,6 @@ private:
ksudoku::KsView* m_gameUI;
ksudoku::Symbols m_symbols;
ksudoku::GameActions* m_gameActions;
};
......
......@@ -21,71 +21,21 @@
#include "symbols.h"
#include "symbols.moc"
#include <KLocale>
#include <QtCore/QChar>
namespace ksudoku {
///////////////////////////////////////////////////////////////////////////////
// struct SymbolTable
///////////////////////////////////////////////////////////////////////////////
SymbolTable::SymbolTable(const QString& name, const QString& text, const QVector<QChar>& symbols)
: m_name(name), m_text(text), m_symbols(symbols)
{ }
int SymbolTable::maxValue() const { return m_symbols.size(); }
QChar SymbolTable::symbolForValue(int i) const {
if(i <= 0 || i > maxValue()) return '\0';
return m_symbols[i-1];
}
QString SymbolTable::name() const { return m_name; }
QString SymbolTable::text() const { return m_text; }
///////////////////////////////////////////////////////////////////////////////
// class Symbols
///////////////////////////////////////////////////////////////////////////////
Symbols::Symbols() {
m_possibleTables << new SymbolTable("symbols", i18n("Simple Forms"), QVector<QChar>() << 0x2610 << 0x2606 << 0x2661 << 0x263E);
m_possibleTables << new SymbolTable("dices", i18n("Dices"), QVector<QChar>() << 0x2680 << 0x2681 << 0x2682 << 0x2683 << 0x2684 << 0x2685);
m_possibleTables << new SymbolTable("digits", i18n("Digits"), QVector<QChar>() << '1' << '2' << '3' << '4' << '5' << '6' << '7' << '8' << '9');
m_possibleTables << new SymbolTable("letters_lower", i18n("Small Letters"), QVector<QChar>() << 'a' << 'b' << 'c' << 'd' << 'e' << 'f' << 'g' << 'h' << 'i' << 'j' << 'k' << 'l' << 'm' << 'n' << 'o' << 'p' << 'q' << 'r' << 's' << 't' << 'u' << 'v' << 'w' << 'x' << 'y' << 'z');
m_possibleTables << new SymbolTable("letters_upper", i18n("Capital Letters"), QVector<QChar>() << 'A' << 'B' << 'C' << 'D' << 'E' << 'F' << 'G' << 'H' << 'I' << 'J' << 'K' << 'L' << 'M' << 'N' << 'O' << 'P' << 'Q' << 'R' << 'S' << 'T' << 'U' << 'V' << 'W' << 'X' << 'Y' << 'Z');
m_enabledTables = m_possibleTables;
}
Symbols::~Symbols()
{
qDeleteAll(m_possibleTables);
}
QList<SymbolTable*> Symbols::possibleTables() const {
return m_possibleTables;
}
QStringList Symbols::enabledTables() const {
QStringList tables;
for(int i = 0; i < m_enabledTables.size(); ++i) {
tables << m_enabledTables[i]->name();
}
return tables;
/// returns the symbol vor a value used for loading and saving
QChar Symbols::ioValue2Symbol(int value) {
if(value <= 0) return '_';
return 'a' + value;
}
void Symbols::setEnabledTables(const QStringList& tables) {
m_enabledTables.clear();
for(int i = 0; i < m_possibleTables.size(); ++i) {
SymbolTable* table = m_possibleTables[i];
if(tables.contains(table->name()))
m_enabledTables << table;
}
emit tablesChanged();
/// returns the number of the index
int Symbols::ioSymbol2Value(const QChar& symbol) {
char c = symbol.toAscii();
if(symbol == '_') return 0;
return c - 'a';
}
}
......@@ -22,75 +22,14 @@
#ifndef KSUDOKUSYMBOLS_H
#define KSUDOKUSYMBOLS_H
#include <QVector>
#include <QString>
#include <QObject>
class QChar;
namespace ksudoku {
struct SymbolTable {
public:
SymbolTable(const QString& name, const QString& text, const QVector<QChar>& symbols);
public:
int maxValue() const;
QChar symbolForValue(int i) const;
QString name() const;
QString text() const;
private:
QString m_name;
QString m_text;
QVector<QChar> m_symbols;
};
/**
* Provides the symbols for puzzles.
*/
class Symbols : public QObject {
Q_OBJECT
class Symbols {
public:
Symbols();
~Symbols();
QList<SymbolTable*> possibleTables() const;
QStringList enabledTables() const;
void setEnabledTables(const QStringList& tables);
SymbolTable* selectTable(int maxValue) {
for(int i = 0; i < m_enabledTables.size(); ++i) {
SymbolTable* table = m_enabledTables[i];
if(table->maxValue() >= maxValue)
return table;
}
return 0;
}
QChar value2Symbol(int value, int maxValue) {
SymbolTable* table = selectTable(maxValue);
if(!table) return '\0';
return table->symbolForValue(value);
}
/// returns the symbol vor a value used for loading and saving
static QChar ioValue2Symbol(int value) {
if(value <= 0) return '_';
return 'a' + value;
}
/// returns the number of the index
static int ioSymbol2Value(const QChar& symbol) {
char c = symbol.toAscii();
if(symbol == '_') return 0;
return c - 'a';
}
signals:
void tablesChanged();
private:
QList<SymbolTable*> m_possibleTables;
QList<SymbolTable*> m_enabledTables;
static QChar ioValue2Symbol(int value);
static int ioSymbol2Value(const QChar& symbol);
};
}
......
......@@ -107,11 +107,15 @@ void Renderer::fillNameHashes() {
m_specialNames << "cell";
m_specialNames << "cell_mistake";
m_specialNames << "cursor";
m_specialNames << "valuelist_item";
m_specialNames << "valuelist_selector";
m_special3dNames << "cell3d";
m_special3dNames << "cell3d_preset";
m_special3dNames << "cell3d";
m_special3dNames << "cell3d_mistake";
m_special3dNames << "cursor";
m_special3dNames << "valuelist_item";
m_special3dNames << "valuelist_selector";
// TODO get this hardcoded values from the SVG file
// m_markerName << "markers9" << "markers9" //...
}
......
......@@ -46,7 +46,9 @@ enum SpecialType {
SpecialCellPreset = 0x01,
SpecialCellMarkers = 0x02,
SpecialCellMistake = 0x03,
SpecialCursor = 0x04
SpecialCursor = 0x04,
SpecialListItem = 0x05,
SpecialListCursor = 0x06
};
enum SymbolType {
......
......@@ -26,90 +26,104 @@
#include <KColorScheme>
#include "renderer.h"
namespace ksudoku {
SymbolGraphicsItem::SymbolGraphicsItem(const QChar& symbol, QGraphicsItem * parent, QGraphicsScene * scene)
: QGraphicsItem(parent, scene)
{
m_text = new QGraphicsSimpleTextItem(symbol, this, scene);
///
KStatefulBrush stattefulBrush(KColorScheme::View, KColorScheme::NormalText);
class SymbolItem : public QGraphicsPixmapItem {
public:
SymbolItem(int value, ValueListWidget* widget);
public:
int value() const;
void setSize(double size);
void mousePressEvent(QGraphicsSceneMouseEvent* event);
private:
int m_value;
double m_size;
ValueListWidget* m_widget;
};
m_text->setBrush(stattefulBrush.brush(QPalette::Active).color());
///
setSize(10);
SymbolItem::SymbolItem(int value, ValueListWidget* widget)
: m_widget(widget)
{
setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
m_value = value;
}
SymbolGraphicsItem::~SymbolGraphicsItem() {
int SymbolItem::value() const {
return m_value;
}
void SymbolGraphicsItem::setSize(double size) {
m_size = size;
QFont resizedFont = m_text->font();
resizedFont.setPixelSize(int(size*0.8));
m_text->setFont(resizedFont);
QRectF rect = m_text->boundingRect();
// TODO improve this or replace it
m_text->setPos(-rect.width()/2, -rect.height()/2 +0.7);
}
void SymbolItem::setSize(double size) {
QPixmap pic = Renderer::instance()->renderSpecial(SpecialListItem, size);
pic = Renderer::instance()->renderSymbolOn(pic, m_value, 0, SymbolPreset);
void SymbolGraphicsItem::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) {
hide();
setPixmap(pic);
setOffset(-size*0.5, -size*0.5);
setPos(0, (m_value-1)*size);
show();
}
QRectF SymbolGraphicsItem::boundingRect() const {
return QRectF(-m_size/2, -m_size/2, m_size, m_size);
void SymbolItem::mousePressEvent(QGraphicsSceneMouseEvent*) {
m_widget->selectValueItem(value());
}
class SymbolSelectionItem : public SymbolGraphicsItem {
class SelectionItem : public QGraphicsPixmapItem {
public:
SymbolSelectionItem(const QChar& symbol, int value, ValueListWidget* widget);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event);
private:
ValueListWidget* m_widget;
SelectionItem();
public:
void setSize(double size);
int selectedValue() const;
void selectValue(int value);
public:
double m_size;
int m_value;
};
SymbolSelectionItem::SymbolSelectionItem(const QChar& symbol, int value, ValueListWidget* widget)
: SymbolGraphicsItem(symbol, 0, widget->scene()), m_widget(widget), m_value(value)
{
SelectionItem::SelectionItem() {
m_value = 0;
setShapeMode(QGraphicsPixmapItem::BoundingRectShape);
}
void SymbolSelectionItem::mousePressEvent(QGraphicsSceneMouseEvent*) {
m_widget->selectValueItem(m_value);
void SelectionItem::setSize(double size) {
QPixmap pic = Renderer::instance()->renderSpecial(SpecialListCursor, size);
m_size = size;
hide();
setPixmap(pic);
setOffset(-size*0.5, -size*0.5);
setPos(0, (m_value-1) * m_size);
show();
}
int SelectionItem::selectedValue() const {
return m_value;
}
void SelectionItem::selectValue(int value) {
m_value = value;
setPos(0, (m_value-1) * m_size);
}
ValueListWidget::ValueListWidget(QWidget* parent)
: QGraphicsView(parent)
{
m_table = 0;
// m_table = 0;
setAlignment(Qt::AlignHCenter | Qt::AlignTop);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
m_scene = new QGraphicsScene(this);
setScene(m_scene);
m_selectionItem = new QGraphicsRectItem(-4.5, 0.5, 9, 9, 0, m_scene);
///
KStatefulBrush stattefulBrush(KColorScheme::View, KColorScheme::NormalText);
dynamic_cast< QGraphicsRectItem* >(m_selectionItem)->setPen(stattefulBrush.brush(QPalette::Active).color());
///
m_selectionItem->setPos(0, 0);
m_selectionItem = new SelectionItem();
m_scene->addItem(m_selectionItem);
m_maxValue = 1;
m_selectedValue = 1;
......@@ -118,45 +132,50 @@ ValueListWidget::ValueListWidget(QWidget* parent)
ValueListWidget::~ValueListWidget() {
}
SymbolTable* ValueListWidget::currentTable() const {
return m_table;
}
// SymbolTable* ValueListWidget::currentTable() const {
// return m_table;
// }
void ValueListWidget::setCurrentTable(SymbolTable* table, int maxValue) {
m_table = table;
// void ValueListWidget::setCurrentTable(SymbolTable* table, int maxValue) {
void ValueListWidget::setMaxValue(int maxValue) {
m_maxValue = maxValue;
SymbolSelectionItem* item;
while(!m_symbols.empty()) {
delete m_symbols.takeLast();
SymbolItem* item;
QList<SymbolItem*>::iterator it;
for(it = m_symbols.begin(); it != m_symbols.end(); ++it) {
delete *it;
}
m_symbols.clear();
if(m_table) {
for(int i = 0; i < maxValue; ++i) {
item = new SymbolSelectionItem(m_table->symbolForValue(i+1), i+1, this);
item->setSize(10);
item->setPos(0, (i+0.5)*10);
m_symbols.append(item);
}
for(int i = 0; i < maxValue; ++i) {
item = new SymbolItem(i+1, this);
item->setSize(20);
item->setPos(0, (i+0.5)*20);
m_scene->addItem(item);
m_symbols.append(item);
}
m_scene->setSceneRect(-5, 0, 10, maxValue*10);
if(m_selectedValue > m_maxValue) m_selectedValue = 1;
m_scene->update();
resizeEvent(0);
}
void ValueListWidget::resizeEvent(QResizeEvent*)
{
fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio);
QSize s = size();
// add -4 as a margin and for avoiding problems with the border
int size = qMin(s.width(), s.height()/m_maxValue) - 4;
for(int i = 0; i < m_maxValue; ++i) {
m_symbols[i]->setSize(size);
}
m_scene->setSceneRect(-size/2, -size/2, size, m_maxValue*size);
m_selectionItem->setSize(size);
}
void ValueListWidget::selectValue(int value) {
m_selectedValue = value;
m_selectionItem->setPos(0, (value-1)*10);
// m_scene->update();
m_selectionItem->selectValue(value);
}
void ValueListWidget::selectValueItem(int value) {
......@@ -170,5 +189,4 @@ void ValueListWidget::wheelEvent (QWheelEvent* e) {
selectValueItem(value);
}
}
......@@ -26,36 +26,23 @@
#include "symbols.h"
class QGraphicsSimpleTextItem;
class QGraphicsPixmapItem;
namespace ksudoku {
class SymbolGraphicsItem : public QGraphicsItem {
public:
SymbolGraphicsItem(const QChar& symbol,QGraphicsItem * parent = 0, QGraphicsScene * scene = 0);
~SymbolGraphicsItem();
public:
void setSize(double size);
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = 0);
QRectF boundingRect() const;
private:
QGraphicsSimpleTextItem* m_text;
double m_size;
};
class SymbolSelectionItem;
class SymbolItem;
class SelectionItem;
class ValueListWidget : public QGraphicsView {
friend class SymbolSelectionItem;
Q_OBJECT
Q_OBJECT
friend class SymbolItem;
public:
ValueListWidget(QWidget* parent = 0);
~ValueListWidget();
SymbolTable* currentTable() const;
void setCurrentTable(SymbolTable* table, int maxValue);
// SymbolTable* currentTable() const;
// void setCurrentTable(SymbolTable* table, int maxValue);
</