Skip to content
Snippets Groups Projects
Commit dee1cc35 authored by Silas Dohm's avatar Silas Dohm
Browse files

basic func

parent 35127515
No related branches found
No related tags found
1 merge request!1Master
......@@ -18,6 +18,8 @@ set(PROJECT_SOURCES
main.cpp
window.h
window.cpp
cell.h
cell.cpp
)
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
......
......@@ -142,6 +142,30 @@ sodoku_solver_autogen/fast:
$(MAKE) $(MAKESILENT) -f CMakeFiles/sodoku_solver_autogen.dir/build.make CMakeFiles/sodoku_solver_autogen.dir/build
.PHONY : sodoku_solver_autogen/fast
cell.o: cell.cpp.o
.PHONY : cell.o
# target to build an object file
cell.cpp.o:
$(MAKE) $(MAKESILENT) -f CMakeFiles/sodoku_solver.dir/build.make CMakeFiles/sodoku_solver.dir/cell.cpp.o
.PHONY : cell.cpp.o
cell.i: cell.cpp.i
.PHONY : cell.i
# target to preprocess a source file
cell.cpp.i:
$(MAKE) $(MAKESILENT) -f CMakeFiles/sodoku_solver.dir/build.make CMakeFiles/sodoku_solver.dir/cell.cpp.i
.PHONY : cell.cpp.i
cell.s: cell.cpp.s
.PHONY : cell.s
# target to generate assembly for a file
cell.cpp.s:
$(MAKE) $(MAKESILENT) -f CMakeFiles/sodoku_solver.dir/build.make CMakeFiles/sodoku_solver.dir/cell.cpp.s
.PHONY : cell.cpp.s
main.o: main.cpp.o
.PHONY : main.o
......@@ -224,6 +248,9 @@ help:
@echo "... rebuild_cache"
@echo "... sodoku_solver_autogen"
@echo "... sodoku_solver"
@echo "... cell.o"
@echo "... cell.i"
@echo "... cell.s"
@echo "... main.o"
@echo "... main.i"
@echo "... main.s"
......
#include "cell.h"
#include <QPushButton>
#include <QDebug>
#include <QSignalMapper>
Cell::Cell(QWidget *parent) :
QWidget(parent)
Cell::Cell(QWidget *parent) : QWidget(parent)
{
// Set size of the window
setFixedSize(100, 50);
// Create and position the button
m_button = new QPushButton("Hello World", this);
m_button->setGeometry(10, 10, 80, 30);
setAutoFillBackground(true);
setStyleSheet("background-color:gray;");
setFixedSize(100, 100);
// qInfo("width=%d,height=%d",parent->width(),height());
float w = width() / 3.0;
float h = height() / 3.0;
QSignalMapper *mapper = new QSignalMapper(this);
connect(mapper, SIGNAL(mapped(int)), this, SLOT(slotButtonClicked(int)));
for (char i = 0; i < 9; i++)
{
states[i] = new QPushButton(QString::number(i), this);
states[i]->setGeometry(i%3 * w, i/3 * h, w, h);
states[i]->setStyleSheet("border:none");
connect(states[i], SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(states[i], i);
}
collapsed = new QPushButton(this);
collapsed->setFixedSize(100, 100);
collapsed->setStyleSheet("font-size:44px");
collapsed->hide();
}
void Cell::slotButtonClicked(int x)
{
collapsed->show();
collapsed->setText(QString::number(x));
emit(collapse(x));
}
void Cell::foo(int x)
{
states[x]->hide();
}
\ No newline at end of file
......@@ -6,10 +6,19 @@
class QPushButton;
class Cell : public QWidget
{
Q_OBJECT
public:
explicit Cell(QWidget *parent = 0);
private:
QPushButton *m_button;
QPushButton *states[9];
QPushButton *collapsed;
signals:
void collapse(int x);
public slots:
void foo(int x);
private slots:
void slotButtonClicked(int x);
};
#endif // CELL_H
\ No newline at end of file
#include "window.h"
#include <QApplication>
#include <QStandardPaths>
#include <QDebug>
Window::Window(QWidget *parent)
: QWidget{parent}
{
setFixedSize(1600, 900);
m_counter = 0;
// quitbutton
// m_buttonQuit = new QPushButton("quit", this);
// m_buttonQuit->setGeometry(0, height() - 30, width(), 30);
for (char x = 0; x < 9; x++)
int dx = 0;
int dy = 0;
for (int x = 0; x < 9; x++)
{
for (char y = 0; y < 1; y++)
for (int y = 0; y < 9; y++)
{
grid[x][y] = new QPushButton("x",this);
grid[x][y]->setGeometry(x*100,y*100,100,100);
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] = new Cell(this);
m_cell[x][y]->setGeometry(x * 100 + dx, y * 100 + dy, 100, 100);
/* code */
}
}
// slider
// m_slider = new QSlider(this);
// m_slider->setOrientation(Qt::Horizontal);
// m_slider->setRange(0, 100);
// m_slider->setValue(0);
// m_slider->setGeometry(10, 20, width() - 10, 20);
// // progressbar
// m_progressBar = new QProgressBar(this);
// m_progressBar->setRange(0, 100);
// m_progressBar->setValue(0);
// m_progressBar->setGeometry(10, 40, width() - 10, 20);
// // button
// m_button = new QPushButton("Hello QT!", this);
// m_button->setGeometry(0, 80, width(), 30);
// m_button->setCheckable(true);
// // signals and slots :)
// connect(m_button, SIGNAL(clicked(bool)), this, SLOT(slotButtonClicked(bool)));
// connect(m_buttonQuit, SIGNAL(clicked()), QApplication::instance(), SLOT(quit()));
// connect(m_slider, SIGNAL(valueChanged(int)), m_progressBar, SLOT(setValue(int)));
// connect(this, SIGNAL(counterReached()), QApplication::instance(), SLOT(quit()));
// init signals
for (int x = 0; x < 9; x++)
{
for (int y = 0; y < 9; y++)
{
for (int d = 0; d < 9; d++)
{
connect(m_cell[x][y], SIGNAL(collapse(int)), m_cell[x][d], SLOT(foo(int)));
connect(m_cell[x][y], SIGNAL(collapse(int)), m_cell[d][y], SLOT(foo(int)));
}
void Window::slotButtonClicked(bool checked)
int a = x/3 *3;
int b = y/3 *3;
for (int x1=a; x1 < a+3; x1++)
{
checked ? m_button->setText("Checked") : m_button->setText("Hello QT!");
m_counter++;
if (m_counter == 10)
for (int y1=b; y1 < b+3; y1++)
{
emit counterReached();
connect(m_cell[x][y], SIGNAL(collapse(int)), m_cell[x1][y1], SLOT(foo(int)));
}
}
}
}
}
......@@ -5,6 +5,7 @@
#include <QPushButton>
#include <QProgressBar>
#include <QSlider>
#include "cell.h"
class Window : public QWidget
{
Q_OBJECT
......@@ -16,11 +17,12 @@ private:
QPushButton *grid[9][9];
QProgressBar *m_progressBar;
QSlider *m_slider;
Cell *m_cell[9][9];
int m_counter;
signals:
void counterReached();
private slots:
void slotButtonClicked(bool checked);
};
#endif // WINDOW_H
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment