QtiPlot 0.9.7.3

MultiLayer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : MultiLayer.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 - 2009 by Ion Vasilief, Knut Franke
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr, knut.franke*gmx.de
00007     Description          : Multi layer widget
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef MULTILAYER_H
00030 #define MULTILAYER_H
00031 
00032 #include <MdiSubWindow.h>
00033 #include <FrameWidget.h>
00034 #include <QPushButton>
00035 #include <QLayout>
00036 #include <QPointer>
00037 
00038 class QTextDocument;
00039 class QLabel;
00040 class LayerButton;
00041 class SelectionMoveResizer;
00042 class LegendWidget;
00043 class Graph;
00044 class QwtPlotCurve;
00045 class Matrix;
00046 
00064 class MultiLayer: public MdiSubWindow
00065 {
00066     Q_OBJECT
00067 
00068 public:
00069     MultiLayer (ApplicationWindow* parent = 0, int layers = 1, int rows = 1, int cols = 1, const QString& label = "", const char* name=0, Qt::WFlags f=0);
00070     ~MultiLayer();
00071 
00072     QList<Graph *> layersList(){return graphsList;};
00073     QList<Graph*> stackOrderedLayersList();
00074     Graph *layer(int num);
00075     int layerIndex(Graph *g){return graphsList.indexOf(g);};
00076 
00077     int numLayers(){return graphsList.size();};
00078     void setNumLayers(int n);
00079 
00080     void copy(MultiLayer* ml);
00081 
00082     enum HorAlignement{HCenter, Left, Right};
00083     enum VertAlignement{VCenter, Top, Bottom};
00084     enum AlignPolicy{AlignLayers = 0, AlignCanvases};
00085     enum SizePolicy{Expanding = 0, UserSize};
00086 
00087     bool scaleLayersOnPrint(){return d_scale_on_print;};
00088     void setScaleLayersOnPrint(bool on){d_scale_on_print = on;};
00089 
00090     bool printCropmarksEnabled(){return d_print_cropmarks;};
00091     void printCropmarks(bool on){d_print_cropmarks = on;};
00092 
00093     bool scaleLayersOnResize(){return d_scale_layers;};
00094     void setScaleLayersOnResize(bool ok){d_scale_layers = ok;};
00095 
00096     QWidget *canvas(){return d_canvas;};
00097     QRect canvasRect(){return d_canvas->rect();};
00098     QRect canvasChildrenRect();
00099     virtual QString sizeToString();
00100 
00101     void setWaterfallLayout(bool on = true);
00102     void createWaterfallBox();
00103     bool isWaterfallPlot(){return d_is_waterfall_plot;};
00104     int waterfallXOffset(){return d_waterfall_offset_x;};
00105     int waterfallYOffset(){return d_waterfall_offset_y;};
00106     void setWaterfallOffset(int x, int y, bool update = false);
00107     bool sideLinesEnabled(){return d_side_lines;};
00108 
00109     void setEqualSizedLayers();
00110 
00111     void plotProfiles(Matrix* m);
00112 
00113     QHBoxLayout *toolBox(){return toolbuttonsBox;};
00114 
00115     AlignPolicy alignPolicy(){return d_align_policy;};
00116     void setAlignPolicy(const AlignPolicy& policy){d_align_policy = policy;};
00117 
00118     SizePolicy sizePolicy(){return d_size_policy;};
00119     void setSizePolicy(const SizePolicy& policy){d_size_policy = policy;};
00120 
00121     void setCommonLayerAxes(bool verticalAxis = true, bool horizontalAxis = true);
00122     void linkXLayerAxes(bool link = true);
00123     bool hasLinkedXLayerAxes(){return d_link_x_axes;};
00124     bool hasCommonAxes(){return d_common_axes_layout;};
00125     void setCommonAxesLayout(bool on){d_common_axes_layout = on;};
00126 
00127 public slots:
00128     Graph* addLayer(int x = 0, int y = 0, int width = 0, int height = 0, bool = false);
00129 
00130     bool isEmpty();
00131     bool removeLayer(Graph *g);
00132     bool removeActiveLayer();
00133     void confirmRemoveLayer();
00134 
00135     Graph* activeLayer(){return active_graph;};
00136     void setActiveLayer(Graph* g);
00137     void activateGraph(LayerButton* button);
00138 
00140     Graph* layerAt(const QPoint& pos);
00141     void setGraphGeometry(int x, int y, int w, int h);
00142 
00143     void findBestLayout(int &rows, int &cols);
00144 
00145     QSize arrangeLayers(bool userSize);
00146     bool arrangeLayers(bool fit, bool userSize);
00147     bool swapLayers(int src, int dest);
00148     void adjustSize();
00149     void updateLayersLayout(Graph *);
00150 
00151     int getRows(){return d_rows;};
00152     void setRows(int r);
00153 
00154     int getCols(){return d_cols;};
00155     void setCols(int c);
00156 
00157     int colsSpacing(){return colsSpace;};
00158     int rowsSpacing(){return rowsSpace;};
00159     void setSpacing (int rgap, int cgap);
00160 
00161     int leftMargin(){return left_margin;};
00162     int rightMargin(){return right_margin;};
00163     int topMargin(){return top_margin;};
00164     int bottomMargin(){return bottom_margin;};
00165     void setMargins (int lm, int rm, int tm, int bm);
00166 
00167     QSize layerCanvasSize(){return QSize(l_canvas_width, l_canvas_height);};
00168     void setLayerCanvasSize (int w, int h);
00169 
00170     int horizontalAlignement(){return hor_align;};
00171     int verticalAlignement(){return vert_align;};
00172     void setAlignement (int ha, int va);
00173 
00175 
00176     QPixmap canvasPixmap(const QSize& size = QSize(), double scaleFontsFactor = 1.0, bool transparent = false);
00177     void exportToFile(const QString& fileName);
00178     void exportImage(QTextDocument *document, int quality = 100, bool transparent = false,
00179         int dpi = 0, const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00180     void exportImage(const QString& fileName, int quality = 100, bool transparent = false,
00181         int dpi = 0, const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00182     void exportSVG(const QString& fname, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00183     void exportPDF(const QString& fname);
00184     void exportVector(const QString& fileName, int res = 0, bool color = true,
00185         const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00186 
00187     void draw(QPaintDevice *, const QSizeF& customSize, int unit, int res, double fontsFactor = 1.0);
00188 
00189 #ifdef EMF_OUTPUT
00190     void exportEMF(const QString& fname, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00191 #endif
00192     void exportTeX(const QString& fname, bool color = true, bool escapeStrings = true, bool fontSizes = true,
00193                     const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0);
00194 
00195     void copyAllLayers();
00196     void print();
00197     void print(QPrinter *);
00198     void printAllLayers(QPainter *painter);
00199     void printActiveLayer();
00201 
00202     void setFonts(const QFont& titleFnt, const QFont& scaleFnt,
00203                             const QFont& numbersFnt, const QFont& legendFnt);
00204 
00205     void connectLayer(Graph *g);
00206 
00207     void save(const QString& fn, const QString& geometry, bool = false);
00208 
00209     bool hasSelectedLayers();
00210 
00212 
00213     void showWaterfallOffsetDialog();
00214     void reverseWaterfallOrder();
00215     void showWaterfallFillDialog();
00216     void setWaterfallFillColor(const QColor&);
00217     void updateWaterfallFill(bool on);
00218     void setWaterfallSideLines(bool on = true);
00219     void changeWaterfallXOffset(int);
00220     void changeWaterfallYOffset(int);
00221     void updateWaterfallLayout();
00222     void updateWaterfallScales(Graph *g, int axis);
00224 
00225     void updateLayerAxes(Graph *g, int axis);
00226 
00227 signals:
00228     void showEnrichementDialog();
00229     void showCurvesDialog();
00230     void drawLineEnded(bool);
00231     void showMarkerPopupMenu();
00232     void modifiedPlot();
00233     void cursorInfo(const QString&);
00234     void showLineDialog();
00235     void pasteMarker();
00236     void setPointerCursor();
00237     void currentFontChanged(const QFont&);
00238 
00239 private:
00241 
00242     void dropEvent(QDropEvent*);
00243     void dragEnterEvent(QDragEnterEvent*);
00244     void wheelEvent(QWheelEvent *);
00245     void keyPressEvent(QKeyEvent *);
00246     bool eventFilter(QObject *object, QEvent *);
00247     void releaseLayer();
00248     void resizeLayers(QResizeEvent *);
00250 
00251     LayerButton* addLayerButton();
00252 
00253     Graph* active_graph;
00255     int d_cols, d_rows, graph_width, graph_height, colsSpace, rowsSpace;
00256     int left_margin, right_margin, top_margin, bottom_margin;
00257     int l_canvas_width, l_canvas_height, hor_align, vert_align;
00258     bool d_scale_on_print, d_print_cropmarks;
00260     bool d_scale_layers;
00261 
00262     QList<LayerButton *> buttonsList;
00263     QList<Graph *> graphsList;
00264     QHBoxLayout *layerButtonsBox, *waterfallBox, *toolbuttonsBox;
00265     QWidget *d_canvas;
00266 
00267     QPointer<SelectionMoveResizer> d_layers_selector;
00268 
00269     int d_waterfall_offset_x, d_waterfall_offset_y;
00270     bool d_is_waterfall_plot;
00272     bool d_side_lines;
00273     QColor d_waterfall_fill_color;
00274 
00275     QPushButton *d_add_layer_btn, *d_remove_layer_btn;
00276 
00277     QSize d_canvas_size;
00278 
00279     AlignPolicy d_align_policy;
00280     SizePolicy d_size_policy;
00281     bool d_link_x_axes;
00282     bool d_common_axes_layout;
00283 };
00284 
00286 class LayerButton: public QPushButton
00287 {
00288     Q_OBJECT
00289 
00290 public:
00291     LayerButton (const QString& text = QString::null, QWidget* parent = 0);
00292     static int btnSize(){return 20;};
00293 
00294 protected:
00295     void mousePressEvent( QMouseEvent * );
00296     void mouseDoubleClickEvent ( QMouseEvent * );
00297 
00298 signals:
00299     void showCurvesDialog();
00300     void clicked(LayerButton*);
00301 };
00302 
00303 #endif