1 //========================================================= 2 // MusE 3 // Linux Music Editor 4 // $Id: scldraw.h,v 1.1.1.1 2003/10/27 18:55:08 wschweer Exp $ 5 // 6 // Copyright (C) 1997 Josef Wilgen 7 // (C) Copyright 2000 Werner Schweer (ws@seh.de) 8 // (C) Copyright 2016 Tim E. Real (terminator356 on sourceforge) 9 // 10 // This program is free software; you can redistribute it and/or 11 // modify it under the terms of the GNU General Public License 12 // as published by the Free Software Foundation; version 2 of 13 // the License, or (at your option) any later version. 14 // 15 // This program is distributed in the hope that it will be useful, 16 // but WITHOUT ANY WARRANTY; without even the implied warranty of 17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 // GNU General Public License for more details. 19 // 20 // You should have received a copy of the GNU General Public License 21 // along with this program; if not, write to the Free Software 22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 23 // 24 //========================================================= 25 26 #ifndef __SCLDRAW_H__ 27 #define __SCLDRAW_H__ 28 29 #include <QString> 30 #include <QRect> 31 32 #include "dimap.h" 33 #include "scldiv.h" 34 35 class QPalette; 36 class QFontMetrics; 37 class QPainter; 38 39 namespace MusEGui { 40 41 class ScaleDraw : public DiMap { 42 public: 43 enum OrientationX { Bottom, Top, Left, Right, InsideHorizontal, InsideVertical, Round }; 44 enum TextHighlightMode { TextHighlightNone, 45 TextHighlightAlways, 46 TextHighlightSplit, 47 TextHighlightShadow, 48 TextHighlightSplitAndShadow }; 49 50 private: 51 ScaleDiv d_scldiv; 52 static const int minLen; 53 OrientationX d_orient; 54 TextHighlightMode d_textHighlightMode; 55 QString _specialText; // Text to show if value = min 56 57 int d_xorg; 58 int d_yorg; 59 int d_len; 60 61 int d_hpad; 62 int d_vpad; 63 64 int d_medLen; 65 int d_majLen; 66 int d_minLen; 67 68 int d_minAngle; 69 int d_maxAngle; 70 71 double d_xCenter; 72 double d_yCenter; 73 double d_radius; 74 75 char d_fmt; 76 int d_prec; 77 78 bool d_drawBackBone; 79 80 // Like QString::number except it allows special 'M' format (Metric suffix G, M, K). 81 QString composeLabelText(double val, char fmt, int prec) const; 82 83 void drawTick(QPainter *p, const QPalette& palette, double curValue, double val, int len) const; 84 void drawBackbone(QPainter *p, const QPalette& palette, double curValue) const; 85 void drawLabel(QPainter *p, const QPalette& palette, double curValue, double val, bool isSpecialText = false) const; 86 87 public: 88 89 ScaleDraw(); 90 91 void setScale(const ScaleDiv &s); 92 void setScale(double vmin, double vmax, int maxMajIntv, int maxMinIntv, 93 double step = 0.0, int logarithmic = 0); 94 void setGeometry(int xorigin, int yorigin, int length, OrientationX o); 95 void setAngleRange(double angle1, double angle2); 96 // Special 'M' format (Metric suffix G, M, K) supported. 97 void setLabelFormat(char f, int prec); setBackBone(bool v)98 void setBackBone(bool v) { d_drawBackBone = v; } 99 scaleDiv()100 const ScaleDiv& scaleDiv() const { return d_scldiv; } orientation()101 OrientationX orientation() const { return d_orient; } textHighlightMode()102 TextHighlightMode textHighlightMode() const { return d_textHighlightMode; } setTextHighlightMode(TextHighlightMode mode)103 void setTextHighlightMode(TextHighlightMode mode) { d_textHighlightMode = mode; } specialText()104 QString specialText() const { return _specialText; } setSpecialText(const QString & s)105 void setSpecialText(const QString& s) { _specialText = s; } 106 107 QRect maxBoundingRect(const QFontMetrics& fm) const; 108 int maxWidth(const QFontMetrics& fm, bool worst = true, int penWidth = 1) const; 109 int maxHeight(const QFontMetrics& fm, int penWidth = 1) const; 110 int maxLabelWidth(const QFontMetrics& fm, bool worst = true) const; 111 int scaleWidth(int penWidth = 1) const; 112 113 void draw(QPainter *p, const QPalette& palette, double curValue = 0.0); // const; 114 }; 115 116 } // namespace MusEGui 117 118 #endif 119 120