casa
$Rev:20696$
|
00001 //# QPOptions.h: Qwt implementation of generic PlotOption classes. 00002 //# Copyright (C) 2008 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: $ 00027 #ifndef QPOPTIONS_QO_H_ 00028 #define QPOPTIONS_QO_H_ 00029 00030 #ifdef AIPS_HAS_QWT 00031 00032 #include <graphics/GenericPlotter/PlotOperation.h> 00033 #include <graphics/GenericPlotter/PlotOptions.h> 00034 00035 #include <QColor> 00036 #include <QFont> 00037 #include <QMutex> 00038 00039 #include <qwt_color_map.h> 00040 #include <qwt_plot.h> 00041 #include <qwt_symbol.h> 00042 00043 #include <casa/namespace.h> 00044 00045 namespace casa { 00046 00047 // Implementation of PlotColor for Qwt plotter, using QColor. 00048 class QPColor : public PlotColor { 00049 public: 00050 // Defaults to QColor::QColor(). 00051 QPColor(); 00052 00053 // Constructor for the given hex value or name. 00054 QPColor(const String& name); 00055 00056 // Constructor using a QColor. 00057 QPColor(const QColor& color); 00058 00059 // Copy constructor for generic PlotColor. 00060 // <group> 00061 QPColor(const PlotColor& color); 00062 QPColor(const PlotColorPtr color); 00063 // </group> 00064 00065 // Copy constructor. 00066 QPColor(const QPColor& color); 00067 00068 // Destructor. 00069 ~QPColor(); 00070 00071 00072 // Include overloaded methods. 00073 using PlotColor::operator=; 00074 00075 00076 // PlotColor Methods // 00077 00078 // Implements PlotColor::asHexadecimal(). 00079 String asHexadecimal() const; 00080 00081 // Implements PlotColor::asName(). 00082 String asName() const; 00083 00084 // Implements PlotColor::asHexadecimalOrName(). 00085 void setAsHexadecimalOrName(const String& str); 00086 00087 // Implements PlotColor::alpha(). 00088 double alpha() const; 00089 00090 // Implements PlotColor::setAlpha(). 00091 void setAlpha(double a); 00092 00093 00094 // QPColor Methods // 00095 00096 // Provides access to the underlying QColor. 00097 // <group> 00098 const QColor& asQColor() const; 00099 void setAsQColor(const QColor& color); 00100 // </group> 00101 00102 private: 00103 QColor m_color; // Color 00104 }; 00105 00106 00107 // Implementation of PlotFont for Qwt plotter, using QFont and QPColor. 00108 class QPFont : public PlotFont { 00109 public: 00110 // Defaults to QFont::QFont() and QPColor::QPColor(). 00111 QPFont(); 00112 00113 // Constructor that takes a QFont and QColor. 00114 QPFont(const QFont& font, const QColor& color); 00115 00116 // Copy constructor for generic PlotFont. 00117 // <group> 00118 QPFont(const PlotFont& font); 00119 QPFont(const PlotFontPtr font); 00120 // </group> 00121 00122 // Copy constructor. 00123 QPFont(const QPFont& font); 00124 00125 // Destructor. 00126 ~QPFont(); 00127 00128 00129 // Include overloaded methods. 00130 using PlotFont::operator=; 00131 using PlotFont::setColor; 00132 00133 00134 // PlotFont Methods // 00135 00136 // Implements PlotFont::pointSize(). 00137 double pointSize() const; 00138 00139 // Implements PlotFont::setPointSize(). 00140 void setPointSize(double size); 00141 00142 // Implements PlotFont::pixelSize(). 00143 int pixelSize() const; 00144 00145 // Implements PlotFont::setPixelSize(). 00146 void setPixelSize(int size); 00147 00148 // Implements PlotFont::fontFamily(). 00149 String fontFamily() const; 00150 00151 // Implements PlotFont::setFontFamily(). 00152 void setFontFamily(const String& font); 00153 00154 // Implements PlotFont::color(). 00155 PlotColorPtr color() const; 00156 00157 // Implements PlotFont::setColor(). 00158 void setColor(const PlotColor& color); 00159 00160 // Implements PlotFont::italics(). 00161 bool italics() const; 00162 00163 // Implements PlotFont::setItalics(). 00164 void setItalics(bool i = true); 00165 00166 // Implements PlotFont::bold(). 00167 bool bold() const; 00168 00169 // Implements PlotFont::setBold(). 00170 void setBold(bool b = true); 00171 00172 // Implements PlotFont::underline(). 00173 bool underline() const; 00174 00175 // Implements PlotFont::setUnderline(). 00176 void setUnderline(bool u = true); 00177 00178 00179 // QPFont Methods // 00180 00181 // Provides access to the underlying QFont. 00182 // <group> 00183 const QFont& asQFont() const; 00184 void setAsQFont(const QFont& font); 00185 // </group> 00186 00187 // Provides access to the underlying QColor through QPColor. 00188 // <group> 00189 const QColor& asQColor() const; 00190 void setAsQColor(const QColor& color); 00191 // </group> 00192 00193 private: 00194 QFont m_font; // Font 00195 QPColor m_color; // Color 00196 }; 00197 00198 00199 // Implementation of PlotLine for Qwt plotter, using QPen. 00200 class QPLine : public PlotLine { 00201 public: 00202 // Defaults to QPen::QPen(). 00203 QPLine(); 00204 00205 // Constructor that takes a QPen. 00206 QPLine(const QPen& pen); 00207 00208 // Copy constructor for generic PlotLine. 00209 // <group> 00210 QPLine(const PlotLine& copy); 00211 QPLine(const PlotLinePtr copy); 00212 // </group> 00213 00214 // Destructor. 00215 ~QPLine(); 00216 00217 00218 // Include overloaded methods. 00219 using PlotLine::operator=; 00220 using PlotLine::setColor; 00221 00222 00223 // PlotLine Methods // 00224 00225 // Implements PlotLine::width(). 00226 double width() const; 00227 00228 // Implements PlotLine::setWidth(). 00229 void setWidth(double width); 00230 00231 // Implements PlotLine::style(). 00232 Style style() const; 00233 00234 // Implements PlotLine::setStyle(). 00235 void setStyle(Style style); 00236 00237 // Implements PlotLine::color(). 00238 PlotColorPtr color() const; 00239 00240 // Implements PlotLine::setColor(). 00241 void setColor(const PlotColor& color); 00242 00243 00244 // QPLine Methods // 00245 00246 // Provides access to the underlying QPen. 00247 // <group> 00248 const QPen& asQPen() const; 00249 void setAsQPen(const QPen& pen); 00250 // </group> 00251 00252 private: 00253 QPen m_pen; // Pen 00254 QPColor m_color; // Color (for convenience) 00255 }; 00256 00257 00258 // Implementation of PlotAreaFill for Qwt plotter, using QBrush. 00259 class QPAreaFill : public PlotAreaFill { 00260 public: 00261 // Defaults to QBrush::QBrush(). 00262 QPAreaFill(); 00263 00264 // Constructor that takes a QBrush. 00265 QPAreaFill(const QBrush& brush); 00266 00267 // Copy constructor for generic PlotAreaFill. 00268 // <group> 00269 QPAreaFill(const PlotAreaFill& copy); 00270 QPAreaFill(const PlotAreaFillPtr copy); 00271 // </group> 00272 00273 // Destructor. 00274 ~QPAreaFill(); 00275 00276 00277 // Include overloaded methods. 00278 using PlotAreaFill::operator=; 00279 using PlotAreaFill::setColor; 00280 00281 00282 // PlotAreaFill Methods // 00283 00284 // Implements PlotAreaFill::color(). 00285 PlotColorPtr color() const; 00286 00287 // Implements PlotAreaFill::setColor(). 00288 void setColor(const PlotColor& color); 00289 00290 // Implements PlotAreaFill::pattern(). 00291 Pattern pattern() const; 00292 00293 // Implements PlotAreaFill::setPattern(). 00294 void setPattern(Pattern pattern); 00295 00296 00297 // QPAreaFill Methods // 00298 00299 // Provides access to the underlying QBrush. 00300 // <group> 00301 const QBrush& asQBrush() const; 00302 void setAsQBrush(const QBrush& brush); 00303 // </group> 00304 00305 private: 00306 QBrush m_brush; // Brush. 00307 QPColor m_color; // color (for convenience). 00308 }; 00309 00310 00311 // Implementation of QPSymbol for Qwt plotter, using QwtSymbol. 00312 class QPSymbol : public PlotSymbol, public QwtSymbol { 00313 public: 00314 // Defaults to QwtSymbol::QwtSymbol(). 00315 QPSymbol(); 00316 00317 // Copy constructor for QwtSymbol. 00318 QPSymbol(const QwtSymbol& s); 00319 00320 // Copy constructor for generic PlotSymbol. 00321 // <group> 00322 QPSymbol(const PlotSymbol& copy); 00323 QPSymbol(const PlotSymbolPtr copy); 00324 // </group> 00325 00326 // Destructor. 00327 ~QPSymbol(); 00328 00329 00330 // Include overloaded methods. 00331 using PlotSymbol::operator=; 00332 using PlotSymbol::setSize; 00333 using PlotSymbol::setAreaFill; 00334 using PlotSymbol::setLine; 00335 00336 00337 // PlotSymbol Methods // 00338 00339 // Implements PlotSymbol::size(). 00340 psize_t size() const; 00341 00342 // Implements PlotSymbol::setSize(). Note that the underlying QwtSymbol 00343 // only supports int sizes. 00344 void setSize(double width, double height, bool heightIsPixel = true); 00345 00346 // Implements PlotSymbol::heightIsPixel(). 00347 bool heightIsPixel() const; 00348 00349 // Implements PlotSymbol::setHeightIsPixel(). 00350 void setHeightIsPixel(bool pixel = true); 00351 00352 // Implements PlotSymbol::symbol(). 00353 Symbol symbol() const; 00354 00355 // Implements PlotSymbol::symbolChar(). 00356 char symbolChar() const; 00357 00358 // Implements PlotSymbol::symbolUChar(). 00359 unsigned short symbolUChar() const; 00360 00361 // Implements PlotSymbol::setSymbol(). 00362 // <group> 00363 void setSymbol(Symbol symbol); 00364 void setSymbol(char c); 00365 // </group> 00366 00367 // Implements PlotSymbol::setUSymbol(). 00368 void setUSymbol(unsigned short unicode); 00369 00370 // Implements PlotSymbol::line(). 00371 PlotLinePtr line() const; 00372 00373 // Implements PlotSymbol::setLine(). 00374 void setLine(const PlotLine& line); 00375 00376 // Implements PlotSymbol::areaFill(). 00377 PlotAreaFillPtr areaFill() const; 00378 00379 // Implements PlotSymbol::setAreaFill(). 00380 void setAreaFill(const PlotAreaFill& fill); 00381 00382 00383 // QwtSymbol Methods // 00384 00385 // Overrides QwtSymbol::draw(). Assumes pen and brush have been set 00386 // beforehand. 00387 void draw(QPainter* p, const QRect& r) const; 00388 00389 // Overrides QwtSymbol::clone(). 00390 QwtSymbol* clone() const; 00391 00392 00393 // QPSymbol Methods // 00394 00395 // Provides access to the underlying QPen and QBrush in a safe way, 00396 // since QPainter::drawPoint works differently than the other draw 00397 // methods. WARNING: the pixel pen is NOT updated if you call 00398 // QwtSymbol::setPen() AFTER a QPSymbol::setSymbol() or a 00399 // QPSymbol::setLine() or a QPSymbol::setAreaFill(). 00400 // <group> 00401 const QPen& drawPen() const; 00402 const QBrush& drawBrush() const; 00403 // </group> 00404 00405 private: 00406 Symbol m_style; // Style 00407 QChar m_char; // Character 00408 00409 bool m_heightIsPixel; // Flag for whether height is in pixels or points. 00410 00411 QPen m_pixelPen; // Pen used to draw pixels. 00412 QBrush m_pixelBrush; // Brush used to draw pixels (empty). 00413 00414 // Points to either QwtSymbol::pen() or the pixel pen. 00415 const QPen* m_drawPen; 00416 00417 // Points to either QwtSymbol::brush() or the pixel brush. 00418 const QBrush* m_drawBrush; 00419 }; 00420 00421 00422 // Implementation of PlotMutex for the qwt plotter. Very thin layer on top of 00423 // QMutex. 00424 class QPMutex : public PlotMutex { 00425 public: 00426 // Constructor. 00427 QPMutex(); 00428 00429 // Destructor. 00430 ~QPMutex(); 00431 00432 00433 // Implements PlotMutex::lock(). 00434 void lock(); 00435 00436 // Implements PlotMutex::unlock(). 00437 void unlock(); 00438 00439 // Implements PlotMutex::tryLock(). 00440 bool tryLock(); 00441 00442 private: 00443 // Mutex. 00444 QMutex m_mutex; 00445 }; 00446 00447 00448 // Class containing useful conversions between the generic plotting stuff and 00449 // the Qt/Qwt plotting stuff. 00450 class QPOptions { 00451 public: 00452 // Converts between Qwt's axis enum and CASA's. 00453 // <group> 00454 static QwtPlot::Axis axis(PlotAxis a); 00455 static PlotAxis axis(QwtPlot::Axis a); 00456 // </group> 00457 00458 // Converts between Qt's cursors and CASA's. 00459 // <group> 00460 static Qt::CursorShape cursor(PlotCursor c) { 00461 switch(c) { 00462 case NORMAL_CURSOR: return Qt::ArrowCursor; 00463 case HAND_OPEN: return Qt::OpenHandCursor; 00464 case HAND_CLOSED: return Qt::ClosedHandCursor; 00465 case CROSSHAIR: return Qt::CrossCursor; 00466 case WAIT: return Qt::WaitCursor; 00467 case TEXT: return Qt::IBeamCursor; 00468 00469 default: return Qt::ArrowCursor; 00470 } 00471 } 00472 static PlotCursor cursor(Qt::CursorShape c) { 00473 switch(c) { 00474 case Qt::ArrowCursor: return NORMAL_CURSOR; 00475 case Qt::OpenHandCursor: return HAND_OPEN; 00476 case Qt::ClosedHandCursor: return HAND_CLOSED; 00477 case Qt::CrossCursor: return CROSSHAIR; 00478 case Qt::WaitCursor: case Qt::BusyCursor: return WAIT; 00479 case Qt::IBeamCursor: return TEXT; 00480 00481 default: return NORMAL_CURSOR; 00482 } 00483 } 00484 // </group> 00485 00486 // Converts between Qt's line style and CASA's. 00487 // <group> 00488 static Qt::PenStyle linestyle(PlotLine::Style s) { 00489 switch(s) { 00490 // supported 00491 case PlotLine::SOLID: return Qt::SolidLine; 00492 case PlotLine::DASHED: return Qt::DashLine; 00493 case PlotLine::DOTTED: return Qt::DotLine; 00494 00495 // unsupported 00496 default: return Qt::NoPen; 00497 } 00498 } 00499 static PlotLine::Style linestyle(Qt::PenStyle s) { 00500 switch(s) { 00501 // supported 00502 case Qt::SolidLine: return PlotLine::SOLID; 00503 case Qt::DashLine: return PlotLine::DASHED; 00504 case Qt::DotLine: return PlotLine::DOTTED; 00505 00506 // unsupported 00507 default: return PlotLine::NOLINE; 00508 } 00509 } 00510 // </group> 00511 00512 // Converts between Qt's brush style and CASA's. 00513 // <group> 00514 static Qt::BrushStyle areapattern(PlotAreaFill::Pattern p) { 00515 switch(p) { 00516 // supported 00517 case PlotAreaFill::FILL: return Qt::SolidPattern; 00518 case PlotAreaFill::MESH1: return Qt::Dense2Pattern; 00519 case PlotAreaFill::MESH2: return Qt::Dense4Pattern; 00520 case PlotAreaFill::MESH3: return Qt::Dense6Pattern; 00521 00522 // unsupported 00523 default: return Qt::NoBrush; 00524 } 00525 } 00526 static PlotAreaFill::Pattern areapattern(Qt::BrushStyle p) { 00527 switch(p) { 00528 // supported 00529 case Qt::SolidPattern: return PlotAreaFill::FILL; 00530 case Qt::Dense1Pattern: case Qt::Dense2Pattern: 00531 return PlotAreaFill::MESH1; 00532 case Qt::Dense3Pattern: case Qt::Dense4Pattern: 00533 return PlotAreaFill::MESH2; 00534 case Qt::Dense5Pattern: case Qt::Dense6Pattern: case Qt::Dense7Pattern: 00535 return PlotAreaFill::MESH3; 00536 00537 // unsupported 00538 default: return PlotAreaFill::NOFILL; 00539 } 00540 } 00541 // </group> 00542 00543 // Converts between Qwt's symbol style and CASA's. 00544 // <group> 00545 static QwtSymbol::Style symbol(PlotSymbol::Symbol s) { 00546 switch(s) { 00547 // supported 00548 case PlotSymbol::AUTOSCALING: 00549 case PlotSymbol::CIRCLE: return QwtSymbol::Ellipse; 00550 case PlotSymbol::SQUARE: return QwtSymbol::Rect; 00551 case PlotSymbol::DIAMOND: return QwtSymbol::Diamond; 00552 00553 // unsupported 00554 default: return QwtSymbol::NoSymbol; 00555 } 00556 } 00557 static PlotSymbol::Symbol symbol(QwtSymbol::Style s) { 00558 switch(s) { 00559 // supported 00560 case QwtSymbol::Ellipse: return PlotSymbol::CIRCLE; 00561 case QwtSymbol::Rect: return PlotSymbol::SQUARE; 00562 case QwtSymbol::Diamond: return PlotSymbol::DIAMOND; 00563 00564 // unsupported 00565 default: return PlotSymbol::NOSYMBOL; 00566 } 00567 } 00568 // </group> 00569 00570 // Returns a string to be used in stylesheet css for the given style. 00571 static String cssLineStyle(PlotLine::Style style) { 00572 switch(style) { 00573 case PlotLine::SOLID: return "solid"; 00574 case PlotLine::DASHED: return "dashed"; 00575 case PlotLine::DOTTED: return "dotted"; 00576 00577 default: return ""; 00578 } 00579 } 00580 00581 // Rounds the given double to the nearest int. 00582 static int round(double d) { 00583 if(d >= 0) return (int)(d + 0.5); 00584 else return (int)(d - 0.5); 00585 } 00586 00587 // Returns color maps for standard CASA objects. 00588 // <group> 00589 static QwtLinearColorMap standardSpectrogramMap(); 00590 static QwtLinearColorMap standardRasterMap(); 00591 static QwtLinearColorMap rasterMap(const vector<double>& values); 00592 // </group> 00593 }; 00594 00595 } 00596 00597 #endif 00598 00599 #endif /*QPOPTIONS_QO_H_*/