228 lines
6.3 KiB
C++
228 lines
6.3 KiB
C++
/*
|
|
QAD - Qt ADvanced
|
|
|
|
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef TOUCHBUTTFRAME_H
|
|
#define TOUCHBUTTFRAME_H
|
|
|
|
#include "qad_touch_widgets_export.h"
|
|
#include "touchbutton.h"
|
|
|
|
#include <QBoxLayout>
|
|
#include <QDebug>
|
|
#include <QFrame>
|
|
|
|
|
|
class QAD_TOUCH_WIDGETS_EXPORT 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
|