1
/***************************************************************************
4
--------------------------------------------------------------------
5
Copyright : (C) 2006 by Ion Vasilief,
6
Tilman Hoener zu Siederdissen,
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>
45
class SelectionMoveResizer;
48
* \brief An MDI window (MyWidget) managing one or more Graph objects.
50
* %Note that several parts of the code, as well as the user interface, refer to MultiLayer as "graph" or "plot",
51
* practically guaranteeing confusion with the classes Graph and Plot.
53
* \section future Future Plans
54
* Manage any QWidget instead of only Graph.
55
* This would allow 3D graphs to be added as well, so you could produce mixed 2D/3D arrangements.
56
* It would also allow text labels to be added directly instead of having to complicate things by wrapping them
57
* up in a Graph (see documentation of ImageMarker for details) (see documentation of ImageMarker for details).
59
* The main problem to be figured out for this is how Graph would interface with the rest of the project.
60
* A possible solution is outlined in the documentation of ApplicationWindow:
61
* If MultiLayer exposes its parent Project to the widgets it manages, they could handle things like creating
62
* tables by calling methods of Project instead of sending signals.
64
class MultiLayer: public MyWidget
69
MultiLayer (const QString& label, QWidget* parent=0, const char* name=0, Qt::WFlags f=0);
70
QWidgetList graphPtrs(){return graphsList;};
71
Graph *layer(int num);
72
LayerButton* addLayerButton();
73
void copy(MultiLayer* ml);
75
enum HorAlignement{HCenter, Left, Right};
76
enum VertAlignement{VCenter, Top, Bottom};
78
//! \name Event Handlers
80
void mousePressEvent(QMouseEvent *);
81
void contextMenuEvent(QContextMenuEvent *);
82
void wheelEvent(QWheelEvent *);
83
void keyPressEvent(QKeyEvent *);
84
void changeEvent(QEvent *);
85
bool eventFilter(QObject *object, QEvent *);
88
bool focusNextPrevChild ( bool next );
91
void setOpenMaximized(){d_open_maximized = 1;};
93
bool scaleLayersOnPrint(){return d_scale_on_print;};
94
void setScaleLayersOnPrint(bool on){d_scale_on_print = on;};
96
bool printCropmarksEnabled(){return d_print_cropmarks;};
97
void printCropmarks(bool on){d_print_cropmarks = on;};
102
Graph* addLayer(int x = 0, int y = 0, int width = 0, int height = 0);
103
void setLayersNumber(int n);
107
void confirmRemoveLayer();
109
/*!\brief Start adding a text layer.
111
* This works by having #canvas grab the mouse, remembering that we are in the midst of adding
112
* text in #addTextOn and dispatching the next mouse click to addTextLayer(const QPoint&) in eventFilter().
114
* \sa #defaultTextMarkerFont, #defaultTextMarkerFrame, #defaultTextMarkerColor, #defaultTextMarkerBackground
116
void addTextLayer(int f, const QFont& font, const QColor& textCol, const QColor& backgroundCol);
117
/*!\brief Finish adding a text layer.
119
* An empty Graph is created and added to me.
120
* Legend, title and axes are removed and a new LegendMarker is added with a placeholder text.
122
* \sa #defaultTextMarkerFont, #defaultTextMarkerFrame, #defaultTextMarkerColor, #defaultTextMarkerBackground, addTextLayer(int,const QFont&,const QColor&,const QColor&)
124
void addTextLayer(const QPoint& pos);
126
Graph* activeGraph(){return active_graph;};
127
void setActiveGraph(Graph* g);
128
void activateGraph(LayerButton* button);
130
void setGraphGeometry(int x, int y, int w, int h);
132
void findBestLayout(int &rows, int &cols);
134
QSize arrangeLayers(bool userSize);
135
void arrangeLayers(bool fit, bool userSize);
138
int getRows(){return rows;};
141
int getCols(){return cols;};
144
int colsSpacing(){return colsSpace;};
145
int rowsSpacing(){return rowsSpace;};
146
void setSpacing (int rgap, int cgap);
148
int leftMargin(){return left_margin;};
149
int rightMargin(){return right_margin;};
150
int topMargin(){return top_margin;};
151
int bottomMargin(){return bottom_margin;};
152
void setMargins (int lm, int rm, int tm, int bm);
154
QSize layerCanvasSize(){return QSize(l_canvas_width, l_canvas_height);};
155
void setLayerCanvasSize (int w, int h);
157
int horizontalAlignement(){return hor_align;};
158
int verticalAlignement(){return vert_align;};
159
void setAlignement (int ha, int va);
161
int layers(){return graphs;};
163
//! \name Print and Export
165
QPixmap canvasPixmap();
166
void exportToFile(const QString& fileName);
167
void exportImage(const QString& fileName, int quality = 100, bool transparent = false);
168
void exportSVG(const QString& fname);
169
void exportPDF(const QString& fname);
170
void exportVector(const QString& fileName, int res = 0, bool color = true);
172
void copyAllLayers();
174
void printAllLayers(QPainter *painter);
175
void printActiveLayer();
178
void setFonts(const QFont& titleFnt, const QFont& scaleFnt,
179
const QFont& numbersFnt, const QFont& legendFnt);
181
void connectLayer(Graph *g);
183
QString saveToString(const QString& geometry);
184
QString saveAsTemplate(const QString& geometryInfo);
187
void showTextDialog();
188
void showPlotDialog(int);
189
void showAxisDialog(int);
190
void showScaleDialog(int);
191
void showGraphContextMenu();
192
void showCurveContextMenu(int);
193
void showWindowContextMenu();
194
void showCurvesDialog();
196
void drawLineEnded(bool);
197
void showXAxisTitleDialog();
198
void showYAxisTitleDialog();
199
void showTopAxisTitleDialog();
200
void showRightAxisTitleDialog();
201
void showMarkerPopupMenu();
203
void cursorInfo(const QString&);
204
void showImageDialog();
205
void showLineDialog();
206
void viewTitleDialog();
207
void createTable(const QString&,int,int,const QString&);
208
void showGeometryDialog();
210
void createIntensityTable(const QString&);
211
void setPointerCursor();
214
void resizeLayers (const QResizeEvent *re);
215
void resizeLayers (const QSize& size, const QSize& oldSize, bool scaleFonts);
218
//! Used for resizing of layers.
219
int graphs, cols, rows, graph_width, graph_height, colsSpace, rowsSpace;
220
int left_margin, right_margin, top_margin, bottom_margin;
221
int l_canvas_width, l_canvas_height, hor_align, vert_align;
223
bool d_scale_on_print, d_print_cropmarks;
225
//! Used when adding text markers on new layers
226
int defaultTextMarkerFrame;
227
QFont defaultTextMarkerFont;
228
QColor defaultTextMarkerColor, defaultTextMarkerBackground;
230
QWidgetList buttonsList, graphsList;
231
QHBoxLayout *layerButtonsBox;
234
QPointer<SelectionMoveResizer> d_layers_selector;
235
int d_open_maximized;
236
//! Stores the size of the widget in the Qt::WindowMaximized state.
238
//! Stores the size of the widget in Qt::WindowNoState (normal state).
243
//! Button with layer number
244
class LayerButton: public QPushButton
249
LayerButton (const QString& text = QString::null, QWidget* parent = 0);
252
static int btnSize(){return 20;};
255
void mousePressEvent( QMouseEvent * );
256
void mouseDoubleClickEvent ( QMouseEvent * );
259
void showCurvesDialog();
260
void clicked(LayerButton*);