summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/dialogs')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp5
-rw-r--r--src/widgets/dialogs/qdialog.cpp11
-rw-r--r--src/widgets/dialogs/qfilesystemmodel.cpp16
-rw-r--r--src/widgets/dialogs/qinputdialog.cpp61
-rw-r--r--src/widgets/dialogs/qinputdialog.h8
-rw-r--r--src/widgets/dialogs/qmessagebox.cpp3
-rw-r--r--src/widgets/dialogs/qprogressdialog.cpp2
-rw-r--r--src/widgets/dialogs/qwizard.cpp32
8 files changed, 98 insertions, 40 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index 47c2333c21..f3b198fdc2 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -41,6 +41,7 @@
#include "qapplication.h"
#include "qdesktopwidget.h"
+#include <private/qdesktopwidget_p.h>
#include "qdrawutil.h"
#include "qevent.h"
#include "qimage.h"
@@ -1700,7 +1701,7 @@ void QColorDialogPrivate::initWidgets()
#else
// small displays (e.g. PDAs) cannot fit the full color dialog,
// so just use the color picker.
- smallDisplay = (QApplication::desktop()->width() < 480 || QApplication::desktop()->height() < 350);
+ smallDisplay = (QDesktopWidgetPrivate::width() < 480 || QDesktopWidgetPrivate::height() < 350);
const int lumSpace = topLay->spacing() / 2;
#endif
@@ -1746,7 +1747,7 @@ void QColorDialogPrivate::initWidgets()
} else {
// better color picker size for small displays
#if defined(QT_SMALL_COLORDIALOG)
- QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
+ QSize screenSize = QDesktopWidgetPrivate::availableGeometry(QCursor::pos()).size();
pWidth = pHeight = qMin(screenSize.width(), screenSize.height());
pHeight -= 20;
if(screenSize.height() > screenSize.width())
diff --git a/src/widgets/dialogs/qdialog.cpp b/src/widgets/dialogs/qdialog.cpp
index 6f7567a94f..f5db4481ee 100644
--- a/src/widgets/dialogs/qdialog.cpp
+++ b/src/widgets/dialogs/qdialog.cpp
@@ -50,6 +50,7 @@
#include "qevent.h"
#include "qdesktopwidget.h"
+#include <private/qdesktopwidget_p.h>
#include "qapplication.h"
#include "qlayout.h"
#if QT_CONFIG(sizegrip)
@@ -815,13 +816,13 @@ void QDialog::adjustPosition(QWidget* w)
w = w->window();
QRect desk;
if (w) {
- scrn = QApplication::desktop()->screenNumber(w);
- } else if (QApplication::desktop()->isVirtualDesktop()) {
- scrn = QApplication::desktop()->screenNumber(QCursor::pos());
+ scrn = QDesktopWidgetPrivate::screenNumber(w);
+ } else if (QDesktopWidgetPrivate::isVirtualDesktop()) {
+ scrn = QDesktopWidgetPrivate::screenNumber(QCursor::pos());
} else {
- scrn = QApplication::desktop()->screenNumber(this);
+ scrn = QDesktopWidgetPrivate::screenNumber(this);
}
- desk = QApplication::desktop()->availableGeometry(scrn);
+ desk = QDesktopWidgetPrivate::availableGeometry(scrn);
QWidgetList list = QApplication::topLevelWidgets();
for (int i = 0; (extraw == 0 || extrah == 0) && i < list.size(); ++i) {
diff --git a/src/widgets/dialogs/qfilesystemmodel.cpp b/src/widgets/dialogs/qfilesystemmodel.cpp
index bf14b5c6fd..f88ac71cf3 100644
--- a/src/widgets/dialogs/qfilesystemmodel.cpp
+++ b/src/widgets/dialogs/qfilesystemmodel.cpp
@@ -778,21 +778,7 @@ QString QFileSystemModelPrivate::size(const QModelIndex &index) const
QString QFileSystemModelPrivate::size(qint64 bytes)
{
- // According to the Si standard KB is 1000 bytes, KiB is 1024
- // but on windows sizes are calculated by dividing by 1024 so we do what they do.
- const qint64 kb = 1024;
- const qint64 mb = 1024 * kb;
- const qint64 gb = 1024 * mb;
- const qint64 tb = 1024 * gb;
- if (bytes >= tb)
- return QFileSystemModel::tr("%1 TB").arg(QLocale().toString(qreal(bytes) / tb, 'f', 3));
- if (bytes >= gb)
- return QFileSystemModel::tr("%1 GB").arg(QLocale().toString(qreal(bytes) / gb, 'f', 2));
- if (bytes >= mb)
- return QFileSystemModel::tr("%1 MB").arg(QLocale().toString(qreal(bytes) / mb, 'f', 1));
- if (bytes >= kb)
- return QFileSystemModel::tr("%1 KB").arg(QLocale().toString(bytes / kb));
- return QFileSystemModel::tr("%1 bytes").arg(QLocale().toString(bytes));
+ return QLocale::system().formattedDataSize(bytes);
}
/*!
diff --git a/src/widgets/dialogs/qinputdialog.cpp b/src/widgets/dialogs/qinputdialog.cpp
index 04d13045e5..4c0f22ae97 100644
--- a/src/widgets/dialogs/qinputdialog.cpp
+++ b/src/widgets/dialogs/qinputdialog.cpp
@@ -1368,12 +1368,48 @@ double QInputDialog::getDouble(QWidget *parent, const QString &title, const QStr
double value, double min, double max, int decimals, bool *ok,
Qt::WindowFlags flags)
{
+ return QInputDialog::getDouble(parent, title, label, value, min, max, decimals, ok, flags, 1.0);
+}
+
+/*!
+ \overload
+ Static convenience function to get a floating point number from the user.
+
+ \a title is the text which is displayed in the title bar of the dialog.
+ \a label is the text which is shown to the user (it should say what should
+ be entered).
+ \a value is the default floating point number that the line edit will be
+ set to.
+ \a min and \a max are the minimum and maximum values the user may choose.
+ \a decimals is the maximum number of decimal places the number may have.
+ \a step is the amount by which the values change as the user presses the
+ arrow buttons to increment or decrement the value.
+
+ If \a ok is nonnull, *\a ok will be set to true if the user pressed \uicontrol OK
+ and to false if the user pressed \uicontrol Cancel. The dialog's parent is
+ \a parent. The dialog will be modal and uses the widget \a flags.
+
+ This function returns the floating point number which has been entered by
+ the user.
+
+ Use this static function like this:
+
+ \snippet dialogs/standarddialogs/dialog.cpp 1
+
+ \sa getText(), getInt(), getItem(), getMultiLineText()
+*/
+
+double QInputDialog::getDouble(QWidget *parent, const QString &title, const QString &label,
+ double value, double min, double max, int decimals, bool *ok,
+ Qt::WindowFlags flags, double step)
+{
QAutoPointer<QInputDialog> dialog(new QInputDialog(parent, flags));
dialog->setWindowTitle(title);
dialog->setLabelText(label);
dialog->setDoubleDecimals(decimals);
dialog->setDoubleRange(min, max);
dialog->setDoubleValue(value);
+ dialog->setDoubleStep(step);
const int ret = dialog->exec();
if (ok)
@@ -1439,6 +1475,31 @@ QString QInputDialog::getItem(QWidget *parent, const QString &title, const QStri
}
/*!
+ \property QInputDialog::doubleStep
+ \since 5.10
+ \brief the step by which the double value is increased and decreased
+
+ This property is only relevant when the input dialog is used in
+ DoubleInput mode.
+*/
+
+void QInputDialog::setDoubleStep(double step)
+{
+ Q_D(QInputDialog);
+ d->ensureDoubleSpinBox();
+ d->doubleSpinBox->setSingleStep(step);
+}
+
+double QInputDialog::doubleStep() const
+{
+ Q_D(const QInputDialog);
+ if (d->doubleSpinBox)
+ return d->doubleSpinBox->singleStep();
+ else
+ return 1.0;
+}
+
+/*!
\fn void QInputDialog::doubleValueChanged(double value)
This signal is emitted whenever the double value changes in the dialog.
diff --git a/src/widgets/dialogs/qinputdialog.h b/src/widgets/dialogs/qinputdialog.h
index 5f06785886..e41d442498 100644
--- a/src/widgets/dialogs/qinputdialog.h
+++ b/src/widgets/dialogs/qinputdialog.h
@@ -74,6 +74,7 @@ class Q_WIDGETS_EXPORT QInputDialog : public QDialog
QDOC_PROPERTY(int doubleDecimals READ doubleDecimals WRITE setDoubleDecimals)
QDOC_PROPERTY(QString okButtonText READ okButtonText WRITE setOkButtonText)
QDOC_PROPERTY(QString cancelButtonText READ cancelButtonText WRITE setCancelButtonText)
+ QDOC_PROPERTY(double doubleStep READ doubleStep WRITE setDoubleStep)
public:
enum InputDialogOption {
@@ -178,6 +179,10 @@ public:
static double getDouble(QWidget *parent, const QString &title, const QString &label, double value = 0,
double minValue = -2147483647, double maxValue = 2147483647,
int decimals = 1, bool *ok = Q_NULLPTR, Qt::WindowFlags flags = Qt::WindowFlags());
+ // ### Qt 6: merge overloads
+ static double getDouble(QWidget *parent, const QString &title, const QString &label, double value,
+ double minValue, double maxValue, int decimals, bool *ok, Qt::WindowFlags flags,
+ double step);
#if QT_DEPRECATED_SINCE(5, 0)
QT_DEPRECATED static inline int getInteger(QWidget *parent, const QString &title, const QString &label, int value = 0,
@@ -188,6 +193,9 @@ public:
}
#endif
+ void setDoubleStep(double step);
+ double doubleStep() const;
+
Q_SIGNALS:
// ### emit signals!
void textValueChanged(const QString &text);
diff --git a/src/widgets/dialogs/qmessagebox.cpp b/src/widgets/dialogs/qmessagebox.cpp
index 9421ea2953..fdfffb45cf 100644
--- a/src/widgets/dialogs/qmessagebox.cpp
+++ b/src/widgets/dialogs/qmessagebox.cpp
@@ -64,6 +64,7 @@
#include <QtGui/qfont.h>
#include <QtGui/qfontmetrics.h>
#include <QtGui/qclipboard.h>
+#include <private/qdesktopwidget_p.h>
#ifdef Q_OS_WIN
# include <QtCore/qt_windows.h>
@@ -361,7 +362,7 @@ void QMessageBoxPrivate::updateSize()
if (!q->isVisible())
return;
- QSize screenSize = QApplication::desktop()->availableGeometry(QCursor::pos()).size();
+ QSize screenSize = QDesktopWidgetPrivate::availableGeometry(QCursor::pos()).size();
int hardLimit = qMin(screenSize.width() - 480, 1000); // can never get bigger than this
// on small screens allows the messagebox be the same size as the screen
if (screenSize.width() <= 1024)
diff --git a/src/widgets/dialogs/qprogressdialog.cpp b/src/widgets/dialogs/qprogressdialog.cpp
index 893920cbd9..a276e28a0c 100644
--- a/src/widgets/dialogs/qprogressdialog.cpp
+++ b/src/widgets/dialogs/qprogressdialog.cpp
@@ -242,7 +242,7 @@ void QProgressDialogPrivate::_q_disconnectOnClose()
A modeless progress dialog is suitable for operations that take
place in the background, where the user is able to interact with the
application. Such operations are typically based on QTimer (or
- QObject::timerEvent()), QSocketNotifier, or QUrlOperator; or performed
+ QObject::timerEvent()) or QSocketNotifier; or performed
in a separate thread. A QProgressBar in the status bar of your main window
is often an alternative to a modeless progress dialog.
diff --git a/src/widgets/dialogs/qwizard.cpp b/src/widgets/dialogs/qwizard.cpp
index 1984cb0a89..22499b3c22 100644
--- a/src/widgets/dialogs/qwizard.cpp
+++ b/src/widgets/dialogs/qwizard.cpp
@@ -48,6 +48,7 @@
#include "qboxlayout.h"
#include "qlayoutitem.h"
#include "qdesktopwidget.h"
+#include <private/qdesktopwidget_p.h>
#include "qevent.h"
#include "qframe.h"
#include "qlabel.h"
@@ -400,7 +401,7 @@ void QWizardHeader::setup(const QWizardLayoutInfo &info, const QString &title,
/*
There is no widthForHeight() function, so we simulate it with a loop.
*/
- int candidateSubTitleWidth = qMin(512, 2 * QApplication::desktop()->width() / 3);
+ int candidateSubTitleWidth = qMin(512, 2 * QDesktopWidgetPrivate::width() / 3);
int delta = candidateSubTitleWidth >> 1;
while (delta > 0) {
if (subTitleLabel->heightForWidth(candidateSubTitleWidth - delta)
@@ -500,6 +501,7 @@ public:
mutable TriState completeState;
bool explicitlyFinal;
bool commit;
+ bool initialized = false;
QMap<int, QString> buttonCustomTexts;
};
@@ -635,7 +637,6 @@ public:
QMap<QString, int> fieldIndexMap;
QVector<QWizardDefaultProperty> defaultPropertyTable;
QList<int> history;
- QSet<int> initialized; // ### remove and move bit to QWizardPage?
int start;
bool startSetByUser;
int current;
@@ -774,7 +775,8 @@ void QWizardPrivate::reset()
for (int i = history.count() - 1; i >= 0; --i)
q->cleanupPage(history.at(i));
history.clear();
- initialized.clear();
+ for (QWizardPage *page : pageMap)
+ page->d_func()->initialized = false;
current = -1;
emit q->currentIdChanged(-1);
@@ -785,14 +787,12 @@ void QWizardPrivate::cleanupPagesNotInHistory()
{
Q_Q(QWizard);
- const QSet<int> original = initialized;
- QSet<int>::const_iterator i = original.constBegin();
- QSet<int>::const_iterator end = original.constEnd();
-
- for (; i != end; ++i) {
- if (!history.contains(*i)) {
- q->cleanupPage(*i);
- initialized.remove(*i);
+ for (auto it = pageMap.begin(), end = pageMap.end(); it != end; ++it) {
+ const auto idx = it.key();
+ const auto page = it.value()->d_func();
+ if (page->initialized && !history.contains(idx)) {
+ q->cleanupPage(idx);
+ page->initialized = false;
}
}
}
@@ -847,7 +847,7 @@ void QWizardPrivate::switchToPage(int newId, Direction direction)
if (direction == Backward) {
if (!(opts & QWizard::IndependentPages)) {
q->cleanupPage(oldId);
- initialized.remove(oldId);
+ oldPage->d_func()->initialized = false;
}
Q_ASSERT(history.constLast() == oldId);
history.removeLast();
@@ -860,8 +860,8 @@ void QWizardPrivate::switchToPage(int newId, Direction direction)
QWizardPage *newPage = q->currentPage();
if (newPage) {
if (direction == Forward) {
- if (!initialized.contains(current)) {
- initialized.insert(current);
+ if (!newPage->d_func()->initialized) {
+ newPage->d_func()->initialized = true;
q->initializePage(current);
}
history.append(current);
@@ -2361,9 +2361,9 @@ void QWizard::removePage(int id)
}
if (removedPage) {
- if (d->initialized.contains(id)) {
+ if (removedPage->d_func()->initialized) {
cleanupPage(id);
- d->initialized.remove(id);
+ removedPage->d_func()->initialized = false;
}
d->pageVBoxLayout->removeWidget(removedPage);