Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sudoku solver
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Silas Dohm
sudoku solver
Commits
c10567c4
Commit
c10567c4
authored
2 years ago
by
Silas Dohm
Browse files
Options
Downloads
Plain Diff
Merge branch 'visualize' into 'main'
responsive design See merge request sdohm/sodoku-solver!3
parents
2b305f7b
e0473e3c
Branches
Branches containing commit
No related tags found
1 merge request
!3
responsive design
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
cell.cpp
+36
-22
36 additions, 22 deletions
cell.cpp
cell.h
+6
-4
6 additions, 4 deletions
cell.h
window.cpp
+29
-21
29 additions, 21 deletions
window.cpp
window.h
+6
-5
6 additions, 5 deletions
window.h
with
77 additions
and
52 deletions
cell.cpp
+
36
−
22
View file @
c10567c4
#include
"cell.h"
#include
"cell.h"
#include
<QPushButton>
#include
<QPushButton>
#include
<QToolButton>
#include
<QDebug>
#include
<QDebug>
#include
<QSignalMapper>
#include
<QSignalMapper>
#include
<QGridLayout>
#include
<QStackedWidget>
#include
<QGroupBox>
Cell
::
Cell
(
QWidget
*
parent
)
:
QWidget
(
parent
)
Cell
::
Cell
(
QWidget
*
parent
)
:
QWidget
(
parent
)
{
{
// Set size of the window
// Create and position the button
setAutoFillBackground
(
true
);
setStyleSheet
(
"background-color:gray;"
);
setFixedSize
(
100
,
100
);
float
w
=
width
()
/
3.0
;
float
h
=
height
()
/
3.0
;
QSignalMapper
*
mapper
=
new
QSignalMapper
(
this
);
QSignalMapper
*
mapper
=
new
QSignalMapper
(
this
);
connect
(
mapper
,
SIGNAL
(
mapped
(
int
)),
this
,
SLOT
(
collapse
(
int
)));
connect
(
mapper
,
SIGNAL
(
mapped
(
int
)),
this
,
SLOT
(
collapse
(
int
)));
QGroupBox
*
groupBox
=
new
QGroupBox
();
QGridLayout
*
layout
=
new
QGridLayout
();
setStyleSheet
(
"border: 1px solid #1e282c; border-radius: 0px;background-color:#52585d;"
);
for
(
char
i
=
0
;
i
<
9
;
i
++
)
for
(
char
i
=
0
;
i
<
9
;
i
++
)
{
{
m_states
[
i
]
=
new
QPushButton
(
QString
::
number
(
i
+
1
),
this
);
m_states
[
i
]
=
new
QPushButton
(
QString
::
number
(
i
+
1
),
this
);
m_states
[
i
]
->
setGeometry
(
i
%
3
*
w
,
i
/
3
*
h
,
w
,
h
);
layout
->
addWidget
(
m_states
[
i
],
i
%
3
,
i
/
3
);
m_states
[
i
]
->
setStyleSheet
(
"border:none"
);
m_states
[
i
]
->
setStyleSheet
(
"border:none"
);
connect
(
m_states
[
i
],
SIGNAL
(
clicked
()),
mapper
,
SLOT
(
map
()));
connect
(
m_states
[
i
],
SIGNAL
(
clicked
()),
mapper
,
SLOT
(
map
()));
mapper
->
setMapping
(
m_states
[
i
],
i
);
mapper
->
setMapping
(
m_states
[
i
],
i
);
m_blocked
[
i
]
=
0
;
m_blocked
[
i
]
=
0
;
}
}
groupBox
->
setLayout
(
layout
);
m_number
=
new
QPushButton
(
this
);
m_number
=
new
QPushButton
(
this
);
m_number
->
setFixedSize
(
100
,
100
);
m_number
->
setStyleSheet
(
"font-size:44px"
);
m_number
->
hide
();
connect
(
m_number
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
un
()));
connect
(
m_number
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
un
()));
m_stackedWidget
=
new
QStackedWidget
(
this
);
m_stackedWidget
->
addWidget
(
groupBox
);
m_stackedWidget
->
addWidget
(
m_number
);
setMinimumSize
(
70
,
70
);
}
void
Cell
::
resizeEvent
(
QResizeEvent
*
event
)
{
QWidget
::
resizeEvent
(
event
);
m_stackedWidget
->
setFixedSize
(
this
->
size
());
int
smallest
=
this
->
width
()
<
this
->
height
()
?
this
->
width
()
:
this
->
height
();
m_number
->
setStyleSheet
(
"font-size:"
+
QString
::
number
(
smallest
/
2
)
+
"px;"
);
return
;
}
}
void
Cell
::
collapse
(
int
x
)
void
Cell
::
collapse
(
int
x
)
{
{
collapsed
=
true
;
collapsed
=
true
;
m_
number
->
show
(
);
m_
stackedWidget
->
setCurrentIndex
(
1
);
m_number
->
setText
(
QString
::
number
(
x
+
1
));
m_number
->
setText
(
QString
::
number
(
x
+
1
));
emit
(
update
(
x
));
emit
(
update
(
x
));
}
}
void
Cell
::
removeOption
(
int
x
)
void
Cell
::
removeOption
(
int
x
)
{
{
// states[x]->hide();
if
(
m_blocked
[
x
]
==
0
)
if
(
m_states
[
x
]
->
isEnabled
())
{
{
m_states
[
x
]
->
setText
(
" "
);
m_states
[
x
]
->
setDisabled
(
true
);
m_states
[
x
]
->
setDisabled
(
true
);
possibleStates
--
;
possibleStates
--
;
index
.
erase
(
std
::
find
(
index
.
begin
(),
index
.
end
(),
x
));
index
.
erase
(
std
::
find
(
index
.
begin
(),
index
.
end
(),
x
));
...
@@ -56,13 +68,15 @@ void Cell::addOption(int x)
...
@@ -56,13 +68,15 @@ void Cell::addOption(int x)
// if (!m_states[x]->isEnabled())
// if (!m_states[x]->isEnabled())
if
(
m_blocked
[
x
]
<
1
)
if
(
m_blocked
[
x
]
<
1
)
{
{
m_states
[
x
]
->
setText
(
QString
::
number
(
x
+
1
));
m_states
[
x
]
->
setDisabled
(
false
);
m_states
[
x
]
->
setDisabled
(
false
);
possibleStates
++
;
possibleStates
++
;
index
.
push_back
(
x
);
index
.
push_back
(
x
);
}
}
}
}
void
Cell
::
un
(
void
){
void
Cell
::
un
(
void
)
{
collapsed
=
false
;
collapsed
=
false
;
m_
number
->
hide
(
);
m_
stackedWidget
->
setCurrentIndex
(
0
);
emit
(
undo
(
m_number
->
text
().
toInt
()
-
1
));
emit
(
undo
(
m_number
->
text
().
toInt
()
-
1
));
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
cell.h
+
6
−
4
View file @
c10567c4
...
@@ -2,13 +2,14 @@
...
@@ -2,13 +2,14 @@
#define CELL_H
#define CELL_H
#include
<QWidget>
#include
<QWidget>
class
QPushButton
;
class
QPushButton
;
class
QStackedWidget
;
class
Cell
:
public
QWidget
class
Cell
:
public
QWidget
{
{
Q_OBJECT
Q_OBJECT
public:
public:
explicit
Cell
(
QWidget
*
parent
=
0
);
explicit
Cell
(
QWidget
*
parent
=
0
);
void
resizeEvent
(
QResizeEvent
*
event
);
int
possibleStates
=
9
;
int
possibleStates
=
9
;
bool
collapsed
=
false
;
bool
collapsed
=
false
;
std
::
vector
<
int
>
index
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
std
::
vector
<
int
>
index
=
{
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
};
...
@@ -17,6 +18,7 @@ private:
...
@@ -17,6 +18,7 @@ private:
QPushButton
*
m_states
[
9
];
QPushButton
*
m_states
[
9
];
QPushButton
*
m_number
;
QPushButton
*
m_number
;
std
::
array
<
int
,
9
>
m_blocked
;
std
::
array
<
int
,
9
>
m_blocked
;
QStackedWidget
*
m_stackedWidget
;
signals
:
signals
:
void
update
(
int
x
);
void
update
(
int
x
);
...
...
This diff is collapsed.
Click to expand it.
window.cpp
+
29
−
21
View file @
c10567c4
...
@@ -5,44 +5,52 @@
...
@@ -5,44 +5,52 @@
#include
<QThread>
#include
<QThread>
#include
<QProgressBar>
#include
<QProgressBar>
#include
<QSlider>
#include
<QSlider>
#include
<QGridLayout>
#include
<QHBoxLayout>
#include
<QVBoxLayout>
#include
<QSpacerItem>
Window
::
Window
(
QWidget
*
parent
)
Window
::
Window
(
QWidget
*
parent
)
:
QWidget
{
parent
}
:
QWidget
{
parent
}
{
{
setFixedWidth
(
1600
);
m_solveButton
=
new
QPushButton
(
"solve"
,
this
);
m_solveButton
=
new
QPushButton
(
"solve"
,
this
);
m_solveButton
->
setGeometry
(
1100
,
height
()
-
100
,
width
()
-
1200
,
30
);
connect
(
m_solveButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
solveButtonClicked
()));
connect
(
m_solveButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
solveButtonClicked
()));
m_clearButton
=
new
QPushButton
(
"Clear"
,
this
);
m_clearButton
=
new
QPushButton
(
"Clear"
,
this
);
m_clearButton
->
setGeometry
(
1100
,
height
()
-
30
,
width
()
-
1200
,
30
);
connect
(
m_clearButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
clearButtonClicked
()));
connect
(
m_clearButton
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
clearButtonClicked
()));
m_slider
=
new
QSlider
(
this
);
m_slider
=
new
QSlider
(
this
);
m_slider
->
setRange
(
0
,
1000
);
m_slider
->
setRange
(
0
,
1000
);
m_slider
->
setOrientation
(
Qt
::
Horizontal
);
m_slider
->
setOrientation
(
Qt
::
Horizontal
);
m_slider
->
setValue
(
m_delay
);
m_slider
->
setValue
(
m_delay
);
m_slider
->
setGeometry
(
1100
,
height
()
-
60
,
width
()
-
1200
,
30
);
connect
(
m_slider
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
setValue
(
int
)));
connect
(
m_slider
,
SIGNAL
(
valueChanged
(
int
)),
this
,
SLOT
(
setValue
(
int
)));
QHBoxLayout
*
horizontalLayout
=
new
QHBoxLayout
(
this
);
QVBoxLayout
*
verticalLayout
=
new
QVBoxLayout
();
QGridLayout
*
layout
=
new
QGridLayout
();
m_spacer
[
0
]
=
new
QSpacerItem
(
4
,
4
,
QSizePolicy
::
Minimum
,
QSizePolicy
::
Fixed
);
m_spacer
[
1
]
=
new
QSpacerItem
(
4
,
4
,
QSizePolicy
::
Minimum
,
QSizePolicy
::
Fixed
);
m_spacer
[
2
]
=
new
QSpacerItem
(
8
,
8
,
QSizePolicy
::
Minimum
,
QSizePolicy
::
Expanding
);
verticalLayout
->
addItem
(
m_spacer
[
2
]);
verticalLayout
->
addWidget
(
m_solveButton
);
verticalLayout
->
addWidget
(
m_slider
);
verticalLayout
->
addWidget
(
m_clearButton
);
horizontalLayout
->
addLayout
(
layout
,
5
);
horizontalLayout
->
addLayout
(
verticalLayout
,
1
);
layout
->
addItem
(
m_spacer
[
0
],
3
,
3
);
layout
->
addItem
(
m_spacer
[
1
],
7
,
7
);
layout
->
setSpacing
(
0
);
int
dx
=
0
;
int
dx
=
0
;
int
dy
=
0
;
int
dy
=
0
;
for
(
int
x
=
0
;
x
<
9
;
x
++
)
for
(
int
x
=
0
;
x
<
9
;
x
++
)
{
{
for
(
int
y
=
0
;
y
<
9
;
y
++
)
for
(
int
y
=
0
;
y
<
9
;
y
++
)
{
{
if
(
x
==
3
)
dx
=
4
;
if
(
x
==
6
)
dx
=
8
;
if
(
y
<
3
)
dy
=
0
;
if
(
y
>=
3
)
dy
=
4
;
if
(
y
>=
6
)
dy
=
8
;
m_cell
[
x
+
y
*
9
].
setParent
(
this
);
m_cell
[
x
+
y
*
9
].
setParent
(
this
);
m_cell
[
x
+
y
*
9
].
setGeometry
(
x
*
100
+
dx
,
y
*
100
+
dy
,
100
,
100
);
layout
->
addWidget
(
&
m_cell
[
x
+
y
*
9
],
y
+
y
/
3
,
x
+
x
/
3
);
// connecting signals & slots
// connecting signals & slots
for
(
int
d
=
0
;
d
<
9
;
d
++
)
// rows and columns
for
(
int
d
=
0
;
d
<
9
;
d
++
)
// rows and columns
{
{
...
...
This diff is collapsed.
Click to expand it.
window.h
+
6
−
5
View file @
c10567c4
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include
<QProgressBar>
#include
<QProgressBar>
#include
<QSlider>
#include
<QSlider>
#include
"cell.h"
#include
"cell.h"
class
QSpacerItem
;
class
Window
:
public
QWidget
class
Window
:
public
QWidget
{
{
Q_OBJECT
Q_OBJECT
...
@@ -15,11 +16,10 @@ public:
...
@@ -15,11 +16,10 @@ public:
private:
private:
QPushButton
*
m_clearButton
;
QPushButton
*
m_clearButton
;
QPushButton
*
m_solveButton
;
QPushButton
*
m_solveButton
;
QPushButton
*
grid
[
9
][
9
];
QProgressBar
*
m_progressBar
;
QSlider
*
m_slider
;
QSlider
*
m_slider
;
std
::
array
<
Cell
,
81
>
m_cell
;
std
::
array
<
Cell
,
81
>
m_cell
;
int
m_delay
=
300
;
int
m_delay
=
300
;
QSpacerItem
*
m_spacer
[
3
];
struct
History
struct
History
{
{
Cell
*
cell
;
Cell
*
cell
;
...
@@ -27,7 +27,8 @@ private:
...
@@ -27,7 +27,8 @@ private:
History
(
Cell
*
c
,
std
::
vector
<
int
>
in
,
int
choice
)
History
(
Cell
*
c
,
std
::
vector
<
int
>
in
,
int
choice
)
{
{
cell
=
c
;
cell
=
c
;
for
(
int
i
=
0
;
i
<
in
.
size
();
i
++
){
for
(
int
i
=
0
;
i
<
in
.
size
();
i
++
)
{
if
(
i
==
choice
)
if
(
i
==
choice
)
continue
;
continue
;
index
.
push_back
(
in
[
i
]);
index
.
push_back
(
in
[
i
]);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment