Commit 6a145021 authored by Johannes Bergmeier's avatar Johannes Bergmeier

* renamed class ksudokuView to SudokuView

* made tiny changes to QSudokuButton rendering code

svn path=/trunk/KDE/kdegames/ksudoku/; revision=717505
parent 5080c933
......@@ -37,7 +37,7 @@
#include <knewstuff/knewstuff.h>
#endif
#include "ksudokuview.h"
#include "sudokuview.h"
#include "roxdokuview.h"
#include "symbols.h"
......
......@@ -23,11 +23,9 @@
#include "sudoku_solver.h"
#include "ksudokuview.h"
#include "puzzle.h"
#include "history.h"
#include "symbols.h"
//Added by qt3to4:
#include <QList>
......
......@@ -3,7 +3,7 @@ set(ksudoku_views_SRCS
ksview.cpp
ArcBall.cpp
roxdokuview.cpp
ksudokuview.cpp
sudokuview.cpp
qsudokubutton.cpp
valuelistwidget.cpp
)
......
......@@ -34,7 +34,7 @@
#include <QtDebug>
#include "ksudokuview.h"
#include "sudokuview.h"
#include "roxdokuview.h"
namespace ksudoku{
......@@ -56,11 +56,11 @@ void KsView::createView() {
GameType type = m_game.puzzle()->gameType();
switch(type) {
case sudoku: {
setWidget(new ksudokuView(0, m_game, false));
setWidget(new SudokuView(0, m_game, false));
break;
}
case custom: {
setWidget(new ksudokuView(0, m_game, true));
setWidget(new SudokuView(0, m_game, true));
break;
}
case roxdoku: {
......
......@@ -26,9 +26,11 @@
#include <QKeyEvent>
#include <QEvent>
#include <QLinearGradient>
#include "ksudoku.h"
#include "ksudokugame.h"
#include "ksudokuview.h"
#include "sudokuview.h"
#include <kmessagebox.h>
#include <klocale.h>
......@@ -70,7 +72,7 @@ const uint highlightColors[] = {
0xff000000, 0xff000000, 0xff000000, 0xff000000,
};
QSudokuButton::QSudokuButton(ksudokuView *parent, int x, int y)
QSudokuButton::QSudokuButton(SudokuView *parent, int x, int y)
: QWidget(parent)
, m_ksView(*parent)
, m_x(x)
......@@ -179,28 +181,36 @@ void QSudokuButton::draw(QPainter& qpainter)
// Graph2d* g = dynamic_cast<m_ksView.game().puzzle()->solver()->g;
// int connections=0;
// int myIndex = g->cellIndex(m_x,m_y,0); //TODO m_x and m_y are swapped but there is definitely something that doesn't work with coordinates
QPen pen(QColor(0xff888a85));
pen.setWidth(1);
bool left = g->hasLeftBorder(m_x, m_y);
bool top = g->hasTopBorder(m_x, m_y);
bool right = g->hasRightBorder(m_x, m_y);
bool bottom = g->hasBottomBorder(m_x, m_y);
//LEFT
pen.setColor(QColor(0xff80b3ff));
pen.setWidth( 1 );
qpainter.setPen(pen);
if(!top) { qpainter.drawLine(0,0,width()-1,0); }
if(!left) { qpainter.drawLine(0,0,0,height()-1); }
if(!bottom) { qpainter.drawLine(0,height()-1,width()-1,height()-1); }
if(!right) { qpainter.drawLine(width()-1,0,width()-1,height()-1); }
pen.setWidth( 1 );
pen.setColor(QColor(0xff00316e));
qpainter.setPen(pen);
if(top) { qpainter.drawLine(0,0,width()-1,0); }
if(left) { qpainter.drawLine(0,0,0,height()-1); }
if(bottom) { qpainter.drawLine(0,height()-1,width()-1,height()-1); }
if(right) { qpainter.drawLine(width()-1,0,width()-1,height()-1); }
QPen pen(QColor(0xff888a85));
if(!(top && left && bottom && right)) {
pen.setWidth( 1 );
qpainter.setPen(pen);
if(!top) { qpainter.drawLine(0,0,width()-1,0); }
if(!left) { qpainter.drawLine(0,0,0,height()-1); }
if(!bottom) { qpainter.drawLine(0,height()-1,width()-1,height()-1); }
if(!right) { qpainter.drawLine(width()-1,0,width()-1,height()-1); }
}
if(top || left) {
pen.setWidth( 4 );
pen.setColor(QColor(0x555753));
qpainter.setPen(pen);
if(top) { qpainter.drawLine(0,0,width()-1,0); }
if(left) { qpainter.drawLine(0,0,0,height()-1); }
}
if(bottom || right) {
pen.setWidth( 3 );
pen.setColor(QColor(0xeeeeec));
qpainter.setPen(pen);
if(bottom) { qpainter.drawLine(0,height()-1,width()-1,height()-1); }
if(right) { qpainter.drawLine(width()-1,0,width()-1,height()-1); }
}
......@@ -252,21 +262,26 @@ void QSudokuButton::draw(QPainter& qpainter)
}
void QSudokuButton::paintHighlight(QPainter& qpainter) {
// QRect pos = rect();
// QLinearGradient grad(pos.topLeft(), pos.bottomRight());
// grad.setColorAt(0.0, 0xffffffff);
// grad.setColorAt(1.0, highlightColors[m_highlights & HighlightMask]);
// qpainter.fillRect(pos, grad);
qpainter.fillRect(rect(), QBrush(highlightColors[m_highlights & HighlightMask]));
}
void QSudokuButton::drawMajorGrid(QPainter& qpainter)
{
QPen pen(QColor(0,0,0));
pen.setWidth(4);
qpainter.setPen(pen);
int puzzle_base = static_cast<int>(sqrt(m_ksView.game().order()));
if(m_x%puzzle_base == puzzle_base-1)
qpainter.drawLine(rect(). width(), 0, rect(). width(), rect().height());
if(m_y%puzzle_base == puzzle_base-1)
qpainter.drawLine(0, (int)rect().height(), (int)rect().width(), (int)rect().height());
}
// void QSudokuButton::drawMajorGrid(QPainter& qpainter)
// {
// QPen pen(QColor(0,0,0));
// pen.setWidth(4);
// qpainter.setPen(pen);
//
// int puzzle_base = static_cast<int>(sqrt(m_ksView.game().order()));
// if(m_x%puzzle_base == puzzle_base-1)
// qpainter.drawLine(rect(). width(), 0, rect(). width(), rect().height());
// if(m_y%puzzle_base == puzzle_base-1)
// qpainter.drawLine(0, (int)rect().height(), (int)rect().width(), (int)rect().height());
// }
void QSudokuButton::drawValue(QPainter& qpainter)
{
......
......@@ -38,7 +38,7 @@ class QPaintEvent;
namespace ksudoku {
class ksudokuView;
class SudokuView;
enum HighlightValues {
HighlightRow = 0x01, // for rows
......@@ -55,7 +55,7 @@ enum HighlightValues {
};
/**
* QSudokuButton represents a tile in KSudokuView
* QSudokuButton represents a tile in SudokuView
*/
class QSudokuButton : public QWidget
{
......@@ -67,7 +67,7 @@ private:
QSudokuButton& operator=(QSudokuButton const& other);
public:
explicit QSudokuButton(ksudokuView *parent = 0, int x=0, int y=0);
explicit QSudokuButton(SudokuView *parent = 0, int x=0, int y=0);
~QSudokuButton();
void resize();
......@@ -129,16 +129,16 @@ private:
void draw(QPainter& qpainter);
///responsable for expressing hightlighting (if needed)
void paintHighlight(QPainter& qpainter);
///responsable for creating the major grid lines
void drawMajorGrid(QPainter& qpainter);
// ///responsable for creating the major grid lines
// void drawMajorGrid(QPainter& qpainter);
///responsable for showing the value (if available)
void drawValue(QPainter& painter);
///reference to ksudokuView parent
///reference to SudokuView parent
///(could use parent, but this makes the code a bit
/// more readable)
ksudokuView& m_ksView;
SudokuView& m_ksView;
uint m_highlights;
......
......@@ -19,7 +19,7 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#include "ksudokuview.h"
#include "sudokuview.h"
#include "sudoku_solver.h"
......@@ -38,7 +38,7 @@
namespace ksudoku {
ksudokuView::ksudokuView(QWidget *parent, const Game& game, bool customd)
SudokuView::SudokuView(QWidget *parent, const Game& game, bool customd)
: QWidget(parent)
{
m_symbolTable = 0;
......@@ -51,14 +51,14 @@ ksudokuView::ksudokuView(QWidget *parent, const Game& game, bool customd)
setGame(game);
}
// void ksudokuView::setup(const ksudoku::Game& game)
// void SudokuView::setup(const ksudoku::Game& game)
// {
// // std::srand( time(0) );//srandom((unsigned)time( NULL ) );
// // puzzle_mark_wrong=true;
//
// }
ksudokuView::~ksudokuView()
SudokuView::~SudokuView()
{
for(int i = 0; i < m_buttons.size(); ++i) {
delete m_buttons[i];
......@@ -66,7 +66,7 @@ ksudokuView::~ksudokuView()
}
}
QString ksudokuView::status() const
QString SudokuView::status() const
{
QString m;
......@@ -89,14 +89,14 @@ QString ksudokuView::status() const
return m;
}
QChar ksudokuView::symbol(int value) const {
QChar SudokuView::symbol(int value) const {
if(m_symbolTable == 0)
return '\0';
return m_symbolTable->symbolForValue(value);
}
void ksudokuView::draw(QPainter& p, int height, int width) const
void SudokuView::draw(QPainter& p, int height, int width) const
{
if(m_buttons.size() == 0)
return;
......@@ -129,11 +129,11 @@ void ksudokuView::draw(QPainter& p, int height, int width) const
}
void ksudokuView::btn_enter(int x, int y) {
void SudokuView::btn_enter(int x, int y) {
emit cellHovered(m_game.index(x,y));
}
void ksudokuView::setCursor(int cell) {
void SudokuView::setCursor(int cell) {
m_buttons[cell]->setFocus();
m_currentCell = cell;
......@@ -196,10 +196,10 @@ void ksudokuView::setCursor(int cell) {
}
void ksudokuView::btn_leave(int /*x*/, int /*y*/)
void SudokuView::btn_leave(int /*x*/, int /*y*/)
{}
void ksudokuView::setGame(const ksudoku::Game& game) {
void SudokuView::setGame(const ksudoku::Game& game) {
// TODO change this member so that its code can only be executed once
// the best way might be removeing this member and move the oce somewhere else
......@@ -235,7 +235,7 @@ void ksudokuView::setGame(const ksudoku::Game& game) {
{
for(int i = 0; i < m_game.size(); ++i) {
bool notConnectedNode = ((GraphCustom*) m_game.puzzle()->solver()->g)->optimized_d[i] == 0;
QSudokuButton* btn = new QSudokuButton((ksudokuView*) this, 0, 0);
QSudokuButton* btn = new QSudokuButton(this, 0, 0);
btn->setCustom(1);
......@@ -270,7 +270,7 @@ void ksudokuView::setGame(const ksudoku::Game& game) {
connect(m_game.interface(), SIGNAL(fullChange()), this, SLOT(update()));
}
void ksudokuView::selectValue(int value) {
void SudokuView::selectValue(int value) {
if(current_selected_number == value) return;
current_selected_number = value;
......@@ -280,17 +280,17 @@ void ksudokuView::selectValue(int value) {
emit valueSelected(value);
}
void ksudokuView::setSymbols(SymbolTable* table) {
void SudokuView::setSymbols(SymbolTable* table) {
m_symbolTable = table;
update();
}
void ksudokuView::setFlags(ViewFlags flags) {
void SudokuView::setFlags(ViewFlags flags) {
m_flags = flags;
update();
}
void ksudokuView::beginHighlight(int val)
void SudokuView::beginHighlight(int val)
{
if( ! m_game.hasSolver()) return;
......@@ -308,7 +308,7 @@ void ksudokuView::beginHighlight(int val)
}
}
void ksudokuView::finishHighlight()
void SudokuView::finishHighlight()
{
highlighted = -1;
......@@ -319,13 +319,13 @@ void ksudokuView::finishHighlight()
}
}
void ksudokuView::resizeEvent(QResizeEvent * /*event*/ )
void SudokuView::resizeEvent(QResizeEvent * /*event*/ )
{
for(int i = 0; i < m_buttons.size(); ++i)
m_buttons[i]->resize();
}
void ksudokuView::wheelEvent (QWheelEvent* e) {
void SudokuView::wheelEvent (QWheelEvent* e) {
int order = m_game.order();
int value = (current_selected_number - e->delta()/120) % order;
if(value <= 0) value = order - value;
......@@ -333,7 +333,7 @@ void ksudokuView::wheelEvent (QWheelEvent* e) {
selectValue(value);
}
void ksudokuView::slotHello(int x, int y)
void SudokuView::slotHello(int x, int y)
{
if(m_game.given(x,y))
{
......@@ -345,7 +345,7 @@ void ksudokuView::slotHello(int x, int y)
}
}
void ksudokuView::slotRight(int x, int y)
void SudokuView::slotRight(int x, int y)
{
if(!m_game.given(x,y))
{
......@@ -353,7 +353,7 @@ void ksudokuView::slotRight(int x, int y)
}
}
void ksudokuView::update(int cell) {
void SudokuView::update(int cell) {
if(cell < 0) {
for(int i = 0; i < m_buttons.count(); i++)
m_buttons[i]->updateData();
......@@ -367,4 +367,4 @@ void ksudokuView::update(int cell) {
}
#include "ksudokuview.moc"
#include "sudokuview.moc"
......@@ -19,8 +19,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
***************************************************************************/
#ifndef _KSUDOKUVIEW_H_
#define _KSUDOKUVIEW_H_
#ifndef _SUDOKUVIEW_H_
#define _SUDOKUVIEW_H_
#include "ksview.h"
......@@ -47,17 +47,16 @@ class Symbols;
/**
* Gui for a sudoku puzzle
* @TODO rename ksudokuView to sudokuView
*/
class ksudokuView : public QWidget, public ViewInterface
class SudokuView : public QWidget, public ViewInterface
{
Q_OBJECT
friend class QSudokuButton;
public:
/// Default constructor
ksudokuView(QWidget *parent, const Game& game, bool custom);
SudokuView(QWidget *parent, const Game& game, bool custom);
// Destructor
virtual ~ksudokuView();
virtual ~SudokuView();
virtual QString status() const;
int getHighlighted(){return highlighted;}
......@@ -131,4 +130,4 @@ private:
}
#endif // _KSUDOKUVIEW_H_
#endif // _SUDOKUVIEW_H_
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment