mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Added zoom-related menus.
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1417 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
parent
c560a61610
commit
dd2801f784
@ -114,6 +114,10 @@ void QETTitleBlockTemplateEditor::initActions() {
|
||||
save_ = new QAction(QET::Icons::DocumentSave, tr("&Enregistrer", "menu entry"), this);
|
||||
save_as_ = new QAction(QET::Icons::DocumentSave, tr("Enregistrer sous", "menu entry"), this);
|
||||
quit_ = new QAction(QET::Icons::ApplicationExit, tr("&Quitter", "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);
|
||||
zoom_reset_ = new QAction(QET::Icons::ZoomOriginal, tr("Pas de zoom", "menu entry"), this);
|
||||
configure_ = new QAction(QET::Icons::Configure, tr("&Configurer QElectroTech", "menu entry"), this);
|
||||
about_qet_ = new QAction(QET::Icons::QETLogo, tr("\300 &propos de QElectroTech", "menu entry"), this);
|
||||
about_qt_ = new QAction(QET::Icons::QtLogo, tr("\300 propos de &Qt", "menu entry"), this);
|
||||
@ -124,6 +128,10 @@ void QETTitleBlockTemplateEditor::initActions() {
|
||||
quit_ -> setShortcut(QKeySequence(tr("Ctrl+Q", "shortcut to quit")));
|
||||
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);
|
||||
zoom_out_ -> setShortcut(QKeySequence::ZoomOut);
|
||||
zoom_fit_ -> setShortcut(QKeySequence(tr("Ctrl+9", "shortcut to enable fit zoom")));
|
||||
zoom_reset_ -> setShortcut(QKeySequence(tr("Ctrl+0", "shortcut to reset zoom")));
|
||||
|
||||
configure_ -> setStatusTip(tr("Permet de r\351gler diff\351rents param\350tres de QElectroTech", "status bar tip"));
|
||||
about_qet_ -> setStatusTip(tr("Affiche des informations sur QElectroTech", "status bar tip"));
|
||||
@ -132,6 +140,10 @@ void QETTitleBlockTemplateEditor::initActions() {
|
||||
connect(save_, SIGNAL(triggered()), this, SLOT(save()));
|
||||
connect(save_as_, SIGNAL(triggered()), this, SLOT(saveAs()));
|
||||
connect(quit_, SIGNAL(triggered()), this, SLOT(quit()));
|
||||
connect(zoom_in_, SIGNAL(triggered()), template_edition_area_view_, SLOT(zoomIn()));
|
||||
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(configure_, SIGNAL(triggered()), qet_app, SLOT(configureQET()));
|
||||
connect(about_qet_, SIGNAL(triggered()), qet_app, SLOT(aboutQET()));
|
||||
connect(about_qt_, SIGNAL(triggered()), qet_app, SLOT(aboutQt()));
|
||||
@ -145,12 +157,14 @@ void QETTitleBlockTemplateEditor::initActions() {
|
||||
void QETTitleBlockTemplateEditor::initMenus() {
|
||||
file_menu_ = new QMenu(tr("&Fichier", "menu title"), this);
|
||||
edit_menu_ = new QMenu(tr("&\311dition", "menu title"), this);
|
||||
display_menu_ = new QMenu(tr("Afficha&ge", "menu title"), this);
|
||||
config_menu_ = new QMenu(tr("&Configuration", "menu title"), this);
|
||||
help_menu_ = new QMenu(tr("&Aide", "menu title"), this);
|
||||
|
||||
file_menu_ -> setTearOffEnabled(true);
|
||||
edit_menu_ -> setTearOffEnabled(true);
|
||||
config_menu_ -> setTearOffEnabled(true);
|
||||
display_menu_ -> setTearOffEnabled(true);
|
||||
help_menu_ -> setTearOffEnabled(true);
|
||||
|
||||
file_menu_ -> addAction(save_);
|
||||
@ -161,6 +175,11 @@ void QETTitleBlockTemplateEditor::initMenus() {
|
||||
edit_menu_ -> addAction(merge_cells_);
|
||||
edit_menu_ -> addAction(split_cell_);
|
||||
|
||||
display_menu_ -> addAction(zoom_in_);
|
||||
display_menu_ -> addAction(zoom_out_);
|
||||
display_menu_ -> addAction(zoom_fit_);
|
||||
display_menu_ -> addAction(zoom_reset_);
|
||||
|
||||
config_menu_ -> addAction(configure_);
|
||||
|
||||
help_menu_ -> addAction(about_qet_);
|
||||
@ -168,6 +187,7 @@ void QETTitleBlockTemplateEditor::initMenus() {
|
||||
|
||||
menuBar() -> addMenu(file_menu_);
|
||||
menuBar() -> addMenu(edit_menu_);
|
||||
menuBar() -> addMenu(display_menu_);
|
||||
menuBar() -> addMenu(config_menu_);
|
||||
menuBar() -> addMenu(help_menu_);
|
||||
}
|
||||
|
@ -47,9 +47,10 @@ class QETTitleBlockTemplateEditor : public QMainWindow {
|
||||
/// is the template read-only?
|
||||
bool read_only;
|
||||
/// menus TODO
|
||||
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, *display_menu_, *tools_menu_,*/ *config_menu_, *help_menu_;
|
||||
QMenu *file_menu_, *edit_menu_,/* *paste_from_menu_, */*display_menu_,/* *tools_menu_,*/ *config_menu_, *help_menu_;
|
||||
/// actions
|
||||
QAction *save_, *save_as_, *quit_, *configure_, *about_qt_, *about_qet_, *merge_cells_, *split_cell_;
|
||||
QAction *zoom_in_, *zoom_out_, *zoom_fit_, *zoom_reset_;
|
||||
/// Parent project of the currently edited template
|
||||
QETProject *parent_project_;
|
||||
/// Name of the currently edited template
|
||||
|
@ -27,6 +27,11 @@
|
||||
#define ROW_OFFSET 2
|
||||
#define COL_OFFSET 1
|
||||
#define DEFAULT_PREVIEW_WIDTH 600
|
||||
#define DEFAULT_PREVIEW_HELPER_CELL_HEIGHT 15
|
||||
#define DEFAULT_COLS_HELPER_CELLS_HEIGHT 15
|
||||
#define DEFAULT_ROWS_HELPER_CELLS_WIDTH 50
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Constructor
|
||||
@ -39,7 +44,8 @@ TitleBlockTemplateView::TitleBlockTemplateView(QWidget *parent) :
|
||||
form_(0),
|
||||
preview_width_(DEFAULT_PREVIEW_WIDTH),
|
||||
apply_columns_widths_count_(0),
|
||||
apply_rows_heights_count_(0)
|
||||
apply_rows_heights_count_(0),
|
||||
first_activation_(true)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -54,7 +60,8 @@ TitleBlockTemplateView::TitleBlockTemplateView(QGraphicsScene *scene, QWidget *p
|
||||
tbgrid_(0),
|
||||
preview_width_(DEFAULT_PREVIEW_WIDTH),
|
||||
apply_columns_widths_count_(0),
|
||||
apply_rows_heights_count_(0)
|
||||
apply_rows_heights_count_(0),
|
||||
first_activation_(true)
|
||||
{
|
||||
init();
|
||||
}
|
||||
@ -71,6 +78,7 @@ TitleBlockTemplateView::~TitleBlockTemplateView() {
|
||||
*/
|
||||
void TitleBlockTemplateView::setTitleBlockTemplate(TitleBlockTemplate *tbtemplate) {
|
||||
loadTemplate(tbtemplate);
|
||||
zoomFit();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,6 +112,22 @@ void TitleBlockTemplateView::zoomOut() {
|
||||
scale(zoom_factor, zoom_factor);
|
||||
}
|
||||
|
||||
/**
|
||||
Fit the rendered title block template in this view.
|
||||
*/
|
||||
void TitleBlockTemplateView::zoomFit() {
|
||||
adjustSceneRect();
|
||||
fitInView(scene() -> sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
/**
|
||||
Reset the zoom level.
|
||||
*/
|
||||
void TitleBlockTemplateView::zoomReset() {
|
||||
adjustSceneRect();
|
||||
resetMatrix();
|
||||
}
|
||||
|
||||
/**
|
||||
Add a column right before the last index selected when calling the context
|
||||
menu.
|
||||
@ -285,6 +309,39 @@ TitleBlockTemplateCellsSet TitleBlockTemplateView::cells(const QRectF &rect) con
|
||||
return(makeCellsSetFromGraphicsItems(items));
|
||||
}
|
||||
|
||||
/**
|
||||
@return the current size of the rendered title block template
|
||||
*/
|
||||
QSizeF TitleBlockTemplateView::templateSize() const {
|
||||
return(QSizeF(templateWidth(), templateHeight()));
|
||||
}
|
||||
|
||||
/**
|
||||
@return the current width of the rendered title block template
|
||||
*/
|
||||
qreal TitleBlockTemplateView::templateWidth() const {
|
||||
if (!tbtemplate_) return(0);
|
||||
|
||||
qreal width = DEFAULT_ROWS_HELPER_CELLS_WIDTH;
|
||||
// the rendered width may exceed the initially planned preview width
|
||||
width += qMax<int>(preview_width_, tbtemplate_ -> width(preview_width_));
|
||||
|
||||
return(width);
|
||||
}
|
||||
|
||||
/**
|
||||
@return the current height of the rendered title block template
|
||||
*/
|
||||
qreal TitleBlockTemplateView::templateHeight() const {
|
||||
if (!tbtemplate_) return(0);
|
||||
|
||||
qreal height = DEFAULT_PREVIEW_HELPER_CELL_HEIGHT;
|
||||
height += DEFAULT_COLS_HELPER_CELLS_HEIGHT;
|
||||
height += tbtemplate_ -> height();
|
||||
|
||||
return(height);
|
||||
}
|
||||
|
||||
/**
|
||||
Handles mouse wheel-related actions
|
||||
@param e QWheelEvent describing the wheel event
|
||||
@ -333,6 +390,7 @@ void TitleBlockTemplateView::init() {
|
||||
connect(delete_row_, SIGNAL(triggered()), this, SLOT(deleteRow()));
|
||||
connect(change_preview_width_, SIGNAL(triggered()), this, SLOT(changePreviewWidth()));
|
||||
|
||||
setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
|
||||
setBackgroundBrush(QBrush(QColor(248, 255, 160)));
|
||||
|
||||
connect(scene(), SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
|
||||
@ -345,7 +403,7 @@ void TitleBlockTemplateView::init() {
|
||||
*/
|
||||
void TitleBlockTemplateView::applyColumnsWidths(bool animate) {
|
||||
// the first column is dedicated to helper cells showing the rows height
|
||||
tbgrid_ -> setColumnFixedWidth(0, 50);
|
||||
tbgrid_ -> setColumnFixedWidth(0, DEFAULT_ROWS_HELPER_CELLS_WIDTH);
|
||||
tbgrid_ -> setColumnSpacing(0, 0);
|
||||
|
||||
// we apply the other columns width based on the title block template data
|
||||
@ -406,14 +464,11 @@ void TitleBlockTemplateView::applyColumnsWidths(bool animate) {
|
||||
*/
|
||||
void TitleBlockTemplateView::applyRowsHeights(bool animate) {
|
||||
// the first row is dedicated to a helper cell showing the total width
|
||||
tbgrid_ -> setRowFixedHeight(0, 15);
|
||||
tbgrid_ -> setRowFixedHeight(0, DEFAULT_PREVIEW_HELPER_CELL_HEIGHT);
|
||||
tbgrid_ -> setRowSpacing(0, 0);
|
||||
// the second row is dedicated to helper cells showing the columns width
|
||||
tbgrid_ -> setRowFixedHeight(1, 15);
|
||||
tbgrid_ -> setRowFixedHeight(1, DEFAULT_COLS_HELPER_CELLS_HEIGHT);
|
||||
tbgrid_ -> setRowSpacing(1, 0);
|
||||
// the first column is dedicated to helper cells showing the rows height
|
||||
tbgrid_ -> setColumnFixedWidth(0, 45);
|
||||
tbgrid_ -> setColumnSpacing(0, 0);
|
||||
|
||||
QList<int> heights = tbtemplate_ -> rowsHeights();
|
||||
for (int i = 0 ; i < heights.count() ; ++ i) {
|
||||
@ -581,6 +636,17 @@ void TitleBlockTemplateView::fillWithEmptyCells() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@param event Object describing the received event
|
||||
*/
|
||||
bool TitleBlockTemplateView::event(QEvent *event) {
|
||||
if (first_activation_ && event -> type() == QEvent::WindowActivate) {
|
||||
QTimer::singleShot(250, this, SLOT(zoomFit()));
|
||||
first_activation_ = false;
|
||||
}
|
||||
return(QGraphicsView::event(event));
|
||||
}
|
||||
|
||||
/**
|
||||
Load the \a tbt title block template.
|
||||
If a different template was previously loaded, it is deleted.
|
||||
@ -763,11 +829,11 @@ void TitleBlockTemplateView::updateLastContextMenuCell(HelperCell *last_context_
|
||||
Adjusts the bounding rect of the scene.
|
||||
*/
|
||||
void TitleBlockTemplateView::adjustSceneRect() {
|
||||
QRectF old_scene_rect = sceneRect();
|
||||
QRectF old_scene_rect = scene() -> sceneRect();
|
||||
|
||||
// rectangle including everything on the scene
|
||||
QRectF bounding_rect = scene() -> itemsBoundingRect();
|
||||
setSceneRect(bounding_rect);
|
||||
QRectF bounding_rect(QPointF(0, 0), templateSize());
|
||||
scene() -> setSceneRect(bounding_rect);
|
||||
|
||||
// met a jour la scene
|
||||
scene() -> update(old_scene_rect.united(bounding_rect));
|
||||
|
@ -46,12 +46,17 @@ class TitleBlockTemplateView : public QGraphicsView {
|
||||
virtual QList<TitleBlockCell *> selectedCells() const;
|
||||
virtual TitleBlockTemplateCellsSet selectedCellsSet() const;
|
||||
virtual TitleBlockTemplateCellsSet cells(const QRectF &) const;
|
||||
virtual QSizeF templateSize() const;
|
||||
virtual qreal templateWidth() const;
|
||||
virtual qreal templateHeight() const;
|
||||
|
||||
public slots:
|
||||
void setTitleBlockTemplate(TitleBlockTemplate *);
|
||||
void selectionChanged();
|
||||
void zoomIn();
|
||||
void zoomOut();
|
||||
void zoomFit();
|
||||
void zoomReset();
|
||||
void addColumnBefore();
|
||||
void addRowBefore();
|
||||
void addColumnAfter();
|
||||
@ -82,6 +87,7 @@ class TitleBlockTemplateView : public QGraphicsView {
|
||||
virtual void wheelEvent(QWheelEvent *);
|
||||
virtual qreal zoomFactor() const;
|
||||
virtual void fillWithEmptyCells();
|
||||
virtual bool event(QEvent *);
|
||||
|
||||
signals:
|
||||
void selectedCellsChanged(QList<TitleBlockCell *>);
|
||||
@ -118,5 +124,6 @@ class TitleBlockTemplateView : public QGraphicsView {
|
||||
HelperCell *last_context_menu_cell_;
|
||||
int apply_columns_widths_count_;
|
||||
int apply_rows_heights_count_;
|
||||
bool first_activation_; ///< Boolean used to detect the first display of this widget
|
||||
};
|
||||
#endif
|
||||
|
@ -665,7 +665,7 @@ QString TitleBlockTemplate::name() const {
|
||||
*/
|
||||
int TitleBlockTemplate::rowDimension(int i) {
|
||||
int index = (i == -1) ? rows_heights_.count() - 1 : i;
|
||||
if (index >= 0 || index < rows_heights_.count()) {
|
||||
if (index >= 0 && index < rows_heights_.count()) {
|
||||
return(rows_heights_.at(index));
|
||||
}
|
||||
return(-1);
|
||||
@ -689,7 +689,7 @@ void TitleBlockTemplate::setRowDimension(int i, const TitleBlockDimension &dimen
|
||||
*/
|
||||
TitleBlockDimension TitleBlockTemplate::columnDimension(int i) {
|
||||
int index = (i == -1) ? columns_width_.count() - 1 : i;
|
||||
if (index >= 0 || index < columns_width_.count()) {
|
||||
if (index >= 0 && index < columns_width_.count()) {
|
||||
return(columns_width_.at(index));
|
||||
}
|
||||
return(TitleBlockDimension(-1));
|
||||
@ -764,6 +764,18 @@ QList<int> TitleBlockTemplate::rowsHeights() const {
|
||||
return(rows_heights_);
|
||||
}
|
||||
|
||||
/**
|
||||
@return the total effective width of this template
|
||||
@param total_width The total width initially planned for the rendering
|
||||
*/
|
||||
int TitleBlockTemplate::width(int total_width) {
|
||||
int width = 0;
|
||||
foreach (int col_width, columnsWidth(total_width)) {
|
||||
width += col_width;
|
||||
}
|
||||
return(width);
|
||||
}
|
||||
|
||||
/**
|
||||
@return the total height of this template
|
||||
*/
|
||||
|
@ -58,6 +58,7 @@ class TitleBlockTemplate : public QObject {
|
||||
int rowsCount() const;
|
||||
QList<int> columnsWidth(int) const;
|
||||
QList<int> rowsHeights() const;
|
||||
int width(int);
|
||||
int height() const;
|
||||
|
||||
bool moveRow(int, int);
|
||||
|
Loading…
x
Reference in New Issue
Block a user