Commit 143a55ad authored by Johannes Bergmeier's avatar Johannes Bergmeier
Browse files

* created ksudoku::GameColors enum for fast access to all color values

* removed is connected from qsudokubutton (only connected buttons will be created from now on)

svn path=/trunk/KDE/kdegames/ksudoku/; revision=718544
parent 14940ce1
......@@ -40,36 +40,68 @@
namespace ksudoku {
enum GameColors {
// Standard background
HColorStd = 0xffbfd9ff,
// Pure highlights
HColorR = 0xff80b3ff, // Row highlight
HColorC = 0xfff082b0, // Column highlight
HColorB = 0xff00cc88, // Block highlight
// Combinations of highlights
HColorRC = 0xffe8b7d7,
HColorRB = 0xff6193cf,
HColorCB = 0xffb3925d,
HColorRCB = 0xff888a85,
// Special highlights
HColorSStd = HColorStd,
HColorSR = HColorR,
HColorSC = HColorC,
HColorSB = HColorB,
HColorSRC = HColorRC,
HColorSRB = HColorRB,
HColorSCB = HColorCB,
HColorSRCB = HColorRCB,
// Highlights for the helper
HColorGood = 0xffbfffbf,
HColorBad = 0xffffbfbf,
// Border colors
BColorDark = 0xff555753,
BColorLight = 0xffffffff, // 0xeeeeec
BColorSimple = 0xff888a85
};
// Highlights
// Lookup for Highlights
// Bit 1: Horz clique highlight
// Bit 2: Vert clique highlight
// Bit 3: Other Clique highlight
// Bit 4: Use Help Highlights
// Bit 5: Help Highlight for "allowed"
// Bit 5: Helper Highlight Good/Bad
// Bit 6: Special highlights (e.g. cross in XSudoku)
const uint highlightColors[] = {
0xffbfd9ff, 0xff80b3ff, 0xfff082b0, 0xffe8b7d7,
0xff00cc88, 0xff6193cf, 0xffb3925d, 0xff888a85,
0xffffbfbf, 0xffffbfbf, 0xffffbfbf, 0xffffbfbf,
0xffffbfbf, 0xffffbfbf, 0xffffbfbf, 0xffffbfbf,
0xffeeeeec, 0xffa4c0e4, 0xfffcd9b0, 0xfff9cade,
0xff99dcc6, 0xffa8dde0, 0xffd8e8c2, 0xffd3d7cf,
0xffbfffbf, 0xffbfffbf, 0xffbfffbf, 0xffbfffbf,
0xffbfffbf, 0xffbfffbf, 0xffbfffbf, 0xffbfffbf,
0xffeeeeec, 0xffa4c0e4, 0xfffcd9b0, 0xfff9cade,
0xff99dcc6, 0xffa8dde0, 0xffd8e8c2, 0xffd3d7cf,
0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000,
0xff000000, 0xff000000, 0xff000000, 0xff000000,
HColorStd, HColorR, HColorC, HColorRC,
HColorB, HColorRB, HColorCB, HColorRCB,
HColorBad, HColorBad, HColorBad, HColorBad,
HColorBad, HColorBad, HColorBad, HColorBad,
HColorStd, HColorR, HColorC, HColorRC,
HColorB, HColorRB, HColorCB, HColorRCB,
HColorGood, HColorGood, HColorGood, HColorGood,
HColorGood, HColorGood, HColorGood, HColorGood,
HColorSStd, HColorSR, HColorSC, HColorSRC,
HColorSB, HColorSRB, HColorSCB, HColorSRCB,
HColorBad, HColorBad, HColorBad, HColorBad,
HColorBad, HColorBad, HColorBad, HColorBad,
HColorSStd, HColorSR, HColorSC, HColorSRC,
HColorSB, HColorSRB, HColorSCB, HColorSRCB,
HColorGood, HColorGood, HColorGood, HColorGood,
HColorGood, HColorGood, HColorGood, HColorGood,
};
QSudokuButton::QSudokuButton(SudokuView *parent, int x, int y)
......@@ -88,8 +120,9 @@ QSudokuButton::QSudokuButton(SudokuView *parent, int x, int y)
m_text = " ";
setFocusPolicy(Qt::ClickFocus);
m_connected=true;
m_custom=false;
setAttribute(Qt::WA_OpaquePaintEvent, true);
}
QSudokuButton::~QSudokuButton()
......@@ -112,34 +145,29 @@ void QSudokuButton::resize()
void QSudokuButton::enterEvent (QEvent *)
{
if(!isConnected()) return;
emit enter(m_x,m_y);
m_mousein = true;
}
void QSudokuButton::focusOutEvent (QEvent *)
{//TODO it does not work
if(!isConnected()) return;
emit finishHighlight();
}
void QSudokuButton::leaveEvent (QEvent *)
{
if(!isConnected()) return;
emit leave(m_x,m_y);
m_mousein = false;
}
void QSudokuButton::exitEvent (QEvent *)
{
if(!isConnected()) return;
m_mousein = false;
emit enter(m_x,m_y);
}
void QSudokuButton::keyPressEvent ( QKeyEvent * e )
{
if(!isConnected()) return;
if(e->modifiers() & Qt::ControlModifier)
emit beginHighlight(m_ksView.game().value(m_x,m_y));
e->ignore(); //pass on
......@@ -168,98 +196,45 @@ void QSudokuButton::draw(QPainter& qpainter)
{
qpainter.eraseRect(rect());
if(isConnected())
paintHighlight(qpainter);
paintHighlight(qpainter);
//draw border
Graph2d* g = dynamic_cast<Graph2d*>(m_ksView.game().puzzle()->solver()->g);
if(!g) return;
if(isConnected())
{
// 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
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
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( 5 );
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( 5 );
// pen.setColor(QColor(0xeeeeec));
pen.setColor(QColor(0xffffff));
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); }
}
// if((m_y-1)>=0)
// {
// if(g->linksLeft[myIndex]!=0)
// {
// connections = 3-g->linksLeft[myIndex];
// if(connections<0) connections = 0;
// pen.setWidth( 1 + connections);
// pen.setColor(QColor(90/(connections+1),90/(connections+1),90/(connections+1)));
// qpainter.setPen(pen);
// qpainter.drawLine(0,0,width(),0);
// }
// }
// //TOP
// if((m_x-1)>=0)
// {
// if(g->linksUp[myIndex]!=0)
// {
// connections = 3-g->linksUp[myIndex];
// if(connections<0) connections = 0;
// pen.setWidth(1 + connections);
// pen.setColor(QColor(90/(connections+1),90/(connections+1),90/(connections+1)));
// qpainter.setPen(pen);
// qpainter.drawLine(0,0,0,height());
// }
// }
} /*else {
// Graph* g = (GraphCustom*)m_ksView.game().puzzle()->solver()->g;
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);
//draw border
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
QPen pen;
if(!(top && left && bottom && right)) {
pen.setWidth( 1 );
pen.setColor(QColor(0xff2e3436));
pen.setColor(QColor(BColorSimple));
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( 5 );
pen.setColor(QColor(BColorDark));
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( 5 );
pen.setColor(QColor(BColorLight));
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); }
}*/
}
if(isConnected())
drawValue (qpainter);
drawValue (qpainter);
}
void QSudokuButton::paintHighlight(QPainter& qpainter) {
......@@ -271,7 +246,6 @@ void QSudokuButton::paintHighlight(QPainter& qpainter) {
bool bottom = g->hasBottomBorder(m_x, m_y);
QRect pos = rect();
// QLinearGradient grad(pos.topLeft()+QPoint(0,-pos.height()), pos.bottomRight());
QLinearGradient grad(0,-pos.height(),pos.width(),pos.height());
grad.setColorAt(0.0, 0xffffffff);
grad.setColorAt(1.0, highlightColors[m_highlights & HighlightMask]);
......@@ -279,19 +253,6 @@ void QSudokuButton::paintHighlight(QPainter& qpainter) {
// 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::drawValue(QPainter& qpainter)
{
bool marker = false;
......@@ -343,7 +304,6 @@ void QSudokuButton::drawValue(QPainter& qpainter)
void QSudokuButton::mousePressEvent (QMouseEvent *mouseevent)
{
if(!isConnected()) return;
if(mouseevent->button() == Qt::LeftButton)
emit clicked2 (m_x,m_y);
......@@ -438,11 +398,6 @@ void QSudokuButton::updateData() {
update();
}
void QSudokuButton::setConnected(bool connected) {
m_connected = connected;
setAttribute(Qt::WA_OpaquePaintEvent, connected);
}
bool QSudokuButton::hasHighlight(int mask) const {
return ((m_highlights & mask) == mask);
}
......
......@@ -81,9 +81,6 @@ public:
void keyPressEvent ( QKeyEvent* e );
void updateData();
bool isConnected(){return m_connected;}
void setConnected(bool b);
bool isCustom(){return m_custom;}
void setCustom(bool b){m_custom=b;}
......@@ -146,7 +143,6 @@ private:
int m_y;
bool m_mousein;
QString m_text;
bool m_connected;
bool m_custom;
QFont m_font;
ksudoku::ButtonState m_state;
......
......@@ -111,6 +111,7 @@ void SudokuView::draw(QPainter& p, int height, int width) const
p.scale(scaleW,scaleH);
for(int i = 0; i < m_buttons.size(); ++i){
if(!m_buttons[i]) continue;
int x,y;
if(custom==0)
{
......@@ -134,6 +135,8 @@ void SudokuView::btn_enter(int x, int y) {
}
void SudokuView::setCursor(int cell) {
if(!m_buttons[cell]) return;
m_buttons[cell]->setFocus();
m_currentCell = cell;
......@@ -191,6 +194,7 @@ void SudokuView::setCursor(int cell) {
}
for(int i = 0; i < m_game.size(); ++i) {
if(!m_buttons[i]) continue;
m_buttons[i]->setHighlight(HighlightBaseMask, m_highlightUpdate[i]);
}
}
......@@ -235,30 +239,30 @@ void SudokuView::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;
if(notConnectedNode) {
m_buttons[i] = 0;
continue;
}
QSudokuButton* btn = new QSudokuButton(this, 0, 0);
btn->setCustom(1);
if(!notConnectedNode)
{
btn->setConnected(true);
connect(btn, SIGNAL(clicked2(int, int)), this, SLOT(slotHello(int, int)));
connect(btn, SIGNAL(rightclicked(int, int)), this, SLOT(slotRight(int, int)));
connect(btn, SIGNAL(enter(int,int)), this, SLOT(btn_enter(int,int)));
connect(btn, SIGNAL(leave(int,int)), this, SLOT(btn_leave(int,int)));
connect(btn, SIGNAL(beginHighlight(int)), this, SLOT(beginHighlight(int)));
connect(btn, SIGNAL(finishHighlight()), this, SLOT(finishHighlight()));
}
else
{
btn->setConnected(false);
}
connect(btn, SIGNAL(clicked2(int, int)), this, SLOT(slotHello(int, int)));
connect(btn, SIGNAL(rightclicked(int, int)), this, SLOT(slotRight(int, int)));
connect(btn, SIGNAL(enter(int,int)), this, SLOT(btn_enter(int,int)));
connect(btn, SIGNAL(leave(int,int)), this, SLOT(btn_leave(int,int)));
connect(btn, SIGNAL(beginHighlight(int)), this, SLOT(beginHighlight(int)));
connect(btn, SIGNAL(finishHighlight()), this, SLOT(finishHighlight()));
m_buttons[i] = btn;
}
}
for(int i = 0; i < m_buttons.size(); ++i) {
if(!m_buttons[i]) continue;
m_buttons[i]->setY(g->cellPosY(i));
m_buttons[i]->setX(g->cellPosX(i));
m_buttons[i]->updateData();
......@@ -303,6 +307,7 @@ void SudokuView::beginHighlight(int val)
return;
for(int i = 0; i < m_game.size(); ++i) {
if(!m_buttons[i]) continue;
m_buttons[i]->setHighlight(HighlightHelpMask, highlightedBtns[i] ? HighlightShowHelp : HighlightHelpMask);
m_buttons[i]->update();
}
......@@ -314,6 +319,7 @@ void SudokuView::finishHighlight()
for(int i = 0; i < m_game.size(); ++i)
{
if(!m_buttons[i]) continue;
m_buttons[i]->setHighlight(HighlightHelpMask, HighlightNone);
m_buttons[i]->update();
}
......@@ -321,8 +327,10 @@ void SudokuView::finishHighlight()
void SudokuView::resizeEvent(QResizeEvent * /*event*/ )
{
for(int i = 0; i < m_buttons.size(); ++i)
for(int i = 0; i < m_buttons.size(); ++i) {
if(!m_buttons[i]) continue;
m_buttons[i]->resize();
}
}
void SudokuView::wheelEvent (QWheelEvent* e) {
......@@ -355,8 +363,10 @@ void SudokuView::slotRight(int x, int y)
void SudokuView::update(int cell) {
if(cell < 0) {
for(int i = 0; i < m_buttons.count(); i++)
for(int i = 0; i < m_buttons.count(); i++) {
if(!m_buttons[i]) continue;
m_buttons[i]->updateData();
}
return;
}
if(m_buttons[cell])
......
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