Qt 4.8
Macros | Functions
qabstractspinbox.cpp File Reference
#include <qplatformdefs.h>
#include <private/qabstractspinbox_p.h>
#include <private/qdatetime_p.h>
#include <private/qlineedit_p.h>
#include <qabstractspinbox.h>
#include <qapplication.h>
#include <qclipboard.h>
#include <qdatetime.h>
#include <qdatetimeedit.h>
#include <qevent.h>
#include <qmenu.h>
#include <qpainter.h>
#include <qpalette.h>
#include <qstylepainter.h>
#include <qdebug.h>
#include <qaccessible.h>
#include <limits.h>
#include "moc_qabstractspinbox.cpp"

Go to the source code of this file.

Macros

#define QASBDEBUG   if (false) qDebug
 

Functions

static int getKeyboardAutoRepeatRate ()
 Used when acceleration is turned on. More...
 
QVariant operator* (const QVariant &arg1, double multiplier)
 Multiplies arg1 by multiplier and returns the result. More...
 
QVariant operator+ (const QVariant &arg1, const QVariant &arg2)
 Adds two variants together and returns the result. More...
 
QVariant operator- (const QVariant &arg1, const QVariant &arg2)
 Subtracts two variants and returns the result. More...
 
double operator/ (const QVariant &arg1, const QVariant &arg2)
 

Macro Definition Documentation

◆ QASBDEBUG

#define QASBDEBUG   if (false) qDebug

Definition at line 77 of file qabstractspinbox.cpp.

Referenced by QAbstractSpinBoxPrivate::interpret().

Function Documentation

◆ getKeyboardAutoRepeatRate()

static int getKeyboardAutoRepeatRate ( )
static

Used when acceleration is turned on.

Warning
This function is not part of the public interface.

We need to get the keyboard auto repeat rate from OS. This value is used as argument when starting acceleration related timers.

Every platform should, either, use native calls to obtain the value or hard code some reasonable rate.

Remember that time value should be given in msecs.

Definition at line 1227 of file qabstractspinbox.cpp.

Referenced by QAbstractSpinBox::timerEvent().

1227  {
1228  int ret = 30;
1229 #if defined(Q_OS_SYMBIAN)
1230  TTimeIntervalMicroSeconds32 initialTime;
1231  TTimeIntervalMicroSeconds32 time;
1232  S60->wsSession().GetKeyboardRepeatRate(initialTime, time);
1233  ret = time.Int() / 1000; // msecs
1234 #elif defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
1235  DWORD time;
1236  if (SystemParametersInfo(SPI_GETKEYBOARDSPEED, 0, &time, 0) != FALSE)
1237  ret = static_cast<int>(1000 / static_cast<int>(time)); // msecs
1238 #endif
1239  return ret; // msecs
1240 }
#define FALSE
Synonym for false.
Definition: qglobal.h:1019

◆ operator*()

QVariant operator* ( const QVariant arg1,
double  multiplier 
)

Multiplies arg1 by multiplier and returns the result.

Warning
This function is not part of the public interface.

Definition at line 2111 of file qabstractspinbox.cpp.

2112 {
2113  QVariant ret;
2114 
2115  switch (arg1.type()) {
2116  case QVariant::Int: ret = QVariant((int)(arg1.toInt() * multiplier)); break;
2117  case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break;
2118  case QVariant::DateTime: {
2119  double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier;
2120  int daysInt = (int)days;
2121  days -= daysInt;
2122  long msecs = (long)((QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) * multiplier)
2123  + (days * (24 * 3600 * 1000)));
2124  ret = QDateTime(QDate().addDays(int(days)), QTime().addMSecs(msecs));
2125  break;
2126  }
2127  default: ret = arg1; break;
2128  }
2129 
2130  return ret;
2131 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
The QDate class provides date functions.
Definition: qdatetime.h:55
#define QDATETIMEEDIT_TIME_MIN
Definition: qdatetime_p.h:67
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
The QTime class provides clock time functions.
Definition: qdatetime.h:148
#define QDATETIMEEDIT_DATE_MIN
Definition: qdatetime_p.h:69
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368

◆ operator+()

QVariant operator+ ( const QVariant arg1,
const QVariant arg2 
)

Adds two variants together and returns the result.

Warning
This function is not part of the public interface.

Definition at line 2045 of file qabstractspinbox.cpp.

2046 {
2047  QVariant ret;
2048  if (arg1.type() != arg2.type())
2049  qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
2050  arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
2051  switch (arg1.type()) {
2052  case QVariant::Int: ret = QVariant(arg1.toInt() + arg2.toInt()); break;
2053  case QVariant::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break;
2054  case QVariant::DateTime: {
2055  QDateTime a2 = arg2.toDateTime();
2056  QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATETIME_MIN.daysTo(a2));
2057  a1.setTime(a1.time().addMSecs(QTime().msecsTo(a2.time())));
2058  ret = QVariant(a1);
2059  }
2060  default: break;
2061  }
2062  return ret;
2063 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
The QTime class provides clock time functions.
Definition: qdatetime.h:148
void setTime(const QTime &time)
Sets the time part of this datetime to time.
Definition: qdatetime.cpp:2416
Q_CORE_EXPORT void qWarning(const char *,...)
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QDateTime addDays(int days) const
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (o...
Definition: qdatetime.cpp:2783
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
QTime addMSecs(int ms) const
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earli...
Definition: qdatetime.cpp:1803
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
#define QDATETIMEEDIT_DATETIME_MIN
Definition: qdatetime_p.h:72

◆ operator-()

QVariant operator- ( const QVariant arg1,
const QVariant arg2 
)

Subtracts two variants and returns the result.

Warning
This function is not part of the public interface.

Definition at line 2074 of file qabstractspinbox.cpp.

2075 {
2076  QVariant ret;
2077  if (arg1.type() != arg2.type())
2078  qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
2079  arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
2080  switch (arg1.type()) {
2081  case QVariant::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break;
2082  case QVariant::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break;
2083  case QVariant::DateTime: {
2084  QDateTime a1 = arg1.toDateTime();
2085  QDateTime a2 = arg2.toDateTime();
2086  int days = a2.daysTo(a1);
2087  int secs = a2.secsTo(a1);
2088  int msecs = qMax(0, a1.time().msec() - a2.time().msec());
2089  if (days < 0 || secs < 0 || msecs < 0) {
2090  ret = arg1;
2091  } else {
2092  QDateTime dt = a2.addDays(days).addSecs(secs);
2093  if (msecs > 0)
2094  dt.setTime(dt.time().addMSecs(msecs));
2095  ret = QVariant(dt);
2096  }
2097  }
2098  default: break;
2099  }
2100  return ret;
2101 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QDateTime addSecs(int secs) const
Returns a QDateTime object containing a datetime s seconds later than the datetime of this object (or...
Definition: qdatetime.cpp:2869
int daysTo(const QDateTime &) const
Returns the number of days from this datetime to the other datetime.
Definition: qdatetime.cpp:2894
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
int msec() const
Returns the millisecond part (0 to 999) of the time.
Definition: qdatetime.cpp:1611
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
void setTime(const QTime &time)
Sets the time part of this datetime to time.
Definition: qdatetime.cpp:2416
int secsTo(const QDateTime &) const
Returns the number of seconds from this datetime to the other datetime.
Definition: qdatetime.cpp:2914
Q_CORE_EXPORT void qWarning(const char *,...)
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QDateTime addDays(int days) const
Returns a QDateTime object containing a datetime ndays days later than the datetime of this object (o...
Definition: qdatetime.cpp:2783
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
QTime addMSecs(int ms) const
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earli...
Definition: qdatetime.cpp:1803
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368

◆ operator/()

double operator/ ( const QVariant arg1,
const QVariant arg2 
)

Definition at line 2135 of file qabstractspinbox.cpp.

2136 {
2137  double a1 = 0;
2138  double a2 = 0;
2139 
2140  switch (arg1.type()) {
2141  case QVariant::Int:
2142  a1 = (double)arg1.toInt();
2143  a2 = (double)arg2.toInt();
2144  break;
2145  case QVariant::Double:
2146  a1 = arg1.toDouble();
2147  a2 = arg2.toDouble();
2148  break;
2149  case QVariant::DateTime:
2150  a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate());
2151  a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate());
2152  a1 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) / (long)(3600 * 24 * 1000);
2153  a2 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg2.toDateTime().time()) / (long)(3600 * 24 * 1000);
2154  default: break;
2155  }
2156 
2157  return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0;
2158 }
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
#define QDATETIMEEDIT_TIME_MIN
Definition: qdatetime_p.h:67
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
Definition: qvariant.cpp:2625
#define QDATETIMEEDIT_DATE_MIN
Definition: qdatetime_p.h:69
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
double toDouble(bool *ok=0) const
Returns the variant as a double if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2710
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368