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 00103 void setEqualSizedLayers(); 00104 00105 void plotProfiles(Matrix* m); 00106 00107 QHBoxLayout *toolBox(){return toolbuttonsBox;}; 00108 00109 AlignPolicy alignPolicy(){return d_align_policy;}; 00110 void setAlignPolicy(const AlignPolicy& policy){d_align_policy = policy;}; 00111 00112 SizePolicy sizePolicy(){return d_size_policy;}; 00113 void setSizePolicy(const SizePolicy& policy){d_size_policy = policy;}; 00114 00115 void setCommonLayerAxes(bool verticalAxis = true, bool horizontalAxis = true); 00116 void linkXLayerAxes(bool link = true); 00117 bool hasLinkedXLayerAxes(){return d_link_x_axes;}; 00118 bool hasCommonAxes(){return d_common_axes_layout;}; 00119 void setCommonAxesLayout(bool on = true){d_common_axes_layout = on;}; 00120 00121 void deselect(); 00122 bool hasSelectedLayers(); 00123 bool isLayerSelected(Graph*); 00124 00125 void adjustLayersToCanvasSize(); 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 void selectLayerCanvas(Graph* g); 00139 00141 Graph* layerAt(const QPoint& pos); 00142 void setGraphGeometry(int x, int y, int w, int h); 00143 00144 void findBestLayout(int &rows, int &cols); 00145 00146 QSize arrangeLayers(bool userSize); 00147 bool arrangeLayers(bool fit, bool userSize); 00148 bool swapLayers(int src, int dest); 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 #if QT_VERSION >= 0x040500 00179 void exportImage(QTextDocument *document, int quality = 100, bool transparent = false, 00180 int dpi = 0, const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00181 #endif 00182 void exportImage(const QString& fileName, int quality = 100, bool transparent = false, int dpi = 0, 00183 const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0, int compression = 0); 00184 void exportSVG(const QString& fname, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00185 void exportPDF(const QString& fname); 00186 void exportVector(const QString& fileName, int res = 0, bool color = true, 00187 const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00188 void exportVector(QPrinter *printer, int res = 0, bool color = true, 00189 const QSizeF& customSize = QSizeF (), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00190 00191 void draw(QPaintDevice *, const QSizeF& customSize, int unit, int res, double fontsFactor = 1.0); 00192 00193 void exportEMF(const QString& fname, const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00194 void exportTeX(const QString& fname, bool color = true, bool escapeStrings = true, bool fontSizes = true, 00195 const QSizeF& customSize = QSizeF(), int unit = FrameWidget::Pixel, double fontsFactor = 1.0); 00196 00197 void copyAllLayers(); 00198 void print(); 00199 void print(QPrinter *); 00200 void printAllLayers(QPainter *painter); 00201 void printActiveLayer(); 00203 00204 void setFonts(const QFont& titleFnt, const QFont& scaleFnt, 00205 const QFont& numbersFnt, const QFont& legendFnt); 00206 00207 void connectLayer(Graph *g); 00208 00209 void save(const QString& fn, const QString& geometry, bool = false); 00210 00212 00213 void showWaterfallOffsetDialog(); 00214 void reverseWaterfallOrder(); 00215 void showWaterfallFillDialog(); 00216 void updateWaterfalls(); 00217 bool isWaterfallPlot(){return d_is_waterfall_plot;} 00218 QColor waterfallFillColor(){return d_waterfall_fill_color;} 00219 void setWaterfallFillColor(const QColor& c); 00221 00222 void updateLayerAxes(Graph *g, int axis); 00223 00224 signals: 00225 void showEnrichementDialog(); 00226 void showCurvesDialog(); 00227 void drawLineEnded(bool); 00228 void showMarkerPopupMenu(); 00229 void modifiedPlot(); 00230 void cursorInfo(const QString&); 00231 void showLineDialog(); 00232 void pasteMarker(); 00233 void setPointerCursor(); 00234 void currentFontChanged(const QFont&); 00235 void currentColorChanged(const QColor&); 00236 00237 private: 00239 00240 void mouseReleaseEvent(QMouseEvent *); 00241 void showEvent(QShowEvent *); 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 Graph* clickedLayer(Graph*); 00252 00253 LayerButton* addLayerButton(); 00254 void createWaterfallBox(); 00255 00256 Graph* active_graph; 00258 int d_cols, d_rows, graph_width, graph_height, colsSpace, rowsSpace; 00259 int left_margin, right_margin, top_margin, bottom_margin; 00260 int l_canvas_width, l_canvas_height, hor_align, vert_align; 00261 bool d_scale_on_print, d_print_cropmarks; 00263 bool d_scale_layers; 00264 00265 QList<LayerButton *> buttonsList; 00266 QList<Graph *> graphsList; 00267 QHBoxLayout *layerButtonsBox, *waterfallBox, *toolbuttonsBox; 00268 QWidget *d_canvas; 00269 00270 QPointer<SelectionMoveResizer> d_layers_selector; 00271 00272 bool d_is_waterfall_plot; 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 QVector<QRectF> d_layer_coordinates; 00285 }; 00286 00288 class LayerButton: public QPushButton 00289 { 00290 Q_OBJECT 00291 00292 public: 00293 LayerButton (const QString& text = QString::null, QWidget* parent = 0); 00294 static int btnSize(){return 20;}; 00295 00296 protected: 00297 void mousePressEvent( QMouseEvent * ); 00298 void mouseDoubleClickEvent ( QMouseEvent * ); 00299 00300 signals: 00301 void showCurvesDialog(); 00302 void clicked(LayerButton*); 00303 void showLayerContextMenu(); 00304 }; 00305 00306 #endif