mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-19 06:20:53 +01:00
Amelioration de l'interface Fichier > Exporter (Oui, encore)
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@50 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -89,7 +89,7 @@ void BorderInset::draw(QPainter *qp, qreal x, qreal y) {
|
||||
qp -> drawText(inset_author, Qt::AlignVCenter | Qt::AlignLeft, tr(" Auteur : ") + bi_author);
|
||||
|
||||
qp -> drawRect(inset_date);
|
||||
qp -> drawText(inset_date, Qt::AlignVCenter | Qt::AlignLeft, tr(" Date : ") + bi_date.toString());
|
||||
qp -> drawText(inset_date, Qt::AlignVCenter | Qt::AlignLeft, tr(" Date : ") + bi_date.toString("dd/MM/yyyy"));
|
||||
|
||||
qp -> drawRect(inset_title);
|
||||
qp -> drawText(inset_title, Qt::AlignVCenter | Qt::AlignCenter, tr("Titre du document: ") + bi_title);
|
||||
@@ -99,8 +99,10 @@ void BorderInset::draw(QPainter *qp, qreal x, qreal y) {
|
||||
|
||||
qp -> drawRect(inset_folio);
|
||||
qp -> drawText(inset_folio, Qt::AlignVCenter | Qt::AlignLeft, tr(" Folio : ") + bi_folio);
|
||||
qp -> restore();
|
||||
}
|
||||
|
||||
qp -> restore();
|
||||
|
||||
// annule la translation des rectangles
|
||||
border .translate(-x, -y);
|
||||
inset .translate(-x, -y);
|
||||
|
||||
277
exportdialog.cpp
277
exportdialog.cpp
@@ -14,58 +14,49 @@ ExportDialog::ExportDialog(Diagram *dia, QWidget *parent) : QDialog(parent) {
|
||||
dontchangewidth = dontchangeheight = false;
|
||||
|
||||
// la taille du dialogue est fixee
|
||||
setFixedSize(400, 310);
|
||||
setFixedSize(800, 360);
|
||||
setWindowTitle(tr("Exporter"));
|
||||
|
||||
// le dialogue est un empilement vertical d'elements
|
||||
QVBoxLayout *vboxLayout = new QVBoxLayout(this);
|
||||
|
||||
/* le dialogue comprend une ligne permettant d'indiquer un chemin de fichier (hboxLayout) */
|
||||
QHBoxLayout *hboxLayout = new QHBoxLayout();
|
||||
hboxLayout -> addWidget(new QLabel(tr("Nom de fichier :"), this));
|
||||
hboxLayout -> addWidget(filename = new QLineEdit(this));
|
||||
hboxLayout -> addWidget(button_browse = new QPushButton(tr("Parcourir"), this));
|
||||
|
||||
vboxLayout -> addLayout(hboxLayout);
|
||||
|
||||
/* une ligne permettant de choisir le format (hboxLayout1) */
|
||||
QHBoxLayout *hboxLayout1 = new QHBoxLayout();
|
||||
hboxLayout1 -> addWidget(new QLabel(tr("Format :"), this));
|
||||
hboxLayout1 -> addWidget(format = new QComboBox(this));
|
||||
format -> addItem(tr("PNG (*.png)"), "PNG");
|
||||
format -> addItem(tr("JPEG (*.jpg)"), "JPG");
|
||||
format -> addItem(tr("Bitmap (*.bmp)"), "BMP");
|
||||
|
||||
vboxLayout -> addLayout(hboxLayout1);
|
||||
|
||||
/* un cadre permettant de specifier les dimensions de l'image finale */
|
||||
vboxLayout -> addWidget(setupDimensionsGroupBox());
|
||||
|
||||
/* un cadre permettant de specifier les options de l'image finale */
|
||||
vboxLayout -> addWidget(setupOptionsGroupBox());
|
||||
|
||||
/* et deux boutons */
|
||||
// le dialogue comporte deux boutons
|
||||
buttons = new QDialogButtonBox(this);
|
||||
buttons -> setOrientation(Qt::Horizontal);
|
||||
buttons -> setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::NoButton|QDialogButtonBox::Save);
|
||||
|
||||
vboxLayout -> addWidget(buttons);
|
||||
|
||||
// ordre des input selectionnes avec la touche tab
|
||||
setTabOrder(filename, button_browse);
|
||||
setTabOrder(button_browse, format);
|
||||
setTabOrder(format, width);
|
||||
setTabOrder(width, height);
|
||||
setTabOrder(height, keep_aspect_ratio);
|
||||
setTabOrder(keep_aspect_ratio, buttons);
|
||||
|
||||
// disposition des elements
|
||||
QGridLayout *layout = new QGridLayout(this);
|
||||
setContentsMargins(0, 0, 5, 5);
|
||||
layout -> setMargin(0);
|
||||
layout -> setSpacing(0);
|
||||
layout -> setColumnMinimumWidth(0, 390);
|
||||
layout -> setColumnMinimumWidth(1, 400);
|
||||
layout -> addWidget(leftPart(), 0, 0);
|
||||
layout -> addWidget(rightPart(), 0, 1);
|
||||
layout -> addWidget(buttons, 1, 1);
|
||||
|
||||
// connexions signaux/slots
|
||||
connect(button_browse, SIGNAL(released()), this, SLOT(slot_chooseAFile()));
|
||||
connect(width, SIGNAL(valueChanged(int)), this, SLOT(slot_correctHeight()));
|
||||
connect(keep_aspect_ratio, SIGNAL(stateChanged(int)), this, SLOT(slot_correctHeight()));
|
||||
connect(height, SIGNAL(valueChanged(int)), this, SLOT(slot_correctWidth()));
|
||||
connect(buttons, SIGNAL(accepted()), this, SLOT(slot_check()));
|
||||
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
connect(button_browse, SIGNAL(released()), this, SLOT(slot_chooseAFile()));
|
||||
connect(width, SIGNAL(valueChanged(int)), this, SLOT(slot_correctHeight()));
|
||||
connect(keep_aspect_ratio, SIGNAL(stateChanged(int)), this, SLOT(slot_correctHeight()));
|
||||
connect(height, SIGNAL(valueChanged(int)), this, SLOT(slot_correctWidth()));
|
||||
connect(buttons, SIGNAL(accepted()), this, SLOT(slot_check()));
|
||||
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
connect(draw_grid, SIGNAL(stateChanged(int) ), this, SLOT(slot_refreshPreview()));
|
||||
connect(draw_border, SIGNAL(stateChanged(int) ), this, SLOT(slot_refreshPreview()));
|
||||
connect(draw_inset, SIGNAL(stateChanged(int) ), this, SLOT(slot_refreshPreview()));
|
||||
connect(draw_columns, SIGNAL(stateChanged(int) ), this, SLOT(slot_refreshPreview()));
|
||||
connect(keep_colors, SIGNAL(stateChanged(int) ), this, SLOT(slot_refreshPreview()));
|
||||
connect(width, SIGNAL(valueChanged(int) ), this, SLOT(slot_refreshPreview()));
|
||||
connect(height, SIGNAL(valueChanged(int) ), this, SLOT(slot_refreshPreview()));
|
||||
connect(export_border, SIGNAL(toggled (bool)), this, SLOT(slot_changeUseBorder()));
|
||||
}
|
||||
|
||||
/**
|
||||
Destructeur - ne fait rien
|
||||
*/
|
||||
ExportDialog::~ExportDialog() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,19 +104,116 @@ QGroupBox *ExportDialog::setupDimensionsGroupBox() {
|
||||
*/
|
||||
QGroupBox *ExportDialog::setupOptionsGroupBox() {
|
||||
QGroupBox *groupbox_options = new QGroupBox(tr("Options"), this);
|
||||
QHBoxLayout *optionshlayout = new QHBoxLayout(groupbox_options);
|
||||
QGridLayout *optionshlayout = new QGridLayout(groupbox_options);
|
||||
|
||||
// exporter la grille
|
||||
export_grid = new QCheckBox(tr("Exporter la grille"), groupbox_options);
|
||||
optionshlayout -> addWidget(export_grid);
|
||||
// Choix de la zone du schema a exporter
|
||||
QButtonGroup *exported_content_choices = new QButtonGroup(groupbox_options);
|
||||
export_border = new QRadioButton(tr("Exporter le cadre"), groupbox_options);
|
||||
optionshlayout -> addWidget(export_border, 0, 0);
|
||||
exported_content_choices -> addButton(export_border);
|
||||
export_elements = new QRadioButton(tr("Exporter les \351l\351ments"), groupbox_options);
|
||||
optionshlayout -> addWidget(export_elements, 0, 1);
|
||||
exported_content_choices -> addButton(export_elements);
|
||||
(diagram -> useBorder() ? export_border : export_elements) -> setChecked(true);
|
||||
|
||||
// dessiner la grille
|
||||
draw_grid = new QCheckBox(tr("Dessiner la grille"), groupbox_options);
|
||||
optionshlayout -> addWidget(draw_grid, 1, 0);
|
||||
draw_grid -> setChecked(diagram -> displayGrid());
|
||||
|
||||
// dessiner le cadre
|
||||
draw_border = new QCheckBox(tr("Dessiner le cadre"), groupbox_options);
|
||||
optionshlayout -> addWidget(draw_border, 1, 1);
|
||||
draw_border -> setChecked(diagram -> border_and_inset.borderIsDisplayed());
|
||||
|
||||
// dessiner le cartouche
|
||||
draw_inset = new QCheckBox(tr("Dessiner le cartouche"), groupbox_options);
|
||||
optionshlayout -> addWidget(draw_inset, 2, 0);
|
||||
draw_inset -> setChecked(diagram -> border_and_inset.insetIsDisplayed());
|
||||
|
||||
// dessiner les colonnes
|
||||
draw_columns = new QCheckBox(tr("Dessiner les colonnes"), groupbox_options);
|
||||
optionshlayout -> addWidget(draw_columns, 2, 1);
|
||||
draw_columns -> setChecked(diagram -> border_and_inset.columnsAreDisplayed());
|
||||
|
||||
// Conserver les couleurs
|
||||
keep_colors = new QCheckBox(tr("Conserver les couleurs"), groupbox_options);
|
||||
optionshlayout -> addWidget(keep_colors);
|
||||
optionshlayout -> addWidget(keep_colors, 3, 0);
|
||||
|
||||
return(groupbox_options);
|
||||
}
|
||||
|
||||
/**
|
||||
Met en place la partie gauche du dialogue
|
||||
@return Le widget representant la moitie gauche du dialogue
|
||||
*/
|
||||
QWidget *ExportDialog::leftPart() {
|
||||
QWidget *retour = new QWidget();
|
||||
|
||||
// la partie gauche du dialogue est un empilement vertical d'elements
|
||||
QVBoxLayout *vboxLayout = new QVBoxLayout(retour);
|
||||
|
||||
/* le dialogue comprend une ligne permettant d'indiquer un chemin de fichier (hboxLayout) */
|
||||
QHBoxLayout *hboxLayout = new QHBoxLayout();
|
||||
hboxLayout -> addWidget(new QLabel(tr("Nom de fichier :"), this));
|
||||
hboxLayout -> addWidget(filename = new QLineEdit(this));
|
||||
hboxLayout -> addWidget(button_browse = new QPushButton(tr("Parcourir"), this));
|
||||
|
||||
vboxLayout -> addLayout(hboxLayout);
|
||||
|
||||
/* une ligne permettant de choisir le format (hboxLayout1) */
|
||||
QHBoxLayout *hboxLayout1 = new QHBoxLayout();
|
||||
hboxLayout1 -> addWidget(new QLabel(tr("Format :"), this));
|
||||
hboxLayout1 -> addWidget(format = new QComboBox(this));
|
||||
format -> addItem(tr("PNG (*.png)"), "PNG");
|
||||
format -> addItem(tr("JPEG (*.jpg)"), "JPG");
|
||||
format -> addItem(tr("Bitmap (*.bmp)"), "BMP");
|
||||
|
||||
vboxLayout -> addLayout(hboxLayout1);
|
||||
|
||||
/* un cadre permettant de specifier les dimensions de l'image finale */
|
||||
vboxLayout -> addWidget(setupDimensionsGroupBox());
|
||||
|
||||
/* un cadre permettant de specifier les options de l'image finale */
|
||||
vboxLayout -> addWidget(setupOptionsGroupBox());
|
||||
|
||||
// ordre des input selectionnes avec la touche tab
|
||||
setTabOrder(filename, button_browse);
|
||||
setTabOrder(button_browse, format);
|
||||
setTabOrder(format, width);
|
||||
setTabOrder(width, height);
|
||||
setTabOrder(height, keep_aspect_ratio);
|
||||
|
||||
return(retour);
|
||||
}
|
||||
|
||||
/**
|
||||
Met en place la partie droite du dialogue
|
||||
@return Le widget representant la moitie droite du dialogue
|
||||
*/
|
||||
QWidget *ExportDialog::rightPart() {
|
||||
QWidget *retour = new QWidget();
|
||||
QHBoxLayout *hboxlayout0 = new QHBoxLayout(retour);
|
||||
|
||||
|
||||
// la partie droite contient une GroupBox intitulee "Apercu"
|
||||
QGroupBox *groupbox_preview = new QGroupBox(tr("Aper\347u"), this);
|
||||
groupbox_preview -> setFixedWidth(390);
|
||||
QHBoxLayout *hboxlayout1 = new QHBoxLayout(groupbox_preview);
|
||||
hboxlayout1 -> setMargin(0);
|
||||
|
||||
// cette GroupBox contient l'apercu
|
||||
preview_scene = new QGraphicsScene();
|
||||
preview_view = new QGraphicsView(preview_scene, groupbox_preview);
|
||||
hboxlayout1 -> addWidget(preview_view);
|
||||
|
||||
// genere le premier apercu
|
||||
slot_refreshPreview();
|
||||
|
||||
hboxlayout0 -> addWidget(groupbox_preview);
|
||||
return(retour);
|
||||
}
|
||||
|
||||
void ExportDialog::slot_correctWidth() {
|
||||
if (!keep_aspect_ratio -> isChecked() || dontchangewidth) return;
|
||||
dontchangeheight = true;
|
||||
@@ -153,6 +241,43 @@ void ExportDialog::slot_chooseAFile() {
|
||||
}
|
||||
}
|
||||
|
||||
QImage ExportDialog::generateImage() {
|
||||
// memorise les parametres relatifs au schema
|
||||
bool state_drawBorder = diagram -> border_and_inset.borderIsDisplayed();
|
||||
bool state_drawColumns = diagram -> border_and_inset.columnsAreDisplayed();
|
||||
bool state_drawInset = diagram -> border_and_inset.insetIsDisplayed();
|
||||
bool state_drawGrid = diagram -> displayGrid();
|
||||
bool state_useBorder = diagram -> useBorder();
|
||||
|
||||
// genere l'image
|
||||
diagram -> setUseBorder(export_border -> isChecked());
|
||||
diagram -> setAffichageGrille(draw_grid -> isChecked());
|
||||
diagram -> border_and_inset.displayBorder(draw_border -> isChecked());
|
||||
diagram -> border_and_inset.displayColumns(draw_columns -> isChecked());
|
||||
diagram -> border_and_inset.displayInset(draw_inset -> isChecked());
|
||||
QImage image = diagram -> toImage(
|
||||
width -> value(),
|
||||
height -> value(),
|
||||
keep_aspect_ratio -> isChecked() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio
|
||||
);
|
||||
|
||||
// convertit l'image en niveaux de gris si besoin
|
||||
if (!keep_colors -> isChecked()) {
|
||||
QVector<QRgb> ColorTab;
|
||||
for (int i = 0 ; i < 256 ; ++ i) ColorTab << qRgb(i, i, i);
|
||||
image = image.convertToFormat(QImage::Format_Indexed8, ColorTab, Qt::ThresholdDither);
|
||||
}
|
||||
|
||||
// restaure les parametres relatifs au schema
|
||||
diagram -> border_and_inset.displayBorder(state_drawBorder);
|
||||
diagram -> border_and_inset.displayColumns(state_drawColumns);
|
||||
diagram -> border_and_inset.displayInset(state_drawInset);
|
||||
diagram -> setAffichageGrille(state_drawGrid);
|
||||
diagram -> setUseBorder(state_useBorder);
|
||||
|
||||
return(image);
|
||||
}
|
||||
|
||||
void ExportDialog::slot_check() {
|
||||
|
||||
// verifie que le fichier a ete specifie
|
||||
@@ -190,21 +315,7 @@ void ExportDialog::slot_check() {
|
||||
// ouvre le fichier
|
||||
QFile fichier(diagram_path);
|
||||
|
||||
// genere l'image
|
||||
if (!export_grid -> isChecked()) diagram -> setAffichageGrille(false);
|
||||
QImage image = diagram -> toImage(
|
||||
width -> value(),
|
||||
height -> value(),
|
||||
keep_aspect_ratio -> isChecked() ? Qt::KeepAspectRatio : Qt::IgnoreAspectRatio
|
||||
);
|
||||
if (!export_grid -> isChecked()) diagram -> setAffichageGrille(true);
|
||||
|
||||
// convertit l'image en niveaux de gris si besoin
|
||||
if (!keep_colors -> isChecked()) {
|
||||
QVector<QRgb> ColorTab;
|
||||
for (int i = 0 ; i < 256 ; ++ i) ColorTab << qRgb(i, i, i);
|
||||
image = image.convertToFormat(QImage::Format_Indexed8, ColorTab, Qt::ThresholdDither);
|
||||
}
|
||||
QImage image = generateImage();
|
||||
|
||||
// enregistre l'image dans le fichier
|
||||
image.save(&fichier, format_acronym.toUtf8().data());
|
||||
@@ -214,3 +325,41 @@ void ExportDialog::slot_check() {
|
||||
accept();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
Slot appele lorsque l'utilisateur change la zone du schema qui doit etre
|
||||
exportee. Il faut alors calculer le nouveau ratio et corriger les
|
||||
dimensions.
|
||||
*/
|
||||
void ExportDialog::slot_changeUseBorder() {
|
||||
// calcule le nouveau ratio
|
||||
bool state_useBorder = diagram -> useBorder();
|
||||
diagram -> setUseBorder(export_border -> isChecked());
|
||||
diagram_size = diagram -> imageSize();
|
||||
diagram_ratio = (qreal)diagram_size.width() / (qreal)diagram_size.height();
|
||||
diagram -> setUseBorder(state_useBorder);
|
||||
|
||||
// corrige les dimensions
|
||||
if (keep_aspect_ratio -> isChecked()) slot_correctHeight();
|
||||
|
||||
// rafraichit l'apercu
|
||||
slot_refreshPreview();
|
||||
}
|
||||
|
||||
void ExportDialog::slot_refreshPreview() {
|
||||
|
||||
// genere le nouvel apercu
|
||||
QImage preview_image = generateImage();
|
||||
|
||||
// nettoie l'apercu
|
||||
foreach (QGraphicsItem *qgi, preview_scene -> items()) {
|
||||
preview_scene -> removeItem(qgi);
|
||||
delete qgi;
|
||||
}
|
||||
|
||||
// ajoute le nouvel apercu
|
||||
QGraphicsPixmapItem *qgpi = new QGraphicsPixmapItem(QPixmap::fromImage(preview_image));
|
||||
preview_scene -> addItem(qgpi);
|
||||
preview_scene -> setSceneRect(QRectF(0.0, 0.0, preview_image.width() + 15.0, preview_image.height() + 15.0));
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
Q_OBJECT
|
||||
public:
|
||||
ExportDialog(Diagram *, QWidget * = 0);
|
||||
~ExportDialog();
|
||||
|
||||
private:
|
||||
// elements graphiques
|
||||
@@ -19,9 +20,16 @@
|
||||
QSpinBox *width;
|
||||
QSpinBox *height;
|
||||
QCheckBox *keep_aspect_ratio;
|
||||
QCheckBox *export_grid;
|
||||
QCheckBox *draw_grid;
|
||||
QCheckBox *draw_border;
|
||||
QCheckBox *draw_inset;
|
||||
QCheckBox *draw_columns;
|
||||
QCheckBox *keep_colors;
|
||||
QRadioButton *export_elements;
|
||||
QRadioButton *export_border;
|
||||
QDialogButtonBox *buttons;
|
||||
QGraphicsScene *preview_scene;
|
||||
QGraphicsView *preview_view;
|
||||
|
||||
// booleens pour ne pas avoir de boucle lors de l'edition des dimensions de l'image
|
||||
bool dontchangewidth;
|
||||
@@ -33,13 +41,18 @@
|
||||
QString diagram_path;
|
||||
qreal diagram_ratio;
|
||||
|
||||
QWidget *leftPart();
|
||||
QWidget *rightPart();
|
||||
QGroupBox *setupDimensionsGroupBox();
|
||||
QGroupBox *setupOptionsGroupBox();
|
||||
QImage generateImage();
|
||||
|
||||
public slots:
|
||||
void slot_correctWidth();
|
||||
void slot_correctHeight();
|
||||
void slot_chooseAFile();
|
||||
void slot_check();
|
||||
void slot_changeUseBorder();
|
||||
void slot_refreshPreview();
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -10,29 +10,30 @@ INCLUDEPATH += .
|
||||
# Input
|
||||
HEADERS += aboutqet.h \
|
||||
borderinset.h \
|
||||
terminal.h \
|
||||
conducer.h \
|
||||
element.h \
|
||||
fixedelement.h \
|
||||
customelement.h \
|
||||
exportdialog.h \
|
||||
elementspanel.h \
|
||||
qetapp.h \
|
||||
diagram.h \
|
||||
diagramview.h
|
||||
diagramview.h \
|
||||
element.h \
|
||||
elementspanel.h \
|
||||
exportdialog.h \
|
||||
fixedelement.h \
|
||||
qetapp.h \
|
||||
terminal.h \
|
||||
divers/export_fichier.h
|
||||
SOURCES += aboutqet.cpp \
|
||||
borderinset.cpp \
|
||||
terminal.cpp \
|
||||
conducer.cpp \
|
||||
element.cpp \
|
||||
fixedelement.cpp \
|
||||
customelement.cpp \
|
||||
exportdialog.cpp \
|
||||
main.cpp \
|
||||
elementspanel.cpp \
|
||||
qetapp.cpp \
|
||||
diagram.cpp \
|
||||
diagramview.cpp
|
||||
diagramview.cpp \
|
||||
element.cpp \
|
||||
elementspanel.cpp \
|
||||
exportdialog.cpp \
|
||||
fixedelement.cpp \
|
||||
main.cpp \
|
||||
qetapp.cpp \
|
||||
terminal.cpp
|
||||
RESOURCES += qelectrotech.qrc
|
||||
TRANSLATIONS += lang/qet_en.ts lang/qt_fr.ts
|
||||
QT += xml
|
||||
|
||||
Reference in New Issue
Block a user