Title block templates now embed a free field for extra information.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1541 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
xavier
2012-03-02 17:55:27 +00:00
parent fac0fea239
commit 6bdd166e57
6 changed files with 160 additions and 4 deletions

View File

@@ -300,6 +300,7 @@ void QETTitleBlockTemplateEditor::initActions() {
quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "menu entry"), this);
undo_ = undo_stack_ -> createUndoAction(this);
redo_ = undo_stack_ -> createRedoAction(this);
edit_info_ = new QAction(QET::Icons::UserInformations, tr("\311diter les informations compl\351mentaires", "menu entry"), this);
zoom_in_ = new QAction(QET::Icons::ZoomIn, tr("Zoom avant", "menu entry"), this);
zoom_out_ = new QAction(QET::Icons::ZoomOut, tr("Zoom arri\350re", "menu entry"), this);
zoom_fit_ = new QAction(QET::Icons::ZoomFitBest, tr("Zoom adapt\351", "menu entry"), this);
@@ -318,6 +319,7 @@ void QETTitleBlockTemplateEditor::initActions() {
quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit")));
undo_ -> setShortcut(QKeySequence::Undo);
redo_ -> setShortcut(QKeySequence::Redo);
edit_info_ -> setShortcut(QKeySequence(tr("Ctrl+Y", "shortcut to edit extra information")));
merge_cells_ -> setShortcut(QKeySequence(tr("Ctrl+K", "shortcut to merge cells")));
split_cell_ -> setShortcut(QKeySequence(tr("Ctrl+J", "shortcut to split merged cell")));
zoom_in_ -> setShortcut(QKeySequence::ZoomIn);
@@ -336,6 +338,7 @@ void QETTitleBlockTemplateEditor::initActions() {
connect(zoom_out_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomOut()));
connect(zoom_fit_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomFit()));
connect(zoom_reset_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomReset()));
connect(edit_info_, SIGNAL(triggered()), this, SLOT(editTemplateInformation()));
connect(merge_cells_, SIGNAL(triggered()), template_edition_area_view_, SLOT(mergeSelectedCells()));
connect(split_cell_, SIGNAL(triggered()), template_edition_area_view_, SLOT(splitSelectedCell()));
}
@@ -360,9 +363,10 @@ void QETTitleBlockTemplateEditor::initMenus() {
edit_menu_ -> addAction(undo_);
edit_menu_ -> addAction(redo_);
edit_menu_ -> addSeparator();
edit_menu_ -> addAction(merge_cells_);
edit_menu_ -> addAction(split_cell_);
edit_menu_ -> addAction(edit_info_);
display_menu_ -> addAction(zoom_in_);
display_menu_ -> addAction(zoom_out_);
display_menu_ -> addAction(zoom_fit_);
@@ -776,3 +780,46 @@ void QETTitleBlockTemplateEditor::savePreviewWidthToApplicationSettings(int form
Q_UNUSED(former_preview_width)
QETApp::settings().setValue("titleblocktemplateeditor/preview_width", new_preview_width);
}
/**
Edit extra information attached to the template.
*/
void QETTitleBlockTemplateEditor::editTemplateInformation() {
if (!tb_template_) return;
QDialog dialog_author(this);
dialog_author.setModal(true);
#ifdef Q_WS_MAC
dialog_author.setWindowFlags(Qt::Sheet);
#endif
dialog_author.setMinimumSize(400, 260);
dialog_author.setWindowTitle(tr("\311diter les informations compl\351mentaires", "window title"));
QVBoxLayout *dialog_layout = new QVBoxLayout(&dialog_author);
// explanation label
QLabel *information_label = new QLabel(tr("Vous pouvez utiliser ce champ libre pour mentionner les auteurs du cartouche, sa licence, ou tout autre renseignement que vous jugerez utile."));
information_label -> setAlignment(Qt::AlignJustify | Qt::AlignVCenter);
information_label -> setWordWrap(true);
dialog_layout -> addWidget(information_label);
// add a QTextEdit to the dialog
QTextEdit *text_field = new QTextEdit();
text_field -> setAcceptRichText(false);
text_field -> setPlainText(tb_template_ -> information());
text_field -> setReadOnly(read_only_);
dialog_layout -> addWidget(text_field);
// add two buttons to the dialog
QDialogButtonBox *dialog_buttons = new QDialogButtonBox(read_only_ ? QDialogButtonBox::Ok : QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dialog_buttons);
connect(dialog_buttons, SIGNAL(accepted()), &dialog_author, SLOT(accept()));
connect(dialog_buttons, SIGNAL(rejected()), &dialog_author, SLOT(reject()));
// run the dialog
if (dialog_author.exec() == QDialog::Accepted && !read_only_) {
QString new_info = text_field -> toPlainText();
if (new_info != tb_template_ -> information()) {
pushUndoCommand(new ChangeTemplateInformationsCommand(tb_template_, tb_template_ -> information(), new_info));
}
}
}

View File

@@ -49,7 +49,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow {
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_*/;
/// actions
QAction *new_, *open_, *open_from_file_, *save_, *save_as_, *save_as_file_, *quit_;
QAction *undo_, *redo_, *merge_cells_, *split_cell_;
QAction *undo_, *redo_, *edit_info_, *merge_cells_, *split_cell_;
QAction *zoom_in_, *zoom_out_, *zoom_fit_, *zoom_reset_;
/// Location of the currently edited template
TitleBlockTemplateLocation location_;
@@ -117,6 +117,7 @@ class QETTitleBlockTemplateEditor : public QETMainWindow {
void setReadOnly(bool);
void quit();
void savePreviewWidthToApplicationSettings(int, int);
void editTemplateInformation();
private slots:
TitleBlockTemplateLocation getTitleBlockTemplateLocationFromUser(const QString & = QString(), bool existing_only = true);

View File

@@ -777,3 +777,40 @@ void SplitCellsCommand::redo() {
if (view_) view_ -> updateLayout();
}
/**
Constructor
@param tbt Changed title block template
@param old_info Former information
@param new_info New information
@param parent Parent QUndoCommand
*/
ChangeTemplateInformationsCommand::ChangeTemplateInformationsCommand(TitleBlockTemplate *tbt, const QString &old_info, const QString &new_info, QUndoCommand *parent) :
QUndoCommand(QObject::tr("modification des informations compl\351mentaires", "undo caption"), parent),
tbtemplate_(tbt),
old_information_(old_info),
new_information_(new_info)
{
}
/**
Destructor
*/
ChangeTemplateInformationsCommand::~ChangeTemplateInformationsCommand() {
}
/**
Undo the information change
*/
void ChangeTemplateInformationsCommand::undo() {
if (!tbtemplate_) return;
tbtemplate_ -> setInformation(old_information_);
}
/**
Redo the information change
*/
void ChangeTemplateInformationsCommand::redo() {
tbtemplate_ -> setInformation(new_information_);
}

View File

@@ -222,4 +222,30 @@ class SplitCellsCommand : public TitleBlockTemplateCommand {
int col_span_before_; ///< the col_span attribute of the spanning cell after the merge
};
/**
This class represents the action of changing extra information of a title
block template.
*/
class ChangeTemplateInformationsCommand : public QUndoCommand {
// constructors, destructor
public:
ChangeTemplateInformationsCommand(TitleBlockTemplate *, const QString &, const QString &, QUndoCommand * = 0);
virtual ~ChangeTemplateInformationsCommand();
private:
ChangeTemplateInformationsCommand(const ChangeTemplateInformationsCommand &);
// methods
public:
virtual void undo();
virtual void redo();
// attributes
private:
/// chnged title block template
TitleBlockTemplate *tbtemplate_;
/// Informations before they are modified
QString old_information_;
/// Informations after they were modified
QString new_information_;
};
#endif