1
/***************************************************************************
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief,
8
Email (use @ for *) : ion_vasilief*yahoo.fr, thzs*gmx.net,
10
Description : Multi layer widget
12
***************************************************************************/
14
/***************************************************************************
16
* This program is free software; you can redistribute it and/or modify *
17
* it under the terms of the GNU General Public License as published by *
18
* the Free Software Foundation; either version 2 of the License, or *
19
* (at your option) any later version. *
21
* This program is distributed in the hope that it will be useful, *
22
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
23
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
24
* GNU General Public License for more details. *
26
* You should have received a copy of the GNU General Public License *
27
* along with this program; if not, write to the Free Software *
28
* Foundation, Inc., 51 Franklin Street, Fifth Floor, *
29
* Boston, MA 02110-1301 USA *
31
***************************************************************************/
37
#include <QPushButton>
40
#include "core/column/Column.h"
46
class SelectionMoveResizer;
47
class ApplicationWindow;
50
* \brief An MDI window (MyWidget) managing one or more Graph objects.
52
* %Note that several parts of the code, as well as the user interface, refer to MultiLayer as "graph" or "plot",
53
* practically guaranteeing confusion with the classes Graph and Plot.
55
* \section future_plans Future Plans
56
* Manage any QWidget instead of only Graph.
57
* This would allow 3D graphs to be added as well, so you could produce mixed 2D/3D arrangements.
58
* It would also allow text labels to be added directly instead of having to complicate things by wrapping them
59
* up in a Graph (see documentation of ImageMarker for details) (see documentation of ImageMarker for details).
61
* The main problem to be figured out for this is how Graph would interface with the rest of the project.
62
* A possible solution is outlined in the documentation of ApplicationWindow:
63
* If MultiLayer exposes its parent Project to the widgets it manages, they could handle things like creating
64
* tables by calling methods of Project instead of sending signals.
66
class MultiLayer: public MyWidget
71
MultiLayer (const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
72
QWidgetList graphPtrs(){return graphsList;};
73
Graph *layer(int num);
74
LayerButton* addLayerButton();
75
void copy(ApplicationWindow * parent, MultiLayer* ml);
77
enum HorAlignement{HCenter, Left, Right};
78
enum VertAlignement{VCenter, Top, Bottom};
80
//! \name Event Handlers
82
void mousePressEvent(QMouseEvent *);
83
void contextMenuEvent(QContextMenuEvent *);
84
void wheelEvent(QWheelEvent *);
85
void keyPressEvent(QKeyEvent *);
86
void changeEvent(QEvent *);
87
bool eventFilter(QObject *object, QEvent *);
90
bool focusNextPrevChild ( bool next );
93
void setOpenMaximized(){d_open_maximized = 1;};
95
bool scaleLayersOnPrint(){return d_scale_on_print;};
96
void setScaleLayersOnPrint(bool on){d_scale_on_print = on;};
98
bool printCropmarksEnabled(){return d_print_cropmarks;};
99
void printCropmarks(bool on){d_print_cropmarks = on;};
104
Graph* addLayer(int x = 0, int y = 0, int width = 0, int height = 0);
105
void setLayersNumber(int n);
109
void confirmRemoveLayer();
111
/*!\brief Start adding a text layer.
113
* This works by having #canvas grab the mouse, remembering that we are in the midst of adding
114
* text in #addTextOn and dispatching the next mouse click to addTextLayer(const QPoint&) in eventFilter().
116
* \sa #defaultTextMarkerFont, #defaultTextMarkerFrame, #defaultTextMarkerColor, #defaultTextMarkerBackground
118
void addTextLayer(int f, const QFont& font, const QColor& textCol, const QColor& backgroundCol);
119
/*!\brief Finish adding a text layer.
121
* An empty Graph is created and added to me.
122
* Legend, title and axes are removed and a new Legend is added with a placeholder text.
124
* \sa #defaultTextMarkerFont, #defaultTextMarkerFrame, #defaultTextMarkerColor, #defaultTextMarkerBackground, addTextLayer(int,const QFont&,const QColor&,const QColor&)
126
void addTextLayer(const QPoint& pos);
128
Graph* activeGraph(){return active_graph;};
129
void setActiveGraph(Graph* g);
130
void activateGraph(LayerButton* button);
132
void setGraphGeometry(int x, int y, int w, int h);
134
void findBestLayout(int &rows, int &cols);
136
QSize arrangeLayers(bool userSize);
137
void arrangeLayers(bool fit, bool userSize);
140
int getRows(){return rows;};
143
int getCols(){return cols;};
146
int colsSpacing(){return colsSpace;};
147
int rowsSpacing(){return rowsSpace;};
148
void setSpacing (int rgap, int cgap);
150
int leftMargin(){return left_margin;};
151
int rightMargin(){return right_margin;};
152
int topMargin(){return top_margin;};
153
int bottomMargin(){return bottom_margin;};
154
void setMargins (int lm, int rm, int tm, int bm);
156
QSize layerCanvasSize(){return QSize(l_canvas_width, l_canvas_height);};
157
void setLayerCanvasSize (int w, int h);
159
int horizontalAlignement(){return hor_align;};
160
int verticalAlignement(){return vert_align;};
161
void setAlignement (int ha, int va);
163
int layers(){return graphs;};
165
//! \name Print and Export
167
QPixmap canvasPixmap();
168
void exportToFile(const QString& fileName);
169
void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
170
void exportSVG(const QString& fname);
171
void exportPDF(const QString& fname);
172
void exportVector(const QString& fileName, int res = 0, bool color = true,
173
bool keepAspect = true, QPrinter::PageSize pageSize = QPrinter::Custom,
174
QPrinter::Orientation orientation = QPrinter::Portrait);
176
void copyAllLayers();
178
void printAllLayers(QPainter *painter);
179
void printActiveLayer();
182
void setFonts(const QFont& titleFnt, const QFont& scaleFnt,
183
const QFont& numbersFnt, const QFont& legendFnt);
185
void connectLayer(Graph *g);
187
QString saveToString(const QString& geometry);
188
QString saveAsTemplate(const QString& geometryInfo);
191
void showTextDialog();
192
void showPlotDialog(int);
193
void showAxisDialog(int);
194
void showScaleDialog(int);
195
void showGraphContextMenu();
196
void showLayerButtonContextMenu();
197
void showCurveContextMenu(int);
198
void showWindowContextMenu();
199
void showCurvesDialog();
201
void drawLineEnded(bool);
202
void showXAxisTitleDialog();
203
void showYAxisTitleDialog();
204
void showTopAxisTitleDialog();
205
void showRightAxisTitleDialog();
206
void showMarkerPopupMenu();
208
void cursorInfo(const QString&);
209
void showImageDialog();
210
void showLineDialog();
211
void viewTitleDialog();
212
void createTable(const QString&,const QString&,QList<Column*>);
213
void showGeometryDialog();
215
void createIntensityTable(const QString&);
216
void setPointerCursor();
219
void resizeLayers (const QResizeEvent *re);
220
void resizeLayers (const QSize& size, const QSize& oldSize, bool scaleFonts);
223
//! Used for resizing of layers.
224
int graphs, cols, rows, graph_width, graph_height, colsSpace, rowsSpace;
225
int left_margin, right_margin, top_margin, bottom_margin;
226
int l_canvas_width, l_canvas_height, hor_align, vert_align;
228
bool d_scale_on_print, d_print_cropmarks;
230
//! Used when adding text markers on new layers
231
int defaultTextMarkerFrame;
232
QFont defaultTextMarkerFont;
233
QColor defaultTextMarkerColor, defaultTextMarkerBackground;
235
QWidgetList buttonsList, graphsList;
236
QHBoxLayout *layerButtonsBox;
239
QPointer<SelectionMoveResizer> d_layers_selector;
240
int d_open_maximized;
241
//! Stores the size of the widget in the Qt::WindowMaximized state.
243
//! Stores the size of the widget in Qt::WindowNoState (normal state).
248
//! Button with layer number
249
class LayerButton: public QPushButton
254
LayerButton (const QString& text = QString::null, QWidget* parent = 0);
257
static int btnSize(){return 20;};
260
void mousePressEvent( QMouseEvent * );
261
void mouseDoubleClickEvent ( QMouseEvent * );
264
void showCurvesDialog();
265
void clicked(LayerButton*);
266
void showContextMenu();