Added time stamps to the chat. Enabled translations.

This commit is contained in:
Dimitar Dobrev 2014-03-10 12:08:33 +02:00
parent 437cadf360
commit 9eb217794c
8 changed files with 2863 additions and 19 deletions

View file

@ -10,6 +10,8 @@ set(MACRO_DIR "${ROOT_DIR}/cmake/macros")
set(TARGET_NAME interface)
project(${TARGET_NAME})
find_package(Qt5LinguistTools REQUIRED)
# setup for find modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/modules/")
set(FACESHIFT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/external/faceshift")
@ -77,6 +79,10 @@ qt5_wrap_ui(QT_UI_HEADERS "${QT_UI_FILES}")
# add them to the interface source files
set(INTERFACE_SRCS ${INTERFACE_SRCS} "${QT_UI_HEADERS}")
set(QM ${TARGET_NAME}_en.qm)
set(TS ${TARGET_NAME}_en.ts)
qt5_create_translation(${QM} ${INTERFACE_SRCS} ${QT_UI_FILES} ${TS})
if (APPLE)
# configure CMake to use a custom Info.plist
SET_TARGET_PROPERTIES( ${this_target} PROPERTIES MACOSX_BUNDLE_INFO_PLIST MacOSXBundleInfo.plist.in )
@ -105,7 +111,7 @@ if (APPLE)
endif()
# create the executable, make it a bundle on OS X
add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS})
add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM})
# link in the hifi shared library
include(${MACRO_DIR}/LinkHifiLibrary.cmake)

161
interface/interface_en.ts Normal file
View file

@ -0,0 +1,161 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="en_US">
<context>
<name>Application</name>
<message>
<location filename="src/Application.cpp" line="1375"/>
<source>Export Voxels</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Application.cpp" line="1376"/>
<source>Sparse Voxel Octree Files (*.svo)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Application.cpp" line="3562"/>
<source>Open Script</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Application.cpp" line="3563"/>
<source>JavaScript Files (*.js)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ChatWindow</name>
<message>
<location filename="ui/chatWindow.ui" line="14"/>
<location filename="../build/interface/ui_chatWindow.h" line="111"/>
<source>Chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="ui/chatWindow.ui" line="41"/>
<location filename="../build/interface/ui_chatWindow.h" line="112"/>
<source>Connecting to XMPP...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="ui/chatWindow.ui" line="60"/>
<location filename="../build/interface/ui_chatWindow.h" line="113"/>
<source> online now:</source>
<translation type="unfinished"></translation>
</message>
<message numerus="yes">
<location filename="src/ui/ChatWindow.cpp" line="93"/>
<source>day</source>
<translation>
<numerusform>%n day</numerusform>
<numerusform>%n days</numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="src/ui/ChatWindow.cpp" line="93"/>
<source>hour</source>
<translation>
<numerusform>%n hour</numerusform>
<numerusform>%n hours</numerusform>
</translation>
</message>
<message numerus="yes">
<location filename="src/ui/ChatWindow.cpp" line="93"/>
<source>minute</source>
<translation>
<numerusform>%n minute</numerusform>
<numerusform>%n minutes</numerusform>
</translation>
</message>
<message numerus="yes">
<source>second</source>
<translation type="vanished">
<numerusform>%n second</numerusform>
<numerusform>%n seconds</numerusform>
</translation>
</message>
<message>
<location filename="src/ui/ChatWindow.cpp" line="140"/>
<source>%1 online now:</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Dialog</name>
<message>
<location filename="ui/updateDialog.ui" line="20"/>
<location filename="ui/updateDialog.ui" line="73"/>
<location filename="../build/interface/ui_updateDialog.h" line="137"/>
<location filename="../build/interface/ui_updateDialog.h" line="138"/>
<source>Update Required</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="ui/updateDialog.ui" line="129"/>
<location filename="../build/interface/ui_updateDialog.h" line="140"/>
<source>Download</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="ui/updateDialog.ui" line="151"/>
<location filename="../build/interface/ui_updateDialog.h" line="141"/>
<source>Skip Version</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="ui/updateDialog.ui" line="173"/>
<location filename="../build/interface/ui_updateDialog.h" line="142"/>
<source>Close</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>Menu</name>
<message>
<location filename="src/Menu.cpp" line="408"/>
<source>Open .ini config file</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Menu.cpp" line="410"/>
<location filename="src/Menu.cpp" line="422"/>
<source>Text files (*.ini)</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/Menu.cpp" line="420"/>
<source>Save .ini config file</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>QObject</name>
<message>
<location filename="src/ImportDialog.cpp" line="22"/>
<location filename="src/ImportDialog.cpp" line="23"/>
<source>Import Voxels</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/ImportDialog.cpp" line="24"/>
<source>Loading ...</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/ImportDialog.cpp" line="25"/>
<source>Place voxels</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/ImportDialog.cpp" line="26"/>
<source>&lt;b&gt;Import&lt;/b&gt; %1 as voxels</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="src/ImportDialog.cpp" line="27"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>

View file

@ -19,6 +19,7 @@
#include <QDebug>
#include <QDir>
#include <QTranslator>
#include <SharedUtil.h>
int main(int argc, const char * argv[]) {
@ -40,6 +41,10 @@ int main(int argc, const char * argv[]) {
{
QSettings::setDefaultFormat(QSettings::IniFormat);
Application app(argc, const_cast<char**>(argv), startup_time);
QTranslator translator;
translator.load("interface_en");
app.installTranslator(&translator);
qDebug( "Created QT Application.");
exitCode = app.exec();

View file

@ -1,13 +1,24 @@
//
// ChatWindow.cpp
// interface
//
// Created by Dimitar Dobrev on 3/6/14.
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
#include <QFormLayout>
#include <QFrame>
#include <QLayoutItem>
#include <QPalette>
#include <QScrollBar>
#include <QSizePolicy>
#include <QTextDocument>
#include <QTimer>
#include "ChatWindow.h"
#include "ui_chatwindow.h"
#include "FlowLayout.h"
#include "qtimespan.h"
#include <QXmppClient.h>
#include <QXmppMessage.h>
@ -16,16 +27,17 @@
const QString DEFAULT_SERVER = "chat.highfidelity.io";
const QString DEFAULT_CHAT_ROOM = "public@public-chat.highfidelity.io";
const int NUM_MESSAGES_TO_TIME_STAMP = 20;
const QRegularExpression regexLinks("((?:(?:ftp)|(?:https?))://\\S+)");
ChatWindow::ChatWindow() :
QDialog(Application::getInstance()->getGLWidget(), Qt::Tool),
ui(new Ui::ChatWindow) {
ui(new Ui::ChatWindow),
numMessagesAfterLastTimeStamp(0) {
ui->setupUi(this);
FlowLayout* flowLayout = new FlowLayout();
flowLayout->setContentsMargins(0, 8, 0, 8);
FlowLayout* flowLayout = new FlowLayout(0, 4, 4);
ui->usersWidget->setLayout(flowLayout);
ui->messagePlainTextEdit->installEventFilter(this);
@ -61,8 +73,11 @@ bool ChatWindow::eventFilter(QObject* sender, QEvent* event) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if ((keyEvent->key() == Qt::Key_Return || keyEvent->key() == Qt::Key_Enter) &&
(keyEvent->modifiers() & Qt::ShiftModifier) == 0) {
_xmppClient.sendMessage(_chatRoom->jid(), ui->messagePlainTextEdit->document()->toPlainText());
ui->messagePlainTextEdit->document()->clear();
QString message = ui->messagePlainTextEdit->document()->toPlainText();
if (!message.trimmed().isEmpty()) {
_xmppClient.sendMessage(_chatRoom->jid(), message);
ui->messagePlainTextEdit->document()->clear();
}
return true;
}
return false;
@ -72,6 +87,26 @@ QString ChatWindow::getParticipantName(const QString& participant) {
return participant.right(participant.count() - 1 - _chatRoom->jid().count());
}
void ChatWindow::addTimeStamp() {
QTimeSpan timePassed = QDateTime::currentDateTime() - lastMessageStamp;
int times[] = { timePassed.daysPart(), timePassed.hoursPart(), timePassed.minutesPart() };
QString strings[] = { tr("day", 0, times[0]), tr("hour", 0, times[1]), tr("minute", 0, times[2]) };
QString timeString = "";
for (int i = 0; i < 3; i++) {
if (times[i] > 0) {
timeString += strings[i] + " ";
}
}
timeString.chop(1);
QLabel* timeLabel = new QLabel(timeString);
timeLabel->setStyleSheet("color: palette(shadow);"
"background-color: palette(highlight);"
"padding: 4px;");
timeLabel->setAlignment(Qt::AlignHCenter);
ui->messagesFormLayout->addRow(timeLabel);
numMessagesAfterLastTimeStamp = 0;
}
void ChatWindow::connected() {
_chatRoom = _xmppMUCManager.addRoom(DEFAULT_CHAT_ROOM);
connect(_chatRoom, SIGNAL(participantsChanged()), this, SLOT(participantsChanged()));
@ -83,6 +118,17 @@ void ChatWindow::connected() {
ui->usersWidget->show();
ui->messagesScrollArea->show();
ui->messagePlainTextEdit->show();
QTimer* timer = new QTimer(this);
timer->setInterval(10 * 60 * 1000);
connect(timer, SIGNAL(timeout()), this, SLOT(timeout()));
timer->start();
}
void ChatWindow::timeout() {
if (numMessagesAfterLastTimeStamp >= NUM_MESSAGES_TO_TIME_STAMP) {
addTimeStamp();
}
}
void ChatWindow::error(QXmppClient::Error error) {
@ -98,13 +144,12 @@ void ChatWindow::participantsChanged() {
}
foreach (const QString& participant, participants) {
QLabel* userLabel = new QLabel(getParticipantName(participant));
userLabel->setStyleSheet(
"background-color: palette(light);"
"border-radius: 5px;"
"color: #267077;"
"padding: 2px;"
"border: 1px solid palette(shadow);"
"font-weight: bold");
userLabel->setStyleSheet("background-color: palette(light);"
"border-radius: 5px;"
"color: #267077;"
"padding: 2px;"
"border: 1px solid palette(shadow);"
"font-weight: bold");
ui->usersWidget->layout()->addWidget(userLabel);
}
}
@ -115,15 +160,25 @@ void ChatWindow::messageReceived(const QXmppMessage& message) {
font.setBold(true);
userLabel->setFont(font);
userLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
userLabel->setStyleSheet("padding: 4px;");
QLabel* messageLabel = new QLabel(message.body().replace(regexLinks, "<a href=\"\\1\">\\1</a>"));
messageLabel->setWordWrap(true);
messageLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
messageLabel->setOpenExternalLinks(true);
messageLabel->setStyleSheet("padding: 4px;");
ui->messagesFormLayout->addRow(userLabel, messageLabel);
ui->messagesFormLayout->parentWidget()->updateGeometry();
Application::processEvents();
QScrollBar* verticalScrollBar = ui->messagesScrollArea->verticalScrollBar();
verticalScrollBar->setSliderPosition(verticalScrollBar->maximum());
++numMessagesAfterLastTimeStamp;
if (message.stamp().isValid()) {
lastMessageStamp = message.stamp().toLocalTime();
}
else {
lastMessageStamp = QDateTime::currentDateTime();
}
}

View file

@ -1,7 +1,17 @@
//
// ChatWindow.h
// interface
//
// Created by Dimitar Dobrev on 3/6/14.
// Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
//
#ifndef __interface__ChatWindow__
#define __interface__ChatWindow__
#include <QDialog>
#include <QDateTime>
#include <QTimer>
#include <Application.h>
@ -23,15 +33,19 @@ protected:
bool eventFilter(QObject* sender, QEvent* event);
private:
QString getParticipantName(const QString& participant);
void addTimeStamp();
Ui::ChatWindow* ui;
QXmppClient _xmppClient;
QXmppMucManager _xmppMUCManager;
QXmppMucRoom* _chatRoom;
QString getParticipantName(const QString& participant);
int numMessagesAfterLastTimeStamp;
QDateTime lastMessageStamp;
private slots:
void connected();
void timeout();
void error(QXmppClient::Error error);
void participantsChanged();
void messageReceived(const QXmppMessage& message);

View file

@ -54,7 +54,7 @@
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">font-weight: bold; color: palette(shadow)</string>
<string notr="true">font-weight: bold; color: palette(shadow); margin-bottom: 4px;</string>
</property>
<property name="text">
<string> online now:</string>
@ -66,6 +66,12 @@
</item>
<item>
<widget class="QScrollArea" name="messagesScrollArea">
<property name="styleSheet">
<string notr="true">margin-top: 12px;</string>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
@ -74,16 +80,19 @@
<rect>
<x>0</x>
<y>0</y>
<width>382</width>
<height>356</height>
<width>358</width>
<height>328</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">margin-top: 0px;</string>
</property>
<layout class="QFormLayout" name="messagesFormLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="horizontalSpacing">
<number>4</number>
<number>0</number>
</property>
<property name="verticalSpacing">
<number>4</number>
@ -112,6 +121,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
</item>
</layout>

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,301 @@
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QTIMESPAN_H
#define QTIMESPAN_H
#include <QtCore/qdatetime.h>
#include <QtCore/qstring.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qsharedpointer.h>
#include <QtCore/qmetatype.h>
QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
QT_MODULE(Core)
//Move this to qnamespace.h when integrating
namespace Qt
{
enum TimeSpanUnit {
Milliseconds = 0x0001,
Seconds = 0x0002,
Minutes = 0x0004,
Hours = 0x0008,
Days = 0x0010,
Weeks = 0x0020,
Months = 0x0040,
Years = 0x0080,
DaysAndTime = Days | Hours | Minutes | Seconds,
AllUnits = Milliseconds | DaysAndTime | Months | Years,
NoUnit = 0
};
Q_DECLARE_FLAGS(TimeSpanFormat, TimeSpanUnit)
}
Q_DECLARE_OPERATORS_FOR_FLAGS(Qt::TimeSpanFormat)
//end of section to move
class QTimeSpanPrivate;
class Q_CORE_EXPORT QTimeSpan
{
public:
QTimeSpan();
explicit QTimeSpan(qint64 msecs);
explicit QTimeSpan(const QDateTime& reference, qint64 msecs = 0);
explicit QTimeSpan(const QDate& reference, quint64 msecs = 0);
explicit QTimeSpan(const QTime& reference, quint64 msecs = 0);
explicit QTimeSpan(const QDateTime& reference, const QTimeSpan& other);
explicit QTimeSpan(const QDate& reference, const QTimeSpan& other);
explicit QTimeSpan(const QTime& reference, const QTimeSpan& other);
QTimeSpan(const QTimeSpan& other);
~QTimeSpan();
// constant time units
static const QTimeSpan Second;
static const QTimeSpan Minute;
static const QTimeSpan Hour;
static const QTimeSpan Day;
static const QTimeSpan Week;
// status/validity of the time span
bool isEmpty() const;
bool isNull() const;
// This set of functions operates on a single component of the time span.
inline int msecsPart(Qt::TimeSpanFormat format = Qt::DaysAndTime | Qt::Milliseconds) const {return part(Qt::Milliseconds, format);}
inline int secsPart(Qt::TimeSpanFormat format = Qt::DaysAndTime) const {return part(Qt::Seconds, format);}
inline int minutesPart(Qt::TimeSpanFormat format = Qt::DaysAndTime) const {return part(Qt::Minutes, format);}
inline int hoursPart(Qt::TimeSpanFormat format = Qt::DaysAndTime) const {return part(Qt::Hours, format);}
inline int daysPart(Qt::TimeSpanFormat format = Qt::DaysAndTime) const {return part(Qt::Days, format);}
inline int weeksPart(Qt::TimeSpanFormat format = Qt::DaysAndTime) const {return part(Qt::Weeks, format);}
//int monthsPart(Qt::TimeSpanFormat format) const;
//int yearsPart(Qt::TimeSpanFormat format) const;
int part(Qt::TimeSpanUnit unit, Qt::TimeSpanFormat format = Qt::DaysAndTime) const;
bool parts(int *msecondsPtr,
int *secondsPtr = 0,
int *minutesPtr = 0,
int *hoursPtr = 0,
int *daysPtr = 0,
int *weeksPtr = 0,
int *monthsPtr = 0,
int *yearsPtr = 0,
qreal *fractionalSmallestUnit = 0) const;
Qt::TimeSpanUnit magnitude();
inline void setMSecsPart(int msecs, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Milliseconds, msecs, format);}
inline void setSecsPart(int seconds, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Seconds, seconds, format);}
inline void setMinutesPart(int minutes, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Minutes, minutes, format);}
inline void setHoursPart(int hours, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Hours, hours, format);}
inline void setDaysPart(int days, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Days, days, format);}
inline void setWeeksPart(int weeks, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Weeks, weeks, format);}
inline void setMonthsPart(int months, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Months, months, format);}
inline void setYearsPart(int years, Qt::TimeSpanFormat format = Qt::DaysAndTime) {setPart(Qt::Years, years, format);}
void setPart(Qt::TimeSpanUnit unit, int interval, Qt::TimeSpanFormat format = Qt::DaysAndTime);
// This set of functions operator on the entire timespan and not
// just a single component of it.
qint64 toMSecs() const;
inline qreal toSecs() const {return toTimeUnit(Qt::Seconds);}
inline qreal toMinutes() const {return toTimeUnit(Qt::Minutes);}
inline qreal toHours() const {return toTimeUnit(Qt::Hours);}
inline qreal toDays() const {return toTimeUnit(Qt::Days);}
inline qreal toWeeks() const {return toTimeUnit(Qt::Weeks);}
inline qreal toMonths() const {return toTimeUnit(Qt::Seconds);}
inline qreal toYears() const {return toTimeUnit(Qt::Seconds);}
qreal toTimeUnit(Qt::TimeSpanUnit unit) const;
void setFromMSecs(qint64 msecs);
inline void setFromSecs(qreal secs) {setFromTimeUnit(Qt::Seconds, secs);}
inline void setFromMinutes(qreal minutes) {setFromTimeUnit(Qt::Minutes, minutes);}
inline void setFromHours(qreal hours) {setFromTimeUnit(Qt::Hours, hours);}
inline void setFromDays(qreal days) {setFromTimeUnit(Qt::Days, days);}
inline void setFromWeeks(qreal weeks) {setFromTimeUnit(Qt::Weeks, weeks);}
void setFromMonths(qreal months);
void setFromYears(qreal years);
void setFromTimeUnit(Qt::TimeSpanUnit unit, qreal interval);
// Reference date
bool hasValidReference() const;
QDateTime referenceDate() const;
void setReferenceDate(const QDateTime &referenceDate);
void moveReferenceDate(const QDateTime &referenceDate);
void setReferencedDate(const QDateTime &referencedDate);
void moveReferencedDate(const QDateTime &referencedDate);
// Referenced date - referenceDate() + *this
QDateTime referencedDate() const;
// Pretty printing
#ifndef QT_NO_DATESTRING
QString toString(const QString &format) const;
QString toApproximateString(int suppresSecondUnitLimit = 3,
Qt::TimeSpanFormat format = Qt::Seconds | Qt::Minutes | Qt::Hours | Qt::Days | Qt::Weeks);
#endif
// Assignment operator
QTimeSpan &operator=(const QTimeSpan& other);
// Comparison operators
bool operator==(const QTimeSpan &other) const;
inline bool operator!=(const QTimeSpan &other) const {return !(operator==(other));}
bool operator<(const QTimeSpan &other) const;
bool operator<=(const QTimeSpan &other) const;
inline bool operator>(const QTimeSpan &other) const {return !(operator<=(other));}
inline bool operator>=(const QTimeSpan &other) const {return !(operator<(other));}
bool matchesLength(const QTimeSpan &other, bool normalize = false) const;
// Arithmetic operators. Operators that don't change *this are declared as non-members.
QTimeSpan &operator+=(const QTimeSpan &other);
QTimeSpan &operator+=(qint64 msecs);
QTimeSpan &operator-=(const QTimeSpan &other);
QTimeSpan &operator-=(qint64 msecs);
QTimeSpan &operator*=(qreal factor);
QTimeSpan &operator*=(int factor);
QTimeSpan &operator/=(qreal factor);
QTimeSpan &operator/=(int factor);
QTimeSpan &operator|=(const QTimeSpan &other); // Union
QTimeSpan &operator&=(const QTimeSpan &other); // Intersection
// Ensure the reference date is before the referenced date
QTimeSpan normalized() const;
void normalize();
QTimeSpan abs() const;
bool isNegative() const;
bool isNormal() const {return !isNegative();}
// Naturally ordered dates
QDateTime startDate() const;
QDateTime endDate() const;
// Containment
bool contains(const QDateTime &dateTime) const;
bool contains(const QDate &date) const;
bool contains(const QTime &time) const;
bool contains(const QTimeSpan &other) const;
bool overlaps(const QTimeSpan &other) const;
QTimeSpan overlapped(const QTimeSpan &other) const;
QTimeSpan united(const QTimeSpan &other) const;
// Static construction methods
#ifndef QT_NO_DATESTRING
static QTimeSpan fromString(const QString &string, const QString &format, const QDateTime& reference = QDateTime());
static QTimeSpan fromString(const QString &string, const QRegExp &pattern, const QDateTime& reference,
Qt::TimeSpanUnit unit1,
Qt::TimeSpanUnit unit2 = Qt::NoUnit, Qt::TimeSpanUnit unit3 = Qt::NoUnit,
Qt::TimeSpanUnit unit4 = Qt::NoUnit, Qt::TimeSpanUnit unit5 = Qt::NoUnit,
Qt::TimeSpanUnit unit6 = Qt::NoUnit, Qt::TimeSpanUnit unit7 = Qt::NoUnit,
Qt::TimeSpanUnit unit8 = Qt::NoUnit);
#endif
//static QTimeSpan fromString(const QString &string, Qt::TimeSpanFormat format);
static QTimeSpan fromTimeUnit(Qt::TimeSpanUnit unit, qreal interval, const QDateTime& reference = QDateTime());
/*
static QTimeSpan fromMSecs(qint64 msecs);
static QTimeSpan fromSecs(qreal secs) {return QTimeSpan::Second * secs;}
static QTimeSpan fromMinutes(qreal minutes) {return QTimeSpan::Minute * minutes;}
static QTimeSpan fromHours(qreal hours) {return QTimeSpan::Hour * hours;}
static QTimeSpan fromDays(qreal days) {return QTimeSpan::Day * days;}
static QTimeSpan fromWeeks(qreal weeks) {return QTimeSpan::Week * weeks;}
*/
private:
#ifndef QT_NO_DATASTREAM
friend Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QTimeSpan &);
friend Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTimeSpan &);
#endif
QSharedDataPointer<QTimeSpanPrivate> d;
};
Q_DECLARE_TYPEINFO(QTimeSpan, Q_MOVABLE_TYPE);
Q_DECLARE_METATYPE(QTimeSpan);
Q_DECLARE_METATYPE(Qt::TimeSpanUnit);
//non-member operators
Q_CORE_EXPORT QTimeSpan operator+(const QTimeSpan &left, const QTimeSpan &right);
Q_CORE_EXPORT QTimeSpan operator-(const QTimeSpan &left, const QTimeSpan &right);
Q_CORE_EXPORT QTimeSpan operator*(const QTimeSpan &left, qreal right);//no problem
Q_CORE_EXPORT QTimeSpan operator*(const QTimeSpan &left, int right);//no problem
inline QTimeSpan operator*(qreal left, const QTimeSpan &right) {return right * left;} // works
inline QTimeSpan operator*(int left, const QTimeSpan &right) {return right * left;} // works
//Q_CORE_EXPORT QTimeSpan operator*(qreal left, const QTimeSpan &right) {return right * left;} //does not work
//Q_CORE_EXPORT QTimeSpan operator*(int left, const QTimeSpan &right) {return right * left;} //does not work
Q_CORE_EXPORT QTimeSpan operator/(const QTimeSpan &left, qreal right);
Q_CORE_EXPORT QTimeSpan operator/(const QTimeSpan &left, int right);
Q_CORE_EXPORT qreal operator/(const QTimeSpan &left, const QTimeSpan &right);
Q_CORE_EXPORT QTimeSpan operator-(const QTimeSpan &right); // Unary negation
Q_CORE_EXPORT QTimeSpan operator|(const QTimeSpan &left, const QTimeSpan &right); // Union
Q_CORE_EXPORT QTimeSpan operator&(const QTimeSpan &left, const QTimeSpan &right); // Intersection
// Operators that use QTimeSpan and other date/time classes
Q_CORE_EXPORT QTimeSpan operator-(const QDateTime &left, const QDateTime &right);
Q_CORE_EXPORT QTimeSpan operator-(const QDate &left, const QDate &right);
Q_CORE_EXPORT QTimeSpan operator-(const QTime &left, const QTime &right);
Q_CORE_EXPORT QDate operator+(const QDate &left, const QTimeSpan &right);
Q_CORE_EXPORT QDate operator-(const QDate &left, const QTimeSpan &right);
Q_CORE_EXPORT QTime operator+(const QTime &left, const QTimeSpan &right);
Q_CORE_EXPORT QTime operator-(const QTime &left, const QTimeSpan &right);
Q_CORE_EXPORT QDateTime operator+(const QDateTime &left, const QTimeSpan &right);
Q_CORE_EXPORT QDateTime operator-(const QDateTime &left, const QTimeSpan &right);
#ifndef QT_NO_DATASTREAM
Q_CORE_EXPORT QDataStream &operator<<(QDataStream &, const QTimeSpan &);
Q_CORE_EXPORT QDataStream &operator>>(QDataStream &, QTimeSpan &);
#endif // QT_NO_DATASTREAM
#if !defined(QT_NO_DEBUG_STREAM) && !defined(QT_NO_DATESTRING)
Q_CORE_EXPORT QDebug operator<<(QDebug, const QTimeSpan &);
#endif
QT_END_NAMESPACE
QT_END_HEADER
#endif // QTIMESPAN_H