Gestion du "Clean State" dans l'editeur

Correction d'un bug avec les polygones.
Amelioration du mode lecture seule.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@107 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavierqet
2007-08-25 15:46:09 +00:00
parent 1dd23c8af8
commit 853827f25c
5 changed files with 47 additions and 12 deletions

View File

@@ -23,6 +23,7 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
element_editor(editor)
{
current_polygon = NULL;
undo_stack.setClean();
connect(this, SIGNAL(changed(const QList<QRectF> &)), this, SLOT(slot_checkSelectionChanged()));
}

View File

@@ -28,9 +28,7 @@ PolygonEditor::PolygonEditor(QETElementEditor *editor, PartPolygon *p, QWidget *
layout -> addWidget(&points_list);
layout -> addWidget(&close_polygon);
// connexions signaux/slots
connect(&close_polygon, SIGNAL(stateChanged(int)), this, SLOT(updatePolygonClosedState()));
connect(&points_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(validColumn(QTreeWidgetItem *, int)));
updateForm();
}
void PolygonEditor::updatePolygon() {
@@ -64,6 +62,7 @@ void PolygonEditor::updatePolygonClosedState() {
}
void PolygonEditor::updateForm() {
activeConnections(false);
while(points_list.takeTopLevelItem(0));
foreach(QPointF point, part -> polygon()) {
point = part -> mapToScene(point);
@@ -74,6 +73,7 @@ void PolygonEditor::updateForm() {
points_list.addTopLevelItem(qtwi);
}
close_polygon.setChecked(part -> isClosed());
activeConnections(true);
}
QVector<QPointF> PolygonEditor::getPointsFromTree() {
@@ -97,3 +97,13 @@ void PolygonEditor::validColumn(QTreeWidgetItem *qtwi, int column) {
updatePolygonPoints();
} else points_list.openPersistentEditor(qtwi, column);
}
void PolygonEditor::activeConnections(bool active) {
if (active) {
connect(&close_polygon, SIGNAL(stateChanged(int)), this, SLOT(updatePolygonClosedState()));
connect(&points_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(validColumn(QTreeWidgetItem *, int)));
} else {
disconnect(&close_polygon, SIGNAL(stateChanged(int)), this, SLOT(updatePolygonClosedState()));
disconnect(&points_list, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(validColumn(QTreeWidgetItem *, int)));
}
}

View File

@@ -31,5 +31,8 @@ class PolygonEditor : public ElementItemEditor {
void updatePolygonClosedState();
void updateForm();
void validColumn(QTreeWidgetItem *qtwi, int column);
private:
void activeConnections(bool);
};
#endif

View File

@@ -132,6 +132,8 @@ void QETElementEditor::setupActions() {
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateInformations()));
connect(ce_scene, SIGNAL(selectionChanged()), this, SLOT(slot_updateMenus()));
connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateMenus()));
connect(&(ce_scene -> undoStack()), SIGNAL(cleanChanged(bool)), this, SLOT(slot_updateTitle()));
}
void QETElementEditor::setupMenus() {
@@ -178,6 +180,17 @@ void QETElementEditor::setupMenus() {
void QETElementEditor::slot_updateMenus() {
edit_delete -> setEnabled(!ce_scene -> selectedItems().isEmpty());
save -> setEnabled(!ce_scene -> undoStack().isClean());
}
void QETElementEditor::slot_updateTitle() {
QString title = min_title;
title += " - " + ce_scene -> names().name() + " ";
if (_filename != QString()) {
if (!ce_scene -> undoStack().isClean()) title += tr("[Modifi\351]");
if (isReadOnly()) title += tr(" [lecture seule]");
}
setWindowTitle(title);
}
void QETElementEditor::setupInterface() {
@@ -319,12 +332,7 @@ void QETElementEditor::fromFile(const QString &filepath) {
}
// memorise le fichier
_filename = filepath;
// modifie le titre de la fenetre
QString new_title = min_title + " - " + ce_scene -> names().name();
if (isReadOnly()) new_title += tr(" [lecture seule]");
setWindowTitle(new_title);
setFileName(filepath);
}
bool QETElementEditor::toFile(const QString &fn) {
@@ -353,6 +361,12 @@ void QETElementEditor::setReadOnly(bool ro) {
ce_view -> setInteractive(!ro);
// active / desactive l'edition de la taille, du hotspot, des noms et des orientations
selectall -> setEnabled(!ro);
deselectall -> setEnabled(!ro);
inv_select -> setEnabled(!ro);
undo -> setEnabled(!ro);
redo -> setEnabled(!ro);
edit_delete -> setEnabled(!ro);
edit_size_hs -> setEnabled(!ro);
edit_names -> setEnabled(!ro);
edit_ori -> setEnabled(!ro);
@@ -388,7 +402,9 @@ bool QETElementEditor::slot_save() {
// si on ne connait pas le nom du fichier en cours, enregistrer revient a enregistrer sous
if (_filename == QString()) return(slot_saveAs());
// sinon on enregistre dans le nom de fichier connu
return(toFile(_filename));
bool result_save = toFile(_filename);
if (result_save) ce_scene -> undoStack().setClean();
return(result_save);
}
bool QETElementEditor::slot_saveAs() {
@@ -406,7 +422,10 @@ bool QETElementEditor::slot_saveAs() {
// tente d'enregistrer le fichier
bool result_save = toFile(fn);
// si l'enregistrement reussit, le nom du fichier est conserve
if (result_save) setFileName(fn);
if (result_save) {
setFileName(fn);
ce_scene -> undoStack().setClean();
}
// retourne un booleen representatif de la reussite de l'enregistrement
return(result_save);
}
@@ -419,6 +438,7 @@ void QETElementEditor::slot_quit(QCloseEvent *event) {
}
bool QETElementEditor::close() {
if (ce_scene -> undoStack().isClean()) return(true);
// demande d'abord a l'utilisateur s'il veut enregistrer l'element en cours
QMessageBox::StandardButton answer = QMessageBox::question(
this,

View File

@@ -84,6 +84,7 @@ class QETElementEditor : public QMainWindow {
void slot_setNormalMode();
void slot_updateInformations();
void slot_updateMenus();
void slot_updateTitle();
void xmlPreview();
};
@@ -122,8 +123,8 @@ inline OrientationSet QETElementEditor::orientations() const {
}
inline void QETElementEditor::setFileName(const QString &fn) {
setWindowTitle(min_title + " - " + fn);
_filename = fn;
slot_updateTitle();
}
inline QString QETElementEditor::fileName() const {