mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-18 08:54:15 +01:00
LP-174 : Add Rcinput value display - UI and style changes, embed font.
All credit for the textbubbleslider files goes to Taulabs and Kenn Sebesta
This commit is contained in:
parent
e68ad5dbd8
commit
9eb8f45e0d
@ -58,7 +58,8 @@ HEADERS += \
|
||||
calibration/gyrobiascalibrationmodel.h \
|
||||
calibration/calibrationuiutils.h \
|
||||
configoplinkwidget.h \
|
||||
configrevonanohwwidget.h
|
||||
configrevonanohwwidget.h \
|
||||
textbubbleslider.h
|
||||
|
||||
SOURCES += \
|
||||
configplugin.cpp \
|
||||
@ -99,7 +100,8 @@ SOURCES += \
|
||||
calibration/levelcalibrationmodel.cpp \
|
||||
calibration/gyrobiascalibrationmodel.cpp \
|
||||
configoplinkwidget.cpp \
|
||||
configrevonanohwwidget.cpp
|
||||
configrevonanohwwidget.cpp \
|
||||
textbubbleslider.cpp
|
||||
|
||||
FORMS += \
|
||||
airframe.ui \
|
||||
|
@ -57,5 +57,6 @@
|
||||
<file>images/error.svg</file>
|
||||
<file>images/nano_top.png</file>
|
||||
<file>images/cc3d_top.png</file>
|
||||
<file>fonts/PTS75F.ttf</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -1666,12 +1666,15 @@ void ConfigInputWidget::updatePositionSlider()
|
||||
if (sp->objectName() == "channelNeutral") {
|
||||
if (count == 4) {
|
||||
sp->setStyleSheet(
|
||||
"QSlider::groove:horizontal {border: 2px solid rgb(196, 196, 196); height: 12px; border-radius: 4px; "
|
||||
"QSlider::groove:horizontal {border: 2px solid rgb(196, 196, 196); margin: 0px 23px 0px 23px; height: 12px; border-radius: 5px; "
|
||||
"border-image:url(:/configgadget/images/flightmode_bg" + fmNumber + ".png); }"
|
||||
"QSlider::add-page:horizontal { background: none; border: none; }"
|
||||
"QSlider::sub-page:horizontal { background: none; border: none; }"
|
||||
"QSlider::handle:horizontal { background: rgba(196, 196, 196, 255); width: 10px; height: 28px; "
|
||||
"margin: -3px -2px; border-radius: 3px; border: 1px solid #777; }");
|
||||
"QSlider::handle:horizontal { background: qlineargradient(x1:0, y1:0, x2:1, y2:0, "
|
||||
"stop: 0 rgba(196, 196, 196, 180), stop: 0.45 rgba(196, 196, 196, 180), "
|
||||
"stop: 0.46 rgba(255,0,0,100), stop: 0.54 rgba(255,0,0,100), "
|
||||
"stop: 0.55 rgba(196, 196, 196, 180), stop: 1 rgba(196, 196, 196, 180)); "
|
||||
"width: 46px; height: 28px; margin: -6px -23px -6px -23px; border-radius: 5px; border: 1px solid #777; }");
|
||||
count++;
|
||||
} else {
|
||||
count++;
|
||||
|
BIN
ground/gcs/src/plugins/config/fonts/PTS75F.ttf
Normal file
BIN
ground/gcs/src/plugins/config/fonts/PTS75F.ttf
Normal file
Binary file not shown.
@ -0,0 +1,26 @@
|
||||
Copyright © 2009 ParaType Ltd.
|
||||
with Reserved Names &quot;PT Sans&quot; and &quot;ParaType&quot;.
|
||||
|
||||
FONT LICENSE
|
||||
|
||||
PERMISSION &amp; CONDITIONS
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of the font software, to use, study, copy, merge, embed, modify, redistribute, and sell modified and unmodified copies of the font software, subject to the following conditions:
|
||||
|
||||
1) Neither the font software nor any of its individual components, in original or modified versions, may be sold by itself.
|
||||
|
||||
2) Original or modified versions of the font software may be bundled, redistributed and/or sold with any software, provided that each copy contains the above copyright notice and this license. These can be included either as stand-alone text files, human-readable headers or in the appropriate machine-readable metadata fields within text or binary files as long as those fields can be easily viewed by the user.
|
||||
|
||||
3) No modified version of the font software may use the Reserved Name(s) or combinations of Reserved Names with other words unless explicit written permission is granted by the ParaType. This restriction only applies to the primary font name as presented to the users.
|
||||
|
||||
4) The name of ParaType or the author(s) of the font software shall not be used to promote, endorse or advertise any modified version, except to acknowledge the contribution(s) of ParaType and the author(s) or with explicit written permission of ParaType.
|
||||
|
||||
5) The font software, modified or unmodified, in part or in whole, must be distributed entirely under this license, and must not be distributed under any other license. The requirement for fonts to remain under this license does not apply to any document created using the Font Software.
|
||||
|
||||
TERMINATION &amp; TERRITORY
|
||||
This license has no limits on time and territory, but it becomes null and void if any of the above conditions are not met.
|
||||
|
||||
DISCLAIMER
|
||||
THE FONT SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL PARATYPE BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
ParaType Ltd
|
||||
http://www.paratype.ru
|
@ -12,7 +12,6 @@ InputChannelForm::InputChannelForm(const int index, QWidget *parent) :
|
||||
connect(ui->channelMin, SIGNAL(valueChanged(int)), this, SLOT(minMaxUpdated()));
|
||||
connect(ui->channelMax, SIGNAL(valueChanged(int)), this, SLOT(minMaxUpdated()));
|
||||
connect(ui->neutralValue, SIGNAL(valueChanged(int)), this, SLOT(neutralUpdated()));
|
||||
connect(ui->channelNeutral, SIGNAL(valueChanged(int)), this, SLOT(updateTooltip()));
|
||||
connect(ui->channelGroup, SIGNAL(currentIndexChanged(int)), this, SLOT(groupUpdated()));
|
||||
connect(ui->channelRev, SIGNAL(toggled(bool)), this, SLOT(reversedUpdated()));
|
||||
|
||||
@ -58,13 +57,6 @@ void InputChannelForm::minMaxUpdated()
|
||||
updateNeutralMark();
|
||||
}
|
||||
|
||||
void InputChannelForm::updateTooltip()
|
||||
{
|
||||
int currentValue = ui->channelNeutral->value();
|
||||
|
||||
ui->channelNeutral->setToolTip(QString::number(currentValue));
|
||||
}
|
||||
|
||||
void InputChannelForm::neutralUpdated()
|
||||
{
|
||||
int neutralValue = ui->neutralValue->value();
|
||||
@ -98,13 +90,17 @@ void InputChannelForm::updateNeutralMark()
|
||||
float neutralPosition = offset / range;
|
||||
|
||||
ui->channelNeutral->setStyleSheet(
|
||||
"QSlider::groove:horizontal { border: 1px solid rgb(196, 196, 196); height: 6px; border-radius: 2px; "
|
||||
"QSlider::groove:horizontal { border: 1px solid rgb(196, 196, 196); margin: 0px 23px 0px 23px; height: 6px; border-radius: 2px; "
|
||||
"background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop:" + QString::number(neutralPosition - 0.01) + " transparent, stop:"
|
||||
+ QString::number(neutralPosition) + " red, stop:" + QString::number(neutralPosition + 0.01) + " transparent); }"
|
||||
"QSlider::add-page:horizontal { background: rgba(255,255,255,180); border: 1px solid #777; margin: 0px 0px 0px 2px; border-radius: 4px; }"
|
||||
"QSlider::sub-page:horizontal { background: rgba(78,147,246,180); border: 1px solid #777; margin: 0px 2px 0px 0px; border-radius: 4px; }"
|
||||
"QSlider::handle:horizontal { background: rgba(196,196,196,180); width: 18px; height: 28px; margin: -2px 0px; border-radius: 3px; "
|
||||
"border: 1px solid #777; }"
|
||||
"QSlider::add-page:horizontal { background: rgba(255,255,255,120); border: 1px solid #777; margin: 0px 23px 0px 2px; border-radius: 4px; }"
|
||||
"QSlider::sub-page:horizontal { background: rgba(78,147,246,120); border: 1px solid #777; margin: 0px 2px 0px 23px; border-radius: 4px; }"
|
||||
|
||||
"QSlider::handle:horizontal { background: qlineargradient(x1:0, y1:0, x2:1, y2:0, "
|
||||
"stop: 0 rgba(196, 196, 196, 180), stop: 0.45 rgba(196, 196, 196, 180), "
|
||||
"stop: 0.46 rgba(255,0,0,100), stop: 0.54 rgba(255,0,0,100), "
|
||||
"stop: 0.55 rgba(196, 196, 196, 180), stop: 1 rgba(196, 196, 196, 180)); "
|
||||
"width: 46px; height: 28px; margin: -6px -23px -6px -23px; border-radius: 6px; border: 1px solid #777; }"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,6 @@ public:
|
||||
|
||||
private slots:
|
||||
void updateNeutralMark();
|
||||
void updateTooltip();
|
||||
void minMaxUpdated();
|
||||
void neutralUpdated();
|
||||
void reversedUpdated();
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>923</width>
|
||||
<height>57</height>
|
||||
<width>993</width>
|
||||
<height>100</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -141,7 +141,7 @@ margin:1px;</string>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>110</width>
|
||||
<width>120</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
@ -169,7 +169,7 @@ margin:1px;</string>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<width>80</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
@ -737,7 +737,7 @@ margin:1px;</string>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="5">
|
||||
<widget class="QSlider" name="channelNeutral">
|
||||
<widget class="TextBubbleSlider" name="channelNeutral">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
@ -746,13 +746,16 @@ margin:1px;</string>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>50</width>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Channel input value (µs)</string>
|
||||
</property>
|
||||
<property name="accessibleName">
|
||||
<string/>
|
||||
</property>
|
||||
@ -841,6 +844,20 @@ margin:1px;</string>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TextBubbleSlider</class>
|
||||
<extends>QSlider</extends>
|
||||
<header>textbubbleslider.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>channelGroup</tabstop>
|
||||
<tabstop>channelNumber</tabstop>
|
||||
<tabstop>channelMin</tabstop>
|
||||
<tabstop>channelNeutral</tabstop>
|
||||
<tabstop>channelMax</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
@ -1,33 +1,33 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file textbubbleslider.h
|
||||
* @author Tau Labs, http://taulabs.org Copyright (C) 2013.
|
||||
* @brief Creates a slider with a text bubble showing the slider value
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Config
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
******************************************************************************
|
||||
*
|
||||
* @file textbubbleslider.h
|
||||
* @author Tau Labs, http://taulabs.org Copyright (C) 2013.
|
||||
* @brief Creates a slider with a text bubble showing the slider value
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Config
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include <QDebug>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#include <QtGui>
|
||||
#include <qmath.h>
|
||||
|
||||
#include "textbubbleslider.h"
|
||||
@ -39,6 +39,8 @@
|
||||
TextBubbleSlider::TextBubbleSlider(QWidget *parent) :
|
||||
QSlider(parent)
|
||||
{
|
||||
QFontDatabase::addApplicationFont(":/configgadget/fonts/PTS75F.ttf");
|
||||
|
||||
construct();
|
||||
}
|
||||
|
||||
@ -71,13 +73,12 @@ TextBubbleSlider::TextBubbleSlider(QSlider *copySlider, QWidget *parent) :
|
||||
*/
|
||||
void TextBubbleSlider::construct()
|
||||
{
|
||||
font = QFont("Arial", 13);
|
||||
font = QFont("PT Sans", 13, QFont::Bold);
|
||||
slideHandleMargin = 2; // This is a dubious way to set the margin. In reality, it should be read from the style sheet.
|
||||
}
|
||||
|
||||
TextBubbleSlider::~TextBubbleSlider()
|
||||
{
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -90,8 +91,9 @@ unsigned int numIntegerDigits(int number)
|
||||
unsigned int digits = 0;
|
||||
|
||||
// If there is a negative sign, be sure to include it in digit count
|
||||
if (number < 0)
|
||||
if (number < 0) {
|
||||
digits = 1;
|
||||
}
|
||||
|
||||
while (number) {
|
||||
number /= 10;
|
||||
@ -113,17 +115,18 @@ void TextBubbleSlider::setMaxPixelWidth()
|
||||
// Generate string with maximum pixel width. Suppose that "0" is
|
||||
// the widest number in pixels.
|
||||
QString maximumWidthString;
|
||||
for (int i=0; i<maxNumDigits; i++) {
|
||||
|
||||
for (int i = 0; i < maxNumDigits; i++) {
|
||||
maximumWidthString.append("0");
|
||||
}
|
||||
|
||||
// Calculate maximum possible pixel width for string.
|
||||
QFontMetrics fontMetrics(font);
|
||||
maximumFontWidth = fontMetrics.width(QString("%1").arg(maximumWidthString));
|
||||
maximumFontWidth = fontMetrics.width(QString("%1").arg(maximumWidthString));
|
||||
maximumFontHeight = fontMetrics.height();
|
||||
|
||||
// Override stylesheet slider handle width
|
||||
slideHandleWidth = maximumFontWidth + 6;
|
||||
slideHandleWidth = maximumFontWidth + 6;
|
||||
setStyleSheet(QString("QSlider::handle:horizontal { width: %1px; margin: -5px 0;}").arg(slideHandleWidth));
|
||||
}
|
||||
|
||||
@ -170,26 +173,27 @@ void TextBubbleSlider::paintEvent(QPaintEvent *paintEvent)
|
||||
/* Add numbers on top of handler */
|
||||
|
||||
// Calculate pixel position for text.
|
||||
int sliderWidth = width();
|
||||
int sliderWidth = width();
|
||||
int sliderHeight = height();
|
||||
double valuePos;
|
||||
|
||||
if (!invertedAppearance()) {
|
||||
valuePos = (slideHandleWidth - maximumFontWidth)/2 + slideHandleMargin + // First part centers text in handle...
|
||||
(value()-minimum())/(double)(maximum()-minimum()) * (sliderWidth - (slideHandleWidth + slideHandleMargin) - 1); //... and second part moves text with handle
|
||||
valuePos = (slideHandleWidth - maximumFontWidth) / 2 + slideHandleMargin + // First part centers text in handle...
|
||||
(value() - minimum()) / (double)(maximum() - minimum()) * (sliderWidth - (slideHandleWidth + slideHandleMargin) - 1); // ... and second part moves text with handle
|
||||
} else {
|
||||
valuePos = (slideHandleWidth - maximumFontWidth)/2 + slideHandleMargin + // First part centers text in handle...
|
||||
(maximum()-value())/(double)(maximum()-minimum()) * (sliderWidth - (slideHandleWidth + slideHandleMargin) - 1); //... and second part moves text with handle
|
||||
valuePos = (slideHandleWidth - maximumFontWidth) / 2 + slideHandleMargin + // First part centers text in handle...
|
||||
(maximum() - value()) / (double)(maximum() - minimum()) * (sliderWidth - (slideHandleWidth + slideHandleMargin) - 1); // ... and second part moves text with handle
|
||||
}
|
||||
|
||||
// Create painter and set font
|
||||
QPainter painter(this);
|
||||
painter.setFont(font);
|
||||
painter.setPen(QPen(QColor(80, 80, 80)));
|
||||
|
||||
// Draw neutral value text. Verically center it in the handle
|
||||
// Draw neutral value text. Vertically center it in the handle
|
||||
QString neutralStringWidth = QString("%1").arg(value());
|
||||
QFontMetrics fontMetrics(font);
|
||||
int textWidth = fontMetrics.width(neutralStringWidth);
|
||||
painter.drawText(QRectF(valuePos + maximumFontWidth - textWidth, ceil((sliderHeight - maximumFontHeight)/2.0), textWidth, maximumFontHeight),
|
||||
painter.drawText(QRectF(valuePos + maximumFontWidth - textWidth, ceil((sliderHeight - maximumFontHeight) / 2.0), textWidth, maximumFontHeight),
|
||||
neutralStringWidth);
|
||||
}
|
||||
|
@ -1,29 +1,29 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
*
|
||||
* @file textbubbleslider.h
|
||||
* @author Tau Labs, http://taulabs.org Copyright (C) 2013.
|
||||
* @brief Creates a slider with a text bubble showing the slider value
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Config
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
******************************************************************************
|
||||
*
|
||||
* @file textbubbleslider.h
|
||||
* @author Tau Labs, http://taulabs.org Copyright (C) 2013.
|
||||
* @brief Creates a slider with a text bubble showing the slider value
|
||||
* @see The GNU Public License (GPL) Version 3
|
||||
* @defgroup Config
|
||||
* @{
|
||||
*
|
||||
*****************************************************************************/
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU 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 General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#ifndef TEXTBUBBLESLIDER_H
|
||||
#define TEXTBUBBLESLIDER_H
|
||||
@ -31,8 +31,7 @@
|
||||
#include <QSlider>
|
||||
#include <QtDesigner/QDesignerExportWidget>
|
||||
|
||||
class TextBubbleSlider : public QSlider
|
||||
{
|
||||
class TextBubbleSlider : public QSlider {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
@ -45,7 +44,7 @@ public:
|
||||
void setMaximum(int);
|
||||
|
||||
protected:
|
||||
void paintEvent ( QPaintEvent * event );
|
||||
void paintEvent(QPaintEvent *event);
|
||||
|
||||
private:
|
||||
void setMaxPixelWidth();
|
||||
@ -55,7 +54,6 @@ private:
|
||||
int maximumFontHeight;
|
||||
int slideHandleWidth;
|
||||
int slideHandleMargin;
|
||||
|
||||
};
|
||||
|
||||
#endif // TEXTBUBBLESLIDER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user