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

test

parent 2b305f7b
Branches
No related tags found
1 merge request!3responsive design
#include "cell.h"
#include <QPushButton>
#include <QToolButton>
#include <QDebug>
#include <QSignalMapper>
#include <QGridLayout>
#include <QStackedWidget>
#include <QGroupBox>
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);
connect(mapper, SIGNAL(mapped(int)), this, SLOT(collapse(int)));
QGroupBox *groupBox = new QGroupBox();
QGridLayout *layout = new QGridLayout();
for (char i = 0; i < 9; i++)
{
m_states[i] = new QPushButton(QString::number(i + 1), this);
m_states[i]->setGeometry(i % 3 * w, i / 3 * h, w, h);
m_states[i]->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
layout->addWidget(m_states[i],i%3,i/3);
m_states[i]->setStyleSheet("border:none");
connect(m_states[i], SIGNAL(clicked()), mapper, SLOT(map()));
mapper->setMapping(m_states[i], i);
m_blocked[i] = 0;
}
groupBox->setLayout(layout);
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()));
m_stackedWidget = new QStackedWidget(this);
m_stackedWidget->addWidget(groupBox);
m_stackedWidget->addWidget(m_number);
m_stackedWidget->setSizePolicy(QSizePolicy::MinimumExpanding,QSizePolicy::MinimumExpanding);
heightForWidth(this->width());
setMinimumSize(100,100);
//m_stackedWidget->setFixedSize(70,70);
}
void Cell::collapse(int x)
{
collapsed = true;
m_number->show();
m_stackedWidget->setCurrentIndex(1);
m_number->setText(QString::number(x + 1));
emit(update(x));
}
......@@ -63,6 +69,6 @@ void Cell::addOption(int x)
}
void Cell::un(void){
collapsed = false;
m_number->hide();
m_stackedWidget->setCurrentIndex(0);
emit(undo(m_number->text().toInt()-1));
}
\ No newline at end of file
......@@ -2,6 +2,7 @@
#define CELL_H
#include <QWidget>
#include <QStackedWidget>
class QPushButton;
class Cell : public QWidget
......@@ -17,6 +18,7 @@ private:
QPushButton *m_states[9];
QPushButton *m_number;
std::array<int,9> m_blocked;
QStackedWidget *m_stackedWidget;
signals:
void update(int x);
......
......@@ -5,43 +5,45 @@
#include <QThread>
#include <QProgressBar>
#include <QSlider>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QSpacerItem>
Window::Window(QWidget *parent)
: QWidget{parent}
{
setFixedWidth(1600);
m_solveButton = new QPushButton("solve", this);
m_solveButton->setGeometry(1100, height() - 100, width() - 1200, 30);
connect(m_solveButton, SIGNAL(clicked()), this, SLOT(solveButtonClicked()));
m_clearButton = new QPushButton("Clear", this);
m_clearButton->setGeometry(1100, height() - 30, width() - 1200, 30);
connect(m_clearButton, SIGNAL(clicked()), this, SLOT(clearButtonClicked()));
m_slider = new QSlider(this);
m_slider->setRange(0, 1000);
m_slider->setOrientation(Qt::Horizontal);
m_slider->setValue(m_delay);
m_slider->setGeometry(1100, height() - 60, width() - 1200, 30);
connect(m_slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)));
QHBoxLayout *horizontalLayout = new QHBoxLayout(this);
QVBoxLayout *verticalLayout = new QVBoxLayout();
QGridLayout *layout = new QGridLayout();
verticalLayout->addWidget(m_solveButton);
verticalLayout->addWidget(m_slider);
verticalLayout->addWidget(m_clearButton);
horizontalLayout->addLayout(layout,5);
horizontalLayout->addLayout(verticalLayout,1);
int dx = 0;
int dy = 0;
for (int x = 0; x < 9; x++)
{
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].setGeometry(x * 100 + dx, y * 100 + dy, 100, 100);
layout->addWidget(&m_cell[x+y*9],y,x);
//connecting signals & slots
for (int d = 0; d < 9; d++) // rows and columns
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment