diff --git a/sources/titleblock/qettemplateeditor.cpp b/sources/titleblock/qettemplateeditor.cpp index 6c11bc6ce..9daebae47 100644 --- a/sources/titleblock/qettemplateeditor.cpp +++ b/sources/titleblock/qettemplateeditor.cpp @@ -377,6 +377,8 @@ void QETTitleBlockTemplateEditor::initMenus() { Initialize layouts and widgets */ void QETTitleBlockTemplateEditor::initWidgets() { + QSettings &settings = QETApp::settings(); + // undo list on the right undo_stack_ = new QUndoStack(this); undo_view_ = new QUndoView(undo_stack_); @@ -390,7 +392,12 @@ void QETTitleBlockTemplateEditor::initWidgets() { // WYSIWYG editor as central widget template_edition_area_scene_ = new QGraphicsScene(this); - template_edition_area_view_ = new TitleBlockTemplateView(template_edition_area_scene_); + template_edition_area_view_ = new TitleBlockTemplateView(template_edition_area_scene_); + bool conv_ok; + int conf_preview_width = settings.value("titleblocktemplateeditor/preview_width", -1).toInt(&conv_ok); + if (conv_ok && conf_preview_width != -1) { + template_edition_area_view_ -> setPreviewWidth(conf_preview_width); + } setCentralWidget(template_edition_area_view_); // cell edition widget at the bottom @@ -422,6 +429,12 @@ void QETTitleBlockTemplateEditor::initWidgets() { this, SLOT(pushGridUndoCommand(TitleBlockTemplateCommand *)) ); + connect( + template_edition_area_view_, + SIGNAL(previewWidthChanged(int,int)), + this, + SLOT(savePreviewWidthToApplicationSettings(int, int)) + ); connect(undo_stack_, SIGNAL(cleanChanged(bool)), this, SLOT(updateEditorTitle())); } @@ -753,3 +766,13 @@ TitleBlockTemplateLocation QETTitleBlockTemplateEditor::getTitleBlockTemplateLoc void QETTitleBlockTemplateEditor::quit() { close(); } + +/** + Save the new preview width to application settings + @param former_preview_width Unused, former preview width + @param new_preview_width New preview width +*/ +void QETTitleBlockTemplateEditor::savePreviewWidthToApplicationSettings(int former_preview_width, int new_preview_width) { + Q_UNUSED(former_preview_width) + QETApp::settings().setValue("titleblocktemplateeditor/preview_width", new_preview_width); +} diff --git a/sources/titleblock/qettemplateeditor.h b/sources/titleblock/qettemplateeditor.h index 3f7fc4dcf..6d20d550f 100644 --- a/sources/titleblock/qettemplateeditor.h +++ b/sources/titleblock/qettemplateeditor.h @@ -116,6 +116,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow { bool saveAsFile(); void setReadOnly(bool); void quit(); + void savePreviewWidthToApplicationSettings(int, int); private slots: TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser(const QString & = QString(), bool existing_only = true); diff --git a/sources/titleblock/templateview.cpp b/sources/titleblock/templateview.cpp index 3d347cad2..efdacf6e3 100644 --- a/sources/titleblock/templateview.cpp +++ b/sources/titleblock/templateview.cpp @@ -23,7 +23,6 @@ #include "templatecommands.h" #include "templatecellsset.h" #include "dimensionwidget.h" -#include "qetapp.h" #include "qeticons.h" #define ROW_OFFSET 2 #define COL_OFFSET 1 @@ -758,12 +757,15 @@ void TitleBlockTemplateView::setReadOnly(bool read_only) { */ void TitleBlockTemplateView::setPreviewWidth(int width) { if (preview_width_ == width) return; + int former_preview_width = preview_width_; preview_width_ = width; - applyColumnsWidths(); - updateTotalWidthLabel(); - //adjustSceneRect(); - centerOn(form_); - /// TODO center again the preview() + if (tbgrid_) { + applyColumnsWidths(); + updateTotalWidthLabel(); + //adjustSceneRect(); + centerOn(form_); + } + emit(previewWidthChanged(former_preview_width, preview_width_)); } /** diff --git a/sources/titleblock/templateview.h b/sources/titleblock/templateview.h index 2e6e593b3..cf99aac9a 100644 --- a/sources/titleblock/templateview.h +++ b/sources/titleblock/templateview.h @@ -69,6 +69,7 @@ class TitleBlockTemplateView : public QGraphicsView { void splitSelectedCell(); void refresh(); void changePreviewWidth(); + void setPreviewWidth(int); void updateLayout(); void rowsDimensionsChanged(); void columnsDimensionsChanged(); @@ -93,11 +94,11 @@ class TitleBlockTemplateView : public QGraphicsView { signals: void selectedCellsChanged(QList); void gridModificationRequested(TitleBlockTemplateCommand *); + void previewWidthChanged(int, int); private: QList rowsActions() const; QList columnsActions() const; - void setPreviewWidth(int); void updateTotalWidthLabel(); void requestGridModification(TitleBlockTemplateCommand *); int lastContextMenuCellIndex() const;