Commit d3d3ae57 authored by Johannes Bergmeier's avatar Johannes Bergmeier

* other game variants are now correctly installed

* fixed loading list of gamevariants
* fixed options
* moved options from setup menu to a config dialog (simpler code, easier to maintain)
* some cleanup in code

svn path=/trunk/KDE/kdegames/ksudoku/; revision=678465
parent c96ac9b3
......@@ -36,6 +36,7 @@ ADD_SUBDIRECTORY( gui )
ADD_SUBDIRECTORY( gui/views )
#ADD_SUBDIRECTORY( gui/export ) #TODO PORT
#ADD_SUBDIRECTORY( gui/export/draw ) #TODO PORT
ADD_SUBDIRECTORY( shapes )
#set(ksudoku_client_SRCS
......@@ -58,11 +59,6 @@ install( FILES gui/ksudoku.desktop DESTINATION ${XDG_APPS_DIR} )
install( FILES gui/ksudokuui.rc DESTINATION ${DATA_INSTALL_DIR}/ksudoku )
install( FILES ksudokurc DESTINATION ${CONFIG_INSTALL_DIR})
install(FILES shapes/4x4.xml shapes/Jigsaw.xml shapes/XSudoku.xml shapes/Samurai.xml DESTINATION ${DATA_INSTALL_DIR}/ksudoku)
kde4_install_icons(${ICON_INSTALL_DIR})
......
......@@ -15,7 +15,7 @@ INCLUDE_DIRECTORIES( views ksudoku_export)
kde4_automoc( ${ksudoku_SRCS} )
kde4_add_ui_files(ksudoku_SRCS welcomescreen.ui)
kde4_add_ui_files(ksudoku_SRCS welcomescreen.ui configgame.ui)
kde4_add_kcfg_files(ksudoku_SRCS settings.kcfgc )
......
......@@ -84,4 +84,10 @@ SymbolConfig::SymbolConfig(Symbols* symbols) : m_symbols(symbols) {
SymbolConfig::~SymbolConfig() {
}
GameConfig::GameConfig(QWidget* parent)
: QWidget(parent)
{
setupUi(this);
}
}
......@@ -24,6 +24,8 @@
#include <QList>
#include <QListWidget>
#include "ui_configgame.h"
namespace ksudoku {
class Symbols;
......@@ -53,6 +55,12 @@ private:
Symbols* m_symbols;
};
class GameConfig : public QWidget, private Ui::ConfigGame {
Q_OBJECT
public:
explicit GameConfig(QWidget* parent = 0);
};
}
#endif
<ui version="4.0" >
<class>ConfigGame</class>
<widget class="QWidget" name="ConfigGame" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
<layout class="QVBoxLayout" >
<item>
<widget class="QCheckBox" name="kcfg_ShowHighlights" >
<property name="whatsThis" >
<string>Highlight the current row, column and box in different colors</string>
</property>
<property name="text" >
<string>Show Highlights</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="kcfg_ShowErrors" >
<property name="whatsThis" >
<string>Highlight cells which values are against the rules in red</string>
</property>
<property name="text" >
<string>Show Errors</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -79,8 +79,6 @@
#include "config.h"
// bool guidedMode;
void KSudoku::onCompleted(bool isCorrect, const QTime& required, bool withHelp) {
if(!isCorrect) {
KMessageBox::information(this, i18n("Sorry the solution you entered is not correct.\nIf you want to see error check Options->Guided mode please."));
......@@ -132,7 +130,6 @@ KSudoku::KSudoku()
connect(m_markValueMapper, SIGNAL(mapped(int)), this, SLOT(markValue(int)));
// then, setup our actions
readProperties( KGlobal::config().data());
setupActions();
// and a status bar
......@@ -156,7 +153,7 @@ KSudoku::KSudoku()
// Register the gamevariants resource
KGlobal::dirs()->addResourceType ("gamevariant", "data",
KCmdLineArgs::aboutData()->appName() + '/');
KCmdLineArgs::aboutData()->appName());
updateShapesList();
......@@ -205,57 +202,24 @@ KSudoku::~KSudoku()
}
void KSudoku::startGame(const Game& game) {
GameType type = game.puzzle()->gameType(); //game solver()->g->sizeZ() > 1) ? 1 : 0;
KsView* view = 0;
view = new KsView(game, this);
KsView* view = new KsView(game, this);
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)));
connect(view, SIGNAL(valueSelected(int)), SLOT(updateStatusBar()));
switch(type){
case sudoku: { //cUrly braces needed to avoid "crosses initialization" compile error
ksudokuView* v = new ksudokuView(wrapper, game, false);
connect(v, SIGNAL(valueSelected(int)), SLOT(updateStatusBar()));
connect(v, SIGNAL(valueSelected(int)), view, SLOT(selectValue(int)));
connect(view, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
view->setWidget(v);
connect(view, SIGNAL(flagsChanged(ViewFlags)), v, SLOT(setFlags(ViewFlags)));
connect(view, SIGNAL(symbolsChanged(SymbolTable*)), v, SLOT(setSymbols(SymbolTable*)));
connect(v, SIGNAL(mouseOverCell(int)), view, SLOT(setCursor(int)));
connect(view, SIGNAL(cursorMoved(int)), v, SLOT(setCursor(int)));
connect(view, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
break; }
case roxdoku: {
RoxdokuView* v = new RoxdokuView(game, &m_symbols, wrapper, "ksudoku-3dwnd");
connect(view, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
connect(view, SIGNAL(flagsChanged(ViewFlags)), v, SLOT(setFlags(ViewFlags)));
view->setWidget(v);
break; }
case custom:{
ksudokuView* v = new ksudokuView(wrapper, game, true);
connect(v, SIGNAL(valueSelected(int)), SLOT(updateStatusBar()));
connect(v, SIGNAL(valueSelected(int)), view, SLOT(selectValue(int)));
connect(view, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
view->setWidget(v);
connect(view, SIGNAL(flagsChanged(ViewFlags)), v, SLOT(setFlags(ViewFlags)));
connect(view, SIGNAL(symbolsChanged(SymbolTable*)), v, SLOT(setSymbols(SymbolTable*)));
connect(v, SIGNAL(mouseOverCell(int)), view, SLOT(setCursor(int)));
connect(view, SIGNAL(cursorMoved(int)), v, SLOT(setCursor(int)));
connect(view, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
}
default:
///@todo if here, BUG => throw exception (??)
break;
}
view->setSymbolTable(m_symbols.selectTable(view->game().order()));
m_welcomeScreen->hide();
QWidget* widget = view->widget();
m_gameUI = view;
wrapper->layout()->addWidget(widget);
Game game2(game);
connect(game2.interface(), SIGNAL(completed(bool,const QTime&,bool)), SLOT(onCompleted(bool,const QTime&,bool)));
connect(game2.interface(), SIGNAL(modified(bool)), SLOT(onModified(bool)));
......@@ -302,7 +266,6 @@ void KSudoku::setCentralWidget(QWidget* widget, bool autoDel) {
wrapper->layout()->addWidget(widget);
activeWidget = widget;
readProperties(KGlobal::config().data()); //correct order: otherwise settings are not loaded
adaptActions2View();
}
......@@ -314,26 +277,6 @@ void KSudoku::showWelcomeScreen() {
setCentralWidget(m_welcomeScreen, false);
}
void KSudoku::mouseOnlySuperscript()
{
// QWidget* current = m_tabs->currentPage();
// QWidget* current = (QWidget*)currentView();
if(ksudokuView* view = dynamic_cast<ksudokuView*>(currentView()))
view->mouseOnlySuperscript = !view->mouseOnlySuperscript;
else return;
saveProperties( KGlobal::config().data());
}
void KSudoku::setGuidedMode()
{
if(KsView* view = currentView()) {
view->setFlags(view->flags() ^ ShowErrors);
}
saveProperties( KGlobal::config().data());
}
void KSudoku::homepage()
{
KRun::runUrl (KUrl("http://ksudoku.sourceforge.net/"), "text/html", this);
......@@ -578,52 +521,9 @@ void KSudoku::setupActions()
KDE3Action(i18n("Home page"), this, SLOT(homepage()), "Home_page");
KDE3Action(i18n("Support this project"), this, SLOT(support()), "support");
KDE3Action(i18n("Send comment"), this, SLOT(sendComment()), "SendComment");
//Settings
KToggleAction* a;
a = new KToggleAction(i18n("Mouse-Only superscript mode"),this);
connect(a, SIGNAL(triggered(bool)),this, SLOT(mouseOnlySuperscript()));
actionCollection()->addAction("mouseOnlySuperscript", a);
a->setChecked(false);
a->setEnabled(false);
a=new KToggleAction(i18n("Guided mode (mark wrong red)"), this);
connect(a, SIGNAL(triggered(bool)),this, SLOT(setGuidedMode()));
actionCollection()->addAction("guidedMode", a);
a->setChecked(false);
a->setEnabled(false);
a=new KToggleAction(i18n("Show tracker"), 0);
connect(a, SIGNAL(triggered(bool)),this, SLOT(setShowTracker()));
actionCollection()->addAction("showTracker", a);
a->setChecked(true);
a->setEnabled(false);
}
void KSudoku::adaptActions2View() {
// TODO This whole function is only a temporary hack, views should have their own UI
if(KsView* view = currentView()) {
KToggleAction* a;
if((a = dynamic_cast<KToggleAction*>(action("guidedMode")))) {
a->setEnabled(true);
a->setChecked(view->flags().testFlag(ShowErrors));
}
} else {
KToggleAction* a;
if((a = dynamic_cast<KToggleAction*>(action("mouseOnlySuperscript")))) {
a->setEnabled(false);
a->setChecked(false);
}
if((a = dynamic_cast<KToggleAction*>(action("guidedMode")))) {
a->setEnabled(false);
a->setChecked(false);
}
if((a = dynamic_cast<KToggleAction*>(action("showTracker")))) {
a->setEnabled(false);
a->setChecked(false);
}
}
Game game = currentGame();
if(game.isValid()) {
action("file_save")->setEnabled(true);
......@@ -691,50 +591,6 @@ void KSudoku::pop()
// if(glwin) glwin->pop();
}
void KSudoku::setShowTracker()
{
// QWidget* current = m_tabs->currentPage();
// QWidget* current = (QWidget*) currentView();
if(ksudokuView* view = dynamic_cast<ksudokuView*>(currentView())) {
view->showTracker = !view->showTracker;
} else return;
saveProperties((KConfig* )KGlobal::config().data());
}
void KSudoku::saveProperties(KConfig *config)
{
// the 'config' object points to the session managed
// config file. anything you write here will be available
// later when this app is restored
KConfigGroup group = config->group("ksudoku General");
if(KsView* view = currentView()) {
group.writeEntry("guidedMode", QVariant(view->flags().testFlag(ShowErrors)));
group.writeEntry("showTracker", QVariant(view->flags().testFlag(ShowTracker)));
}
config->sync();
}
void KSudoku::readProperties(KConfig *config)
{
// the 'config' object points to the session managed
// config file. this function is automatically called whenever
// the app is being restored. read in here whatever you wrote
// in 'saveProperties'
KConfigGroup group = config->group("ksudoku General");
QString Url = group.readEntry("lastUrl", "");
if(KsView* view = currentView()) {
ViewFlags flags = view->flags();
if(flags.testFlag(ShowErrors) xor group.readEntry("guidedMode", true))
flags ^= ShowErrors;
view->setFlags(flags);
}
}
void KSudoku::dragEnterEvent(QDragEnterEvent */*event*/)
{
// accept uri drops only
......@@ -866,9 +722,12 @@ void KSudoku::optionsPreferences()
KConfigDialog *dialog = new KConfigDialog(this, "settings", Settings::self());
GameConfig* gameConfig = new GameConfig();
dialog->addPage(gameConfig, i18nc("Game Section in Config", "Game"), "game");
SymbolConfig* symbolConfig = new SymbolConfig(&m_symbols);
dialog->addPage(symbolConfig, i18n("Symbol Themes"), "theme");
connect(dialog, SIGNAL(settingsChanged(const QString&)), SLOT(settingsChanged()));
dialog->show();
}
......@@ -882,6 +741,8 @@ void KSudoku::settingsChanged() {
SymbolTable* table = m_symbols.selectTable(order);
view->setSymbolTable(table);
m_valueListWidget->setCurrentTable(table, order);
view->settingsChanged();
}
}
......
......@@ -116,20 +116,6 @@ protected:
virtual void dragEnterEvent(QDragEnterEvent *event);
virtual void dropEvent(QDropEvent *event);
protected:
/**
* This function is called when it is time for the app to save its
* properties for session management purposes.
*/
void saveProperties(KConfig *);
/**
* This function is called when this app is restored. The KConfig
* object points to the session management config file that was saved
* with @ref saveProperties
*/
void readProperties(KConfig *);
public slots:
void onCompleted(bool isCorrect, const QTime& required, bool withHelp = false);
......@@ -166,7 +152,6 @@ private slots:
void optionsPreferences();
void settingsChanged();
void setShowTracker();
void changeStatusbar(const QString& text);
void changeCaption(const QString& text);
......@@ -174,9 +159,6 @@ private slots:
void homepage();
void support();
void sendComment();
//settings
void mouseOnlySuperscript();
void setGuidedMode();
void updateStatusBar();
......
......@@ -5,6 +5,12 @@
http://www.kde.org/standards/kcfg/1.0/kcfg.xsd" >
<kcfgfile/>
<group name="Options">
<entry name="ShowHighlights" type="Bool" key="showHighlights">
<default>true</default>
</entry>
<entry name="ShowErrors" type="Bool" key="showErrors">
<default>true</default>
</entry>
</group>
<group name="Themes">
<entry name="Symbols" type="StringList" key="symbols">
......
......@@ -25,12 +25,6 @@
<Action name="move_dub_puzzle" />
</Menu>
<Menu name="settings"><text>&amp;Settings</text>
<Action name="showTracker" />
<Action name="guidedMode" />
<Action name="mouseOnlySuperscript" />
</Menu>
<Menu name="help"><text>&amp;Help</text>
<Action name="Home_page" />
<Action name="support" />
......
......@@ -42,14 +42,10 @@ ksudokuView::ksudokuView(QWidget *parent, const Game& game, bool customd)
: QWidget(parent)
{
m_symbolTable = 0;
isWaitingForNumber = -1;
highlighted = -1;
custom = customd;
m_color0 = 0;
// m_buttons.setAutoDelete(true);
m_guidedMode = true;
current_selected_number = 1;
setGame(game);
......@@ -134,7 +130,7 @@ void ksudokuView::draw(QPainter& p, int height, int width) const
void ksudokuView::btn_enter(int x, int y) {
emit mouseOverCell(m_game.index(x,y));
emit cellHovered(m_game.index(x,y));
}
void ksudokuView::setCursor(int cell) {
......@@ -145,8 +141,6 @@ void ksudokuView::setCursor(int cell) {
int x = g->cellPosX(cell);
int y = g->cellPosY(cell);
isWaitingForNumber = -1;
if(m_highlightUpdate.size() != m_game.size())
m_highlightUpdate.resize(m_game.size());
......@@ -154,8 +148,8 @@ void ksudokuView::setCursor(int cell) {
m_highlightUpdate[i] = HighlightNone;
}
if(custom==0) {
if(!m_flags.testFlag(ShowHighlights)) {
} else if(custom==0) {
for(int i = 0; i < m_game.order(); ++i) {
int base = static_cast<int>(sqrt(m_game.puzzle()->order()));
m_highlightUpdate[m_game.index(i, y)] |= HighlightRow;
......@@ -172,27 +166,26 @@ void ksudokuView::setCursor(int cell) {
{
for(uint j=0; j<gc->cliques[i].size(); j++)
{
if(gc->cliques[i][j]==cell)
if(gc->cliques[i][j] != cell) continue;
uint mask = HighlightNone;
switch(count) {
case 0:
mask = HighlightColumn;
break;
case 1:
mask = HighlightRow;
break;
default:
mask = HighlightClique;
break;
}
for(uint k=0; k<gc->cliques[i].size(); k++)
{
uint mask = HighlightNone;
switch(count) {
case 0:
mask = HighlightColumn;
break;
case 1:
mask = HighlightRow;
break;
default:
mask = HighlightClique;
break;
}
for(uint k=0; k<gc->cliques[i].size(); k++)
{
m_highlightUpdate[gc->cliques[i][k]] |= mask;
}
count = (count+1)%3;
break;
m_highlightUpdate[gc->cliques[i][k]] |= mask;
}
count = (count+1)%3;
break;
}
}
}
......@@ -278,10 +271,13 @@ void ksudokuView::setGame(const ksudoku::Game& game) {
}
void ksudokuView::selectValue(int value) {
if(current_selected_number == value) return;
current_selected_number = value;
if(getHighlighted() != -1)
beginHighlight(value);
emit valueSelected(value);
}
void ksudokuView::setSymbols(SymbolTable* table) {
......@@ -290,7 +286,7 @@ void ksudokuView::setSymbols(SymbolTable* table) {
}
void ksudokuView::setFlags(ViewFlags flags) {
m_guidedMode = flags.testFlag(ShowErrors);
m_flags = flags;
update();
}
......@@ -333,14 +329,15 @@ void ksudokuView::wheelEvent (QWheelEvent* e) {
int order = m_game.order();
int value = (current_selected_number - e->delta()/120) % order;
if(value <= 0) value = order - value;
emit valueSelected(value);
selectValue(value);
}
void ksudokuView::slotHello(int x, int y)
{
if(m_game.given(x,y))
{
emit valueSelected(m_game.value(x,y));
selectValue(m_game.value(x,y));
}
else
{
......@@ -352,15 +349,7 @@ void ksudokuView::slotRight(int x, int y)
{
if(!m_game.given(x,y))
{
if(mouseOnlySuperscript == 1)
{
m_game.flipMarker(current_selected_number, x, y);
}
else
{
isWaitingForNumber = m_game.index(x,y);
m_buttons[m_game.index(x,y)]->update();
}
m_game.flipMarker(current_selected_number, x, y);
}
}
......
......@@ -49,7 +49,7 @@ class Symbols;
* Gui for a sudoku puzzle
* @TODO rename ksudokuView to sudokuView
*/
class ksudokuView : public QWidget
class ksudokuView : public QWidget, public ViewInterface
{
Q_OBJECT
friend class QSudokuButton;
......@@ -73,13 +73,10 @@ public:
virtual void draw(QPainter& p, int height, int width) const;
signals:
void mouseOverCell(int cell);
void cellHovered(int cell);
void valueSelected(int value);
public:
bool mouseOnlySuperscript;
bool showTracker;
int isWaitingForNumber;
int current_selected_number;
bool custom;
......@@ -124,11 +121,9 @@ private:
QVector<int> m_highlightUpdate;
bool puzzle_mark_wrong;
int highlighted;
int m_color0;
bool m_guidedMode;
ViewFlags m_flags;
Game m_game;
SymbolTable* m_symbolTable;
......
......@@ -22,6 +22,7 @@
#include "ksview.h"
#include "ksudokugame.h"
#include "settings.h"
#include <qpixmap.h>