-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add WDoubleSpinbox: allow . and , in library BPM editor #13068
base: 2.5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
#include <QTableView> | ||
|
||
#include "moc_bpmdelegate.cpp" | ||
#include "widget/wdoublespinbox.h" | ||
|
||
// We override the typical QDoubleSpinBox editor by registering this class with | ||
// a QItemEditorFactory for the BPMDelegate. | ||
|
@@ -18,10 +19,10 @@ class BpmEditorCreator : public QItemEditorCreatorBase { | |
} | ||
|
||
QWidget* createWidget(QWidget* parent) const override { | ||
QDoubleSpinBox* pBpmSpinbox = new QDoubleSpinBox(parent); | ||
WDoubleSpinBox* pBpmSpinbox = new WDoubleSpinBox(parent); | ||
pBpmSpinbox->setFrame(false); | ||
pBpmSpinbox->setMinimum(0); | ||
pBpmSpinbox->setMaximum(1000); | ||
pBpmSpinbox->setMaximum(99999); | ||
pBpmSpinbox->setSingleStep(1e-3); | ||
pBpmSpinbox->setDecimals(8); | ||
Comment on lines
26
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR but these settings feel overly precise, would you know if that something that was requested at some point or just arbitrary value that could be reviewed for a better UX? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, 8 decimals look scary. I think there are two reason:
|
||
pBpmSpinbox->setObjectName("LibraryBPMSpinBox"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "widget/wdoublespinbox.h" | ||
|
||
#include <QLineEdit> | ||
#include <QLocale> | ||
|
||
#include "moc_wdoublespinbox.cpp" | ||
|
||
WDoubleSpinBox::WDoubleSpinBox(QWidget* pParent) | ||
: QDoubleSpinBox(pParent), | ||
m_decSep(QLocale().decimalPoint()) { | ||
lineEdit()->setValidator(new QRegExpValidator( | ||
QRegExp("[0-9]{1,5}[." + | ||
// add locale decimal point if it's not a dot | ||
(m_decSep != '.' ? m_decSep : QChar()) + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be worth to simply allow both I guess the risk is that some users may type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as #13068 (comment) |
||
"]?[0-9]{,8}"), | ||
this)); | ||
} | ||
|
||
// This gets the text from lineEdit() | ||
double WDoubleSpinBox::valueFromText(const QString& text) const { | ||
QString temp = text; | ||
// replace , with dot before toDouble() | ||
temp.replace(",", "."); | ||
return temp.toDouble(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <QDoubleSpinBox> | ||
|
||
// This spinbox accepts , and . as decimal separator which comes in handy when | ||
// the used (typed) decimal separator doesn't match the locale's separator for | ||
// some reason, e.g. when typing with numpads that have a fixed separator char. | ||
class WDoubleSpinBox : public QDoubleSpinBox { | ||
Q_OBJECT | ||
public: | ||
explicit WDoubleSpinBox(QWidget* pParent); | ||
|
||
double valueFromText(const QString& text) const override; | ||
|
||
private: | ||
const QChar m_decSep; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason for allowing this much BPM?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Obviously sky is the limit ; )
#12942 (comment)