git-svn-id: svn://db.shs.com.ru/libs@586 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
1
test/qad/touch_widgets/CMakeLists.txt
Normal file
1
test/qad/touch_widgets/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
qad_project(touch_widgets "Gui;Widgets" "")
|
||||
1
test/qad/touch_widgets/plugin/CMakeLists.txt
Normal file
1
test/qad/touch_widgets/plugin/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
qad_plugin(touch_widgets "Gui;Widgets" "")
|
||||
21
test/qad/touch_widgets/plugin/qad_touch_widgets.cpp
Normal file
21
test/qad/touch_widgets/plugin/qad_touch_widgets.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#include "qad_touch_widgets.h"
|
||||
#include "touchsliderplugin.h"
|
||||
#include "touchbuttframeplugin.h"
|
||||
#include "touchbuttonplugin.h"
|
||||
|
||||
|
||||
QADTouchWidgets::QADTouchWidgets(QObject * parent): QObject(parent) {
|
||||
m_widgets.append(new TouchSliderPlugin(this));
|
||||
m_widgets.append(new TouchButtFramePlugin(this));
|
||||
m_widgets.append(new TouchButtonPlugin(this));
|
||||
}
|
||||
|
||||
|
||||
QList<QDesignerCustomWidgetInterface*> QADTouchWidgets::customWidgets() const {
|
||||
return m_widgets;
|
||||
}
|
||||
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
Q_EXPORT_PLUGIN2(qad_touch_widgets_plugin, QADTouchWidgets)
|
||||
#endif
|
||||
23
test/qad/touch_widgets/plugin/qad_touch_widgets.h
Normal file
23
test/qad/touch_widgets/plugin/qad_touch_widgets.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef QAD_TOUCH_WIDGETS_H
|
||||
#define QAD_TOUCH_WIDGETS_H
|
||||
|
||||
#include <QtDesigner/QtDesigner>
|
||||
#include <QtCore/qplugin.h>
|
||||
|
||||
class QADTouchWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "qad.touch_widgets")
|
||||
#endif
|
||||
public:
|
||||
explicit QADTouchWidgets(QObject *parent = 0);
|
||||
virtual QList<QDesignerCustomWidgetInterface * > customWidgets() const;
|
||||
|
||||
private:
|
||||
QList<QDesignerCustomWidgetInterface * > m_widgets;
|
||||
|
||||
};
|
||||
|
||||
#endif // QAD_TOUCH_WIDGETS_H
|
||||
90
test/qad/touch_widgets/plugin/touchbuttframeplugin.cpp
Normal file
90
test/qad/touch_widgets/plugin/touchbuttframeplugin.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "touchbuttframe.h"
|
||||
#include "touchbuttframeplugin.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QDesignerFormEditorInterface>
|
||||
#include <QDesignerPropertyEditorInterface>
|
||||
|
||||
|
||||
TouchButtFramePlugin::TouchButtFramePlugin(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
void TouchButtFramePlugin::initialize(QDesignerFormEditorInterface * /*core*/ )
|
||||
{
|
||||
if (m_initialized)
|
||||
return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
//core->propertyEditor()->property();
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
bool TouchButtFramePlugin::isInitialized() const
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
QWidget *TouchButtFramePlugin::createWidget(QWidget *parent)
|
||||
{
|
||||
TouchButtFrame * tbw = new TouchButtFrame(parent);
|
||||
QStringList l;
|
||||
l.append("First");
|
||||
l.append("Second");
|
||||
tbw->setButtons(l);
|
||||
return tbw;
|
||||
}
|
||||
|
||||
QString TouchButtFramePlugin::name() const
|
||||
{
|
||||
return QLatin1String("TouchButtFrame");
|
||||
}
|
||||
|
||||
QString TouchButtFramePlugin::group() const
|
||||
{
|
||||
return QLatin1String("Touch Widgets");
|
||||
}
|
||||
|
||||
QIcon TouchButtFramePlugin::icon() const
|
||||
{
|
||||
return QIcon(":/icons/touchbuttframe.png");
|
||||
}
|
||||
|
||||
QString TouchButtFramePlugin::toolTip() const
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString TouchButtFramePlugin::whatsThis() const
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
bool TouchButtFramePlugin::isContainer() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString TouchButtFramePlugin::domXml() const
|
||||
{
|
||||
return QLatin1String("<ui language=\"c++\">\n"
|
||||
" <widget class=\"TouchButtFrame\" name=\"touchButtFrame\">\n"
|
||||
" <property name=\"geometry\">\n"
|
||||
" <rect>\n"
|
||||
" <x>0</x>\n"
|
||||
" <y>0</y>\n"
|
||||
" <width>100</width>\n"
|
||||
" <height>100</height>\n"
|
||||
" </rect>\n"
|
||||
" </property>\n"
|
||||
" </widget>\n"
|
||||
"</ui>\n");
|
||||
}
|
||||
|
||||
QString TouchButtFramePlugin::includeFile() const
|
||||
{
|
||||
return QLatin1String("touchbuttframe.h");
|
||||
}
|
||||
|
||||
35
test/qad/touch_widgets/plugin/touchbuttframeplugin.h
Normal file
35
test/qad/touch_widgets/plugin/touchbuttframeplugin.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef TOUCHBUTTFRAMEPLUGIN_H
|
||||
#define TOUCHBUTTFRAMEPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#if QT_VERSION >= 0x050000
|
||||
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
|
||||
#else
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class TouchButtFramePlugin : public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
public:
|
||||
TouchButtFramePlugin(QObject *parent = 0);
|
||||
|
||||
bool isContainer() const;
|
||||
bool isInitialized() const;
|
||||
QIcon icon() const;
|
||||
QString domXml() const;
|
||||
QString group() const;
|
||||
QString includeFile() const;
|
||||
QString name() const;
|
||||
QString toolTip() const;
|
||||
QString whatsThis() const;
|
||||
QWidget *createWidget(QWidget *parent);
|
||||
void initialize(QDesignerFormEditorInterface *core);
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
};
|
||||
|
||||
#endif
|
||||
74
test/qad/touch_widgets/plugin/touchbuttonplugin.cpp
Normal file
74
test/qad/touch_widgets/plugin/touchbuttonplugin.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include "touchbutton.h"
|
||||
#include "touchbuttonplugin.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QDesignerFormEditorInterface>
|
||||
#include <QDesignerPropertyEditorInterface>
|
||||
|
||||
|
||||
TouchButtonPlugin::TouchButtonPlugin(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
void TouchButtonPlugin::initialize(QDesignerFormEditorInterface * /* core */)
|
||||
{
|
||||
if (m_initialized)
|
||||
return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
bool TouchButtonPlugin::isInitialized() const
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
QWidget *TouchButtonPlugin::createWidget(QWidget *parent)
|
||||
{
|
||||
return new TouchButton(parent);
|
||||
}
|
||||
|
||||
QString TouchButtonPlugin::name() const
|
||||
{
|
||||
return QLatin1String("TouchButton");
|
||||
}
|
||||
|
||||
QString TouchButtonPlugin::group() const
|
||||
{
|
||||
return QLatin1String("Touch Widgets");
|
||||
}
|
||||
|
||||
QIcon TouchButtonPlugin::icon() const
|
||||
{
|
||||
return QIcon(":/icons/touchbutton.png");
|
||||
}
|
||||
|
||||
QString TouchButtonPlugin::toolTip() const
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString TouchButtonPlugin::whatsThis() const
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
bool TouchButtonPlugin::isContainer() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString TouchButtonPlugin::domXml() const
|
||||
{
|
||||
return QLatin1String("<widget class=\"TouchButton\" name=\"touchButton\">\n</widget>\n");
|
||||
}
|
||||
|
||||
QString TouchButtonPlugin::includeFile() const
|
||||
{
|
||||
return QLatin1String("touchbutton.h");
|
||||
}
|
||||
|
||||
35
test/qad/touch_widgets/plugin/touchbuttonplugin.h
Normal file
35
test/qad/touch_widgets/plugin/touchbuttonplugin.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef TOUCHBUTTONPLUGIN_H
|
||||
#define TOUCHBUTTONPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#if QT_VERSION >= 0x050000
|
||||
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
|
||||
#else
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class TouchButtonPlugin : public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
public:
|
||||
TouchButtonPlugin(QObject *parent = 0);
|
||||
|
||||
bool isContainer() const;
|
||||
bool isInitialized() const;
|
||||
QIcon icon() const;
|
||||
QString domXml() const;
|
||||
QString group() const;
|
||||
QString includeFile() const;
|
||||
QString name() const;
|
||||
QString toolTip() const;
|
||||
QString whatsThis() const;
|
||||
QWidget *createWidget(QWidget *parent);
|
||||
void initialize(QDesignerFormEditorInterface *core);
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
};
|
||||
|
||||
#endif // TOUCHBUTTONPLUGIN_H
|
||||
81
test/qad/touch_widgets/plugin/touchsliderplugin.cpp
Normal file
81
test/qad/touch_widgets/plugin/touchsliderplugin.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "touchslider.h"
|
||||
#include "touchsliderplugin.h"
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QDesignerFormEditorInterface>
|
||||
#include <QDesignerPropertyEditorInterface>
|
||||
|
||||
|
||||
TouchSliderPlugin::TouchSliderPlugin(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_initialized = false;
|
||||
}
|
||||
|
||||
void TouchSliderPlugin::initialize(QDesignerFormEditorInterface * /* core */)
|
||||
{
|
||||
if (m_initialized)
|
||||
return;
|
||||
|
||||
// Add extension registrations, etc. here
|
||||
|
||||
m_initialized = true;
|
||||
}
|
||||
|
||||
bool TouchSliderPlugin::isInitialized() const
|
||||
{
|
||||
return m_initialized;
|
||||
}
|
||||
|
||||
QWidget *TouchSliderPlugin::createWidget(QWidget *parent)
|
||||
{
|
||||
TouchSlider * ts = new TouchSlider(parent);
|
||||
ts->setMinimum(-5.);
|
||||
ts->setMaximum(5.);
|
||||
ts->setPrecision(0.2);
|
||||
ts->setValue(2.2);
|
||||
ts->setPrefix("Distanse");
|
||||
ts->setSuffix("meters");
|
||||
return ts;
|
||||
}
|
||||
|
||||
QString TouchSliderPlugin::name() const
|
||||
{
|
||||
return QLatin1String("TouchSlider");
|
||||
}
|
||||
|
||||
QString TouchSliderPlugin::group() const
|
||||
{
|
||||
return QLatin1String("Touch Widgets");
|
||||
}
|
||||
|
||||
QIcon TouchSliderPlugin::icon() const
|
||||
{
|
||||
return QIcon(":/icons/touchslider.png");
|
||||
}
|
||||
|
||||
QString TouchSliderPlugin::toolTip() const
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
QString TouchSliderPlugin::whatsThis() const
|
||||
{
|
||||
return QLatin1String("");
|
||||
}
|
||||
|
||||
bool TouchSliderPlugin::isContainer() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QString TouchSliderPlugin::domXml() const
|
||||
{
|
||||
return QLatin1String("<widget class=\"TouchSlider\" name=\"touchSlider\">\n</widget>\n");
|
||||
}
|
||||
|
||||
QString TouchSliderPlugin::includeFile() const
|
||||
{
|
||||
return QLatin1String("touchslider.h");
|
||||
}
|
||||
|
||||
35
test/qad/touch_widgets/plugin/touchsliderplugin.h
Normal file
35
test/qad/touch_widgets/plugin/touchsliderplugin.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef TOUCHSLIDERPLUGIN_H
|
||||
#define TOUCHSLIDERPLUGIN_H
|
||||
|
||||
#include <QObject>
|
||||
#if QT_VERSION >= 0x050000
|
||||
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
|
||||
#else
|
||||
# include <QDesignerCustomWidgetInterface>
|
||||
#endif
|
||||
|
||||
class TouchSliderPlugin : public QObject, public QDesignerCustomWidgetInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||
|
||||
public:
|
||||
TouchSliderPlugin(QObject *parent = 0);
|
||||
|
||||
bool isContainer() const;
|
||||
bool isInitialized() const;
|
||||
QIcon icon() const;
|
||||
QString domXml() const;
|
||||
QString group() const;
|
||||
QString includeFile() const;
|
||||
QString name() const;
|
||||
QString toolTip() const;
|
||||
QString whatsThis() const;
|
||||
QWidget *createWidget(QWidget *parent);
|
||||
void initialize(QDesignerFormEditorInterface *core);
|
||||
|
||||
private:
|
||||
bool m_initialized;
|
||||
};
|
||||
|
||||
#endif
|
||||
17
test/qad/touch_widgets/touch_bar.h
Normal file
17
test/qad/touch_widgets/touch_bar.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef TOUCH_BAR_H
|
||||
#define TOUCH_BAR_H
|
||||
|
||||
#include <QProgressBar>
|
||||
|
||||
class touch_bar: public QProgressBar {
|
||||
Q_OBJECT
|
||||
public:
|
||||
touch_bar(QWidget * parent = 0): QProgressBar(parent)
|
||||
{
|
||||
//setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum);
|
||||
}
|
||||
signals:
|
||||
void mouseMoveEvent(QMouseEvent * e);
|
||||
void mousePressEvent(QMouseEvent * e);
|
||||
};
|
||||
#endif // TOUCH_BAR_H
|
||||
7
test/qad/touch_widgets/touch_widgets.qrc
Normal file
7
test/qad/touch_widgets/touch_widgets.qrc
Normal file
@@ -0,0 +1,7 @@
|
||||
<RCC>
|
||||
<qresource prefix="/" >
|
||||
<file>../icons/touchbuttframe.png</file>
|
||||
<file>../icons/touchbutton.png</file>
|
||||
<file>../icons/touchslider.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
84
test/qad/touch_widgets/touchbuttframe.cpp
Normal file
84
test/qad/touch_widgets/touchbuttframe.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "touchbuttframe.h"
|
||||
|
||||
|
||||
TouchButtFrame::TouchButtFrame(QWidget * parent, Qt::Orientation orientation): QFrame(parent) {
|
||||
id_click = id_set = -1;
|
||||
TouchButton b;
|
||||
colr = b.noColor();
|
||||
colg = b.yesColor();
|
||||
colw = b.grayColor();
|
||||
colp = b.downColor();
|
||||
setFrameShape(QFrame::StyledPanel);
|
||||
lay = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
lay->setContentsMargins(0, 0, 0, 0);
|
||||
if (orientation == Qt::Vertical) lay->setDirection(QBoxLayout::TopToBottom);
|
||||
}
|
||||
|
||||
|
||||
void TouchButtFrame::addButton(const QString & caption) {
|
||||
TouchButton * butt = new TouchButton(lay->count(), caption);
|
||||
butt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
butt->setCheckable(true);
|
||||
butt->setAutoExclusive(true);
|
||||
//butt->setAutoFillBackground(true);
|
||||
lay->addWidget(butt);
|
||||
this->setLayout(lay);
|
||||
connect(butt, SIGNAL(clickedID(int)), SLOT(butt_click(int)));
|
||||
connect(butt, SIGNAL(toggledID(int, bool)), SLOT(butt_toggle(int, bool)));
|
||||
}
|
||||
|
||||
|
||||
void TouchButtFrame::resetColors() {
|
||||
for (int i = 0; i < lay->count(); ++i) {
|
||||
button(i)->setYesColor(colg);
|
||||
button(i)->setNoColor(colr);
|
||||
button(i)->setGrayColor(colw);
|
||||
button(i)->setDownColor(colp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TouchButtFrame::deleteButtons() {
|
||||
while (!lay->isEmpty())
|
||||
delete button(0);
|
||||
}
|
||||
|
||||
|
||||
void TouchButtFrame::setButtons(const QStringList & captions) {
|
||||
int cur = currentButton();
|
||||
deleteButtons();
|
||||
for (int i = 0; i < captions.size(); ++i)
|
||||
addButton(captions.at(i));
|
||||
if (button(cur) != 0) button(cur)->setChecked(true);
|
||||
else if (!captions.isEmpty()) button(0)->setChecked(true);
|
||||
}
|
||||
|
||||
|
||||
void TouchButtFrame::setCurrentButton(int index) {
|
||||
if (button(index) != 0) {
|
||||
if (currentButton() != -1) button(currentButton())->setChecked(false);
|
||||
button(index)->setChecked(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int TouchButtFrame::currentButton() {
|
||||
for (int i = 0; i < buttonsCount(); ++i)
|
||||
if (button(i)->isChecked()) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
QStringList TouchButtFrame::buttons() {
|
||||
QStringList l;
|
||||
for (int i = 0; i < lay->count(); ++i)
|
||||
l.append(button(i)->text());
|
||||
return l;
|
||||
}
|
||||
|
||||
|
||||
TouchButton * TouchButtFrame::button(int index) {
|
||||
if (index >= 0 && index < lay->count())
|
||||
return (qobject_cast<TouchButton * >(lay->itemAt(index)->widget()));
|
||||
return 0;
|
||||
}
|
||||
113
test/qad/touch_widgets/touchbuttframe.h
Normal file
113
test/qad/touch_widgets/touchbuttframe.h
Normal file
@@ -0,0 +1,113 @@
|
||||
#ifndef TOUCHBUTTFRAME_H
|
||||
#define TOUCHBUTTFRAME_H
|
||||
|
||||
#include <QFrame>
|
||||
#include <QBoxLayout>
|
||||
#include <QDebug>
|
||||
#include "touchbutton.h"
|
||||
|
||||
|
||||
class TouchButtFrame: public QFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor colorYes READ colorYes WRITE setColorYes)
|
||||
Q_PROPERTY(QColor colorNo READ colorNo WRITE setColorNo)
|
||||
Q_PROPERTY(QColor colorGray READ colorGray WRITE setColorGray)
|
||||
Q_PROPERTY(QColor colorDown READ colorDown WRITE setColorDown)
|
||||
Q_PROPERTY(QStringList buttons READ buttons WRITE setButtons)
|
||||
Q_PROPERTY(int currentButton READ currentButton WRITE setCurrentButton)
|
||||
Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation)
|
||||
Q_PROPERTY(int clickID READ clickID WRITE setClickID)
|
||||
Q_PROPERTY(int setID READ setID WRITE setSetID)
|
||||
|
||||
public:
|
||||
TouchButtFrame(QWidget * parent = 0, Qt::Orientation orientation = Qt::Horizontal);
|
||||
|
||||
int clickID() const {return id_click;}
|
||||
int setID() const {return id_set;}
|
||||
|
||||
void setButtons(const QStringList & captions);
|
||||
QStringList buttons();
|
||||
TouchButton * button(int index);
|
||||
int buttonsCount() const {return lay->count();}
|
||||
int currentButton();
|
||||
Qt::Orientation orientation() const {if (lay->direction() == 0) return Qt::Horizontal; else return Qt::Vertical;}
|
||||
QColor colorYes() const {return colg;}
|
||||
QColor colorNo() const {return colr;}
|
||||
QColor colorGray() const {return colw;}
|
||||
QColor colorDown() const {return colp;}
|
||||
|
||||
void setCurrentButton(int index);
|
||||
void setColorYes(QColor col) {colg = col; resetColors();}
|
||||
void setColorNo(QColor col) {colr = col; resetColors();}
|
||||
void setColorGray(QColor col) {colw = col; resetColors();}
|
||||
void setColorDown(QColor col) {colp = col; resetColors();}
|
||||
void setOrientation(Qt::Orientation orientation) {if (orientation == Qt::Horizontal) lay->setDirection(QBoxLayout::LeftToRight); else lay->setDirection(QBoxLayout::TopToBottom);}
|
||||
|
||||
private:
|
||||
void resetColors();
|
||||
void deleteButtons();
|
||||
void addButton(const QString & caption);
|
||||
|
||||
int id_click, id_set;
|
||||
QColor colr, colg, colw, colp;
|
||||
QBoxLayout * lay;
|
||||
//int count;
|
||||
|
||||
private slots:
|
||||
void butt_click(int index) {emit clicked(index); emit clickedID(id_click, index);}
|
||||
void butt_toggle(int index, bool checked) {emit toggled(index, checked); emit toggledID(id_click, index, checked);}
|
||||
|
||||
public slots:
|
||||
void enable() {setEnabled(true);}
|
||||
void disable() {setAllButtonsGray(); setEnabled(false);}
|
||||
|
||||
void setClickID(int id) {id_click = id;}
|
||||
void setSetID(int id) {id_set = id;}
|
||||
|
||||
|
||||
void setButtonChecked(int index) {if (button(index) != 0) button(index)->setChecked(true);}
|
||||
void setButtonUnchecked(int index) {if (button(index) != 0) button(index)->setChecked(false);}
|
||||
void setButtonState(int index, TouchButton::State state) {if (button(index) != 0) button(index)->setState(state);}
|
||||
void setButtonYes(int index) {if (button(index) != 0) button(index)->setStateYes();}
|
||||
void setButtonNo(int index) {if (button(index) != 0) button(index)->setStateNo();}
|
||||
void setButtonGray(int index) {if (button(index) != 0) button(index)->setStateGray();}
|
||||
void setAllButtonsState(TouchButton::State state) {for (int i = 0; i < buttonsCount(); ++i) button(i)->setState(state);}
|
||||
void setAllButtonsYes() {for (int i = 0; i < buttonsCount(); ++i) button(i)->setStateYes();}
|
||||
void setAllButtonsNo() {for (int i = 0; i < buttonsCount(); ++i) button(i)->setStateNo();}
|
||||
void setAllButtonsGray() {for (int i = 0; i < buttonsCount(); ++i) button(i)->setStateGray();}
|
||||
|
||||
void hideButton(int index) {if (button(index) != 0) button(index)->hide();}
|
||||
void showButton(int index) {if (button(index) != 0) button(index)->show();}
|
||||
void enableButton(int index) {if (button(index) != 0) button(index)->enable();}
|
||||
void disableButton(int index) {if (button(index) != 0) button(index)->disable();}
|
||||
|
||||
|
||||
void enableID(int set_id) {if (set_id == id_set) enable();}
|
||||
void disableID(int set_id) {if (set_id == id_set) disable();}
|
||||
|
||||
void setButtonCheckedID(int set_id, int index) {if (set_id == id_set) setButtonChecked(index);}
|
||||
void setButtonUncheckedID(int set_id, int index) {if (set_id == id_set) setButtonUnchecked(index);}
|
||||
void setButtonStateID(int set_id, int index, TouchButton::State state) {if (set_id == id_set) setButtonState(index, state);}
|
||||
void setButtonYesID(int set_id, int index) {if (set_id == id_set) setButtonYes(index);}
|
||||
void setButtonNoID(int set_id, int index) {if (set_id == id_set) setButtonNo(index);}
|
||||
void setButtonGrayID(int set_id, int index) {if (set_id == id_set) setButtonGray(index);}
|
||||
void setAllButtonsStateID(int set_id, TouchButton::State state) {if (set_id == id_set) setAllButtonsState(state);}
|
||||
void setAllButtonsYesID(int set_id) {if (set_id == id_set) setAllButtonsYes();}
|
||||
void setAllButtonsNoID(int set_id) {if (set_id == id_set) setAllButtonsNo();}
|
||||
void setAllButtonsGrayID(int set_id) {if (set_id == id_set) setAllButtonsGray();}
|
||||
|
||||
void hideButtonID(int set_id, int index) {if (set_id == id_set) hideButton(index);}
|
||||
void showButtonID(int set_id, int index) {if (set_id == id_set) showButton(index);}
|
||||
void enableButtonID(int set_id, int index) {if (set_id == id_set) enableButton(index);}
|
||||
void disableButtonID(int set_id, int index) {if (set_id == id_set) disableButton(index);}
|
||||
|
||||
signals:
|
||||
void clicked(int index);
|
||||
void toggled(int index, bool checked);
|
||||
void clickedID(int id, int index);
|
||||
void toggledID(int id, int index, bool checked);
|
||||
|
||||
};
|
||||
|
||||
#endif // TOUCHBUTTFRAME_H
|
||||
104
test/qad/touch_widgets/touchbutton.cpp
Normal file
104
test/qad/touch_widgets/touchbutton.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include "touchbutton.h"
|
||||
|
||||
|
||||
TouchButton::TouchButton(QWidget * parent): QToolButton(parent) {
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
TouchButton::TouchButton(int id__, const QString & text): QToolButton(0) {
|
||||
init();
|
||||
id_click = id_yes = id_no = id__;
|
||||
setText(text);
|
||||
}
|
||||
|
||||
|
||||
TouchButton::~TouchButton() {
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::init() {
|
||||
connect(this, SIGNAL(clicked(bool)), this, SLOT(_clicked()));
|
||||
connect(this, SIGNAL(toggled(bool)), this, SLOT(_toggled(bool)));
|
||||
animation.setTargetObject(this);
|
||||
animation.setPropertyName("currentColor");
|
||||
animation.setEasingCurve(QEasingCurve::OutSine);
|
||||
animation.setDuration(350);
|
||||
delay_blink = 500;
|
||||
anim = auto_gray = true;
|
||||
state_ = Gray;
|
||||
id_click = id_yes = id_no = -1;
|
||||
timer = 0;
|
||||
pal = palette();
|
||||
col_yes = QColor(Qt::green);
|
||||
col_no = QColor(Qt::red);
|
||||
col_down = QColor(Qt::yellow);
|
||||
col_gray = col_cur = col_up = pal.button().color();
|
||||
col_dst = col_gray;
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::timerEvent(QTimerEvent * e) {
|
||||
if (e->timerId() == timer) {
|
||||
killTimer(e->timerId());
|
||||
timer = 0;
|
||||
setCurrentColor(col_blink);
|
||||
animateColor(col_dst);
|
||||
return;
|
||||
}
|
||||
QToolButton::timerEvent(e);
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::mousePressEvent(QMouseEvent * e) {
|
||||
animateColor(col_down);
|
||||
QToolButton::mousePressEvent(e);
|
||||
emit pressedID(id_click);
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::mouseReleaseEvent(QMouseEvent * e) {
|
||||
setCurrentColor(col_down);
|
||||
animateColor(col_dst);
|
||||
QToolButton::mouseReleaseEvent(e);
|
||||
emit releasedID(id_click);
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::animateColor(const QColor & tc) {
|
||||
if (anim) {
|
||||
animation.stop();
|
||||
animation.setStartValue(currentColor());
|
||||
animation.setEndValue(tc);
|
||||
animation.start();
|
||||
} else {
|
||||
col_cur = tc;
|
||||
applyColor();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::applyState(State s) {
|
||||
if (s == state_) return;
|
||||
State ps = state_;
|
||||
state_ = s;
|
||||
emit stateChanged(state_, ps);
|
||||
emit stateChangedID(id_click, state_, ps);
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::blink(const QColor & tc) {
|
||||
col_blink = tc;
|
||||
if (timer > 0) killTimer(timer);
|
||||
timer = startTimer(delay_blink);
|
||||
}
|
||||
|
||||
|
||||
void TouchButton::setState(State s) {
|
||||
switch (s) {
|
||||
case Gray: setStateGray(); break;
|
||||
case Yes: setStateYes(); break;
|
||||
case No: setStateNo(); break;
|
||||
default: break;
|
||||
};
|
||||
}
|
||||
154
test/qad/touch_widgets/touchbutton.h
Normal file
154
test/qad/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
|
||||
242
test/qad/touch_widgets/touchslider.cpp
Normal file
242
test/qad/touch_widgets/touchslider.cpp
Normal file
@@ -0,0 +1,242 @@
|
||||
#include "touchslider.h"
|
||||
#include "ui_touchslider.h"
|
||||
|
||||
|
||||
TouchSlider::TouchSlider(QWidget * parent): QGroupBox(parent), ui(new Ui::TouchSlider) {
|
||||
ui->setupUi(this);
|
||||
ui->barNeg->setMinimum(0);
|
||||
prec = 1;
|
||||
id_click = id_set = -1;
|
||||
hasZero = true;
|
||||
m_readOnly = false;
|
||||
m_showMinMax = false;
|
||||
}
|
||||
|
||||
|
||||
TouchSlider::~TouchSlider() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_pbMin_clicked() {
|
||||
if (m_readOnly) return;
|
||||
ui->barNeg->setValue(ui->barNeg->maximum());
|
||||
ui->barPos->setValue(ui->barPos->minimum());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_pbMax_clicked() {
|
||||
if (m_readOnly) return;
|
||||
ui->barNeg->setValue(ui->barNeg->minimum());
|
||||
ui->barPos->setValue(ui->barPos->maximum());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_pbInc_clicked() {
|
||||
if (ui->barPos->value() >= 0 && ui->barNeg->value() == 0) ui->barPos->setValue(ui->barPos->value() + 1);
|
||||
if (ui->barNeg->value() > 0) ui->barNeg->setValue(ui->barNeg->value() - 1);
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_pbDec_clicked() {
|
||||
if (ui->barNeg->value() >= 0 && ui->barPos->value() == 0 && hasZero) ui->barNeg->setValue(ui->barNeg->value() + 1);
|
||||
if (ui->barPos->value() > 0) ui->barPos->setValue(ui->barPos->value() - 1);
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_pbZero_clicked() {
|
||||
ui->barNeg->setValue(ui->barNeg->minimum());
|
||||
ui->barPos->setValue(ui->barPos->minimum());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::setValue(double val) {
|
||||
if (val < minimum()) val = minimum();
|
||||
if (val > maximum()) val = maximum();
|
||||
if (val < 0) {
|
||||
ui->barPos->setValue(ui->barPos->minimum());
|
||||
if (hasZero) ui->barNeg->setValue(qRound(-val / prec));
|
||||
} else {
|
||||
ui->barPos->setValue(qRound(val / prec));
|
||||
ui->barNeg->setValue(ui->barNeg->minimum());
|
||||
}
|
||||
updateCaption();
|
||||
}
|
||||
|
||||
|
||||
double TouchSlider::value() const {
|
||||
if (ui->barNeg->value() <= ui->barNeg->minimum())
|
||||
return (double)(ui->barPos->value()) * prec;
|
||||
else return -(double)(ui->barNeg->value()) * prec;
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::setMaximum(double max) {
|
||||
double val = value();
|
||||
if (max < 0) return;
|
||||
ui->barPos->setMaximum(qRound(max / prec));
|
||||
setValue(val);
|
||||
ui->pbMax->setText(QString::number(maximum()));
|
||||
}
|
||||
|
||||
|
||||
double TouchSlider::maximum() const {
|
||||
return (double)(ui->barPos->maximum()) * prec;
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::setMinimum(double min) {
|
||||
double val = value();
|
||||
if (min < 0) {
|
||||
hasZero = true;
|
||||
ui->barNeg->setMaximum(qRound(-min / prec));
|
||||
ui->barPos->setMinimum(0);
|
||||
ui->barNeg->setVisible(true);
|
||||
ui->pbZero->setVisible(true);
|
||||
setValue(val);
|
||||
} else {
|
||||
hasZero = false;
|
||||
ui->barNeg->setMaximum(0);
|
||||
ui->barNeg->setVisible(false);
|
||||
ui->pbZero->setVisible(false);
|
||||
ui->barPos->setMinimum(qRound(min / prec));
|
||||
setValue(val);
|
||||
}
|
||||
ui->pbMin->setText(QString::number(minimum()));
|
||||
}
|
||||
|
||||
|
||||
double TouchSlider::minimum() const {
|
||||
if (hasZero) return -(double)(ui->barNeg->maximum()) * prec;
|
||||
return (double)(ui->barPos->minimum()) * prec;
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::setPrecision(double precision) {
|
||||
double min = minimum();
|
||||
double max = maximum();
|
||||
double val = value();
|
||||
prec = precision;
|
||||
setMinimum(min);
|
||||
setMaximum(max);
|
||||
setValue(val);
|
||||
ui->pbInc->setText("+" + QString::number(precision));
|
||||
ui->pbDec->setText("-" + QString::number(precision));
|
||||
}
|
||||
|
||||
|
||||
double TouchSlider::precision() const {
|
||||
return prec;
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::updateCaption() {
|
||||
setTitle(pref + " " + QString::number(value()) + " " + suff);
|
||||
emit valueChanged(value());
|
||||
emit valueChanged((int)value());
|
||||
emit valueChangedID(id_click, value());
|
||||
emit valueChangedID(id_click, (int)value());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_barPos_mouseMoveEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
int tx = e->x();
|
||||
if (tx > ui->barPos->width()) tx = ui->barPos->width();
|
||||
if (tx < 0) {
|
||||
if (hasZero) {
|
||||
int nx = tx + ui->barNeg->width() + layout()->spacing();
|
||||
if (nx < ui->barNeg->width()) {
|
||||
QMouseEvent * event = new QMouseEvent(QMouseEvent::MouseMove, QPoint(nx, 0), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
on_barNeg_mouseMoveEvent(event);
|
||||
return;
|
||||
}
|
||||
}
|
||||
tx = 0;
|
||||
}
|
||||
ui->barPos->setValue(ui->barPos->minimum() + qRound((double)(tx * (ui->barPos->maximum() - ui->barPos->minimum())) / (double)(ui->barPos->width())));
|
||||
ui->barNeg->setValue(ui->barNeg->minimum());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_barNeg_mouseMoveEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
int tx = e->x();
|
||||
if (tx < 0) tx = 0;
|
||||
if (tx > ui->barNeg->width()) {
|
||||
int nx = tx - ui->barPos->width() - layout()->spacing();
|
||||
if (nx > 0) {
|
||||
QMouseEvent * event = new QMouseEvent(QMouseEvent::MouseMove, QPoint(nx, 0), Qt::NoButton, Qt::NoButton, Qt::NoModifier);
|
||||
on_barPos_mouseMoveEvent(event);
|
||||
return;
|
||||
}
|
||||
tx = ui->barNeg->width();
|
||||
}
|
||||
ui->barNeg->setValue(ui->barNeg->maximum() - qRound((double)(tx * ui->barNeg->maximum()) / (double)(ui->barNeg->width())));
|
||||
ui->barPos->setValue(ui->barPos->minimum());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_barPos_mousePressEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
ui->barPos->setValue(ui->barPos->minimum() + qRound((double)(e->x() * (ui->barPos->maximum() - ui->barPos->minimum())) / (double)(ui->barPos->width())));
|
||||
ui->barNeg->setValue(ui->barNeg->minimum());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_barNeg_mousePressEvent(QMouseEvent * e) {
|
||||
if (m_readOnly) return;
|
||||
ui->barNeg->setValue(ui->barNeg->maximum() - qRound((double)(e->x()*ui->barNeg->maximum()) / (double)(ui->barNeg->width())));
|
||||
ui->barPos->setValue(ui->barPos->minimum());
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_barNeg_valueChanged(int) {
|
||||
updateCaption();
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::on_barPos_valueChanged(int) {
|
||||
updateCaption();
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::setReadOnly(bool arg) {
|
||||
QBoxLayout * bl = qobject_cast<QBoxLayout *>(layout());
|
||||
m_readOnly = arg;
|
||||
if (arg) {
|
||||
ui->pbDec->hide();
|
||||
ui->pbInc->hide();
|
||||
if (hasZero)
|
||||
ui->pbZero->hide();
|
||||
bl->setStretchFactor(ui->pbMin, 2);
|
||||
bl->setStretchFactor(ui->pbMax, 2);
|
||||
} else {
|
||||
ui->pbDec->show();
|
||||
ui->pbInc->show();
|
||||
if (hasZero)
|
||||
ui->pbZero->show();
|
||||
bl->setStretchFactor(ui->pbMin, 1);
|
||||
bl->setStretchFactor(ui->pbMax, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TouchSlider::setShowMinMax(bool arg) {
|
||||
QBoxLayout * bl = qobject_cast<QBoxLayout *>(layout());
|
||||
m_showMinMax = arg;
|
||||
if (arg) {
|
||||
ui->pbMin->hide();
|
||||
ui->pbMax->hide();
|
||||
bl->setStretchFactor(ui->pbInc, 2);
|
||||
bl->setStretchFactor(ui->pbDec, 2);
|
||||
bl->setStretchFactor(ui->pbZero, 2);
|
||||
} else {
|
||||
ui->pbMin->show();
|
||||
ui->pbMax->show();
|
||||
bl->setStretchFactor(ui->pbInc, 1);
|
||||
bl->setStretchFactor(ui->pbDec, 1);
|
||||
bl->setStretchFactor(ui->pbZero, 1);
|
||||
}
|
||||
}
|
||||
|
||||
105
test/qad/touch_widgets/touchslider.h
Normal file
105
test/qad/touch_widgets/touchslider.h
Normal file
@@ -0,0 +1,105 @@
|
||||
#ifndef TOUCHSLIDER_H
|
||||
#define TOUCHSLIDER_H
|
||||
|
||||
#include <QGroupBox>
|
||||
#include <QMouseEvent>
|
||||
|
||||
namespace Ui {
|
||||
class TouchSlider;
|
||||
}
|
||||
|
||||
class TouchSlider: public QGroupBox
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool readOnly READ readOnly WRITE setReadOnly)
|
||||
Q_PROPERTY(bool showMinMax READ showMinMax WRITE setShowMinMax)
|
||||
Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
|
||||
Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
|
||||
Q_PROPERTY(double value READ value WRITE setValue)
|
||||
Q_PROPERTY(double precision READ precision WRITE setPrecision)
|
||||
Q_PROPERTY(QString prefix READ prefix WRITE setPrefix)
|
||||
Q_PROPERTY(QString suffix READ suffix WRITE setSuffix)
|
||||
Q_PROPERTY(int clickID READ clickID WRITE setClickID)
|
||||
Q_PROPERTY(int setID READ setID WRITE setSetID)
|
||||
|
||||
public:
|
||||
explicit TouchSlider(QWidget *parent = 0);
|
||||
~TouchSlider();
|
||||
|
||||
int clickID() const {return id_click;}
|
||||
int setID() const {return id_set;}
|
||||
|
||||
double minimum() const;
|
||||
double maximum() const;
|
||||
double value() const;
|
||||
double precision() const;
|
||||
QString prefix() const {return pref;}
|
||||
QString suffix() const {return suff;}
|
||||
bool readOnly() const {return m_readOnly;}
|
||||
bool showMinMax() const {return m_showMinMax;}
|
||||
|
||||
private:
|
||||
void updateCaption();
|
||||
|
||||
Ui::TouchSlider *ui;
|
||||
bool hasZero;
|
||||
bool m_readOnly;
|
||||
bool m_showMinMax;
|
||||
double prec;
|
||||
int id_click, id_set;
|
||||
QString pref, suff;
|
||||
|
||||
public slots:
|
||||
void enable() {setEnabled(true);}
|
||||
void disable() {setEnabled(false);}
|
||||
|
||||
void setClickID(int id) {id_click = id;}
|
||||
void setSetID(int id) {id_set = id;}
|
||||
|
||||
void setSuffix(const QString & text) {suff = text; updateCaption();}
|
||||
void setPrefix(const QString & text) {pref = text; updateCaption();}
|
||||
void setPrecision(double precision);
|
||||
void setPrecision(int precision) {setPrecision((double)precision);}
|
||||
void setMinimum(double min);
|
||||
void setMinimum(int min) {setMinimum((double)min);}
|
||||
void setMaximum(double max);
|
||||
void setMaximum(int max) {setMaximum((double)max);}
|
||||
void setReadOnly(bool yes);
|
||||
void setShowMinMax(bool yes);
|
||||
|
||||
void setValue(double val);
|
||||
void setValue(int val) {setValue((double)val);}
|
||||
|
||||
void enableID(int set_id) {if (set_id == id_set) enable();}
|
||||
void disableID(int set_id) {if (set_id == id_set) disable();}
|
||||
|
||||
void setValueID(int set_id, double val) {if (set_id == id_set) setValue(val);}
|
||||
void setValueID(int set_id, int val) {if (set_id == id_set) setValue(val);}
|
||||
|
||||
void clickMin() {on_pbMin_clicked();}
|
||||
void clickMax() {on_pbMax_clicked();}
|
||||
void clickInc() {on_pbInc_clicked();}
|
||||
void clickDec() {on_pbDec_clicked();}
|
||||
void clickZero() {on_pbZero_clicked();}
|
||||
|
||||
private slots:
|
||||
void on_barPos_valueChanged(int value);
|
||||
void on_barNeg_valueChanged(int value);
|
||||
void on_barNeg_mousePressEvent(QMouseEvent*);
|
||||
void on_barPos_mousePressEvent(QMouseEvent*);
|
||||
void on_barNeg_mouseMoveEvent(QMouseEvent*);
|
||||
void on_barPos_mouseMoveEvent(QMouseEvent*);
|
||||
void on_pbZero_clicked();
|
||||
void on_pbDec_clicked();
|
||||
void on_pbInc_clicked();
|
||||
void on_pbMax_clicked();
|
||||
void on_pbMin_clicked();
|
||||
|
||||
signals:
|
||||
void valueChanged(double val);
|
||||
void valueChanged(int val);
|
||||
void valueChangedID(int id, double val);
|
||||
void valueChangedID(int id, int val);
|
||||
};
|
||||
|
||||
#endif // TOUCHSLIDER_H
|
||||
187
test/qad/touch_widgets/touchslider.ui
Normal file
187
test/qad/touch_widgets/touchslider.ui
Normal file
@@ -0,0 +1,187 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TouchSlider</class>
|
||||
<widget class="QGroupBox" name="TouchSlider">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>449</width>
|
||||
<height>77</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>val</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,4,4,0,0,0,0">
|
||||
<property name="spacing">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="margin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="TouchButton" name="pbMin">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>45</width>
|
||||
<height>45</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>-100</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="touch_bar" name="barNeg">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="textVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="touch_bar" name="barPos">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>50</number>
|
||||
</property>
|
||||
<property name="textVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TouchButton" name="pbMax">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>45</width>
|
||||
<height>45</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>100</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TouchButton" name="pbDec">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>45</width>
|
||||
<height>45</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>-</string>
|
||||
</property>
|
||||
<property name="autoRepeat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRepeatDelay">
|
||||
<number>500</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TouchButton" name="pbZero">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>45</width>
|
||||
<height>45</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>0</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="TouchButton" name="pbInc">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>45</width>
|
||||
<height>45</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>+</string>
|
||||
</property>
|
||||
<property name="autoRepeat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="autoRepeatDelay">
|
||||
<number>500</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TouchButton</class>
|
||||
<extends>QToolButton</extends>
|
||||
<header>touchbutton.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>touch_bar</class>
|
||||
<extends>QProgressBar</extends>
|
||||
<header>touch_bar.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user