Better Qt input dialogs - need clear button in text input.
This commit is contained in:
committed by
craig.p.drummond
parent
a9cf9d8051
commit
f03134dd12
@@ -142,6 +142,7 @@
|
||||
81. Show MTP track list progress in percentages.
|
||||
82. Fix memleak with MTP devices.
|
||||
83. Open MTP devices in un-cached mode (faster)
|
||||
84. Add clear button to Qt input dialogs.
|
||||
|
||||
1.1.3
|
||||
-----
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
set(SUPPORT_SRCS action.cpp actioncollection.cpp fancytabwidget.cpp messagewidget.cpp icon.cpp buddylabel.cpp
|
||||
lineedit.cpp gtkstyle.cpp utils.cpp spinner.cpp messagebox.cpp inputdialog.cpp thread.cpp squeezedtextlabel.cpp)
|
||||
|
||||
set(SUPPORT_MOC_HDRS action.h actioncollection.h fancytabwidget.h messagewidget.h thread.h)
|
||||
set(SUPPORT_MOC_HDRS action.h actioncollection.h fancytabwidget.h messagewidget.h inputdialog.h thread.h)
|
||||
|
||||
if (NOT WIN32)
|
||||
set(SUPPORT_SRCS ${SUPPORT_SRCS} onoffbutton.cpp spinbox.cpp windowmanager.cpp gtkproxystyle.cpp combobox.cpp shortcuthandler.cpp)
|
||||
|
||||
@@ -24,57 +24,91 @@
|
||||
#include "inputdialog.h"
|
||||
#include "gtkstyle.h"
|
||||
#include "spinbox.h"
|
||||
#include "lineedit.h"
|
||||
#include "dialog.h"
|
||||
#include "utils.h"
|
||||
#include <QLabel>
|
||||
#include <QFormLayout>
|
||||
#include <QBoxLayout>
|
||||
|
||||
class IntInputDialog : public Dialog
|
||||
InputDialog::InputDialog(const QString &caption, const QString &label, const QString &value, QLineEdit::EchoMode echo, QWidget *parent)
|
||||
: Dialog(parent)
|
||||
, spin(0)
|
||||
{
|
||||
public:
|
||||
IntInputDialog(const QString &caption, const QString &label, int value, int minValue, int maxValue, int step, QWidget *parent)
|
||||
: Dialog(parent) {
|
||||
setButtons(Ok|Cancel);
|
||||
QWidget *wid=new QWidget(this);
|
||||
QFormLayout *layout=new QFormLayout(wid);
|
||||
init(false, caption, label);
|
||||
edit->setText(value);
|
||||
edit->setEchoMode(echo);
|
||||
enableOkButton();
|
||||
connect(edit, SIGNAL(textChanged(QString)), this, SLOT(enableOkButton()));
|
||||
}
|
||||
|
||||
InputDialog::InputDialog(const QString &caption, const QString &label, int value, int minValue, int maxValue, int step, QWidget *parent)
|
||||
: Dialog(parent)
|
||||
, edit(0)
|
||||
{
|
||||
init(true, caption, label);
|
||||
spin->setRange(minValue, maxValue);
|
||||
spin->setValue(value);
|
||||
spin->setSingleStep(step);
|
||||
}
|
||||
|
||||
void InputDialog::init(bool intInput, const QString &caption, const QString &label)
|
||||
{
|
||||
setButtons(Ok|Cancel);
|
||||
QWidget *wid=new QWidget(this);
|
||||
QBoxLayout *layout=new QBoxLayout(QBoxLayout::TopToBottom, wid);
|
||||
|
||||
if (intInput) {
|
||||
spin=new SpinBox(wid);
|
||||
spin->setRange(minValue, maxValue);
|
||||
spin->setValue(value);
|
||||
spin->setSingleStep(step);
|
||||
spin->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
layout->setWidget(0, QFormLayout::LabelRole, new QLabel(label, wid));
|
||||
layout->setWidget(0, QFormLayout::FieldRole, spin);
|
||||
layout->setMargin(0);
|
||||
|
||||
setCaption(caption);
|
||||
setMainWidget(wid);
|
||||
setButtons(Ok|Cancel);
|
||||
}
|
||||
|
||||
SpinBox *spin;
|
||||
};
|
||||
|
||||
int InputDialog::getInteger(const QString &caption, const QString &label, int value, int minValue, int maxValue, int step, int base, bool *ok, QWidget *parent) {
|
||||
|
||||
if (GtkStyle::mimicWidgets()) {
|
||||
IntInputDialog dlg(caption, label, value, minValue, maxValue, step, parent);
|
||||
if (QDialog::Accepted==dlg.exec()) {
|
||||
if (ok) {
|
||||
*ok=true;
|
||||
}
|
||||
return dlg.spin->value();
|
||||
} else {
|
||||
if (ok) {
|
||||
*ok=false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
setMinimumWidth(Utils::isHighDpi() ? 600 : 300);
|
||||
} else {
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
return KInputDialog::getInteger(caption, label, value, minValue, maxValue, step, base, ok, parent);
|
||||
#else
|
||||
Q_UNUSED(base)
|
||||
return QInputDialog::getInt(parent, caption, label, value, minValue, maxValue, step, ok);
|
||||
#endif
|
||||
edit=new LineEdit(wid);
|
||||
edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
|
||||
setMinimumWidth(Utils::isHighDpi() ? 700 : 350);
|
||||
}
|
||||
layout->addWidget(new QLabel(label, wid));
|
||||
layout->addWidget(intInput ? (QWidget *)spin : (QWidget *)edit);
|
||||
layout->setMargin(0);
|
||||
|
||||
setCaption(caption);
|
||||
setMainWidget(wid);
|
||||
setButtons(Ok|Cancel);
|
||||
}
|
||||
|
||||
void InputDialog::enableOkButton()
|
||||
{
|
||||
enableButton(Ok, 0==edit || !edit->text().trimmed().isEmpty());
|
||||
}
|
||||
|
||||
int InputDialog::getInteger(const QString &caption, const QString &label, int value, int minValue, int maxValue, int step, int base, bool *ok, QWidget *parent)
|
||||
{
|
||||
Q_UNUSED(base)
|
||||
InputDialog dlg(caption, label, value, minValue, maxValue, step, parent);
|
||||
if (QDialog::Accepted==dlg.exec()) {
|
||||
if (ok) {
|
||||
*ok=true;
|
||||
}
|
||||
return dlg.spin->value();
|
||||
} else {
|
||||
if (ok) {
|
||||
*ok=false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
QString InputDialog::getText(const QString &caption, const QString &label, QLineEdit::EchoMode echoMode, const QString &value, bool *ok, QWidget *parent)
|
||||
{
|
||||
InputDialog dlg(caption, label, value, echoMode, parent);
|
||||
if (QDialog::Accepted==dlg.exec()) {
|
||||
if (ok) {
|
||||
*ok=true;
|
||||
}
|
||||
return dlg.edit->text();
|
||||
} else {
|
||||
if (ok) {
|
||||
*ok=false;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,28 +24,42 @@
|
||||
#ifndef INPUT_DIALOG_H
|
||||
#define INPUT_DIALOG_H
|
||||
|
||||
#include <QInputDialog>
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
#include <KDE/KInputDialog>
|
||||
#endif
|
||||
#include <QLineEdit>
|
||||
#include "localize.h"
|
||||
#include "dialog.h"
|
||||
|
||||
namespace InputDialog
|
||||
class SpinBox;
|
||||
class LineEdit;
|
||||
|
||||
class InputDialog : public Dialog
|
||||
{
|
||||
inline QString getText(const QString &caption, const QString &label, const QString &value=QString(), bool *ok=0, QWidget *parent=0) {
|
||||
#ifdef ENABLE_KDE_SUPPORT
|
||||
return KInputDialog::getText(caption, label, value, ok, parent=0);
|
||||
#else
|
||||
return QInputDialog::getText(parent, caption, label, QLineEdit::Normal, value, ok);
|
||||
#endif
|
||||
}
|
||||
Q_OBJECT
|
||||
|
||||
extern int getInteger(const QString &caption, const QString &label, int value=0, int minValue=INT_MIN, int maxValue=INT_MAX,
|
||||
public:
|
||||
InputDialog(const QString &caption, const QString &label, const QString &value, QLineEdit::EchoMode echo, QWidget *parent);
|
||||
InputDialog(const QString &caption, const QString &label, int value, int minValue, int maxValue, int step, QWidget *parent);
|
||||
|
||||
static QString getText(const QString &caption, const QString &label, QLineEdit::EchoMode echoMode, const QString &value=QString(),
|
||||
bool *ok=0, QWidget *parent=0);
|
||||
static int getInteger(const QString &caption, const QString &label, int value=0, int minValue=INT_MIN, int maxValue=INT_MAX,
|
||||
int step=1, int base=10, bool *ok=0, QWidget *parent=0);
|
||||
|
||||
inline QString getPassword(const QString &value=QString(), bool *ok=0, QWidget *parent=0) {
|
||||
return QInputDialog::getText(parent, i18n("Password"), i18n("Please enter password:"), QLineEdit::Password, value, ok);
|
||||
static QString getText(const QString &caption, const QString &label, const QString &value=QString(), bool *ok=0, QWidget *parent=0) {
|
||||
return getText(caption, label, QLineEdit::Normal, value, ok, parent);
|
||||
}
|
||||
static QString getPassword(const QString &value=QString(), bool *ok=0, QWidget *parent=0) {
|
||||
return getText(i18n("Password"), i18n("Please enter password:"), QLineEdit::Password, value, ok, parent);
|
||||
}
|
||||
|
||||
private:
|
||||
void init(bool intInput, const QString &caption, const QString &label);
|
||||
|
||||
private Q_SLOTS:
|
||||
void enableOkButton();
|
||||
|
||||
private:
|
||||
SpinBox *spin;
|
||||
LineEdit *edit;
|
||||
};
|
||||
|
||||
#endif // INPUT_DIALOG_H
|
||||
|
||||
@@ -129,7 +129,6 @@ SpinBox::SpinBox(QWidget *p)
|
||||
layout->addWidget(spin);
|
||||
layout->addWidget(decButton);
|
||||
layout->addWidget(incButton);
|
||||
layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
|
||||
connect(spin, SIGNAL(valueChanged(int)), SLOT(checkValue()));
|
||||
connect(decButton, SIGNAL(pressed()), SLOT(decPressed()));
|
||||
connect(incButton, SIGNAL(pressed()), SLOT(incPressed()));
|
||||
|
||||
@@ -63,7 +63,11 @@ private:
|
||||
};
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
typedef EmptySpinBox SpinBox;
|
||||
class SpinBox : public EmptySpinBox
|
||||
{
|
||||
public:
|
||||
SpinBox(QWidget *p) : EmptySpinBox(p) { }
|
||||
};
|
||||
#else
|
||||
class SpinBoxButton;
|
||||
|
||||
@@ -87,6 +91,7 @@ public:
|
||||
int maximum() const { return spin->maximum(); }
|
||||
void setFocus() const { spin->setFocus(); }
|
||||
void setAllowEmpty() { spin->setAllowEmpty(); }
|
||||
void setSizePolicy(QSizePolicy::Policy horizontal, QSizePolicy::Policy vertical) { spin->setSizePolicy(horizontal, vertical); }
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged(int v);
|
||||
|
||||
Reference in New Issue
Block a user