[qet] [1417] Added zoom-related menus. |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/qet Archives
]
Revision: 1417
Author: xavier
Date: 2011-12-30 03:05:46 +0100 (Fri, 30 Dec 2011)
Log Message:
-----------
Added zoom-related menus.
Modified Paths:
--------------
branches/0.3/sources/titleblock/qettemplateeditor.cpp
branches/0.3/sources/titleblock/qettemplateeditor.h
branches/0.3/sources/titleblock/templateview.cpp
branches/0.3/sources/titleblock/templateview.h
branches/0.3/sources/titleblocktemplate.cpp
branches/0.3/sources/titleblocktemplate.h
Modified: branches/0.3/sources/titleblock/qettemplateeditor.cpp
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.cpp 2011-12-29 17:42:18 UTC (rev 1416)
+++ branches/0.3/sources/titleblock/qettemplateeditor.cpp 2011-12-30 02:05:46 UTC (rev 1417)
@@ -114,6 +114,10 @@
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 @@
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 @@
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::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 @@
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 @@
menuBar() -> addMenu(file_menu_);
menuBar() -> addMenu(edit_menu_);
+ menuBar() -> addMenu(display_menu_);
menuBar() -> addMenu(config_menu_);
menuBar() -> addMenu(help_menu_);
}
Modified: branches/0.3/sources/titleblock/qettemplateeditor.h
===================================================================
--- branches/0.3/sources/titleblock/qettemplateeditor.h 2011-12-29 17:42:18 UTC (rev 1416)
+++ branches/0.3/sources/titleblock/qettemplateeditor.h 2011-12-30 02:05:46 UTC (rev 1417)
@@ -47,9 +47,10 @@
/// 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
Modified: branches/0.3/sources/titleblock/templateview.cpp
===================================================================
--- branches/0.3/sources/titleblock/templateview.cpp 2011-12-29 17:42:18 UTC (rev 1416)
+++ branches/0.3/sources/titleblock/templateview.cpp 2011-12-30 02:05:46 UTC (rev 1417)
@@ -27,7 +27,12 @@
#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
@param parent Parent QWidget.
@@ -39,7 +44,8 @@
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 @@
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 @@
*/
void TitleBlockTemplateView::setTitleBlockTemplate(TitleBlockTemplate *tbtemplate) {
loadTemplate(tbtemplate);
+ zoomFit();
}
/**
@@ -105,6 +113,22 @@
}
/**
+ 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.
*/
@@ -286,6 +310,39 @@
}
/**
+ @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 @@
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::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::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) {
@@ -582,6 +637,17 @@
}
/**
+ @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 @@
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));
Modified: branches/0.3/sources/titleblock/templateview.h
===================================================================
--- branches/0.3/sources/titleblock/templateview.h 2011-12-29 17:42:18 UTC (rev 1416)
+++ branches/0.3/sources/titleblock/templateview.h 2011-12-30 02:05:46 UTC (rev 1417)
@@ -46,12 +46,17 @@
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 @@
virtual void wheelEvent(QWheelEvent *);
virtual qreal zoomFactor() const;
virtual void fillWithEmptyCells();
+ virtual bool event(QEvent *);
signals:
void selectedCellsChanged(QList<TitleBlockCell *>);
@@ -118,5 +124,6 @@
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
Modified: branches/0.3/sources/titleblocktemplate.cpp
===================================================================
--- branches/0.3/sources/titleblocktemplate.cpp 2011-12-29 17:42:18 UTC (rev 1416)
+++ branches/0.3/sources/titleblocktemplate.cpp 2011-12-30 02:05:46 UTC (rev 1417)
@@ -665,7 +665,7 @@
*/
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 @@
*/
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));
@@ -765,6 +765,18 @@
}
/**
+ @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
*/
int TitleBlockTemplate::height() const {
Modified: branches/0.3/sources/titleblocktemplate.h
===================================================================
--- branches/0.3/sources/titleblocktemplate.h 2011-12-29 17:42:18 UTC (rev 1416)
+++ branches/0.3/sources/titleblocktemplate.h 2011-12-30 02:05:46 UTC (rev 1417)
@@ -58,6 +58,7 @@
int rowsCount() const;
QList<int> columnsWidth(int) const;
QList<int> rowsHeights() const;
+ int width(int);
int height() const;
bool moveRow(int, int);