1 //========================================================= 2 // MusE 3 // Linux Music Editor 4 // $Id: slider.h,v 1.3.2.2 2008/01/19 13:33:47 wschweer Exp $ 5 // 6 // Copyright (C) 1997 Josef Wilgen 7 // (C) Copyright 1999 Werner Schweer (ws@seh.de) 8 // (C) Copyright 2011 Orcan Ogetbil (ogetbilo at sf.net) 9 // (C) Copyright 2015-2016 Tim E. Real (terminator356 on sourceforge) 10 // 11 // This program is free software; you can redistribute it and/or 12 // modify it under the terms of the GNU General Public License 13 // as published by the Free Software Foundation; version 2 of 14 // the License, or (at your option) any later version. 15 // 16 // This program is distributed in the hope that it will be useful, 17 // but WITHOUT ANY WARRANTY; without even the implied warranty of 18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 // GNU General Public License for more details. 20 // 21 // You should have received a copy of the GNU General Public License 22 // along with this program; if not, write to the Free Software 23 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 24 // 25 //========================================================= 26 27 #ifndef __SLIDER_H__ 28 #define __SLIDER_H__ 29 30 #include <QWidget> 31 #include <QPainter> 32 #include <QPaintEvent> 33 #include <QString> 34 #include <QResizeEvent> 35 #include <QSize> 36 #include <QPoint> 37 #include <QColor> 38 #include <QRect> 39 #include <QBrush> 40 #include <QFont> 41 42 #include "sclif.h" 43 #include "sliderbase.h" 44 #include "scldraw.h" 45 46 namespace MusEGui { 47 48 //--------------------------------------------------------- 49 // Slider 50 //--------------------------------------------------------- 51 52 class Slider : public SliderBase, public ScaleIf 53 { 54 Q_OBJECT 55 Q_PROPERTY( double lineStep READ lineStep WRITE setLineStep ) 56 Q_PROPERTY( double pageStep READ pageStep WRITE setPageStep ) 57 Q_PROPERTY( Qt::Orientation orientation READ orientation WRITE setOrientation ) 58 59 public: 60 enum ScalePos { None, Left, Right, Top, Bottom, InsideHorizontal, InsideVertical }; 61 62 private: 63 Qt::Orientation d_orient; 64 ScalePos d_scalePos; 65 66 int d_grooveWidth; 67 QColor d_fillColor; 68 QColor d_handleColor; 69 bool d_fillThumb; 70 bool d_fillEmptySide; 71 bool d_frame; 72 QColor d_frameColor; 73 74 int d_radius; 75 int d_radiusHandle; 76 bool d_useGradient; 77 78 QRect d_sliderRect; 79 80 int d_thumbLength; 81 int d_thumbHalf; 82 int d_thumbWidth; 83 int d_scaleDist; 84 int d_xMargin; 85 int d_yMargin; 86 int d_mMargin; 87 88 bool d_autoResize; 89 double d_scaleStep; 90 91 int d_bgStyle; 92 int markerPos; 93 94 uint vertical_hint; 95 uint horizontal_hint; 96 97 void drawHsBgSlot(QPainter *, const QRect&, const QRect&,const QBrush&); 98 void drawVsBgSlot(QPainter *, const QRect&, const QRect&,const QBrush&); 99 100 protected: 101 virtual void drawThumb (QPainter *p, const QRect &r); 102 virtual void drawSlider (QPainter *p, const QRect &r); 103 104 // Determine the value corresponding to a specified mouse location. 105 // If borderless mouse is enabled p is a delta value not absolute, so can be negative. 106 double getValue(const QPoint &p); 107 // Determine the value corresponding to a specified mouse movement. 108 double moveValue(const QPoint& /*deltaP*/, bool /*fineMode*/ = false); 109 // Determine scrolling mode and direction. 110 void getScrollMode( QPoint &p, const Qt::MouseButton &button, const Qt::KeyboardModifiers& modifiers, int &scrollMode, int &direction); 111 112 // Setup all slider and scale rectangles. 113 void adjustSize(const QSize& s); 114 // Adjust scale so marks are not too close together. 115 void adjustScale(); 116 117 virtual void resizeEvent(QResizeEvent *e); 118 virtual void paintEvent (QPaintEvent *e); 119 void valueChange(); 120 void rangeChange(); 121 void scaleChange(); 122 void fontChange(const QFont &oldFont); 123 124 public: 125 126 Slider(QWidget *parent, const char *name = 0, 127 Qt::Orientation orient = Qt::Vertical, 128 ScalePos scalePos = None, 129 int grooveWidth = 8, 130 QColor fillColor = QColor(), 131 ScaleDraw::TextHighlightMode textHighlightMode = ScaleDraw::TextHighlightNone, 132 QColor handleColor = QColor()); 133 134 ~Slider(); 135 void setThumbLength(int l); 136 void setThumbWidth(int w); 137 138 void setOrientation(Qt::Orientation o); 139 Qt::Orientation orientation() const; 140 141 int scaleEndpointsMargin() const; 142 143 void setScale (double vmin, double vmax, int logarithmic = 0); 144 void setScale (double vmin, double vmax, double step, int logarithmic = 0); 145 void setScale(const ScaleDiv &s); 146 void setScaleMaxMajor( int ticks); 147 void setScaleMaxMinor( int ticks); 148 void setScaleBackBone(bool v); 149 150 double lineStep() const; 151 double pageStep() const; 152 153 void setLineStep(double); 154 void setPageStep(double); 155 156 void setMargins(int x, int y); grooveWidth()157 int grooveWidth() const { return d_grooveWidth; } setGrooveWidth(int w)158 void setGrooveWidth(int w) { d_grooveWidth = w; } 159 160 // QColor fillColor() const { return d_fillColor; } setFillColor(const QColor & color)161 void setFillColor(const QColor& color) { d_fillColor = color; update(); } setHandleColor(const QColor & color)162 void setHandleColor(const QColor& color) { d_handleColor = color; update(); } 163 fillThumb()164 bool fillThumb() const { return d_fillThumb; } setFillThumb(bool v)165 void setFillThumb(bool v) { d_fillThumb = v; } 166 fillEmptySide()167 bool fillEmptySide() const { return d_fillEmptySide; } setFillEmptySide(bool v)168 void setFillEmptySide(bool v) { d_fillEmptySide = v; } 169 170 virtual QSize sizeHint() const; 171 void setSizeHint(uint w, uint h); 172 setRadius(int r)173 void setRadius(int r) { d_radius = r; } setRadiusHandle(int r)174 void setRadiusHandle(int r) { d_radiusHandle = r; } setHandleHeight(int h)175 void setHandleHeight(int h) { d_thumbLength = h; } setHandleWidth(int w)176 void setHandleWidth(int w) { d_thumbWidth = w; d_thumbHalf = d_thumbLength / 2; } setUseGradient(bool b)177 void setUseGradient(bool b) { d_useGradient = b; } setScalePos(ScalePos s)178 void setScalePos(ScalePos s) { d_scalePos = s; } setFrame(bool b)179 void setFrame(bool b) { d_frame = b; } setFrameColor(QColor c)180 void setFrameColor(QColor c) { d_frameColor = c; } 181 }; 182 183 } // namespace MusEGui 184 185 #endif 186