1 /************************************************************************ 2 * 3 * Copyright 2010 Jakob Leben (jakob.leben@gmail.com) 4 * 5 * This file is part of SuperCollider Qt GUI. 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * 20 ************************************************************************/ 21 22 #pragma once 23 24 #include "QcAbstractStepValue.h" 25 #include "../QcHelper.h" 26 #include "../style/style.hpp" 27 #include "image_painter.h" 28 29 #include <QWidget> 30 31 class QcSlider2D : public QWidget, QcHelper, QcAbstractStepValue, QtCollider::Style::Client { 32 Q_OBJECT 33 Q_PROPERTY(double xValue READ xValue WRITE setXValue) 34 Q_PROPERTY(double yValue READ yValue WRITE setYValue) 35 Q_PROPERTY(double shiftScale READ dummyFloat WRITE setShiftScale); 36 Q_PROPERTY(double ctrlScale READ dummyFloat WRITE setCtrlScale); 37 Q_PROPERTY(double altScale READ dummyFloat WRITE setAltScale); 38 Q_PROPERTY(double step READ dummyFloat WRITE setStep) 39 Q_PROPERTY(QColor grooveColor READ grooveColor WRITE setGrooveColor); 40 Q_PROPERTY(QColor focusColor READ focusColor WRITE setFocusColor); 41 Q_PROPERTY(QColor knobColor READ knobColor WRITE setKnobColor); 42 43 public: 44 QcSlider2D(); xValue()45 double xValue() const { return _x; } yValue()46 double yValue() const { return _y; } setXValue(double x)47 void setXValue(double x) { setValue(QPointF(x, _y), false); } setYValue(double y)48 void setYValue(double y) { setValue(QPointF(_x, y), false); } setStep(double f)49 void setStep(double f) { _step = f; } knobColor()50 const QColor& knobColor() const { 51 return _knobColor.isValid() ? _knobColor : palette().color(QPalette::ButtonText); 52 } setKnobColor(const QColor & c)53 void setKnobColor(const QColor& c) { 54 _knobColor = c; 55 update(); 56 } sizeHint()57 QSize sizeHint() const { return QSize(150, 150); } minimumSizeHint()58 QSize minimumSizeHint() const { return QSize(30, 30); } 59 60 Q_INVOKABLE 61 void setBackgroundImage(const QtCollider::SharedImage& image, const QRectF& rect, int tileMode, double opacity); 62 public Q_SLOTS: 63 void incrementX(double factor = 1.f); 64 void decrementX(double factor = 1.f); 65 void incrementY(double factor = 1.f); 66 void decrementY(double factor = 1.f); 67 Q_SIGNALS: 68 void action(); 69 void randomize(); 70 71 private: 72 QRect thumbRect(); 73 void setValue(const QPointF val, bool doAction = true); 74 void mouseMoveEvent(QMouseEvent*); 75 void mousePressEvent(QMouseEvent*); 76 void keyPressEvent(QKeyEvent*); 77 void paintEvent(QPaintEvent*); 78 79 double _x; 80 double _y; 81 QSize _thumbSize; 82 double _step; 83 84 QColor _knobColor; 85 QtCollider::ImagePainter _backgroundImage; 86 }; 87