1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
154
touch_widgets/touchbutton.h
Normal file
154
touch_widgets/touchbutton.h
Normal file
@@ -0,0 +1,154 @@
|
||||
#ifndef TOUCHBUTTON_H
|
||||
#define TOUCHBUTTON_H
|
||||
|
||||
#include <QToolButton>
|
||||
#include <QFrame>
|
||||
#include <QMouseEvent>
|
||||
#include <QPropertyAnimation>
|
||||
#include <QDebug>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
class TouchButton: public QToolButton
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_ENUMS(State)
|
||||
Q_PROPERTY(QColor downColor READ downColor WRITE setDownColor)
|
||||
Q_PROPERTY(QColor upColor READ upColor WRITE setUpColor)
|
||||
Q_PROPERTY(QColor grayColor READ grayColor WRITE setGrayColor)
|
||||
Q_PROPERTY(QColor yesColor READ yesColor WRITE setYesColor)
|
||||
Q_PROPERTY(QColor noColor READ noColor WRITE setNoColor)
|
||||
Q_PROPERTY(QColor currentColor READ currentColor WRITE setCurrentColor DESIGNABLE false)
|
||||
Q_PROPERTY(State state READ state WRITE setState)
|
||||
Q_PROPERTY(bool autoGray READ autoGray WRITE setAutoGray)
|
||||
Q_PROPERTY(bool animated READ animated WRITE setAnimated)
|
||||
Q_PROPERTY(int animationDuration READ animationDuration WRITE setAnimationDuration)
|
||||
Q_PROPERTY(QEasingCurve::Type animationCurve READ animationCurve WRITE setAnimationCurve)
|
||||
Q_PROPERTY(int blinkDelay READ blinkDelay WRITE setBlinkDelay)
|
||||
Q_PROPERTY(int clickID READ clickID WRITE setClickID)
|
||||
Q_PROPERTY(int yesID READ yesID WRITE setYesID)
|
||||
Q_PROPERTY(int noID READ noID WRITE setNoID)
|
||||
|
||||
public:
|
||||
explicit TouchButton(QWidget * parent = 0);
|
||||
TouchButton(int id, const QString & text = QString());
|
||||
~TouchButton();
|
||||
|
||||
enum State {Gray, Yes, No};
|
||||
|
||||
int clickID() const {return id_click;}
|
||||
int yesID() const {return id_yes;}
|
||||
int noID() const {return id_no;}
|
||||
|
||||
QColor downColor() const {return col_down;}
|
||||
QColor upColor() const {return col_up;}
|
||||
QColor grayColor() const {return col_gray;}
|
||||
QColor yesColor() const {return col_yes;}
|
||||
QColor noColor() const {return col_no;}
|
||||
QColor currentColor() const {return col_cur;}
|
||||
State state() const {return state_;}
|
||||
bool autoGray() const {return auto_gray;}
|
||||
bool animated() const {return anim;}
|
||||
int animationDuration() const {return animation.duration();}
|
||||
QEasingCurve::Type animationCurve() const {return animation.easingCurve().type();}
|
||||
int blinkDelay() const {return delay_blink;}
|
||||
|
||||
void blink(const QColor & tc);
|
||||
|
||||
private:
|
||||
void timerEvent(QTimerEvent * e);
|
||||
void mousePressEvent(QMouseEvent * e);
|
||||
void mouseReleaseEvent(QMouseEvent * e);
|
||||
|
||||
void init();
|
||||
void animateColor(const QColor & tc);
|
||||
void applyColor() {pal.setColor(QPalette::Button, col_cur); setPalette(pal);}
|
||||
void applyState(State s);
|
||||
|
||||
QPalette pal;
|
||||
QColor col_down, col_up, col_gray, col_yes, col_no, col_cur, col_dst, col_blink;
|
||||
QPropertyAnimation animation;
|
||||
State state_;
|
||||
int id_click, id_yes, id_no, delay_blink, timer;
|
||||
bool anim, auto_gray;
|
||||
|
||||
private slots:
|
||||
void _clicked() {emit clickedID(id_click);}
|
||||
void _toggled(bool on) {if (!on && auto_gray) setStateGray(); emit toggledID(id_click, on);}
|
||||
|
||||
public slots:
|
||||
void enable() {setEnabled(true);}
|
||||
void disable() {setStateGray(); setEnabled(false);}
|
||||
|
||||
void setClickID(int id) {id_click = id;}
|
||||
void setYesID(int id) {id_yes = id;}
|
||||
void setNoID(int id) {id_no = id;}
|
||||
|
||||
void setDownColor(const QColor & col) {col_down = col;}
|
||||
void setUpColor(const QColor & col) {col_up = col;}
|
||||
void setGrayColor(const QColor & col) {col_gray = col;}
|
||||
void setYesColor(const QColor & col) {col_yes = col;}
|
||||
void setNoColor(const QColor & col) {col_no = col;}
|
||||
|
||||
|
||||
void setState(State s);
|
||||
void setStateGray() {col_dst = col_gray; applyState(Gray); animateColor(col_dst);}
|
||||
void setStateYes() {col_dst = col_yes; applyState(Yes); animateColor(col_dst);}
|
||||
void setStateNo() {col_dst = col_no; applyState(No); animateColor(col_dst);}
|
||||
void setStateYesOrNo(bool yes) {if (yes) setStateYes(); else setStateNo();}
|
||||
void setStateYesOrGray(bool yes) {if (yes) setStateYes(); else setStateGray();}
|
||||
void setStateNoOrYes(bool no) {if (no) setStateNo(); else setStateYes();}
|
||||
void setStateNoOrGray(bool no) {if (no) setStateNo(); else setStateGray();}
|
||||
|
||||
void blinkYes() {blink(col_yes);}
|
||||
void blinkNo() {blink(col_no);}
|
||||
void blinkYesOrNo(bool yes) {blink(yes ? col_yes : col_no);}
|
||||
void blinkNoOrYes(bool no) {blink(no ? col_no : col_yes);}
|
||||
|
||||
|
||||
void enableID(int yes_id) {if (yes_id == id_yes) enable();}
|
||||
void disableID(int yes_id) {if (yes_id == id_yes) disable();}
|
||||
|
||||
void setStateID(int yes_id, State s) {if (yes_id == id_yes) setState(s);}
|
||||
void setStateGrayID(int yes_id) {if (yes_id == id_yes) setStateGray();}
|
||||
void setStateYesID(int yes_id) {if (yes_id == id_yes) setStateYes();}
|
||||
void setStateNoID(int no_id) {if (no_id == id_no) setStateNo();}
|
||||
void setStateYesOrNoID(int yes_id, bool yes) {if (yes_id == id_yes) setStateYesOrNo(yes);}
|
||||
void setStateYesOrGrayID(int yes_id, bool yes) {if (yes_id == id_yes) setStateYesOrGray(yes);}
|
||||
void setStateNoOrYesID(int no_id, bool no) {if (no_id == id_no) setStateNoOrYes(no);}
|
||||
void setStateNoOrGrayID(int no_id, bool no) {if (no_id == id_no) setStateNoOrGray(no);}
|
||||
|
||||
void blinkYesID(int yes_id) {if (yes_id == id_yes) blinkYes();}
|
||||
void blinkNoID(int no_id) {if (no_id == id_no) blinkNo();}
|
||||
void blinkYesOrNoID(int yes_id, bool yes) {if (yes_id == id_yes) blinkYesOrNo(yes);}
|
||||
void blinkNoOrYesID(int no_id, bool no) {if (no_id == id_no) blinkNoOrYes(no);}
|
||||
|
||||
|
||||
void setColor(const QColor & col) {col_dst = col; animateColor(col_dst);}
|
||||
void setCurrentColor(const QColor & col) {col_cur = col; applyColor();}
|
||||
|
||||
void setAutoGray(bool yes) {auto_gray = yes;}
|
||||
void setAnimated(bool yes) {anim = yes;}
|
||||
void setAnimationDuration(int dur) {animation.setDuration(dur);}
|
||||
void setAnimationCurve(QEasingCurve::Type curve) {animation.setEasingCurve(QEasingCurve(curve));}
|
||||
void setBlinkDelay(int dur) {delay_blink = dur;}
|
||||
|
||||
void delayedClick() {QMetaObject::invokeMethod(this, "click", Qt::QueuedConnection);}
|
||||
void delayedToggle() {QMetaObject::invokeMethod(this, "toggle", Qt::QueuedConnection);}
|
||||
|
||||
void delayedClickID(int yes_id) {if (yes_id == id_yes) delayedClick();}
|
||||
void delayedToggleID(int yes_id) {if (yes_id == id_yes) delayedToggle();}
|
||||
|
||||
signals:
|
||||
void clickedID(int id);
|
||||
void pressedID(int id);
|
||||
void releasedID(int id);
|
||||
void toggledID(int id, bool on);
|
||||
void stateChanged(State state, State prev_state);
|
||||
void stateChangedID(int id, State state, State prev_state);
|
||||
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // TOUCHBUTTON_H
|
||||
Reference in New Issue
Block a user