QtiPlot 0.9.8.2
|
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 = true){d_common_axes_layout = on;}; 00126 00127 void deselect(); 00128 bool hasSelectedLayers(); 00129 bool isLayerSelected(Graph*); 00130 00131 public slots: 00132 Graph* addLayer(int x = 0, int y = 0, int width = 0, int height = 0, bool = false); 00133 00134 bool isEmpty(); 00135 bool removeLayer(Graph *g); 00136 bool removeActiveLayer(); 00137 void confirmRemoveLayer(); 00138 00139 Graph* activeLayer(){return active_graph;}; 00140 void setActiveLayer(Graph* g); 00141 void activateGraph(LayerButton* button); 00142 void selectLayerCanvas(Graph* g); 00143 00145 Graph* layerAt(const QPoint& pos); 00146 void setGraphGeometry(int x, int y, int w, int h); 00147 00148 void findBestLayout(int &rows, int &cols); 00149 00150 QSize arrangeLayers(bool userSize); 00151 bool arrangeLayers(bool fit, bool userSize); 00152 bool swapLayers(int src, int dest); 00153 void adjustSize(); 00154 void updateLayersLayout(Graph *); 00155 00156 int getRows(){return d_rows;}; 00157 void setRows(int r); 00158 00159 int getCols(){return d_cols;}; 00160 void setCols(int c); 00161 00162 int colsSpacing(){return colsSpace;}; 00163 int rowsSpacing(){return rowsSpace;}; 00164 void setSpacing (int rgap, int cgap); 00165 00166 int leftMargin(){return left_margin;}; 00167 int rightMargin(){return right_margin;}; 00168 int topMargin(){return top_margin;}; 00169 int bottomMargin(){return bottom_margin;}; 00170 void setMargins (int lm, int rm, int tm, int bm); 00171 00172 QSize layerCanvasSize(){return QSize(l_canvas_width, l_canvas_height);}; 00173 void setLayerCanvasSize (int w, int h); 00174 00175 int horizontalAlignement(){return hor_align;}; 00176 int verticalAlignement(){return vert_align;}; 00177 void setAlignement (int ha, int va); 00178 00180 00181 QPixmap canvasPixmap(const QSize& size = QSize(), double scaleFontsFactor = 1.0, bool transparent = false); 00182 void exportToFile(const QString& fileName); 00183 #if QT_VERSION >= 0x040500 00184 void exportImage(QTextDocument *document, int quality = 100, bool transparent = false, 00185 int dpi = 0, const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00186 #endif 00187 void exportImage(const QString& fileName, int quality = 100, bool transparent = false, 00188 int dpi = 0, const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00189 void exportSVG(const QString& fname, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00190 void exportPDF(const QString& fname); 00191 void exportVector(const QString& fileName, int res = 0, bool color = true, 00192 const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00193 00194 void draw(QPaintDevice *, const QSizeF& customSize, int unit, int res, double fontsFactor = 1.0); 00195 00196 void exportEMF(const QString& fname, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00197 void exportTeX(const QString& fname, bool color = true, bool escapeStrings = true, bool fontSizes = true, 00198 const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00199 00200 void copyAllLayers(); 00201 void print(); 00202 void print(QPrinter *); 00203 void printAllLayers(QPainter *painter); 00204 void printActiveLayer(); 00206 00207 void setFonts(const QFont& titleFnt, const QFont& scaleFnt, 00208 const QFont& numbersFnt, const QFont& legendFnt); 00209 00210 void connectLayer(Graph *g); 00211 00212 void save(const QString& fn, const QString& geometry, bool = false); 00213 00215 00216 void showWaterfallOffsetDialog(); 00217 void reverseWaterfallOrder(); 00218 void showWaterfallFillDialog(); 00219 void setWaterfallFillColor(const QColor&); 00220 void updateWaterfallFill(bool on); 00221 void setWaterfallSideLines(bool on = true); 00222 void changeWaterfallXOffset(int); 00223 void changeWaterfallYOffset(int); 00224 void updateWaterfallLayout(); 00225 void updateWaterfallScales(Graph *g, int axis); 00227 00228 void updateLayerAxes(Graph *g, int axis); 00229 00230 signals: 00231 void showEnrichementDialog(); 00232 void showCurvesDialog(); 00233 void drawLineEnded(bool); 00234 void showMarkerPopupMenu(); 00235 void modifiedPlot(); 00236 void cursorInfo(const QString&); 00237 void showLineDialog(); 00238 void pasteMarker(); 00239 void setPointerCursor(); 00240 void currentFontChanged(const QFont&); 00241 void currentColorChanged(const QColor&); 00242 00243 private: 00245 00246 void mouseReleaseEvent(QMouseEvent *); 00247 void dropEvent(QDropEvent*); 00248 void dragEnterEvent(QDragEnterEvent*); 00249 void wheelEvent(QWheelEvent *); 00250 void keyPressEvent(QKeyEvent *); 00251 bool eventFilter(QObject *object, QEvent *); 00252 void releaseLayer(); 00253 void resizeLayers(QResizeEvent *); 00255 Graph* clickedLayer(Graph*); 00257 00258 LayerButton* addLayerButton(); 00259 00260 Graph* active_graph; 00262 int d_cols, d_rows, graph_width, graph_height, colsSpace, rowsSpace; 00263 int left_margin, right_margin, top_margin, bottom_margin; 00264 int l_canvas_width, l_canvas_height, hor_align, vert_align; 00265 bool d_scale_on_print, d_print_cropmarks; 00267 bool d_scale_layers; 00268 00269 QList<LayerButton *> buttonsList; 00270 QList<Graph *> graphsList; 00271 QHBoxLayout *layerButtonsBox, *waterfallBox, *toolbuttonsBox; 00272 QWidget *d_canvas; 00273 00274 QPointer<SelectionMoveResizer> d_layers_selector; 00275 00276 int d_waterfall_offset_x, d_waterfall_offset_y; 00277 bool d_is_waterfall_plot; 00279 bool d_side_lines; 00280 QColor d_waterfall_fill_color; 00281 00282 QPushButton *d_add_layer_btn, *d_remove_layer_btn; 00283 00284 QSize d_canvas_size; 00285 00286 AlignPolicy d_align_policy; 00287 SizePolicy d_size_policy; 00288 bool d_link_x_axes; 00289 bool d_common_axes_layout; 00290 00291 QVector<QRectF> d_layer_coordinates; 00292 }; 00293 00295 class LayerButton: public QPushButton 00296 { 00297 Q_OBJECT 00298 00299 public: 00300 LayerButton (const QString& text = QString::null, QWidget* parent = 0); 00301 static int btnSize(){return 20;}; 00302 00303 protected: 00304 void mousePressEvent( QMouseEvent * ); 00305 void mouseDoubleClickEvent ( QMouseEvent * ); 00306 00307 signals: 00308 void showCurvesDialog(); 00309 void clicked(LayerButton*); 00310 void showLayerContextMenu(); 00311 }; 00312 00313 #endif