Fix doc path
[opentx.git] / companion / src / shared / genericpanel.cpp
blob5dfad648e420623fad96822403101b85b5751e56
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "genericpanel.h"
23 #include <TimerEdit>
24 #include <QComboBox>
25 #include <QEvent>
26 #include <QLabel>
27 #include <QGridLayout>
28 #include <QSpacerItem>
30 GenericPanel::GenericPanel(QWidget * parent, ModelData * model, GeneralSettings & generalSettings, Firmware * firmware):
31 QWidget(parent),
32 model(model),
33 generalSettings(generalSettings),
34 firmware(firmware),
35 lock(false)
39 GenericPanel::~GenericPanel()
43 void GenericPanel::update()
47 void GenericPanel::addLabel(QGridLayout *gridLayout, const QString &text, int col, bool minimize)
49 QLabel *label = new QLabel(this);
50 label->setFrameShape(QFrame::Panel);
51 label->setFrameShadow(QFrame::Raised);
52 label->setMidLineWidth(0);
53 label->setAlignment(Qt::AlignCenter);
54 label->setMargin(5);
55 label->setText(text);
56 if (!minimize)
57 label->setMinimumWidth(100);
58 gridLayout->addWidget(label, 0, col, 1, 1);
61 void GenericPanel::addEmptyLabel(QGridLayout * gridLayout, int col)
63 QLabel *label = new QLabel(this);
64 label->setText("");
65 gridLayout->addWidget(label, 0, col, 1, 1);
68 void GenericPanel::addHSpring(QGridLayout * gridLayout, int col, int row)
70 QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
71 gridLayout->addItem(spacer, row, col);
74 void GenericPanel::addVSpring(QGridLayout * gridLayout, int col, int row)
76 QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
77 gridLayout->addItem(spacer, row, col);
80 void GenericPanel::addDoubleSpring(QGridLayout * gridLayout, int col, int row)
82 QSpacerItem * spacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding );
83 gridLayout->addItem(spacer, row, col);
86 bool GenericPanel::eventFilter(QObject *object, QEvent * event)
88 QWidget * widget = qobject_cast<QWidget*>(object);
89 if (widget) {
90 if (event->type() == QEvent::Wheel) {
91 if (widget->focusPolicy() == Qt::WheelFocus) {
92 event->accept();
93 return false;
95 else {
96 event->ignore();
97 return true;
100 else if (event->type() == QEvent::FocusIn) {
101 widget->setFocusPolicy(Qt::WheelFocus);
103 else if (event->type() == QEvent::FocusOut) {
104 widget->setFocusPolicy(Qt::StrongFocus);
107 return QWidget::eventFilter(object, event);
110 void GenericPanel::setFocusFilter(QWidget * w)
112 w->installEventFilter(this);
113 w->setFocusPolicy(Qt::StrongFocus);
116 void GenericPanel::disableMouseScrolling()
118 foreach(QWidget * cb, findChildren<QComboBox*>())
119 setFocusFilter(cb);
121 foreach(QWidget * sb, findChildren<QAbstractSpinBox*>())
122 setFocusFilter(sb);
124 foreach(QWidget * slider, findChildren<QSlider*>())
125 setFocusFilter(slider);
127 foreach(QWidget * te, findChildren<TimerEdit*>())
128 setFocusFilter(te);