//Dessin.h
#ifndef DESSIN_H
#define DESSIN_H
#include <QtGui>
#include "FenPrincipale.h"
{
public:
Dessin ( FenPrincipale* parent);
private:
FenPrincipale * ref;
protected:
};
#endif
//FenCC.h
#ifndef FENCC_H
#define FENCC_H
#include <QtGui>
{
public:
private:
private slots:
};
#endif
//FenDessin.h
#ifndef FENDESSIN_H
//FenDessin.h
#define FENDESSIN_H
#include "FenPrincipale.h"
#include "FenCC.h"
#include "Dessin.h"
{
public:
FenDessin ( FenPrincipale* parent);
private:
FenPrincipale *ref;
Dessin *dessin;
FenPrincipale *fenetre1;
FenCC *fenetre3;
private slots:
void CC ();
};
#endif // FENDESSIN_H
//FenPrinicipale.h
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
class FenPrincipale
: public QWidget{
Q_OBJECT
public:
FenPrincipale();
bool M[10][10];
private slots:
void FillIn();
void FenetreDessin();
private:
};
#endif // FENPRINCIPALE_H
//Dessin.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
Dessin
::Dessin( FenPrincipale
*parent
) :QWidget(parent
),ref
(parent
)//doit avoir fenprincipale comme parent{
setFixedSize(900,900);
paintEvent(c);
}
{
int tour=0;
int x=10;
int y=10;
int Num_Sommet=0;
int T_Coordonnees [10][3];
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
(T_Coordonnees[Num_Sommet][0])=x;
(T_Coordonnees[Num_Sommet][1])=y;
(T_Coordonnees[Num_Sommet][2])=tour;
if (tour==0)
{
x+=35;
tour=1;
}
else
{
y+=55;
tour=0;
}
}
int w1=0;
int w2=0;
int cpt=10;
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
if ( (T_Coordonnees[Num_Sommet][2])==1)
{ if(w1==0)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;
w1=1;
}
else
{
if(w1==1)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;
w1=0;
cpt=cpt+15;
}
}
if (Num_Sommet==9)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}
}
else
{
if(w2==0)
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;
w2=1;
}
else
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;
w2=0;
cpt=cpt+15;
}
if (Num_Sommet==4)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}
}
painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);
}
int i,j;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j])==1)
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
}
}
}
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j]==1) && (ref->M[j][i]==1))
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )
{
painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));
}
else
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));
}
}
}
}
////////////////////////////////////////////////
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
QPoint point
= QPoint( (((T_Coordonnees
[Num_Sommet
][0])+15)),
((T_Coordonnees
[Num_Sommet
][1])+15) );
str.setNum(Num_Sommet);
painter.drawText( point,str);
}
}
//FenCC.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
{
connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));
}
//FenDessin.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
FenDessin
::FenDessin( FenPrincipale
*parent
) :QWidget(parent
),ref
(parent
){
dessin = new Dessin((fenetre1));
vBoxLayout->addWidget(dessin);
vBoxLayout->addWidget(Composante);
setLayout(vBoxLayout);
connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));
}
void FenDessin::CC()
{
fenetre3 = new FenCC (this);
fenetre3->show();
}
//FenPrincipale.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
FenPrincipale::FenPrincipale()
{
tabM->setRowCount(10);
tabM->setColumnCount(10);
vbox->addWidget(generer);
vbox->addWidget(dessiner);
vbox->addWidget(tabM);
this->setLayout(vbox);
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; c++) {
tabM->setItem(r, c, it);
it->setData(Qt::EditRole, 0);
}
}
connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
}
void FenPrincipale::FillIn()
{
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; c++) {
Q_ASSERT(it);
qDebug() <<it;
int val = (it->data(Qt::EditRole)).toInt();
M[r][c] = (val == 1)? true: false;
// qDebug() <<M[r][c];
}
}
connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));
}
void FenPrincipale::FenetreDessin()
{
FenDessin *fenetre2 = new FenDessin(this);
fenetre2->setFixedSize(950,900);
fenetre2->show();
}
//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
FenPrincipale fenetre1;
fenetre1.show();
return app.exec();
}
//Dessin.h
#ifndef DESSIN_H
#define DESSIN_H
#include <QtGui>
#include "FenPrincipale.h"
class Dessin : public QWidget
{
public:
Dessin ( FenPrincipale* parent);
private:
QPainter *painter;
FenPrincipale * ref;
protected:
void paintEvent(QPaintEvent *event);
};
#endif
//FenCC.h
#ifndef FENCC_H
#define FENCC_H
#include <QtGui>
class FenCC : public QDialog
{
public:
FenCC(QWidget *parent = 0);
private:
QPushButton *fermer;
private slots:
};
#endif
//FenDessin.h
#ifndef FENDESSIN_H
//FenDessin.h
#define FENDESSIN_H
#include "FenPrincipale.h"
#include "FenCC.h"
#include "Dessin.h"
class FenDessin : public QWidget
{
public:
FenDessin ( FenPrincipale* parent);
private:
QPushButton *Composante;
FenPrincipale *ref;
Dessin *dessin;
FenPrincipale *fenetre1;
FenCC *fenetre3;
private slots:
void CC ();
};
#endif // FENDESSIN_H
//FenPrinicipale.h
#ifndef FENPRINCIPALE_H
#define FENPRINCIPALE_H
#include <QtGui>
class FenPrincipale : public QWidget
{
Q_OBJECT
public:
FenPrincipale();
bool M[10][10];
private slots:
void FillIn();
void FenetreDessin();
private:
QTableWidget *tabM;
QPushButton * generer;
QPushButton * dessiner;
QVBoxLayout * vbox;
};
#endif // FENPRINCIPALE_H
//Dessin.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
Dessin::Dessin( FenPrincipale *parent) :QWidget(parent),ref(parent)//doit avoir fenprincipale comme parent
{
setFixedSize(900,900);
QPaintEvent *c=NULL;
paintEvent(c);
}
void Dessin::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
int tour=0;
int x=10;
int y=10;
int Num_Sommet=0;
int T_Coordonnees [10][3];
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
(T_Coordonnees[Num_Sommet][0])=x;
(T_Coordonnees[Num_Sommet][1])=y;
(T_Coordonnees[Num_Sommet][2])=tour;
if (tour==0)
{
x+=35;
tour=1;
}
else
{
y+=55;
tour=0;
}
}
int w1=0;
int w2=0;
int cpt=10;
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
if ( (T_Coordonnees[Num_Sommet][2])==1)
{ if(w1==0)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+500) ;
w1=1;
}
else
{
if(w1==1)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+250+cpt) ;
w1=0;
cpt=cpt+15;
}
}
if (Num_Sommet==9)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}
}
else
{
if(w2==0)
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+200;
w2=1;
}
else
{
(T_Coordonnees[Num_Sommet][0])=(T_Coordonnees[Num_Sommet][0])+100+cpt;
w2=0;
cpt=cpt+15;
}
if (Num_Sommet==4)
{
(T_Coordonnees[Num_Sommet][0])=((T_Coordonnees[Num_Sommet][0])+45) ;
}
}
painter.drawEllipse((T_Coordonnees[Num_Sommet][0]), (T_Coordonnees[Num_Sommet][1]), 30.0, 30.0);
}
int i,j;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j])==1)
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
}
}
}
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
if ((ref->M[i][j]==1) && (ref->M[j][i]==1))
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]));
if( (T_Coordonnees[i][1]>45)||(T_Coordonnees[j][1]>45) )
{
painter.drawLine(((T_Coordonnees[i][0]+20)-10),(T_Coordonnees[i][1]),((T_Coordonnees[j][0]+20)-10),(T_Coordonnees[j][1]));
}
else
{
painter.drawLine((T_Coordonnees[i][0]+20),(T_Coordonnees[i][1]+30),(T_Coordonnees[j][0]+20),(T_Coordonnees[j][1]+30));
}
}
}
}
////////////////////////////////////////////////
Num_Sommet=0;
for (Num_Sommet=0; Num_Sommet<10; Num_Sommet++)
{
QPoint point = QPoint( (((T_Coordonnees[Num_Sommet][0])+15)), ((T_Coordonnees[Num_Sommet][1])+15) );
QString str;
str.setNum(Num_Sommet);
painter.drawText( point,str);
}
}
//FenCC.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
FenCC::FenCC(QWidget *parent) : QDialog(parent)
{
fermer = new QPushButton("Fermer",this);
connect(fermer, SIGNAL(clicked()), this, SLOT(accept()));
}
//FenDessin.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
FenDessin::FenDessin( FenPrincipale *parent) :QWidget(parent),ref(parent)
{
Composante = new QPushButton("Composante",this);
dessin = new Dessin((fenetre1));
QVBoxLayout *vBoxLayout = new QVBoxLayout;
vBoxLayout->addWidget(dessin);
vBoxLayout->addWidget(Composante);
setLayout(vBoxLayout);
connect(Composante, SIGNAL(clicked()), this, SLOT(CC()));
}
void FenDessin::CC()
{
fenetre3 = new FenCC (this);
fenetre3->show();
}
//FenPrincipale.cpp
#include "qDebug.h"
#include "FenPrincipale.h"
#include "FenDessin.h"
#include "FenCC.h"
#include "Dessin.h"
FenPrincipale::FenPrincipale()
{
tabM =new QTableWidget(this);
tabM->setRowCount(10);
tabM->setColumnCount(10);
generer = new QPushButton("&Générer !",this);
dessiner = new QPushButton("&Dessiner !",this);
QVBoxLayout* vbox = new QVBoxLayout();
vbox->addWidget(generer);
vbox->addWidget(dessiner);
vbox->addWidget(tabM);
this->setLayout(vbox);
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; c++) {
QTableWidgetItem *it = new QTableWidgetItem;
tabM->setItem(r, c, it);
it->setData(Qt::EditRole, 0);
}
}
connect(generer, SIGNAL(clicked()), this, SLOT(FillIn()));
}
void FenPrincipale::FillIn()
{
for (int r = 0; r < 10; r++) {
for (int c = 0; c < 10; c++) {
QTableWidgetItem *it = tabM->item(r,c);;
Q_ASSERT(it);
qDebug() <<it;
int val = (it->data(Qt::EditRole)).toInt();
M[r][c] = (val == 1)? true: false;
// qDebug() <<M[r][c];
}
}
connect(dessiner, SIGNAL(clicked()), this, SLOT(FenetreDessin()));
}
void FenPrincipale::FenetreDessin()
{
FenDessin *fenetre2 = new FenDessin(this);
fenetre2->setFixedSize(950,900);
fenetre2->show();
}
//main.cpp
#include <QApplication>
#include "FenPrincipale.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
FenPrincipale fenetre1;
fenetre1.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Please help me with this .
Bookmarks