d = dNew;

    align = o.align;
    wordWrap = o.wordWrap;
    design = o.design;
    direction = o.direction;

/****************************************************************************
**
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: http://example.com and
** http://example.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qtextoption.h"
#include "qguiapplication.h"
#include "qlist.h"

QT_BEGIN_NAMESPACE

struct QTextOptionPrivate
{
    QList<QTextOption::Tab> tabStops;
};

/*!
    Constructs a text option with default properties for text.
    The text alignment property is set to Qt::AlignLeft. The
    word wrap property is set to QTextOption::WordWrap. The
    using of design metrics flag is set to false.
*/
QTextOption::QTextOption()
    : QTextOption(Qt::AlignLeft)
{
    direction = Qt::LayoutDirectionAuto;
}

/*!
    Constructs a text option with the given \a alignment for text.
    The word wrap property is set to QTextOption::WordWrap. The using
    of design metrics flag is set to false.
*/
QTextOption::QTextOption(Qt::Alignment alignment)
    : align(alignment),
      wordWrap(QTextOption::WordWrap),
      design(false),
      unused(0),
      f(0),
      tab(-1),
      d(nullptr)
{
    direction = QGuiApplication::layoutDirection();
}

/*!
    Destroys the text option.
*/
QTextOption::~QTextOption()
{
    delete d;
}

/*!
    \fn QTextOption::QTextOption(const QTextOption &other)

    Construct a copy of the \a other text option.
*/
QTextOption::QTextOption(const QTextOption &o)
    : align(o.align),
      wordWrap(o.wordWrap),
      design(o.design),
      direction(o.direction),
      unused(o.unused),
      f(o.f),
      tab(o.tab),
      d(nullptr)
{
    if (o.d)
        d = new QTextOptionPrivate(*o.d);
}

/*!
    \fn QTextOption &QTextOption::operator=(const QTextOption &other)

    Returns \c true if the text option is the same as the \a other text option;
    otherwise returns \c false.
*/
QTextOption &QTextOption::operator=(const QTextOption &o)
{
    if (this == &o)
        return *this;

    QTextOptionPrivate* dNew = nullptr;
    if (o.d)
        dNew = new QTextOptionPrivate(*o.d);
    delete d;

    unused = o.unused;
    f = o.f;
    tab = o.tab;
    return *this;
}

/*!
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabArray(), setTabStopDistance(), setTabs()
*/
void QTextOption::setTabArray(const QList<qreal> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    QList<QTextOption::Tab> tabs;
    QTextOption::Tab tab;
    tabs.reserve(tabStops.count());
    for (qreal pos : tabStops) {
        tab.position = pos;
        tabs.append(tab);
    }
    d->tabStops = tabs;
}

/*!
    \since 4.4
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabStopDistance()
*/
void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    d->tabStops = tabStops;
}

/*!
    Returns a list of tab positions defined for the text layout.

    \sa setTabArray(), tabStopDistance()
*/
QList<qreal> QTextOption::tabArray() const
{
    QList<qreal> answer;
    if (!d)
        return answer;

    answer.reserve(d->tabStops.count());
    QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
    while(iter != d->tabStops.constEnd()) {
        answer.append( (*iter).position);
        ++iter;
    }
    return answer;
}

QList<QTextOption::Tab> QTextOption::tabs() const
{
    if (!d)
        return QList<QTextOption::Tab>();
    return d->tabStops;
}

/*!
    \class QTextOption
    \reentrant

    \brief The QTextOption class provides a description of general rich text
    properties.
    \inmodule QtGui

    \ingroup richtext-processing

    QTextOption is used to encapsulate common rich text properties in a single
    object. It contains information about text alignment, layout direction,
    word wrapping, and other standard properties associated with text rendering
    and layout.

    \sa QTextEdit, QTextDocument, QTextCursor
*/

/*!
    \enum QTextOption::WrapMode

    This enum describes how text is wrapped in a document.

    \value NoWrap       Text is not wrapped at all.
    \value WordWrap     Text is wrapped at word boundaries.
    \value ManualWrap   Same as QTextOption::NoWrap
    \value WrapAnywhere Text can be wrapped at any point on a line, even if
                        it occurs in the middle of a word.
    \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
                        boundary; otherwise it will occur at the appropriate
                        point on the line, even in the middle of a word.
*/

/*!
  \fn void QTextOption::setUseDesignMetrics(bool enable)

    If \a enable is true then the layout will use design metrics;
    otherwise it will use the metrics of the paint device (which is
    the default behavior).

    \sa useDesignMetrics()
*/

/*!
  \fn bool QTextOption::useDesignMetrics() const

    Returns \c true if the layout uses design rather than device metrics;
    otherwise returns \c false.

    \sa setUseDesignMetrics()
*/

/*!
  \fn Qt::Alignment QTextOption::alignment() const

  Returns the text alignment defined by the option.

  \sa setAlignment()
*/

/*!
  \fn void QTextOption::setAlignment(Qt::Alignment alignment);

  Sets the option's text alignment to the specified \a alignment.

  \sa alignment()
*/

/*!
  \fn Qt::LayoutDirection QTextOption::textDirection() const

  Returns the direction of the text layout defined by the option.

  \sa setTextDirection()
*/

/*!
  \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)

  Sets the direction of the text layout defined by the option to the
  given \a direction.

  \sa textDirection()
*/

/*!
  \fn WrapMode QTextOption::wrapMode() const

  Returns the text wrap mode defined by the option.

  \sa setWrapMode()
*/

/*!
  \fn void QTextOption::setWrapMode(WrapMode mode)

  Sets the option's text wrap mode to the given \a mode.
*/

/*!
  \enum QTextOption::Flag

  \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
                               return a value that includes the width of trailing spaces in the text; otherwise
                               this width is excluded.
  \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
            shown differently to breaking spaces.
  \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  \value ShowDocumentTerminator Visualize the end of the document with a section sign. This enum value was added
            in Qt 5.7.
  \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
            space added for drawing a separator character.
  \value SuppressColors Suppress all color changes in the character formats (except the main selection).
*/

/*!
  \fn Flags QTextOption::flags() const

  Returns the flags associated with the option.

  \sa setFlags()
*/

/*!
  \fn void QTextOption::setFlags(Flags flags)

  Sets the flags associated with the option to the given \a flags.

  \sa flags()
*/

/*!
  \fn qreal QTextOption::tabStopDistance() const
  \since 5.10

  Returns the distance in device units between tab stops.

  \sa setTabStopDistance(), tabArray(), setTabs(), tabs()
*/

/*!
  \fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
  \since 5.10

  Sets the default distance in device units between tab stops to the value specified
  by \a tabStopDistance.

  \sa tabStopDistance(), setTabArray(), setTabs(), tabs()
*/

/*!
    \enum QTextOption::TabType
    \since 4.4

    This enum holds the different types of tabulator

    \value LeftTab      A left-tab
    \value RightTab     A right-tab
    \value CenterTab    A centered-tab
    \value DelimiterTab A tab stopping at a certain delimiter-character
*/

/*!
    \class QTextOption::Tab
    \since 4.4
    \inmodule QtGui
    Each tab definition is represented by this struct.
*/

/*!
    \variable Tab::position
    Distance from the start of the paragraph.
    The position of a tab is from the start of the paragraph which implies that when
    the alignment of the paragraph is set to centered, the tab is interpreted to be
    moved the same distance as the left edge of the paragraph does.
    In case the paragraph is set to have a layoutDirection() RightToLeft the position
    is interpreted to be from the right side of the paragraph with higher numbers moving
    the tab to the left.
*/

/*!
    \variable QTextOption::Tab::type
    Determine which type is used.
    In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
    be interpreted to be a RightTab and vice versa.
*/

/*!
    \variable QTextOption::Tab::delimiter
    If type is DelimitorTab; tab until this char is found in the text.
*/

/*!
    \fn QTextOption::Tab::Tab()
    Creates a default left tab with position 80.
*/

/*!
    \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())

    Creates a tab with the given position, tab type, and delimiter
    (\a pos, \a tabType, \a delim).

    \note \a delim is only used when \a tabType is DelimiterTab.

    \since 4.7
*/

/*!
    \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is equal to this tab;
    otherwise returns \c false.
*/

/*!
    \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is not equal to this tab;
    otherwise returns \c false.
*/

/*!
  \since 4.4
  \fn QList<QTextOption::Tab> QTextOption::tabs() const
  Returns a list of tab positions defined for the text layout.

  \sa tabStopDistance(), setTabs(), setTabStopDistance()
*/

QT_END_NAMESPACE


unused = o.unused;
    f = o.f;
    tab = o.tab;
    return *this;
}

/****************************************************************************
**
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: http://example.com and
** http://example.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qtextoption.h"
#include "qguiapplication.h"
#include "qlist.h"

QT_BEGIN_NAMESPACE

struct QTextOptionPrivate
{
    QList<QTextOption::Tab> tabStops;
};

/*!
    Constructs a text option with default properties for text.
    The text alignment property is set to Qt::AlignLeft. The
    word wrap property is set to QTextOption::WordWrap. The
    using of design metrics flag is set to false.
*/
QTextOption::QTextOption()
    : QTextOption(Qt::AlignLeft)
{
    direction = Qt::LayoutDirectionAuto;
}

/*!
    Constructs a text option with the given \a alignment for text.
    The word wrap property is set to QTextOption::WordWrap. The using
    of design metrics flag is set to false.
*/
QTextOption::QTextOption(Qt::Alignment alignment)
    : align(alignment),
      wordWrap(QTextOption::WordWrap),
      design(false),
      unused(0),
      f(0),
      tab(-1),
      d(nullptr)
{
    direction = QGuiApplication::layoutDirection();
}

/*!
    Destroys the text option.
*/
QTextOption::~QTextOption()
{
    delete d;
}

/*!
    \fn QTextOption::QTextOption(const QTextOption &other)

    Construct a copy of the \a other text option.
*/
QTextOption::QTextOption(const QTextOption &o)
    : align(o.align),
      wordWrap(o.wordWrap),
      design(o.design),
      direction(o.direction),
      unused(o.unused),
      f(o.f),
      tab(o.tab),
      d(nullptr)
{
    if (o.d)
        d = new QTextOptionPrivate(*o.d);
}

/*!
    \fn QTextOption &QTextOption::operator=(const QTextOption &other)

    Returns \c true if the text option is the same as the \a other text option;
    otherwise returns \c false.
*/
QTextOption &QTextOption::operator=(const QTextOption &o)
{
    if (this == &o)
        return *this;

    QTextOptionPrivate* dNew = nullptr;
    if (o.d)
        dNew = new QTextOptionPrivate(*o.d);
    delete d;
    d = dNew;

    align = o.align;
    wordWrap = o.wordWrap;
    design = o.design;
    direction = o.direction;

/*!
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabArray(), setTabStopDistance(), setTabs()
*/
void QTextOption::setTabArray(const QList<qreal> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    QList<QTextOption::Tab> tabs;
    QTextOption::Tab tab;
    tabs.reserve(tabStops.count());
    for (qreal pos : tabStops) {
        tab.position = pos;
        tabs.append(tab);
    }
    d->tabStops = tabs;
}

/*!
    \since 4.4
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabStopDistance()
*/
void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    d->tabStops = tabStops;
}

/*!
    Returns a list of tab positions defined for the text layout.

    \sa setTabArray(), tabStopDistance()
*/
QList<qreal> QTextOption::tabArray() const
{
    QList<qreal> answer;
    if (!d)
        return answer;

    answer.reserve(d->tabStops.count());
    QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
    while(iter != d->tabStops.constEnd()) {
        answer.append( (*iter).position);
        ++iter;
    }
    return answer;
}

QList<QTextOption::Tab> QTextOption::tabs() const
{
    if (!d)
        return QList<QTextOption::Tab>();
    return d->tabStops;
}

/*!
    \class QTextOption
    \reentrant

    \brief The QTextOption class provides a description of general rich text
    properties.
    \inmodule QtGui

    \ingroup richtext-processing

    QTextOption is used to encapsulate common rich text properties in a single
    object. It contains information about text alignment, layout direction,
    word wrapping, and other standard properties associated with text rendering
    and layout.

    \sa QTextEdit, QTextDocument, QTextCursor
*/

/*!
    \enum QTextOption::WrapMode

    This enum describes how text is wrapped in a document.

    \value NoWrap       Text is not wrapped at all.
    \value WordWrap     Text is wrapped at word boundaries.
    \value ManualWrap   Same as QTextOption::NoWrap
    \value WrapAnywhere Text can be wrapped at any point on a line, even if
                        it occurs in the middle of a word.
    \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
                        boundary; otherwise it will occur at the appropriate
                        point on the line, even in the middle of a word.
*/

/*!
  \fn void QTextOption::setUseDesignMetrics(bool enable)

    If \a enable is true then the layout will use design metrics;
    otherwise it will use the metrics of the paint device (which is
    the default behavior).

    \sa useDesignMetrics()
*/

/*!
  \fn bool QTextOption::useDesignMetrics() const

    Returns \c true if the layout uses design rather than device metrics;
    otherwise returns \c false.

    \sa setUseDesignMetrics()
*/

/*!
  \fn Qt::Alignment QTextOption::alignment() const

  Returns the text alignment defined by the option.

  \sa setAlignment()
*/

/*!
  \fn void QTextOption::setAlignment(Qt::Alignment alignment);

  Sets the option's text alignment to the specified \a alignment.

  \sa alignment()
*/

/*!
  \fn Qt::LayoutDirection QTextOption::textDirection() const

  Returns the direction of the text layout defined by the option.

  \sa setTextDirection()
*/

/*!
  \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)

  Sets the direction of the text layout defined by the option to the
  given \a direction.

  \sa textDirection()
*/

/*!
  \fn WrapMode QTextOption::wrapMode() const

  Returns the text wrap mode defined by the option.

  \sa setWrapMode()
*/

/*!
  \fn void QTextOption::setWrapMode(WrapMode mode)

  Sets the option's text wrap mode to the given \a mode.
*/

/*!
  \enum QTextOption::Flag

  \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
                               return a value that includes the width of trailing spaces in the text; otherwise
                               this width is excluded.
  \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
            shown differently to breaking spaces.
  \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  \value ShowDocumentTerminator Visualize the end of the document with a section sign. This enum value was added
            in Qt 5.7.
  \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
            space added for drawing a separator character.
  \value SuppressColors Suppress all color changes in the character formats (except the main selection).
*/

/*!
  \fn Flags QTextOption::flags() const

  Returns the flags associated with the option.

  \sa setFlags()
*/

/*!
  \fn void QTextOption::setFlags(Flags flags)

  Sets the flags associated with the option to the given \a flags.

  \sa flags()
*/

/*!
  \fn qreal QTextOption::tabStopDistance() const
  \since 5.10

  Returns the distance in device units between tab stops.

  \sa setTabStopDistance(), tabArray(), setTabs(), tabs()
*/

/*!
  \fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
  \since 5.10

  Sets the default distance in device units between tab stops to the value specified
  by \a tabStopDistance.

  \sa tabStopDistance(), setTabArray(), setTabs(), tabs()
*/

/*!
    \enum QTextOption::TabType
    \since 4.4

    This enum holds the different types of tabulator

    \value LeftTab      A left-tab
    \value RightTab     A right-tab
    \value CenterTab    A centered-tab
    \value DelimiterTab A tab stopping at a certain delimiter-character
*/

/*!
    \class QTextOption::Tab
    \since 4.4
    \inmodule QtGui
    Each tab definition is represented by this struct.
*/

/*!
    \variable Tab::position
    Distance from the start of the paragraph.
    The position of a tab is from the start of the paragraph which implies that when
    the alignment of the paragraph is set to centered, the tab is interpreted to be
    moved the same distance as the left edge of the paragraph does.
    In case the paragraph is set to have a layoutDirection() RightToLeft the position
    is interpreted to be from the right side of the paragraph with higher numbers moving
    the tab to the left.
*/

/*!
    \variable QTextOption::Tab::type
    Determine which type is used.
    In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
    be interpreted to be a RightTab and vice versa.
*/

/*!
    \variable QTextOption::Tab::delimiter
    If type is DelimitorTab; tab until this char is found in the text.
*/

/*!
    \fn QTextOption::Tab::Tab()
    Creates a default left tab with position 80.
*/

/*!
    \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())

    Creates a tab with the given position, tab type, and delimiter
    (\a pos, \a tabType, \a delim).

    \note \a delim is only used when \a tabType is DelimiterTab.

    \since 4.7
*/

/*!
    \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is equal to this tab;
    otherwise returns \c false.
*/

/*!
    \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is not equal to this tab;
    otherwise returns \c false.
*/

/*!
  \since 4.4
  \fn QList<QTextOption::Tab> QTextOption::tabs() const
  Returns a list of tab positions defined for the text layout.

  \sa tabStopDistance(), setTabs(), setTabStopDistance()
*/

QT_END_NAMESPACE


/****************************************************************************
**
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: http://example.com and
** http://example.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qtextoption.h"
#include "qguiapplication.h"
#include "qlist.h"

QT_BEGIN_NAMESPACE

struct QTextOptionPrivate
{
    QList<QTextOption::Tab> tabStops;
};

/*!
    Constructs a text option with default properties for text.
    The text alignment property is set to Qt::AlignLeft. The
    word wrap property is set to QTextOption::WordWrap. The
    using of design metrics flag is set to false.
*/
QTextOption::QTextOption()
    : QTextOption(Qt::AlignLeft)
{
    direction = Qt::LayoutDirectionAuto;
}

/*!
    Constructs a text option with the given \a alignment for text.
    The word wrap property is set to QTextOption::WordWrap. The using
    of design metrics flag is set to false.
*/
QTextOption::QTextOption(Qt::Alignment alignment)
    : align(alignment),
      wordWrap(QTextOption::WordWrap),
      design(false),
      unused(0),
      f(0),
      tab(-1),
      d(nullptr)
{
    direction = QGuiApplication::layoutDirection();
}

/*!
    Destroys the text option.
*/
QTextOption::~QTextOption()
{
    delete d;
}

/*!
    \fn QTextOption::QTextOption(const QTextOption &other)

    Construct a copy of the \a other text option.
*/
QTextOption::QTextOption(const QTextOption &o)
    : align(o.align),
      wordWrap(o.wordWrap),
      design(o.design),
      direction(o.direction),
      unused(o.unused),
      f(o.f),
      tab(o.tab),
      d(nullptr)
{
    if (o.d)
        d = new QTextOptionPrivate(*o.d);
}

/*!
    \fn QTextOption &QTextOption::operator=(const QTextOption &other)

    Returns \c true if the text option is the same as the \a other text option;
    otherwise returns \c false.
*/
QTextOption &QTextOption::operator=(const QTextOption &o)
{
    if (this == &o)
        return *this;

    QTextOptionPrivate* dNew = nullptr;
    if (o.d)
        dNew = new QTextOptionPrivate(*o.d);
    delete d;
    d = dNew;

    align = o.align;
    wordWrap = o.wordWrap;
    design = o.design;
    direction = o.direction;
    unused = o.unused;
    f

    tab = o.tab;
    return *this;
}

/*!
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabArray(), setTabStopDistance(), setTabs()
*/
void QTextOption::setTabArray(const QList<qreal> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    QList<QTextOption::Tab> tabs;
    QTextOption::Tab tab;
    tabs.reserve(tabStops.count());
    for (qreal pos : tabStops) {
        tab.position = pos;
        tabs.append(tab);
    }
    d->tabStops = tabs;
}

/*!
    \since 4.4
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabStopDistance()
*/
void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    d->tabStops = tabStops;
}

/*!
    Returns a list of tab positions defined for the text layout.

    \sa setTabArray(), tabStopDistance()
*/
QList<qreal> QTextOption::tabArray() const
{
    QList<qreal> answer;
    if (!d)
        return answer;

    answer.reserve(d->tabStops.count());
    QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
    while(iter != d->tabStops.constEnd()) {
        answer.append( (*iter).position);
        ++iter;
    }
    return answer;
}

QList<QTextOption::Tab> QTextOption::tabs() const
{
    if (!d)
        return QList<QTextOption::Tab>();
    return d->tabStops;
}

/*!
    \class QTextOption
    \reentrant

    \brief The QTextOption class provides a description of general rich text
    properties.
    \inmodule QtGui

    \ingroup richtext-processing

    QTextOption is used to encapsulate common rich text properties in a single
    object. It contains information about text alignment, layout direction,
    word wrapping, and other standard properties associated with text rendering
    and layout.

    \sa QTextEdit, QTextDocument, QTextCursor
*/

/*!
    \enum QTextOption::WrapMode

    This enum describes how text is wrapped in a document.

    \value NoWrap       Text is not wrapped at all.
    \value WordWrap     Text is wrapped at word boundaries.
    \value ManualWrap   Same as QTextOption::NoWrap
    \value WrapAnywhere Text can be wrapped at any point on a line, even if
                        it occurs in the middle of a word.
    \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
                        boundary; otherwise it will occur at the appropriate
                        point on the line, even in the middle of a word.
*/

/*!
  \fn void QTextOption::setUseDesignMetrics(bool enable)

    If \a enable is true then the layout will use design metrics;
    otherwise it will use the metrics of the paint device (which is
    the default behavior).

    \sa useDesignMetrics()
*/

/*!
  \fn bool QTextOption::useDesignMetrics() const

    Returns \c true if the layout uses design rather than device metrics;
    otherwise returns \c false.

    \sa setUseDesignMetrics()
*/

/*!
  \fn Qt::Alignment QTextOption::alignment() const

  Returns the text alignment defined by the option.

  \sa setAlignment()
*/

/*!
  \fn void QTextOption::setAlignment(Qt::Alignment alignment);

  Sets the option's text alignment to the specified \a alignment.

  \sa alignment()
*/

/*!
  \fn Qt::LayoutDirection QTextOption::textDirection() const

  Returns the direction of the text layout defined by the option.

  \sa setTextDirection()
*/

/*!
  \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)

  Sets the direction of the text layout defined by the option to the
  given \a direction.

  \sa textDirection()
*/

/*!
  \fn WrapMode QTextOption::wrapMode() const

  Returns the text wrap mode defined by the option.

  \sa setWrapMode()
*/

/*!
  \fn void QTextOption::setWrapMode(WrapMode mode)

  Sets the option's text wrap mode to the given \a mode.
*/

/*!
  \enum QTextOption::Flag

  \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
                               return a value that includes the width of trailing spaces in the text; otherwise
                               this width is excluded.
  \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
            shown differently to breaking spaces.
  \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  \value ShowDocumentTerminator Visualize the end of the document with a section sign. This enum value was added
            in Qt 5.7.
  \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
            space added for drawing a separator character.
  \value SuppressColors Suppress all color changes in the character formats (except the main selection).
*/

/*!
  \fn Flags QTextOption::flags() const

  Returns the flags associated with the option.

  \sa setFlags()
*/

/*!
  \fn void QTextOption::setFlags(Flags flags)

  Sets the flags associated with the option to the given \a flags.

  \sa flags()
*/

/*!
  \fn qreal QTextOption::tabStopDistance() const
  \since 5.10

  Returns the distance in device units between tab stops.

  \sa setTabStopDistance(), tabArray(), setTabs(), tabs()
*/

/*!
  \fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
  \since 5.10

  Sets the default distance in device units between tab stops to the value specified
  by \a tabStopDistance.

  \sa tabStopDistance(), setTabArray(), setTabs(), tabs()
*/

/*!
    \enum QTextOption::TabType
    \since 4.4

    This enum holds the different types of tabulator

    \value LeftTab      A left-tab
    \value RightTab     A right-tab
    \value CenterTab    A centered-tab
    \value DelimiterTab A tab stopping at a certain delimiter-character
*/

/*!
    \class QTextOption::Tab
    \since 4.4
    \inmodule QtGui
    Each tab definition is represented by this struct.
*/

/*!
    \variable Tab::position
    Distance from the start of the paragraph.
    The position of a tab is from the start of the paragraph which implies that when
    the alignment of the paragraph is set to centered, the tab is interpreted to be
    moved the same distance as the left edge of the paragraph does.
    In case the paragraph is set to have a layoutDirection() RightToLeft the position
    is interpreted to be from the right side of the paragraph with higher numbers moving
    the tab to the left.
*/

/*!
    \variable QTextOption::Tab::type
    Determine which type is used.
    In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
    be interpreted to be a RightTab and vice versa.
*/

/*!
    \variable QTextOption::Tab::delimiter
    If type is DelimitorTab; tab until this char is found in the text.
*/

/*!
    \fn QTextOption::Tab::Tab()
    Creates a default left tab with position 80.
*/

/*!
    \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())

    Creates a tab with the given position, tab type, and delimiter
    (\a pos, \a tabType, \a delim).

    \note \a delim is only used when \a tabType is DelimiterTab.

    \since 4.7
*/

/*!
    \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is equal to this tab;
    otherwise returns \c false.
*/

/*!
    \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is not equal to this tab;
    otherwise returns \c false.
*/

/*!
  \since 4.4
  \fn QList<QTextOption::Tab> QTextOption::tabs() const
  Returns a list of tab positions defined for the text layout.

  \sa tabStopDistance(), setTabs(), setTabStopDistance()
*/

QT_END_NAMESPACE


void QTextOption::setTabArray(const QList<qreal> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    QList<QTextOption::Tab> tabs;
    QTextOption::Tab tab;
    tabs.reserve(tabStops.count());
    for (qreal pos : tabStops) {
        tab.position = pos;
        tabs.append(tab);
    }
    d->tabStops = tabs;
}

/****************************************************************************
**
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: http://example.com and
** http://example.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qtextoption.h"
#include "qguiapplication.h"
#include "qlist.h"

QT_BEGIN_NAMESPACE

struct QTextOptionPrivate
{
    QList<QTextOption::Tab> tabStops;
};

/*!
    Constructs a text option with default properties for text.
    The text alignment property is set to Qt::AlignLeft. The
    word wrap property is set to QTextOption::WordWrap. The
    using of design metrics flag is set to false.
*/
QTextOption::QTextOption()
    : QTextOption(Qt::AlignLeft)
{
    direction = Qt::LayoutDirectionAuto;
}

/*!
    Constructs a text option with the given \a alignment for text.
    The word wrap property is set to QTextOption::WordWrap. The using
    of design metrics flag is set to false.
*/
QTextOption::QTextOption(Qt::Alignment alignment)
    : align(alignment),
      wordWrap(QTextOption::WordWrap),
      design(false),
      unused(0),
      f(0),
      tab(-1),
      d(nullptr)
{
    direction = QGuiApplication::layoutDirection();
}

/*!
    Destroys the text option.
*/
QTextOption::~QTextOption()
{
    delete d;
}

/*!
    \fn QTextOption::QTextOption(const QTextOption &other)

    Construct a copy of the \a other text option.
*/
QTextOption::QTextOption(const QTextOption &o)
    : align(o.align),
      wordWrap(o.wordWrap),
      design(o.design),
      direction(o.direction),
      unused(o.unused),
      f(o.f),
      tab(o.tab),
      d(nullptr)
{
    if (o.d)
        d = new QTextOptionPrivate(*o.d);
}

/*!
    \fn QTextOption &QTextOption::operator=(const QTextOption &other)

    Returns \c true if the text option is the same as the \a other text option;
    otherwise returns \c false.
*/
QTextOption &QTextOption::operator=(const QTextOption &o)
{
    if (this == &o)
        return *this;

    QTextOptionPrivate* dNew = nullptr;
    if (o.d)
        dNew = new QTextOptionPrivate(*o.d);
    delete d;
    d = dNew;

    align = o.align;
    wordWrap = o.wordWrap;
    design = o.design;
    direction = o.direction;
    unused = o.unused;
    f = o.f;
    tab = o.tab;
    return *this;
}

/*!
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabArray(), setTabStopDistance(), setTabs()
*/

/*!
    \since 4.4
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabStopDistance()
*/
void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    d->tabStops = tabStops;
}

/*!
    Returns a list of tab positions defined for the text layout.

    \sa setTabArray(), tabStopDistance()
*/
QList<qreal> QTextOption::tabArray() const
{
    QList<qreal> answer;
    if (!d)
        return answer;

    answer.reserve(d->tabStops.count());
    QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
    while(iter != d->tabStops.constEnd()) {
        answer.append( (*iter).position);
        ++iter;
    }
    return answer;
}

QList<QTextOption::Tab> QTextOption::tabs() const
{
    if (!d)
        return QList<QTextOption::Tab>();
    return d->tabStops;
}

/*!
    \class QTextOption
    \reentrant

    \brief The QTextOption class provides a description of general rich text
    properties.
    \inmodule QtGui

    \ingroup richtext-processing

    QTextOption is used to encapsulate common rich text properties in a single
    object. It contains information about text alignment, layout direction,
    word wrapping, and other standard properties associated with text rendering
    and layout.

    \sa QTextEdit, QTextDocument, QTextCursor
*/

/*!
    \enum QTextOption::WrapMode

    This enum describes how text is wrapped in a document.

    \value NoWrap       Text is not wrapped at all.
    \value WordWrap     Text is wrapped at word boundaries.
    \value ManualWrap   Same as QTextOption::NoWrap
    \value WrapAnywhere Text can be wrapped at any point on a line, even if
                        it occurs in the middle of a word.
    \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
                        boundary; otherwise it will occur at the appropriate
                        point on the line, even in the middle of a word.
*/

/*!
  \fn void QTextOption::setUseDesignMetrics(bool enable)

    If \a enable is true then the layout will use design metrics;
    otherwise it will use the metrics of the paint device (which is
    the default behavior).

    \sa useDesignMetrics()
*/

/*!
  \fn bool QTextOption::useDesignMetrics() const

    Returns \c true if the layout uses design rather than device metrics;
    otherwise returns \c false.

    \sa setUseDesignMetrics()
*/

/*!
  \fn Qt::Alignment QTextOption::alignment() const

  Returns the text alignment defined by the option.

  \sa setAlignment()
*/

/*!
  \fn void QTextOption::setAlignment(Qt::Alignment alignment);

  Sets the option's text alignment to the specified \a alignment.

  \sa alignment()
*/

/*!
  \fn Qt::LayoutDirection QTextOption::textDirection() const

  Returns the direction of the text layout defined by the option.

  \sa setTextDirection()
*/

/*!
  \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)

  Sets the direction of the text layout defined by the option to the
  given \a direction.

  \sa textDirection()
*/

/*!
  \fn WrapMode QTextOption::wrapMode() const

  Returns the text wrap mode defined by the option.

  \sa setWrapMode()
*/

/*!
  \fn void QTextOption::setWrapMode(WrapMode mode)

  Sets the option's text wrap mode to the given \a mode.
*/

/*!
  \enum QTextOption::Flag

  \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
                               return a value that includes the width of trailing spaces in the text; otherwise
                               this width is excluded.
  \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
            shown differently to breaking spaces.
  \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  \value ShowDocumentTerminator Visualize the end of the document with a section sign. This enum value was added
            in Qt 5.7.
  \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
            space added for drawing a separator character.
  \value SuppressColors Suppress all color changes in the character formats (except the main selection).
*/

/*!
  \fn Flags QTextOption::flags() const

  Returns the flags associated with the option.

  \sa setFlags()
*/

/*!
  \fn void QTextOption::setFlags(Flags flags)

  Sets the flags associated with the option to the given \a flags.

  \sa flags()
*/

/*!
  \fn qreal QTextOption::tabStopDistance() const
  \since 5.10

  Returns the distance in device units between tab stops.

  \sa setTabStopDistance(), tabArray(), setTabs(), tabs()
*/

/*!
  \fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
  \since 5.10

  Sets the default distance in device units between tab stops to the value specified
  by \a tabStopDistance.

  \sa tabStopDistance(), setTabArray(), setTabs(), tabs()
*/

/*!
    \enum QTextOption::TabType
    \since 4.4

    This enum holds the different types of tabulator

    \value LeftTab      A left-tab
    \value RightTab     A right-tab
    \value CenterTab    A centered-tab
    \value DelimiterTab A tab stopping at a certain delimiter-character
*/

/*!
    \class QTextOption::Tab
    \since 4.4
    \inmodule QtGui
    Each tab definition is represented by this struct.
*/

/*!
    \variable Tab::position
    Distance from the start of the paragraph.
    The position of a tab is from the start of the paragraph which implies that when
    the alignment of the paragraph is set to centered, the tab is interpreted to be
    moved the same distance as the left edge of the paragraph does.
    In case the paragraph is set to have a layoutDirection() RightToLeft the position
    is interpreted to be from the right side of the paragraph with higher numbers moving
    the tab to the left.
*/

/*!
    \variable QTextOption::Tab::type
    Determine which type is used.
    In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
    be interpreted to be a RightTab and vice versa.
*/

/*!
    \variable QTextOption::Tab::delimiter
    If type is DelimitorTab; tab until this char is found in the text.
*/

/*!
    \fn QTextOption::Tab::Tab()
    Creates a default left tab with position 80.
*/

/*!
    \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())

    Creates a tab with the given position, tab type, and delimiter
    (\a pos, \a tabType, \a delim).

    \note \a delim is only used when \a tabType is DelimiterTab.

    \since 4.7
*/

/*!
    \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is equal to this tab;
    otherwise returns \c false.
*/

/*!
    \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is not equal to this tab;
    otherwise returns \c false.
*/

/*!
  \since 4.4
  \fn QList<QTextOption::Tab> QTextOption::tabs() const
  Returns a list of tab positions defined for the text layout.

  \sa tabStopDistance(), setTabs(), setTabStopDistance()
*/

QT_END_NAMESPACE


if (!d)
        return QList<QTextOption::Tab>();

/****************************************************************************
**
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: http://example.com and
** http://example.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qtextoption.h"
#include "qguiapplication.h"
#include "qlist.h"

QT_BEGIN_NAMESPACE

struct QTextOptionPrivate
{
    QList<QTextOption::Tab> tabStops;
};

/*!
    Constructs a text option with default properties for text.
    The text alignment property is set to Qt::AlignLeft. The
    word wrap property is set to QTextOption::WordWrap. The
    using of design metrics flag is set to false.
*/
QTextOption::QTextOption()
    : QTextOption(Qt::AlignLeft)
{
    direction = Qt::LayoutDirectionAuto;
}

/*!
    Constructs a text option with the given \a alignment for text.
    The word wrap property is set to QTextOption::WordWrap. The using
    of design metrics flag is set to false.
*/
QTextOption::QTextOption(Qt::Alignment alignment)
    : align(alignment),
      wordWrap(QTextOption::WordWrap),
      design(false),
      unused(0),
      f(0),
      tab(-1),
      d(nullptr)
{
    direction = QGuiApplication::layoutDirection();
}

/*!
    Destroys the text option.
*/
QTextOption::~QTextOption()
{
    delete d;
}

/*!
    \fn QTextOption::QTextOption(const QTextOption &other)

    Construct a copy of the \a other text option.
*/
QTextOption::QTextOption(const QTextOption &o)
    : align(o.align),
      wordWrap(o.wordWrap),
      design(o.design),
      direction(o.direction),
      unused(o.unused),
      f(o.f),
      tab(o.tab),
      d(nullptr)
{
    if (o.d)
        d = new QTextOptionPrivate(*o.d);
}

/*!
    \fn QTextOption &QTextOption::operator=(const QTextOption &other)

    Returns \c true if the text option is the same as the \a other text option;
    otherwise returns \c false.
*/
QTextOption &QTextOption::operator=(const QTextOption &o)
{
    if (this == &o)
        return *this;

    QTextOptionPrivate* dNew = nullptr;
    if (o.d)
        dNew = new QTextOptionPrivate(*o.d);
    delete d;
    d = dNew;

    align = o.align;
    wordWrap = o.wordWrap;
    design = o.design;
    direction = o.direction;
    unused = o.unused;
    f = o.f;
    tab = o.tab;
    return *this;
}

/*!
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabArray(), setTabStopDistance(), setTabs()
*/
void QTextOption::setTabArray(const QList<qreal> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    QList<QTextOption::Tab> tabs;
    QTextOption::Tab tab;
    tabs.reserve(tabStops.count());
    for (qreal pos : tabStops) {
        tab.position = pos;
        tabs.append(tab);
    }
    d->tabStops = tabs;
}

/*!
    \since 4.4
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabStopDistance()
*/
void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    d->tabStops = tabStops;
}

/*!
    Returns a list of tab positions defined for the text layout.

    \sa setTabArray(), tabStopDistance()
*/
QList<qreal> QTextOption::tabArray() const
{
    QList<qreal> answer;
    if (!d)
        return answer;

    answer.reserve(d->tabStops.count());
    QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
    while(iter != d->tabStops.constEnd()) {
        answer.append( (*iter).position);
        ++iter;
    }
    return answer;
}

QList<QTextOption::Tab> QTextOption::tabs() const
{

    return d->tabStops;
}

/*!
    \class QTextOption
    \reentrant

    \brief The QTextOption class provides a description of general rich text
    properties.
    \inmodule QtGui

    \ingroup richtext-processing

    QTextOption is used to encapsulate common rich text properties in a single
    object. It contains information about text alignment, layout direction,
    word wrapping, and other standard properties associated with text rendering
    and layout.

    \sa QTextEdit, QTextDocument, QTextCursor
*/

/*!
    \enum QTextOption::WrapMode

    This enum describes how text is wrapped in a document.

    \value NoWrap       Text is not wrapped at all.
    \value WordWrap     Text is wrapped at word boundaries.
    \value ManualWrap   Same as QTextOption::NoWrap
    \value WrapAnywhere Text can be wrapped at any point on a line, even if
                        it occurs in the middle of a word.
    \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
                        boundary; otherwise it will occur at the appropriate
                        point on the line, even in the middle of a word.
*/

/*!
  \fn void QTextOption::setUseDesignMetrics(bool enable)

    If \a enable is true then the layout will use design metrics;
    otherwise it will use the metrics of the paint device (which is
    the default behavior).

    \sa useDesignMetrics()
*/

/*!
  \fn bool QTextOption::useDesignMetrics() const

    Returns \c true if the layout uses design rather than device metrics;
    otherwise returns \c false.

    \sa setUseDesignMetrics()
*/

/*!
  \fn Qt::Alignment QTextOption::alignment() const

  Returns the text alignment defined by the option.

  \sa setAlignment()
*/

/*!
  \fn void QTextOption::setAlignment(Qt::Alignment alignment);

  Sets the option's text alignment to the specified \a alignment.

  \sa alignment()
*/

/*!
  \fn Qt::LayoutDirection QTextOption::textDirection() const

  Returns the direction of the text layout defined by the option.

  \sa setTextDirection()
*/

/*!
  \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)

  Sets the direction of the text layout defined by the option to the
  given \a direction.

  \sa textDirection()
*/

/*!
  \fn WrapMode QTextOption::wrapMode() const

  Returns the text wrap mode defined by the option.

  \sa setWrapMode()
*/

/*!
  \fn void QTextOption::setWrapMode(WrapMode mode)

  Sets the option's text wrap mode to the given \a mode.
*/

/*!
  \enum QTextOption::Flag

  \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
                               return a value that includes the width of trailing spaces in the text; otherwise
                               this width is excluded.
  \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
            shown differently to breaking spaces.
  \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  \value ShowDocumentTerminator Visualize the end of the document with a section sign. This enum value was added
            in Qt 5.7.
  \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
            space added for drawing a separator character.
  \value SuppressColors Suppress all color changes in the character formats (except the main selection).
*/

/*!
  \fn Flags QTextOption::flags() const

  Returns the flags associated with the option.

  \sa setFlags()
*/

/*!
  \fn void QTextOption::setFlags(Flags flags)

  Sets the flags associated with the option to the given \a flags.

  \sa flags()
*/

/*!
  \fn qreal QTextOption::tabStopDistance() const
  \since 5.10

  Returns the distance in device units between tab stops.

  \sa setTabStopDistance(), tabArray(), setTabs(), tabs()
*/

/*!
  \fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
  \since 5.10

  Sets the default distance in device units between tab stops to the value specified
  by \a tabStopDistance.

  \sa tabStopDistance(), setTabArray(), setTabs(), tabs()
*/

/*!
    \enum QTextOption::TabType
    \since 4.4

    This enum holds the different types of tabulator

    \value LeftTab      A left-tab
    \value RightTab     A right-tab
    \value CenterTab    A centered-tab
    \value DelimiterTab A tab stopping at a certain delimiter-character
*/

/*!
    \class QTextOption::Tab
    \since 4.4
    \inmodule QtGui
    Each tab definition is represented by this struct.
*/

/*!
    \variable Tab::position
    Distance from the start of the paragraph.
    The position of a tab is from the start of the paragraph which implies that when
    the alignment of the paragraph is set to centered, the tab is interpreted to be
    moved the same distance as the left edge of the paragraph does.
    In case the paragraph is set to have a layoutDirection() RightToLeft the position
    is interpreted to be from the right side of the paragraph with higher numbers moving
    the tab to the left.
*/

/*!
    \variable QTextOption::Tab::type
    Determine which type is used.
    In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
    be interpreted to be a RightTab and vice versa.
*/

/*!
    \variable QTextOption::Tab::delimiter
    If type is DelimitorTab; tab until this char is found in the text.
*/

/*!
    \fn QTextOption::Tab::Tab()
    Creates a default left tab with position 80.
*/

/*!
    \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())

    Creates a tab with the given position, tab type, and delimiter
    (\a pos, \a tabType, \a delim).

    \note \a delim is only used when \a tabType is DelimiterTab.

    \since 4.7
*/

/*!
    \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is equal to this tab;
    otherwise returns \c false.
*/

/*!
    \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is not equal to this tab;
    otherwise returns \c false.
*/

/*!
  \since 4.4
  \fn QList<QTextOption::Tab> QTextOption::tabs() const
  Returns a list of tab positions defined for the text layout.

  \sa tabStopDistance(), setTabs(), setTabStopDistance()
*/

QT_END_NAMESPACE


while(iter != d->tabStops.constEnd()) {
        answer.append( (*iter).position);
        ++iter;
    }

/****************************************************************************
**
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: http://example.com and
** http://example.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qtextoption.h"
#include "qguiapplication.h"
#include "qlist.h"

QT_BEGIN_NAMESPACE

struct QTextOptionPrivate
{
    QList<QTextOption::Tab> tabStops;
};

/*!
    Constructs a text option with default properties for text.
    The text alignment property is set to Qt::AlignLeft. The
    word wrap property is set to QTextOption::WordWrap. The
    using of design metrics flag is set to false.
*/
QTextOption::QTextOption()
    : QTextOption(Qt::AlignLeft)
{
    direction = Qt::LayoutDirectionAuto;
}

/*!
    Constructs a text option with the given \a alignment for text.
    The word wrap property is set to QTextOption::WordWrap. The using
    of design metrics flag is set to false.
*/
QTextOption::QTextOption(Qt::Alignment alignment)
    : align(alignment),
      wordWrap(QTextOption::WordWrap),
      design(false),
      unused(0),
      f(0),
      tab(-1),
      d(nullptr)
{
    direction = QGuiApplication::layoutDirection();
}

/*!
    Destroys the text option.
*/
QTextOption::~QTextOption()
{
    delete d;
}

/*!
    \fn QTextOption::QTextOption(const QTextOption &other)

    Construct a copy of the \a other text option.
*/
QTextOption::QTextOption(const QTextOption &o)
    : align(o.align),
      wordWrap(o.wordWrap),
      design(o.design),
      direction(o.direction),
      unused(o.unused),
      f(o.f),
      tab(o.tab),
      d(nullptr)
{
    if (o.d)
        d = new QTextOptionPrivate(*o.d);
}

/*!
    \fn QTextOption &QTextOption::operator=(const QTextOption &other)

    Returns \c true if the text option is the same as the \a other text option;
    otherwise returns \c false.
*/
QTextOption &QTextOption::operator=(const QTextOption &o)
{
    if (this == &o)
        return *this;

    QTextOptionPrivate* dNew = nullptr;
    if (o.d)
        dNew = new QTextOptionPrivate(*o.d);
    delete d;
    d = dNew;

    align = o.align;
    wordWrap = o.wordWrap;
    design = o.design;
    direction = o.direction;
    unused = o.unused;
    f = o.f;
    tab = o.tab;
    return *this;
}

/*!
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabArray(), setTabStopDistance(), setTabs()
*/
void QTextOption::setTabArray(const QList<qreal> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    QList<QTextOption::Tab> tabs;
    QTextOption::Tab tab;
    tabs.reserve(tabStops.count());
    for (qreal pos : tabStops) {
        tab.position = pos;
        tabs.append(tab);
    }
    d->tabStops = tabs;
}

/*!
    \since 4.4
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabStopDistance()
*/
void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    d->tabStops = tabStops;
}

/*!
    Returns a list of tab positions defined for the text layout.

    \sa setTabArray(), tabStopDistance()
*/
QList<qreal> QTextOption::tabArray() const
{
    QList<qreal> answer;
    if (!d)
        return answer;

    answer.reserve(d->tabStops.count());
    QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();

    return answer;
}

QList<QTextOption::Tab> QTextOption::tabs() const
{
    if (!d)
        return QList<QTextOption::Tab>();
    return d->tabStops;
}

/*!
    \class QTextOption
    \reentrant

    \brief The QTextOption class provides a description of general rich text
    properties.
    \inmodule QtGui

    \ingroup richtext-processing

    QTextOption is used to encapsulate common rich text properties in a single
    object. It contains information about text alignment, layout direction,
    word wrapping, and other standard properties associated with text rendering
    and layout.

    \sa QTextEdit, QTextDocument, QTextCursor
*/

/*!
    \enum QTextOption::WrapMode

    This enum describes how text is wrapped in a document.

    \value NoWrap       Text is not wrapped at all.
    \value WordWrap     Text is wrapped at word boundaries.
    \value ManualWrap   Same as QTextOption::NoWrap
    \value WrapAnywhere Text can be wrapped at any point on a line, even if
                        it occurs in the middle of a word.
    \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
                        boundary; otherwise it will occur at the appropriate
                        point on the line, even in the middle of a word.
*/

/*!
  \fn void QTextOption::setUseDesignMetrics(bool enable)

    If \a enable is true then the layout will use design metrics;
    otherwise it will use the metrics of the paint device (which is
    the default behavior).

    \sa useDesignMetrics()
*/

/*!
  \fn bool QTextOption::useDesignMetrics() const

    Returns \c true if the layout uses design rather than device metrics;
    otherwise returns \c false.

    \sa setUseDesignMetrics()
*/

/*!
  \fn Qt::Alignment QTextOption::alignment() const

  Returns the text alignment defined by the option.

  \sa setAlignment()
*/

/*!
  \fn void QTextOption::setAlignment(Qt::Alignment alignment);

  Sets the option's text alignment to the specified \a alignment.

  \sa alignment()
*/

/*!
  \fn Qt::LayoutDirection QTextOption::textDirection() const

  Returns the direction of the text layout defined by the option.

  \sa setTextDirection()
*/

/*!
  \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)

  Sets the direction of the text layout defined by the option to the
  given \a direction.

  \sa textDirection()
*/

/*!
  \fn WrapMode QTextOption::wrapMode() const

  Returns the text wrap mode defined by the option.

  \sa setWrapMode()
*/

/*!
  \fn void QTextOption::setWrapMode(WrapMode mode)

  Sets the option's text wrap mode to the given \a mode.
*/

/*!
  \enum QTextOption::Flag

  \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
                               return a value that includes the width of trailing spaces in the text; otherwise
                               this width is excluded.
  \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
            shown differently to breaking spaces.
  \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  \value ShowDocumentTerminator Visualize the end of the document with a section sign. This enum value was added
            in Qt 5.7.
  \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
            space added for drawing a separator character.
  \value SuppressColors Suppress all color changes in the character formats (except the main selection).
*/

/*!
  \fn Flags QTextOption::flags() const

  Returns the flags associated with the option.

  \sa setFlags()
*/

/*!
  \fn void QTextOption::setFlags(Flags flags)

  Sets the flags associated with the option to the given \a flags.

  \sa flags()
*/

/*!
  \fn qreal QTextOption::tabStopDistance() const
  \since 5.10

  Returns the distance in device units between tab stops.

  \sa setTabStopDistance(), tabArray(), setTabs(), tabs()
*/

/*!
  \fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
  \since 5.10

  Sets the default distance in device units between tab stops to the value specified
  by \a tabStopDistance.

  \sa tabStopDistance(), setTabArray(), setTabs(), tabs()
*/

/*!
    \enum QTextOption::TabType
    \since 4.4

    This enum holds the different types of tabulator

    \value LeftTab      A left-tab
    \value RightTab     A right-tab
    \value CenterTab    A centered-tab
    \value DelimiterTab A tab stopping at a certain delimiter-character
*/

/*!
    \class QTextOption::Tab
    \since 4.4
    \inmodule QtGui
    Each tab definition is represented by this struct.
*/

/*!
    \variable Tab::position
    Distance from the start of the paragraph.
    The position of a tab is from the start of the paragraph which implies that when
    the alignment of the paragraph is set to centered, the tab is interpreted to be
    moved the same distance as the left edge of the paragraph does.
    In case the paragraph is set to have a layoutDirection() RightToLeft the position
    is interpreted to be from the right side of the paragraph with higher numbers moving
    the tab to the left.
*/

/*!
    \variable QTextOption::Tab::type
    Determine which type is used.
    In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
    be interpreted to be a RightTab and vice versa.
*/

/*!
    \variable QTextOption::Tab::delimiter
    If type is DelimitorTab; tab until this char is found in the text.
*/

/*!
    \fn QTextOption::Tab::Tab()
    Creates a default left tab with position 80.
*/

/*!
    \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())

    Creates a tab with the given position, tab type, and delimiter
    (\a pos, \a tabType, \a delim).

    \note \a delim is only used when \a tabType is DelimiterTab.

    \since 4.7
*/

/*!
    \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is equal to this tab;
    otherwise returns \c false.
*/

/*!
    \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is not equal to this tab;
    otherwise returns \c false.
*/

/*!
  \since 4.4
  \fn QList<QTextOption::Tab> QTextOption::tabs() const
  Returns a list of tab positions defined for the text layout.

  \sa tabStopDistance(), setTabs(), setTabStopDistance()
*/

QT_END_NAMESPACE


/****************************************************************************
**
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: http://example.com and
** http://example.com.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qtextoption.h"
#include "qguiapplication.h"
#include "qlist.h"

QT_BEGIN_NAMESPACE

struct QTextOptionPrivate
{
    QList<QTextOption::Tab> tabStops;
};

/*!
    Constructs a text option with default properties for text.
    The text alignment property is set to Qt::AlignLeft. The
    word wrap property is set to QTextOption::WordWrap. The
    using of design metrics flag is set to false.
*/
QTextOption::QTextOption()
    : QTextOption(Qt::AlignLeft)
{
    direction = Qt::LayoutDirectionAuto;
}

/*!
    Constructs a text option with the given \a alignment for text.
    The word wrap property is set to QTextOption::WordWrap. The using
    of design metrics flag is set to false.
*/
QTextOption::QTextOption(Qt::Alignment alignment)
    : align(alignment),
      wordWrap(QTextOption::WordWrap),
      design(false),
      unused(0),
      f(0),
      tab(-1),
      d(nullptr)
{
    direction = QGuiApplication::layoutDirection();
}

/*!
    Destroys the text option.
*/
QTextOption::~QTextOption()
{
    delete d;
}

/*!
    \fn QTextOption::QTextOption(const QTextOption &other)

    Construct a copy of the \a other text option.
*/
QTextOption::QTextOption(const QTextOption &o)
    : align(o.align),
      wordWrap(o.wordWrap),
      design(o.design),
      direction(o.direction),
      unused(o.unused),
      f(o.f),
      tab(o.tab),
      d(nullptr)
{
    if (o.d)
        d = new QTextOptionPrivate(*o.d);
}

/*!
    \fn QTextOption &QTextOption::operator=(const QTextOption &other)

    Returns \c true if the text option is the same as the \a other text option;
    otherwise returns \c false.
*/
QTextOption &QTextOption::operator=(const QTextOption &o)
{
    if (this == &o)
        return *this;

    QTextOptionPrivate* dNew = nullptr;
    if (o.d)
        dNew = new QTextOptionPrivate(*o.d);
    delete d;
    d = dNew;

    align = o.align;
    wordWrap = o.wordWrap;
    design = o.design;
    direction = o.direction;
    unused = o.unused;
    f = o.f;
    tab = o.tab;
    return *this;
}

/*!
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabArray(), setTabStopDistance(), setTabs()
*/
void QTextOption::setTabArray(const QList<qreal> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    QList<QTextOption::Tab> tabs;
    QTextOption::Tab tab;
    tabs.reserve(tabStops.count());
    for (qreal pos : tabStops) {
        tab.position = pos;
        tabs.append(tab);
    }
    d->tabStops = tabs;
}

/*!
    \since 4.4
    Sets the tab positions for the text layout to those specified by
    \a tabStops.

    \sa tabStopDistance()
*/
void QTextOption::setTabs(const QList<QTextOption::Tab> &tabStops)
{
    if (!d)
        d = new QTextOptionPrivate;
    d->tabStops = tabStops;
}

/*!
    Returns a list of tab positions defined for the text layout.

    \sa setTabArray(), tabStopDistance()
*/
QList<qreal> QTextOption::tabArray() const
{
    QList<qreal> answer;
    if (!d)
        return answer;

    answer.reserve(d->tabStops.count());

    QList<QTextOption::Tab>::ConstIterator iter = d->tabStops.constBegin();
    while(iter != d->tabStops.constEnd()) {
        answer.append( (*iter).position);
        ++iter;
    }
    return answer;
}

QList<QTextOption::Tab> QTextOption::tabs() const
{
    if (!d)
        return QList<QTextOption::Tab>();
    return d->tabStops;
}

/*!
    \class QTextOption
    \reentrant

    \brief The QTextOption class provides a description of general rich text
    properties.
    \inmodule QtGui

    \ingroup richtext-processing

    QTextOption is used to encapsulate common rich text properties in a single
    object. It contains information about text alignment, layout direction,
    word wrapping, and other standard properties associated with text rendering
    and layout.

    \sa QTextEdit, QTextDocument, QTextCursor
*/

/*!
    \enum QTextOption::WrapMode

    This enum describes how text is wrapped in a document.

    \value NoWrap       Text is not wrapped at all.
    \value WordWrap     Text is wrapped at word boundaries.
    \value ManualWrap   Same as QTextOption::NoWrap
    \value WrapAnywhere Text can be wrapped at any point on a line, even if
                        it occurs in the middle of a word.
    \value WrapAtWordBoundaryOrAnywhere If possible, wrapping occurs at a word
                        boundary; otherwise it will occur at the appropriate
                        point on the line, even in the middle of a word.
*/

/*!
  \fn void QTextOption::setUseDesignMetrics(bool enable)

    If \a enable is true then the layout will use design metrics;
    otherwise it will use the metrics of the paint device (which is
    the default behavior).

    \sa useDesignMetrics()
*/

/*!
  \fn bool QTextOption::useDesignMetrics() const

    Returns \c true if the layout uses design rather than device metrics;
    otherwise returns \c false.

    \sa setUseDesignMetrics()
*/

/*!
  \fn Qt::Alignment QTextOption::alignment() const

  Returns the text alignment defined by the option.

  \sa setAlignment()
*/

/*!
  \fn void QTextOption::setAlignment(Qt::Alignment alignment);

  Sets the option's text alignment to the specified \a alignment.

  \sa alignment()
*/

/*!
  \fn Qt::LayoutDirection QTextOption::textDirection() const

  Returns the direction of the text layout defined by the option.

  \sa setTextDirection()
*/

/*!
  \fn void QTextOption::setTextDirection(Qt::LayoutDirection direction)

  Sets the direction of the text layout defined by the option to the
  given \a direction.

  \sa textDirection()
*/

/*!
  \fn WrapMode QTextOption::wrapMode() const

  Returns the text wrap mode defined by the option.

  \sa setWrapMode()
*/

/*!
  \fn void QTextOption::setWrapMode(WrapMode mode)

  Sets the option's text wrap mode to the given \a mode.
*/

/*!
  \enum QTextOption::Flag

  \value IncludeTrailingSpaces When this option is set, QTextLine::naturalTextWidth() and naturalTextRect() will
                               return a value that includes the width of trailing spaces in the text; otherwise
                               this width is excluded.
  \value ShowTabsAndSpaces Visualize spaces with little dots, and tabs with little arrows. Non-breaking spaces are
            shown differently to breaking spaces.
  \value ShowLineAndParagraphSeparators Visualize line and paragraph separators with appropriate symbol characters.
  \value ShowDocumentTerminator Visualize the end of the document with a section sign. This enum value was added
            in Qt 5.7.
  \value AddSpaceForLineAndParagraphSeparators While determining the line-break positions take into account the
            space added for drawing a separator character.
  \value SuppressColors Suppress all color changes in the character formats (except the main selection).
*/

/*!
  \fn Flags QTextOption::flags() const

  Returns the flags associated with the option.

  \sa setFlags()
*/

/*!
  \fn void QTextOption::setFlags(Flags flags)

  Sets the flags associated with the option to the given \a flags.

  \sa flags()
*/

/*!
  \fn qreal QTextOption::tabStopDistance() const
  \since 5.10

  Returns the distance in device units between tab stops.

  \sa setTabStopDistance(), tabArray(), setTabs(), tabs()
*/

/*!
  \fn void QTextOption::setTabStopDistance(qreal tabStopDistance)
  \since 5.10

  Sets the default distance in device units between tab stops to the value specified
  by \a tabStopDistance.

  \sa tabStopDistance(), setTabArray(), setTabs(), tabs()
*/

/*!
    \enum QTextOption::TabType
    \since 4.4

    This enum holds the different types of tabulator

    \value LeftTab      A left-tab
    \value RightTab     A right-tab
    \value CenterTab    A centered-tab
    \value DelimiterTab A tab stopping at a certain delimiter-character
*/

/*!
    \class QTextOption::Tab
    \since 4.4
    \inmodule QtGui
    Each tab definition is represented by this struct.
*/

/*!
    \variable Tab::position
    Distance from the start of the paragraph.
    The position of a tab is from the start of the paragraph which implies that when
    the alignment of the paragraph is set to centered, the tab is interpreted to be
    moved the same distance as the left edge of the paragraph does.
    In case the paragraph is set to have a layoutDirection() RightToLeft the position
    is interpreted to be from the right side of the paragraph with higher numbers moving
    the tab to the left.
*/

/*!
    \variable QTextOption::Tab::type
    Determine which type is used.
    In a paragraph that has layoutDirection() RightToLeft the type LeftTab will
    be interpreted to be a RightTab and vice versa.
*/

/*!
    \variable QTextOption::Tab::delimiter
    If type is DelimitorTab; tab until this char is found in the text.
*/

/*!
    \fn QTextOption::Tab::Tab()
    Creates a default left tab with position 80.
*/

/*!
    \fn QTextOption::Tab::Tab(qreal pos, TabType tabType, QChar delim = QChar())

    Creates a tab with the given position, tab type, and delimiter
    (\a pos, \a tabType, \a delim).

    \note \a delim is only used when \a tabType is DelimiterTab.

    \since 4.7
*/

/*!
    \fn bool QTextOption::Tab::operator==(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is equal to this tab;
    otherwise returns \c false.
*/

/*!
    \fn bool QTextOption::Tab::operator!=(const QTextOption::Tab &other) const

    Returns \c true if tab \a other is not equal to this tab;
    otherwise returns \c false.
*/

/*!
  \since 4.4
  \fn QList<QTextOption::Tab> QTextOption::tabs() const
  Returns a list of tab positions defined for the text layout.

  \sa tabStopDistance(), setTabs(), setTabStopDistance()
*/

QT_END_NAMESPACE


CPeripheralDisk::CPeripheralDisk(const PeripheralScanResult& scanResult, CPeripheralBus* bus) :
  CPeripheral(scanResult, bus)

/*
 *
 *
 */

#include "PeripheralDisk.h"
#include "guilib/LocalizeStrings.h"

using namespace PERIPHERALS;

{
  m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35003) : scanResult.m_strDeviceName;
  m_features.push_back(FEATURE_DISK);
}


{
  m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35003) : scanResult.m_strDeviceName;
  m_features.push_back(FEATURE_DISK);
}

/*
 *
 *
 */

#include "PeripheralDisk.h"
#include "guilib/LocalizeStrings.h"

using namespace PERIPHERALS;

CPeripheralDisk::CPeripheralDisk(const PeripheralScanResult& scanResult, CPeripheralBus* bus) :
  CPeripheral(scanResult, bus)


/*
 *
 *
 */

#include "PeripheralDisk.h"
#include "guilib/LocalizeStrings.h"

using namespace PERIPHERALS;

CPeripheralDisk::CPeripheralDisk(const PeripheralScanResult& scanResult, CPeripheralBus* bus) :
  CPeripheral(scanResult, bus)
{
  m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35003) : scanResult.m_strDeviceName;
  m_features.push_back(FEATURE_DI


/*
 *
 *
 */

#include "PeripheralDisk.h"
#include "guilib/LocalizeStrings.h"

using namespace PERI

PHERALS;

CPeripheralDisk::CPeripheralDisk(const PeripheralScanResult& scanResult, CPeripheralBus* bus) :
  CPeripheral(scanResult, bus)
{
  m_strDeviceName = scanResult.m_strDeviceName.empty() ? g_localizeStrings.Get(35003) : scanResult.m_strDeviceName;
  m_features.push_back(FEATURE_DISK);
}


void StringComparatorLocale::setNextReader(const IndexReaderPtr& reader, int32_t docBase)

#include "LuceneInc.h"
#include "FieldComparator.h"
#include "FieldCache.h"
#include "ScoreCachingWrappingScorer.h"
#include "Collator.h"

namespace Lucene {

FieldComparator::~FieldComparator() {
}

void FieldComparator::setScorer(const ScorerPtr& scorer) {
    // Empty implementation since most comparators don't need the score.
    // This can be overridden by those that need it.
}

ByteComparator::ByteComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<uint8_t>(numHits, field) {
    this->parser = boost::static_pointer_cast<ByteParser>(parser);
}

ByteComparator::~ByteComparator() {
}

void ByteComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getBytes(reader, field, parser);
}

DocComparator::DocComparator(int32_t numHits) : NumericComparator<int32_t>(numHits) {
    this->docBase = 0;
}

DocComparator::~DocComparator() {
}

int32_t DocComparator::compareBottom(int32_t doc) {
    // No overflow risk because docIDs are non-negative
    return (bottom - (docBase + doc));
}

void DocComparator::copy(int32_t slot, int32_t doc) {
    values[slot] = docBase + doc;
}

void DocComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    this->docBase = docBase;
}

DoubleComparator::DoubleComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<double>(numHits, field) {
    this->parser = boost::static_pointer_cast<DoubleParser>(parser);
}

DoubleComparator::~DoubleComparator() {
}

int32_t DoubleComparator::compare(int32_t slot1, int32_t slot2) {
    double v1 = values[slot1];
    double v2 = values[slot2];
    return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
}

int32_t DoubleComparator::compareBottom(int32_t doc) {
    double v2 = currentReaderValues[doc];
    return bottom > v2 ? 1 : (bottom < v2 ? -1 : 0);
}

void DoubleComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getDoubles(reader, field, parser);
}

IntComparator::IntComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<int32_t>(numHits, field) {
    this->parser = boost::static_pointer_cast<IntParser>(parser);
}

IntComparator::~IntComparator() {
}

int32_t IntComparator::compare(int32_t slot1, int32_t slot2) {
    int32_t v1 = values[slot1];
    int32_t v2 = values[slot2];
    return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
}

int32_t IntComparator::compareBottom(int32_t doc) {
    int32_t v2 = currentReaderValues[doc];
    return bottom > v2 ? 1 : (bottom < v2 ? -1 : 0);
}

void IntComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getInts(reader, field, parser);
}

LongComparator::LongComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<int64_t>(numHits, field) {
    this->parser = boost::static_pointer_cast<LongParser>(parser);
}

LongComparator::~LongComparator() {
}

int32_t LongComparator::compare(int32_t slot1, int32_t slot2) {
    int64_t v1 = values[slot1];
    int64_t v2 = values[slot2];
    return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
}

int32_t LongComparator::compareBottom(int32_t doc) {
    int64_t v2 = currentReaderValues[doc];
    return bottom > v2 ? 1 : (bottom < v2 ? -1 : 0);
}

void LongComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getLongs(reader, field, parser);
}

RelevanceComparator::RelevanceComparator(int32_t numHits) : NumericComparator<double>(numHits) {
}

RelevanceComparator::~RelevanceComparator() {
}

int32_t RelevanceComparator::compare(int32_t slot1, int32_t slot2) {
    double score1 = values[slot1];
    double score2 = values[slot2];
    return score1 > score2 ? -1 : (score1 < score2 ? 1 : 0);
}

int32_t RelevanceComparator::compareBottom(int32_t doc) {
    double score = scorer->score();
    return bottom > score ? -1 : (bottom < score ? 1 : 0);
}

void RelevanceComparator::copy(int32_t slot, int32_t doc) {
    values[slot] = scorer->score();
}

void RelevanceComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
}

void RelevanceComparator::setScorer(const ScorerPtr& scorer) {
    this->scorer = newLucene<ScoreCachingWrappingScorer>(scorer);
}

StringComparatorLocale::StringComparatorLocale(int32_t numHits, const String& field, const std::locale& locale) : collator(newLucene<Collator>(locale)) {
    this->values = Collection<String>::newInstance(numHits);
    this->field = field;
}

StringComparatorLocale::~StringComparatorLocale() {
}

int32_t StringComparatorLocale::compare(int32_t slot1, int32_t slot2) {
    return collator->compare(values[slot1], values[slot2]);
}

int32_t StringComparatorLocale::compareBottom(int32_t doc) {
    return collator->compare(bottom, currentReaderValues[doc]);
}

void StringComparatorLocale::copy(int32_t slot, int32_t doc) {
    values[slot] = currentReaderValues[doc];
}

{
    currentReaderValues = FieldCache::DEFAULT()->getStrings(reader, field);
}

void StringComparatorLocale::setBottom(int32_t slot) {
    bottom = values[slot];
}

ComparableValue StringComparatorLocale::value(int32_t slot) {
    return values[slot];
}

StringOrdValComparator::StringOrdValComparator(int32_t numHits, const String& field, int32_t sortPos, bool reversed) {
    this->ords = Collection<int32_t>::newInstance(numHits);
    this->values = Collection<String>::newInstance(numHits);
    this->readerGen = Collection<int32_t>::newInstance(numHits);
    this->sortPos = sortPos;
    this->reversed = reversed;
    this->field = field;
    this->currentReaderGen = -1;
    this->bottomSlot = -1;
    this->bottomOrd = 0;
}

StringOrdValComparator::~StringOrdValComparator() {
}

int32_t StringOrdValComparator::compare(int32_t slot1, int32_t slot2) {
    if (readerGen[slot1] == readerGen[slot2]) {
        int32_t cmp = ords[slot1] - ords[slot2];
        if (cmp != 0) {
            return cmp;
        }
    }
    return values[slot1].compare(values[slot2]);
}

int32_t StringOrdValComparator::compareBottom(int32_t doc) {
    BOOST_ASSERT(bottomSlot != -1);
    int32_t order = this->order[doc];
    int32_t cmp = bottomOrd - order;
    if (cmp != 0) {
        return cmp;
    }
    return bottomValue.compare(lookup[order]);
}

void StringOrdValComparator::convert(int32_t slot) {
    readerGen[slot] = currentReaderGen;
    int32_t index = 0;
    String value(values[slot]);
    if (value.empty()) {
        ords[slot] = 0;
        return;
    }

    if (sortPos == 0 && bottomSlot != -1 && bottomSlot != slot) {
        // Since we are the primary sort, the entries in the queue are bounded by bottomOrd
        BOOST_ASSERT(bottomOrd < lookup.size());
        if (reversed) {
            index = binarySearch(lookup, value, bottomOrd, lookup.size() - 1);
        } else {
            index = binarySearch(lookup, value, 0, bottomOrd);
        }
    } else {
        // Full binary search
        index = binarySearch(lookup, value, 0, lookup.size() - 1);
    }

    if (index < 0) {
        index = -index - 2;
    }

    ords[slot] = index;
}

int32_t StringOrdValComparator::binarySearch(Collection<String> lookup, const String& key, int32_t low, int32_t high) {
    Collection<String>::iterator search = std::lower_bound(lookup.begin() + low, lookup.begin() + high, key);
    int32_t keyPos = std::distance(lookup.begin(), search);
    return (search == lookup.end() || key < *search) ? -(keyPos + 1) : keyPos;
}

void StringOrdValComparator::copy(int32_t slot, int32_t doc) {
    int32_t ord = order[doc];
    ords[slot] = ord;
    BOOST_ASSERT(ord >= 0);
    values[slot] = lookup[ord];
    readerGen[slot] = currentReaderGen;
}

void StringOrdValComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    StringIndexPtr currentReaderValues(FieldCache::DEFAULT()->getStringIndex(reader, field));
    ++currentReaderGen;
    order = currentReaderValues->order;
    lookup = currentReaderValues->lookup;
    BOOST_ASSERT(!lookup.empty());
    if (bottomSlot != -1) {
        convert(bottomSlot);
        bottomOrd = ords[bottomSlot];
    }
}

void StringOrdValComparator::setBottom(int32_t slot) {
    bottomSlot = slot;
    if (readerGen[slot] != currentReaderGen) {
        convert(bottomSlot);
    }
    bottomOrd = ords[slot];
    BOOST_ASSERT(bottomOrd >= 0);
    BOOST_ASSERT(bottomOrd < lookup.size());
    bottomValue = values[slot];
}

ComparableValue StringOrdValComparator::value(int32_t slot) {
    return values[slot];
}

Collection<String> StringOrdValComparator::getValues() {
    return values;
}

int32_t StringOrdValComparator::getBottomSlot() {
    return bottomSlot;
}

String StringOrdValComparator::getField() {
    return field;
}

StringValComparator::StringValComparator(int32_t numHits, const String& field) {
    this->values = Collection<String>::newInstance(numHits);
    this->field = field;
}

StringValComparator::~StringValComparator() {
}

int32_t StringValComparator::compare(int32_t slot1, int32_t slot2) {
    return values[slot1].compare(values[slot2]);
}

int32_t StringValComparator::compareBottom(int32_t doc) {
    return bottom.compare(currentReaderValues[doc]);
}

void StringValComparator::copy(int32_t slot, int32_t doc) {
    values[slot] = currentReaderValues[doc];
}

void StringValComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getStrings(reader, field);
}

void StringValComparator::setBottom(int32_t slot) {
    bottom = values[slot];
}

ComparableValue StringValComparator::value(int32_t slot) {
    return values[slot];
}

}


{
    this->parser = boost::static_pointer_cast<DoubleParser>(parser);
}

#include "LuceneInc.h"
#include "FieldComparator.h"
#include "FieldCache.h"
#include "ScoreCachingWrappingScorer.h"
#include "Collator.h"

namespace Lucene {

FieldComparator::~FieldComparator() {
}

void FieldComparator::setScorer(const ScorerPtr& scorer) {
    // Empty implementation since most comparators don't need the score.
    // This can be overridden by those that need it.
}

ByteComparator::ByteComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<uint8_t>(numHits, field) {
    this->parser = boost::static_pointer_cast<ByteParser>(parser);
}

ByteComparator::~ByteComparator() {
}

void ByteComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getBytes(reader, field, parser);
}

DocComparator::DocComparator(int32_t numHits) : NumericComparator<int32_t>(numHits) {
    this->docBase = 0;
}

DocComparator::~DocComparator() {
}

int32_t DocComparator::compareBottom(int32_t doc) {
    // No overflow risk because docIDs are non-negative
    return (bottom - (docBase + doc));
}

void DocComparator::copy(int32_t slot, int32_t doc) {
    values[slot] = docBase + doc;
}

void DocComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    this->docBase = docBase;
}

DoubleComparator::DoubleComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<double>(numHits, field)

DoubleComparator::~DoubleComparator() {
}

int32_t DoubleComparator::compare(int32_t slot1, int32_t slot2) {
    double v1 = values[slot1];
    double v2 = values[slot2];
    return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
}

int32_t DoubleComparator::compareBottom(int32_t doc) {
    double v2 = currentReaderValues[doc];
    return bottom > v2 ? 1 : (bottom < v2 ? -1 : 0);
}

void DoubleComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getDoubles(reader, field, parser);
}

IntComparator::IntComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<int32_t>(numHits, field) {
    this->parser = boost::static_pointer_cast<IntParser>(parser);
}

IntComparator::~IntComparator() {
}

int32_t IntComparator::compare(int32_t slot1, int32_t slot2) {
    int32_t v1 = values[slot1];
    int32_t v2 = values[slot2];
    return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
}

int32_t IntComparator::compareBottom(int32_t doc) {
    int32_t v2 = currentReaderValues[doc];
    return bottom > v2 ? 1 : (bottom < v2 ? -1 : 0);
}

void IntComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getInts(reader, field, parser);
}

LongComparator::LongComparator(int32_t numHits, const String& field, const ParserPtr& parser) : NumericComparator<int64_t>(numHits, field) {
    this->parser = boost::static_pointer_cast<LongParser>(parser);
}

LongComparator::~LongComparator() {
}

int32_t LongComparator::compare(int32_t slot1, int32_t slot2) {
    int64_t v1 = values[slot1];
    int64_t v2 = values[slot2];
    return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
}

int32_t LongComparator::compareBottom(int32_t doc) {
    int64_t v2 = currentReaderValues[doc];
    return bottom > v2 ? 1 : (bottom < v2 ? -1 : 0);
}

void LongComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getLongs(reader, field, parser);
}

RelevanceComparator::RelevanceComparator(int32_t numHits) : NumericComparator<double>(numHits) {
}

RelevanceComparator::~RelevanceComparator() {
}

int32_t RelevanceComparator::compare(int32_t slot1, int32_t slot2) {
    double score1 = values[slot1];
    double score2 = values[slot2];
    return score1 > score2 ? -1 : (score1 < score2 ? 1 : 0);
}

int32_t RelevanceComparator::compareBottom(int32_t doc) {
    double score = scorer->score();
    return bottom > score ? -1 : (bottom < score ? 1 : 0);
}

void RelevanceComparator::copy(int32_t slot, int32_t doc) {
    values[slot] = scorer->score();
}

void RelevanceComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
}

void RelevanceComparator::setScorer(const ScorerPtr& scorer) {
    this->scorer = newLucene<ScoreCachingWrappingScorer>(scorer);
}

StringComparatorLocale::StringComparatorLocale(int32_t numHits, const String& field, const std::locale& locale) : collator(newLucene<Collator>(locale)) {
    this->values = Collection<String>::newInstance(numHits);
    this->field = field;
}

StringComparatorLocale::~StringComparatorLocale() {
}

int32_t StringComparatorLocale::compare(int32_t slot1, int32_t slot2) {
    return collator->compare(values[slot1], values[slot2]);
}

int32_t StringComparatorLocale::compareBottom(int32_t doc) {
    return collator->compare(bottom, currentReaderValues[doc]);
}

void StringComparatorLocale::copy(int32_t slot, int32_t doc) {
    values[slot] = currentReaderValues[doc];
}

void StringComparatorLocale::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getStrings(reader, field);
}

void StringComparatorLocale::setBottom(int32_t slot) {
    bottom = values[slot];
}

ComparableValue StringComparatorLocale::value(int32_t slot) {
    return values[slot];
}

StringOrdValComparator::StringOrdValComparator(int32_t numHits, const String& field, int32_t sortPos, bool reversed) {
    this->ords = Collection<int32_t>::newInstance(numHits);
    this->values = Collection<String>::newInstance(numHits);
    this->readerGen = Collection<int32_t>::newInstance(numHits);
    this->sortPos = sortPos;
    this->reversed = reversed;
    this->field = field;
    this->currentReaderGen = -1;
    this->bottomSlot = -1;
    this->bottomOrd = 0;
}

StringOrdValComparator::~StringOrdValComparator() {
}

int32_t StringOrdValComparator::compare(int32_t slot1, int32_t slot2) {
    if (readerGen[slot1] == readerGen[slot2]) {
        int32_t cmp = ords[slot1] - ords[slot2];
        if (cmp != 0) {
            return cmp;
        }
    }
    return values[slot1].compare(values[slot2]);
}

int32_t StringOrdValComparator::compareBottom(int32_t doc) {
    BOOST_ASSERT(bottomSlot != -1);
    int32_t order = this->order[doc];
    int32_t cmp = bottomOrd - order;
    if (cmp != 0) {
        return cmp;
    }
    return bottomValue.compare(lookup[order]);
}

void StringOrdValComparator::convert(int32_t slot) {
    readerGen[slot] = currentReaderGen;
    int32_t index = 0;
    String value(values[slot]);
    if (value.empty()) {
        ords[slot] = 0;
        return;
    }

    if (sortPos == 0 && bottomSlot != -1 && bottomSlot != slot) {
        // Since we are the primary sort, the entries in the queue are bounded by bottomOrd
        BOOST_ASSERT(bottomOrd < lookup.size());
        if (reversed) {
            index = binarySearch(lookup, value, bottomOrd, lookup.size() - 1);
        } else {
            index = binarySearch(lookup, value, 0, bottomOrd);
        }
    } else {
        // Full binary search
        index = binarySearch(lookup, value, 0, lookup.size() - 1);
    }

    if (index < 0) {
        index = -index - 2;
    }

    ords[slot] = index;
}

int32_t StringOrdValComparator::binarySearch(Collection<String> lookup, const String& key, int32_t low, int32_t high) {
    Collection<String>::iterator search = std::lower_bound(lookup.begin() + low, lookup.begin() + high, key);
    int32_t keyPos = std::distance(lookup.begin(), search);
    return (search == lookup.end() || key < *search) ? -(keyPos + 1) : keyPos;
}

void StringOrdValComparator::copy(int32_t slot, int32_t doc) {
    int32_t ord = order[doc];
    ords[slot] = ord;
    BOOST_ASSERT(ord >= 0);
    values[slot] = lookup[ord];
    readerGen[slot] = currentReaderGen;
}

void StringOrdValComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    StringIndexPtr currentReaderValues(FieldCache::DEFAULT()->getStringIndex(reader, field));
    ++currentReaderGen;
    order = currentReaderValues->order;
    lookup = currentReaderValues->lookup;
    BOOST_ASSERT(!lookup.empty());
    if (bottomSlot != -1) {
        convert(bottomSlot);
        bottomOrd = ords[bottomSlot];
    }
}

void StringOrdValComparator::setBottom(int32_t slot) {
    bottomSlot = slot;
    if (readerGen[slot] != currentReaderGen) {
        convert(bottomSlot);
    }
    bottomOrd = ords[slot];
    BOOST_ASSERT(bottomOrd >= 0);
    BOOST_ASSERT(bottomOrd < lookup.size());
    bottomValue = values[slot];
}

ComparableValue StringOrdValComparator::value(int32_t slot) {
    return values[slot];
}

Collection<String> StringOrdValComparator::getValues() {
    return values;
}

int32_t StringOrdValComparator::getBottomSlot() {
    return bottomSlot;
}

String StringOrdValComparator::getField() {
    return field;
}

StringValComparator::StringValComparator(int32_t numHits, const String& field) {
    this->values = Collection<String>::newInstance(numHits);
    this->field = field;
}

StringValComparator::~StringValComparator() {
}

int32_t StringValComparator::compare(int32_t slot1, int32_t slot2) {
    return values[slot1].compare(values[slot2]);
}

int32_t StringValComparator::compareBottom(int32_t doc) {
    return bottom.compare(currentReaderValues[doc]);
}

void StringValComparator::copy(int32_t slot, int32_t doc) {
    values[slot] = currentReaderValues[doc];
}

void StringValComparator::setNextReader(const IndexReaderPtr& reader, int32_t docBase) {
    currentReaderValues = FieldCache::DEFAULT()->getStrings(reader, field);
}

void StringValComparator::setBottom(int32_t slot) {
    bottom = values[slot];
}

ComparableValue StringValComparator::value(int32_t slot) {
    return values[slot];
}

}