~valavanisalex/ubuntu/maverick/scidavis/scidavis-fix-565206

« back to all changes in this revision

Viewing changes to scidavis/src/MultiLayer.h

  • Committer: Bazaar Package Importer
  • Author(s): Ruben Molina
  • Date: 2009-09-06 11:34:04 UTC
  • Revision ID: james.westby@ubuntu.com-20090906113404-4awaey82l3686w4q
Tags: upstream-0.2.3
ImportĀ upstreamĀ versionĀ 0.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
    File                 : MultiLayer.h
 
3
    Project              : SciDAVis
 
4
    --------------------------------------------------------------------
 
5
    Copyright            : (C) 2006 by Ion Vasilief,
 
6
                           Tilman Benkert,
 
7
                           Knut Franke
 
8
    Email (use @ for *)  : ion_vasilief*yahoo.fr, thzs*gmx.net,
 
9
                           knut.franke*gmx.de
 
10
    Description          : Multi layer widget
 
11
 
 
12
 ***************************************************************************/
 
13
 
 
14
/***************************************************************************
 
15
 *                                                                         *
 
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.                                    *
 
20
 *                                                                         *
 
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.                           *
 
25
 *                                                                         *
 
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                                           *
 
30
 *                                                                         *
 
31
 ***************************************************************************/
 
32
#ifndef MULTILAYER_H
 
33
#define MULTILAYER_H
 
34
 
 
35
#include "MyWidget.h"
 
36
#include "Graph.h"
 
37
#include <QPushButton>
 
38
#include <QLayout>
 
39
#include <QPointer>
 
40
#include "core/column/Column.h"
 
41
 
 
42
class QWidget;
 
43
class QLabel;
 
44
class QWidget;
 
45
class LayerButton;
 
46
class SelectionMoveResizer;
 
47
class ApplicationWindow;
 
48
 
 
49
/**
 
50
 * \brief An MDI window (MyWidget) managing one or more Graph objects.
 
51
 *
 
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.
 
54
 *
 
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).
 
60
 *
 
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.
 
65
 */
 
66
class MultiLayer: public MyWidget
 
67
{
 
68
        Q_OBJECT
 
69
 
 
70
public:
 
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);
 
76
 
 
77
        enum HorAlignement{HCenter, Left, Right};
 
78
        enum VertAlignement{VCenter, Top, Bottom};
 
79
 
 
80
        //! \name Event Handlers
 
81
        //@{
 
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 *);
 
88
        void releaseLayer();
 
89
 
 
90
        bool focusNextPrevChild ( bool next );
 
91
        //@}
 
92
 
 
93
        void setOpenMaximized(){d_open_maximized = 1;};
 
94
 
 
95
        bool scaleLayersOnPrint(){return d_scale_on_print;};
 
96
        void setScaleLayersOnPrint(bool on){d_scale_on_print = on;};
 
97
 
 
98
        bool printCropmarksEnabled(){return d_print_cropmarks;};
 
99
        void printCropmarks(bool on){d_print_cropmarks = on;};
 
100
 
 
101
        void setHidden();
 
102
 
 
103
public slots:
 
104
        Graph* addLayer(int x = 0, int y = 0, int width = 0, int height = 0);
 
105
        void setLayersNumber(int n);
 
106
 
 
107
        bool isEmpty();
 
108
    void removeLayer();
 
109
        void confirmRemoveLayer();
 
110
 
 
111
        /*!\brief Start adding a text layer.
 
112
         *
 
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().
 
115
         *
 
116
         * \sa #defaultTextMarkerFont, #defaultTextMarkerFrame, #defaultTextMarkerColor, #defaultTextMarkerBackground
 
117
         */
 
118
        void addTextLayer(int f, const QFont& font, const QColor& textCol, const QColor& backgroundCol);
 
119
        /*!\brief Finish adding a text layer.
 
120
         *
 
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.
 
123
         *
 
124
         * \sa #defaultTextMarkerFont, #defaultTextMarkerFrame, #defaultTextMarkerColor, #defaultTextMarkerBackground, addTextLayer(int,const QFont&,const QColor&,const QColor&)
 
125
         */
 
126
        void addTextLayer(const QPoint& pos);
 
127
 
 
128
        Graph* activeGraph(){return active_graph;};
 
129
        void setActiveGraph(Graph* g);
 
130
        void activateGraph(LayerButton* button);
 
131
 
 
132
        void setGraphGeometry(int x, int y, int w, int h);
 
133
 
 
134
        void findBestLayout(int &rows, int &cols);
 
135
 
 
136
        QSize arrangeLayers(bool userSize);
 
137
        void arrangeLayers(bool fit, bool userSize);
 
138
    void adjustSize();
 
139
 
 
140
        int getRows(){return rows;};
 
141
        void setRows(int r);
 
142
 
 
143
        int getCols(){return cols;};
 
144
        void setCols(int c);
 
145
 
 
146
        int colsSpacing(){return colsSpace;};
 
147
        int rowsSpacing(){return rowsSpace;};
 
148
        void setSpacing (int rgap, int cgap);
 
149
 
 
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);
 
155
 
 
156
        QSize layerCanvasSize(){return QSize(l_canvas_width, l_canvas_height);};
 
157
        void setLayerCanvasSize (int w, int h);
 
158
 
 
159
        int horizontalAlignement(){return hor_align;};
 
160
        int verticalAlignement(){return vert_align;};
 
161
        void setAlignement (int ha, int va);
 
162
 
 
163
        int layers(){return graphs;};
 
164
 
 
165
        //! \name Print and Export
 
166
        //@{
 
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);
 
175
 
 
176
        void copyAllLayers();
 
177
        void print();
 
178
        void printAllLayers(QPainter *painter);
 
179
        void printActiveLayer();
 
180
        //@}
 
181
 
 
182
        void setFonts(const QFont& titleFnt, const QFont& scaleFnt,
 
183
                                                        const QFont& numbersFnt, const QFont& legendFnt);
 
184
 
 
185
        void connectLayer(Graph *g);
 
186
 
 
187
        QString saveToString(const QString& geometry);
 
188
        QString saveAsTemplate(const QString& geometryInfo);
 
189
 
 
190
signals:
 
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();
 
200
        void drawTextOff();
 
201
        void drawLineEnded(bool);
 
202
        void showXAxisTitleDialog();
 
203
        void showYAxisTitleDialog();
 
204
        void showTopAxisTitleDialog();
 
205
        void showRightAxisTitleDialog();
 
206
        void showMarkerPopupMenu();
 
207
        void modifiedPlot();
 
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();
 
214
        void pasteMarker();
 
215
        void createIntensityTable(const QString&);
 
216
        void setPointerCursor();
 
217
 
 
218
private:
 
219
        void resizeLayers (const QResizeEvent *re);
 
220
        void resizeLayers (const QSize& size, const QSize& oldSize, bool scaleFonts);
 
221
 
 
222
        Graph* active_graph;
 
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;
 
227
        bool addTextOn;
 
228
        bool d_scale_on_print, d_print_cropmarks;
 
229
 
 
230
        //! Used when adding text markers on new layers
 
231
        int defaultTextMarkerFrame;
 
232
        QFont defaultTextMarkerFont;
 
233
        QColor defaultTextMarkerColor, defaultTextMarkerBackground;
 
234
 
 
235
    QWidgetList buttonsList, graphsList;
 
236
        QHBoxLayout *layerButtonsBox;
 
237
    QWidget *canvas;
 
238
 
 
239
        QPointer<SelectionMoveResizer> d_layers_selector;
 
240
        int d_open_maximized;
 
241
        //! Stores the size of the widget in the Qt::WindowMaximized state.
 
242
        QSize d_max_size;
 
243
        //! Stores the size of the widget in Qt::WindowNoState (normal state).
 
244
    QSize d_normal_size;
 
245
};
 
246
 
 
247
 
 
248
//! Button with layer number
 
249
class LayerButton: public QPushButton
 
250
{
 
251
        Q_OBJECT
 
252
 
 
253
public:
 
254
    LayerButton (const QString& text = QString::null, QWidget* parent = 0);
 
255
        ~LayerButton(){};
 
256
 
 
257
        static int btnSize(){return 20;};
 
258
 
 
259
protected:
 
260
        void mousePressEvent( QMouseEvent * );
 
261
        void mouseDoubleClickEvent ( QMouseEvent * );
 
262
 
 
263
signals:
 
264
        void showCurvesDialog();
 
265
        void clicked(LayerButton*);
 
266
        void showContextMenu();
 
267
};
 
268
 
 
269
#endif