⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qt_widget.h

📁 很多二维 三维几何计算算法 C++ 类库
💻 H
📖 第 1 页 / 共 2 页
字号:
// Copyright (c) 2002-2004  INRIA Sophia-Antipolis (France).// All rights reserved.//// This file is part of CGAL (www.cgal.org); you can redistribute it and/or// modify it under the terms of the GNU Lesser General Public License as// published by the Free Software Foundation; version 2.1 of the License.// See the file LICENSE.LGPL distributed with CGAL.//// Licensees holding a valid commercial license may use this file in// accordance with the commercial license agreement provided with the software.//// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.//// $URL: svn+ssh://scm.gforge.inria.fr/svn/cgal/branches/CGAL-3.3-branch/Qt_widget/include/CGAL/IO/Qt_widget.h $// $Id: Qt_widget.h 36699 2007-02-28 17:43:49Z fcacciola $// //// Author(s)     : Laurent Rineau#ifndef CGAL_QT_WIDGET_H#define CGAL_QT_WIDGET_H#include <CGAL/basic.h>#include <CGAL/Simple_cartesian.h>#include <CGAL/intersections.h>//temporary, should remove next line!!#include <CGAL/Triangle_2_Iso_rectangle_2_intersection.h>#include <CGAL/IO/Color.h>#include <vector>#include <list>#include <map>#include <cmath>#include <qwidget.h>#include <qpainter.h>#include <qcolor.h>#include <qpixmap.h>#include <qprinter.h>#include <CGAL/auto_link/CGALQt.h>namespace CGAL {class Qt_widget_layer;enum PointStyle { PIXEL, CROSS, PLUS, CIRCLE, DISC, RECT, BOX };class Qt_widget : public QWidget {  Q_OBJECTpublic:  // constructor  Qt_widget(QWidget *parent = 0, const char *name = 0);  // destructor  ~Qt_widget() {};  // initialization of coordinates system  void set_window(const double x_min,		  const double x_max, 		  const double y_min, 		  const double y_max,		  bool const_ranges = false);  void zoom(double ratio);  void zoom(double ratio, double xc, double yc);  void set_x_scale(const double xscale){ xscal = xscale; }  void set_y_scale(const double yscale){ yscal = yscale; }  void move_center(const double distx, const double disty);  void set_center(const double x, const double y);  // painting system  inline QPainter& get_painter() { return (*painter); };  inline QPixmap& get_pixmap() { return (*pixmap); };  inline QWMatrix& get_matrix() { return (*matrix); };  void lock() { ++Locked; };  void unlock() { if (Locked>0) --Locked; do_paint(); };  void do_paint() { if (Locked==0) repaint(FALSE); };  virtual QSize sizeHint() const {return QSize(geometry().width(),					geometry().height());}     // properties  // ~~~~~~~~~~  // color  QColor color() const;  void setColor(const QColor c);  // backGroundColor  QColor backgroundColor() const;  void setBackgroundColor(const QColor& c);  // fillColor  QColor fillColor() const;  void setFillColor(const QColor c);  // isFilled  bool isFilled() const;  void setFilled(const bool f);  // lineWidth  uint lineWidth() const;  void setLineWidth(const uint i);  // pointSize  uint pointSize() const;  void setPointSize(const uint i);  // pointStyle  typedef CGAL::PointStyle PointStyle;  PointStyle pointStyle() const;  void setPointStyle(const PointStyle s);  // rasterOp  RasterOp rasterOp() {return painter->rasterOp();}  void setRasterOp(const RasterOp r) {painter->setRasterOp(r);}  // CGAL version of setFooColor  // used by the manipulators system  // DO NOT USE THESE THREE UNDOCUMENTED FUNCTIONS !!  inline void setColor(const Color c)    { setColor(CGAL2Qt_Color(c)); };  inline void setBackgroundColor(const Color c)    { setBackgroundColor(CGAL2Qt_Color(c)); };  inline void setFillColor(const Color c)    { setFillColor(CGAL2Qt_Color(c)); };  // set pen() color to c, cf. manipulators below for setting  // backgroundColor and fillColor  Qt_widget& operator<<(const Color& c);  // set point style  Qt_widget& operator<<(const PointStyle& ps);  // clear the Widget, fill it with backgroundColor()  void clear();  // coordinates system  // ~~~~~~~~~~~~~~~~~~  // real world coordinates  double x_real(int x) const;  double y_real(int y) const;  template <class FT>  void x_real(int, FT&) const;  template <class FT>  void y_real(int y, FT&) const;  double x_real_dist(double d) const;  double y_real_dist(double d) const;  // pixel coordinates  int x_pixel(double x) const;  int y_pixel(double y) const;  int x_pixel_dist(double d) const;  int y_pixel_dist(double d) const;  inline double x_min() const { return xmin; };  inline double y_min() const { return ymin; };  inline double x_max() const { return xmax; };  inline double y_max() const { return ymax; };  inline double x_scal() { return xscal; }  inline double y_scal() { return yscal; }  void new_object(CGAL::Object obj) { emit(new_cgal_object(obj)); };    //layers    void attach(Qt_widget_layer *layer);      // remove a layer from the list of displayable scenes  void detach(Qt_widget_layer* s);signals:  void s_mousePressEvent(QMouseEvent *e);  void s_mouseReleaseEvent(QMouseEvent *e);  void s_mouseMoveEvent(QMouseEvent *e);  void s_paintEvent(QPaintEvent *e);  void s_resizeEvent(QResizeEvent *e);  void s_wheelEvent(QWheelEvent *e);  void s_mouseDoubleClickEvent(QMouseEvent *e);  void s_keyPressEvent(QKeyEvent *e);  void s_keyReleaseEvent(QKeyEvent *e);  void s_enterEvent(QEvent *e);  void s_leaveEvent(QEvent *e);  void s_event(QEvent *e);    void custom_redraw(); //deprecated:  if user want to draw something                        //after layers replaced by redraw_on_front  void redraw_on_front(); //called by redraw at the end  void redraw_on_back();  //called by redraw at the beginning  void new_cgal_object(CGAL::Object);	//this signal is emited every time an					//attached tool constructed an object  void rangesChanged();   // triggered when ranges (xmin, xmax, ymin,...) are changedpublic slots:  void print_to_ps();  virtual void redraw();// backward-compatibility with CGAL-2.4, back() and forth() are// deprecated, as well as add_to_history() or clear_history().signals:  void internal_back();  void internal_forth();  void internal_add_to_history();  void internal_clear_history();public slots:  bool back() { emit(internal_back()); return true; }  bool forth() { emit(internal_forth()); return true; }public:  void add_to_history() { emit(internal_add_to_history()); }  void clear_history() { emit(internal_clear_history()); }protected:  void paintEvent(QPaintEvent *e);  void resizeEvent(QResizeEvent *e);  void showEvent(QShowEvent *e);  void mousePressEvent(QMouseEvent *e);  void mouseReleaseEvent(QMouseEvent *e);  void mouseMoveEvent(QMouseEvent *e);  void wheelEvent(QWheelEvent *e);  void mouseDoubleClickEvent(QMouseEvent *e);  void keyPressEvent(QKeyEvent *e);  void keyReleaseEvent(QKeyEvent *e);  void enterEvent(QEvent *e);  void leaveEvent(QEvent *e);  bool event(QEvent *e);private:  // private functions  // ~~~~~~~~~~~~~~~~~  void resize_pixmap();  // resize properly the pixmap size, saving then restoring the  // painter properties  void	  set_scales();   // set xscal and yscal. Update ranges if const_ranges is false.  // color types convertors  static QColor CGAL2Qt_Color(Color c);  static Color Qt2CGAL_color(QColor c);  void attach_standard(Qt_widget_layer *layer);  bool is_standard_active();  bool does_standard_eat_events();  friend class Qt_widget_standard_toolbar;  // private member datas  // ~~~~~~~~~~~~~~~~~~~~  bool    set_scales_to_be_done;  // this flag is set when the widget is not visible and should  // postpone the set_scales() call.  unsigned int Locked;  // point style and size  uint	      _pointSize;  PointStyle  _pointStyle;  QPixmap     *pixmap;	// the pixmap on which paints the painter  QPainter    *painter;	// the painter  QPrinter    *printer;	// the printer  QWMatrix    *matrix;  // the world matrix  QBrush      savedBrush; // saved brush, to be able to restore it on  // setFilled(true)  double    xmin, xmax, ymin, ymax; // real dimensions  double    xmin_old, xmax_old, ymin_old, ymax_old;            //backup ranges for resize  double    xscal, yscal; // scales int/double  bool      constranges; // tell if the ranges should be const  //for layers  std::list<Qt_widget_layer*>	qt_layers;  std::list<Qt_widget_layer*> qt_standard_layers;};//end Qt_widget class// manipulators// ~~~~~~~~~~~~// single manipulatorsinlineQt_widget& operator<<(Qt_widget& w, Qt_widget& (*m)(Qt_widget&)){  return m(w);};// w << noFill << ... stop the filling of geometrical objectinlineQt_widget& noFill(Qt_widget& w){  w.setFilled(false);  return w;}// manipulators with one argumenttemplate <class Param>struct Qt_widgetManip {  Qt_widget& (*f)(Qt_widget&, Param);  Param p;  Qt_widgetManip(Qt_widget& (*ff)(Qt_widget&, Param),		 Param pp) : f(ff), p(pp) {}};// usage: w << manip(Param) f ...template <class Param>Qt_widget& operator<<(Qt_widget& w, Qt_widgetManip<Param> m){  return m.f(w, m.p);}#define CGAL_QTWIDGET_MANIP(param,function) \inline \Qt_widget& __Qt_widgetManip##function##Aux (Qt_widget& w, param p) \{ w.set##function(p); return w; } \inline \Qt_widgetManip<param> function(param p) \{ return Qt_widgetManip<param>( __Qt_widgetManip##function##Aux, p); }// w << BackgroundColor(c) << ... sets the background colorCGAL_QTWIDGET_MANIP( Color, BackgroundColor )// w << FillColor(c) << ... sets the fill colorCGAL_QTWIDGET_MANIP( Color, FillColor )// w << LineWidth(i) << ... sets lines widthCGAL_QTWIDGET_MANIP( unsigned int, LineWidth )// w << PointSize(i) << ... sets points sizeCGAL_QTWIDGET_MANIP( unsigned int, PointSize )// color types convertors// ~~~~~~~~~~~~~~~~~~~~~~inlineQColor Qt_widget::CGAL2Qt_Color(Color c){  return QColor(c.red(), c.green(), c.blue());}inlineColor Qt_widget::Qt2CGAL_color(QColor c){  return Color(c.red(),c.green(),c.blue());}// properties// ~~~~~~~~~~inlineQColor Qt_widget::color() const{  return painter->pen().color();};inlinevoid Qt_widget::setColor(const QColor c){  QPen p=get_painter().pen();  p.setColor(c);  get_painter().setPen(p);}inlineQColor Qt_widget::backgroundColor() const{  return painter->backgroundColor();}inlinevoid Qt_widget::setBackgroundColor(const QColor& c){  QWidget::setPaletteBackgroundColor(c);  get_painter().setBackgroundColor(c);  clear();}inlineQColor Qt_widget::fillColor() const{  return painter->brush().color();}inlinevoid Qt_widget::setFillColor(const QColor c){  setFilled(true);  get_painter().setBrush(c);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -