Commit 94b32835 authored by Johannes Bergmeier's avatar Johannes Bergmeier

* Replaced the select Number toolbar with an number selector widget

(this widget's look is not the final version)
* Some improvements in the views
(views are a big mess, require cleanup)

svn path=/trunk/kdereview/ksudoku/; revision=663277
parent 26c5b3a8
......@@ -73,6 +73,7 @@
#include "gamevariants.h"
#include "welcomescreen.h"
#include "valuelistwidget.h"
#include "settings.h"
#include "config.h"
......@@ -133,17 +134,24 @@ KSudoku::KSudoku()
setupGUI();
wrapper = new QWidget();
(void) new QVBoxLayout(wrapper);
(void) new QHBoxLayout(wrapper);
activeWidget = 0;
QMainWindow::setCentralWidget(wrapper);
wrapper->show();
m_gameWidget = 0;
// Create ValueListWidget
m_valueListWidget = new ValueListWidget(wrapper);
wrapper->layout()->addWidget(m_valueListWidget);
// m_valueListWidget->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Minimum);
m_valueListWidget->setFixedWidth(60);
m_welcomeScreen = new WelcomeScreen(wrapper, m_gameVariants);
connect(m_welcomeScreen, SIGNAL(newGameStarted(const Game&,GameVariant*)), this, SLOT(startGame(const Game&)));
setCentralWidget(m_welcomeScreen, false);
showWelcomeScreen();
// Register the gamevariants resource
KGlobal::dirs()->addResourceType ("gamevariant", KStandardDirs::kde_default("data") +
......@@ -201,35 +209,61 @@ void KSudoku::startGame(const Game& game) {
switch(type){
case sudoku: { //cUrly braces needed to avoid "crosses initialization" compile error
ksudokuView* v = new ksudokuView(this, game, &m_symbols, false);
ksudokuView* v = new ksudokuView(wrapper, game, false);
// v->setup(game);
connect( v, SIGNAL(changedSelectedNum()), this, SLOT(updateStatusBar()) );
connect(v, SIGNAL(valueSelected(int)), SLOT(updateStatusBar()));
view = v;
connect(v, SIGNAL(valueSelected(int)), m_valueListWidget, SLOT(selectValue(int)));
connect(m_valueListWidget, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
break; }
case roxdoku: {
view = new RoxdokuView(game, &m_symbols, this, "ksudoku-3dwnd");
RoxdokuView* v = new RoxdokuView(game, &m_symbols, wrapper, "ksudoku-3dwnd");
connect(m_valueListWidget, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
view = v;
break; }
case custom:{
// SKPuzzle* puzzle = game.puzzle()->puzzle();
//GraphCustom* gc = game.puzzle()->solver()->g;
ksudokuView* v = new ksudokuView(this, game, &m_symbols, true);
ksudokuView* v = new ksudokuView(wrapper, game, true);
// v->setup(game);
connect( v, SIGNAL(changedSelectedNum()), this, SLOT(updateStatusBar()) );
connect(v, SIGNAL(valueSelected(int)), SLOT(updateStatusBar()));
view = v;
connect(v, SIGNAL(valueSelected(int)), m_valueListWidget, SLOT(selectValue(int)));
connect(m_valueListWidget, SIGNAL(valueSelected(int)), v, SLOT(selectValue(int)));
}
default:
///@todo if here, BUG => throw exception (??)
break;
}
// m_tabs->insertTab(view, "Test");
// m_tabs->showPage(view);
view->setSymbolTable(m_symbols.selectTable(view->game().order()));
m_welcomeScreen->hide();
QWidget* widget = view->widget();
setCentralWidget(widget, true);
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)));
widget->show();
wrapper->layout()->addWidget(widget);
activeWidget = widget;
m_autoDelCentralWidget = true;
adaptActions2View();
QSizePolicy policy(QSizePolicy::Expanding, QSizePolicy::Expanding);
policy.setHorizontalStretch(1);
policy.setVerticalStretch(1);
widget->setSizePolicy(policy);
widget->addAction(m_moveUpAct);
widget->addAction(m_moveDownAct);
widget->addAction(m_moveLeftAct);
widget->addAction(m_moveRightAct);
m_valueListWidget->setCurrentTable(m_symbols.selectTable(view->game(). order()), view->game().order());
m_valueListWidget->selectValue(1);
m_valueListWidget->show();
}
void KSudoku::loadGame(const KUrl& Url) {
......@@ -258,7 +292,8 @@ void KSudoku::setCentralWidget(QWidget* widget, bool autoDel) {
}
void KSudoku::showWelcomeScreen() {
m_gameOptionsDlg = 0;
m_valueListWidget->hide();
setCentralWidget(m_welcomeScreen, false);
}
......@@ -275,18 +310,13 @@ void KSudoku::mouseOnlySuperscript()
void KSudoku::setGuidedMode()
{
// QWidget* current = m_tabs->currentPage();
// QWidget* current = (QWidget*) currentView();
if(KsView* view = dynamic_cast<ksudokuView*>(currentView())) {
((ksudokuView*)view)->toggleGuided();
((ksudokuView*)view)->update();
// /// TODO fix this (rerender through reinit); ???
// view->setGame(view->game());
if(ksudokuView* view = dynamic_cast<ksudokuView*>(currentView())) {
view->toggleGuided();
view->update();
} else if(RoxdokuView* view = dynamic_cast<RoxdokuView*>(currentView())) {
view->toggleGuided();
view->update();
}
else
return;
saveProperties( KGlobal::config().data());
}
......@@ -859,6 +889,14 @@ void KSudoku::optionsPreferences()
void KSudoku::settingsChanged() {
m_symbols.setEnabledTables(Settings::symbols());
KsView* view = currentView();
if(view) {
int order = view->game().order();
SymbolTable* table = m_symbols.selectTable(order);
view->setSymbolTable(table);
m_valueListWidget->setCurrentTable(table, order);
}
}
void KSudoku::changeStatusbar(const QString& text)
......
......@@ -44,6 +44,8 @@
#include <QSignalMapper>
#include <QListWidget>
//#include "skgraph.h"
//#include "sksolver.h"
......@@ -56,6 +58,7 @@ namespace ksudoku {
class GameSelectionDialog;
class GameOptionsDialog;
class GameVariantCollection;
class ValueListWidget;
class WelcomeScreen;
}
......@@ -82,7 +85,6 @@ public:
};
#endif
class KSudoku : public KXmlGuiWindow
{
Q_OBJECT
......@@ -214,10 +216,12 @@ private:
GameVariantCollection* m_gameVariants;
WelcomeScreen* m_welcomeScreen;
QWidget* m_gameWidget;
ValueListWidget* m_valueListWidget;
bool m_autoDelCentralWidget;
QString m_defaultAction;
GameOptionsDialog* m_gameOptionsDlg;
bool m_optionEnterOwnGame;
QMap<QString, SKSolver*> m_shapes;
......
......@@ -38,18 +38,6 @@
</Menu>
</MenuBar>
<ToolBar noMerge="1" name="numberSelector" position="Left" iconText="textOnly">
<text>Number Selector</text>
<Action name="val-select01" />
<Action name="val-select02" />
<Action name="val-select03" />
<Action name="val-select04" />
<Action name="val-select05" />
<Action name="val-select06" />
<Action name="val-select07" />
<Action name="val-select08" />
<Action name="val-select09" />
</ToolBar>
<ToolBar noMerge="1" name="actionsToolbar" position="Top" iconText="textOnly" >
<text>Actions Toolbar</text>
......
/***************************************************************************
* Copyright 2007 Francesco Rossi <redsh@email.it> *
* Copyright 2007 Mick Kappenburg <ksudoku@kappendburg.net> *
* Copyright 2007 Johannes Bergmeier <Johannes.Bergmeier@gmx.net> +
* *
* 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 *
......
/***************************************************************************
* Copyright 2007 Francesco Rossi <redsh@email.it> *
* Copyright 2007 Mick Kappenburg <ksudoku@kappendburg.net> *
* Copyright 2007 Johannes Bergmeier <Johannes.Bergmeier@gmx.net> +
* *
* 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 *
......
......@@ -5,6 +5,7 @@ set(ksudoku_views_SRCS
roxdokuview.cpp
ksudokuview.cpp
qsudokubutton.cpp
valuelistwidget.cpp
)
kde4_automoc( ${ksudoku_views_SRCS} )
......
......@@ -34,13 +34,13 @@
#include "symbols.h"
#include "valuelistwidget.h"
namespace ksudoku {
ksudokuView::ksudokuView(QWidget *parent, const Game& game, Symbols* symbols, bool customd)
ksudokuView::ksudokuView(QWidget *parent, const Game& game, bool customd)
: QWidget(parent)
, KsView()
, m_symbols(symbols)
{
isWaitingForNumber = -1;
highlighted = -1;
......@@ -53,8 +53,6 @@ ksudokuView::ksudokuView(QWidget *parent, const Game& game, Symbols* symbols, bo
current_selected_number = 1;
setGame(game);
connect(symbols, SIGNAL(tablesChanged()), SLOT(onFullChange()));
}
// void ksudokuView::setup(const ksudoku::Game& game)
......@@ -75,19 +73,22 @@ ksudokuView::~ksudokuView()
QString ksudokuView::status() const
{
QString m;
SymbolTable* table = symbolTable();
if(!table) return m;
int secs = QTime(0,0).secsTo(m_game.time());
if(secs % 36 < 12)
m = i18n("Selected item %1, Time elapsed %2. Press SHIFT to highlight.",
m_symbols->value2Symbol(current_selected_number, m_game.order()),
table->symbolForValue(current_selected_number),
m_game.time().toString("hh:mm:ss"));
else if(secs % 36 < 24)
m = i18n("Selected item %1, Time elapsed %2. Use RMB to pencil-mark(superscript).",
m_symbols->value2Symbol(current_selected_number, m_game.order()),
table->symbolForValue(current_selected_number),
m_game.time().toString("hh:mm:ss"));
else
m = i18n("Selected item %1, Time elapsed %2. Type in a cell to replace that number in it.",
m_symbols->value2Symbol(current_selected_number, m_game.order()),
table->symbolForValue(current_selected_number),
m_game.time().toString("hh::mm::ss"));
return m;
......@@ -292,16 +293,7 @@ void ksudokuView::setGame(const ksudoku::Game& game) {
connect(m_game.interface(), SIGNAL(cellChange(int)), this, SLOT(onCellChange(int)));
connect(m_game.interface(), SIGNAL(fullChange()), this, SLOT(onFullChange()));
connect(m_game.interface(), SIGNAL(completed(bool,const QTime&,bool)), parent(), SLOT(onCompleted(bool,const QTime&,bool)));
connect(m_game.interface(), SIGNAL(modified(bool)), parent(), SLOT(onModified(bool)));
//printf("DONE\n");
}
}
#include <QtDebug>
namespace ksudoku {
void ksudokuView::selectValue(int value) {
current_selected_number = value;
......@@ -351,6 +343,10 @@ void ksudokuView::moveRight() {
btn_enter(x,y);
}
void ksudokuView::updateSymbols() {
onFullChange();
}
void ksudokuView::beginHighlight(int val)
{
if( ! m_game.hasSolver()) return;
......@@ -385,13 +381,21 @@ void ksudokuView::resizeEvent(QResizeEvent * /*event*/ )
for(int i = 0; i < m_buttons.size(); ++i)
m_buttons[i]->resize();
}
void ksudokuView::wheelEvent (QWheelEvent* e) {
int order = game().order();
int value = (current_selected_number - e->delta()/120) % order;
if(value <= 0) value = order - value;
current_selected_number = value;
emit valueSelected(value);
}
void ksudokuView::slotHello(int x, int y)
{
if(m_game.given(x,y))
{
current_selected_number = m_game.value(x,y);
emit changedSelectedNum();
emit valueSelected(current_selected_number);
}
else
{
......
......@@ -44,6 +44,7 @@ namespace ksudoku {
class QSudokuButton;
class Symbols;
class SymbolTable;
/**
......@@ -56,7 +57,7 @@ class ksudokuView : public QWidget, public KsView
friend class QSudokuButton;
public:
/// Default constructor
ksudokuView(QWidget *parent, const Game& game, Symbols* symbols, bool custom);
ksudokuView(QWidget *parent, const Game& game, bool custom);
// Destructor
virtual ~ksudokuView();
......@@ -73,10 +74,8 @@ public:
*/
virtual void draw(QPainter& p, int height, int width) const;
Symbols* symbols() const { return m_symbols; }
signals:
void changedSelectedNum();
void valueSelected(int value);
public:
// void setup (const Game& game);
......@@ -88,7 +87,6 @@ public:
bool custom;
void selectValue(int value);
void enterValue(int value);
void markValue(int value);
void moveUp();
......@@ -96,9 +94,14 @@ public:
void moveLeft();
void moveRight();
public slots:
void selectValue(int value);
protected:
void resizeEvent(QResizeEvent *);
//void paintEvent(QPaintEvent *);
void wheelEvent(QWheelEvent* e);
void updateSymbols();
private slots:
void slotHello(int x, int y);
......@@ -127,8 +130,6 @@ private:
bool puzzle_mark_wrong;
int highlighted;
int m_color0;
Symbols* m_symbols;
};
}
......
......@@ -31,6 +31,7 @@ namespace ksudoku{
KsView::KsView()
: m_game()
{
m_symbolTable = 0;
}
KsView::~KsView()
......@@ -43,7 +44,6 @@ void KsView::draw(QPainter& /*p*/, int /*height*/, int /*width*/) const
// QPixmap const qp(const_cast< KsView* >(this)->renderPixmap(width, height, FALSE));
// //copy to QPainter
// p.drawPixmap(0,0,qp,-1,-1);
}
void KsView::selectValue(int value) {
......@@ -67,5 +67,16 @@ void KsView::moveLeft() {
void KsView::moveRight() {
}
SymbolTable* KsView::symbolTable() const {
return m_symbolTable;
}
void KsView::setSymbolTable(SymbolTable* table) {
m_symbolTable = table;
updateSymbols();
}
void KsView::updateSymbols() {
}
}
......@@ -30,6 +30,7 @@
namespace ksudoku {
class Game;
class SymbolTable;
/**
* Interface for all views
......@@ -80,13 +81,22 @@ public:
virtual void moveDown();
virtual void moveLeft();
virtual void moveRight();
SymbolTable* symbolTable() const;
void setSymbolTable(SymbolTable* table);
protected:
virtual void updateSymbols();
protected:
///pointer to external Game
Game m_game;
///whether wrong entries (by user) should be visable color marked
bool m_guidedMode;
SymbolTable* m_symbolTable;
};
}
......
......@@ -330,6 +330,12 @@ void QSudokuButton::mousePressEvent (QMouseEvent *mouseevent)
void QSudokuButton::updateData() {
CellInfo info = m_ksView.game().cellInfo(m_x,m_y);
if(!m_ksView.symbolTable()) {
m_state = ObviouslyWrong;
m_text = "?";
return;
}
m_state = info.state();
switch(info.state()) {
case GivenValue:
......@@ -337,16 +343,16 @@ void QSudokuButton::updateData() {
case WrongValue:
case ObviouslyWrong:
if(!info.value()) {
m_text = "";
m_text = QString();
} else {
m_text = m_ksView.symbols()->value2Symbol(info.value(), m_ksView.game().order());
m_text = m_ksView.symbolTable()->symbolForValue(info.value());
}
break;
case Marker:
m_text = "";
for(int i = 0; i < m_ksView.game().order(); ++i) {
if(info.marker(i+1))
m_text += m_ksView.symbols()->value2Symbol(i+1, m_ksView.game().order()) + ' ';
m_text += m_ksView.symbolTable()->symbolForValue(i+1) + ' ';
}
break;
}
......
......@@ -71,12 +71,12 @@ RoxdokuView::RoxdokuView(ksudoku::Game game, Symbols* symbols, QWidget *parent,
order = m_game.order();
base = (int) sqrt(order);
size = base*order;
connect(m_game.interface(), SIGNAL(cellChange(uint)), this, SLOT(updateGL()));
connect(m_game.interface(), SIGNAL(completed(bool,const QTime&,bool)), parent, SLOT(onCompleted(bool,const QTime&,bool)));
connect(m_game.interface(), SIGNAL(cellChange(int)), this, SLOT(updateGL()));
connect(m_game.interface(), SIGNAL(fullChange()), this, SLOT(updateGL()));
wheelmove = 0.0f;
dist = 5.3f;
selected_number = -1;
selected_number = 1;
m_guidedMode = false;
......
......@@ -97,8 +97,10 @@ public:
QWidget* widget() { return this; }
public slots:
void selectValue(int value);
void enterValue(int value);
protected:
void paintGL();
protected:
......
/***************************************************************************
* Copyright 2007 Johannes Bergmeier <johannes.bergmeier@gmx.net> *
* *
* 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., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "valuelistwidget.h"
#include "valuelistwidget.moc"
#include <QDebug>
#include <QGraphicsSimpleTextItem>
#include <QWheelEvent>
namespace ksudoku {
SymbolGraphicsItem::SymbolGraphicsItem(const QChar& symbol, QGraphicsItem * parent, QGraphicsScene * scene)
: QGraphicsItem(parent, scene)
{
m_text = new QGraphicsSimpleTextItem(symbol, this, scene);
setSize(10);
}
SymbolGraphicsItem::~SymbolGraphicsItem() {
}
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 SymbolGraphicsItem::paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) {
}
QRectF SymbolGraphicsItem::boundingRect() const {
return QRectF(-m_size/2, -m_size/2, m_size, m_size);
}
class SymbolSelectionItem : public SymbolGraphicsItem {
public:
SymbolSelectionItem(const QChar& symbol, int value, ValueListWidget* widget);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event);
private:
ValueListWidget* m_widget;
int m_value;
};
SymbolSelectionItem::SymbolSelectionItem(const QChar& symbol, int value, ValueListWidget* widget)
: SymbolGraphicsItem(symbol, 0, widget->scene()), m_widget(widget), m_value(value)
{
}
void SymbolSelectionItem::mousePressEvent(QGraphicsSceneMouseEvent*) {
m_widget->selectValueItem(m_value);
}
ValueListWidget::ValueListWidget(QWidget* parent)
: QGraphicsView(parent)
{
m_table = 0;
setAlignment(Qt::AlignHCenter | Qt::AlignTop);
m_scene = new QGraphicsScene(this);
setScene(m_scene);
m_selectionItem = new QGraphicsRectItem(-4.5, 0.5, 9, 9, 0, m_scene);
m_selectionItem->setPos(0, 0);
m_maxValue = 1;
m_selectedValue = 1;
}
ValueListWidget::~ValueListWidget() {
}
SymbolTable* ValueListWidget::currentTable() const {
return m_table;
}
void ValueListWidget::setCurrentTable(SymbolTable* table, int maxValue) {
m_table = table;
m_maxValue = maxValue;
SymbolSelectionItem* item;
while(!m_symbols.empty()) {
delete m_symbols.takeLast();
}