diff options
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 62 | ||||
-rw-r--r-- | src/widgets/styles/qgtkstyle.cpp | 1 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac.mm | 26 | ||||
-rw-r--r-- | src/widgets/styles/qmacstyle_mac_p.h | 8 | ||||
-rw-r--r-- | src/widgets/styles/qmotifstyle_p.h | 82 |
5 files changed, 41 insertions, 138 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 85d46bb0a3..5c34caef6b 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -712,6 +712,24 @@ static void drawArrow(const QStyle *style, const QStyleOptionToolButton *toolbut #ifndef QT_NO_ITEMVIEWS +static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth) +{ + qreal height = 0; + qreal widthUsed = 0; + textLayout.beginLayout(); + while (true) { + QTextLine line = textLayout.createLine(); + if (!line.isValid()) + break; + line.setLineWidth(lineWidth); + line.setPosition(QPointF(0, height)); + height += line.height(); + widthUsed = qMax(widthUsed, line.naturalTextWidth()); + } + textLayout.endLayout(); + return QSizeF(widthUsed, height); +} + QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int role) const { const QWidget *widget = option->widget; @@ -725,10 +743,8 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int if (option->features & QStyleOptionViewItem::HasDisplay) { QTextOption textOption; textOption.setWrapMode(QTextOption::WordWrap); - QTextLayout textLayout; + QTextLayout textLayout(option->text, option->font); textLayout.setTextOption(textOption); - textLayout.setFont(option->font); - textLayout.setText(option->text); const bool wrapText = option->features & QStyleOptionViewItem::WrapText; const int textMargin = proxyStyle->pixelMetric(QStyle::PM_FocusFrameHMargin, option, widget) + 1; QRect bounds = option->rect; @@ -745,20 +761,9 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int break; } - qreal height = 0, widthUsed = 0; - textLayout.beginLayout(); - while (true) { - QTextLine line = textLayout.createLine(); - if (!line.isValid()) - break; - line.setLineWidth(bounds.width()); - line.setPosition(QPointF(0, height)); - height += line.height(); - widthUsed = qMax(widthUsed, line.naturalTextWidth()); - } - textLayout.endLayout(); - const QSize size(qCeil(widthUsed), qCeil(height)); - return QSize(size.width() + 2 * textMargin, size.height()); + const int lineWidth = bounds.width(); + const QSizeF size = viewItemTextLayout(textLayout, lineWidth); + return QSize(qCeil(size.width()) + 2 * textMargin, qCeil(size.height())); } break; case Qt::DecorationRole: @@ -773,25 +778,6 @@ QSize QCommonStylePrivate::viewItemSize(const QStyleOptionViewItem *option, int return QSize(0, 0); } -static QSizeF viewItemTextLayout(QTextLayout &textLayout, int lineWidth) -{ - qreal height = 0; - qreal widthUsed = 0; - textLayout.beginLayout(); - while (true) { - QTextLine line = textLayout.createLine(); - if (!line.isValid()) - break; - line.setLineWidth(lineWidth); - line.setPosition(QPointF(0, height)); - height += line.height(); - widthUsed = qMax(widthUsed, line.naturalTextWidth()); - } - textLayout.endLayout(); - return QSizeF(widthUsed, height); -} - - void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewItem *option, const QRect &rect) const { const QWidget *widget = option->widget; @@ -803,10 +789,8 @@ void QCommonStylePrivate::viewItemDrawText(QPainter *p, const QStyleOptionViewIt textOption.setWrapMode(wrapText ? QTextOption::WordWrap : QTextOption::ManualWrap); textOption.setTextDirection(option->direction); textOption.setAlignment(QStyle::visualAlignment(option->direction, option->displayAlignment)); - QTextLayout textLayout; + QTextLayout textLayout(option->text, option->font); textLayout.setTextOption(textOption); - textLayout.setFont(option->font); - textLayout.setText(option->text); viewItemTextLayout(textLayout, textRect.width()); diff --git a/src/widgets/styles/qgtkstyle.cpp b/src/widgets/styles/qgtkstyle.cpp index 552e2354c5..9bcf45e928 100644 --- a/src/widgets/styles/qgtkstyle.cpp +++ b/src/widgets/styles/qgtkstyle.cpp @@ -1935,7 +1935,6 @@ void QGtkStyle::drawComplexControl(ComplexControl control, const QStyleOptionCom gint interiorFocus = true; d->gtk_widget_style_get(gtkToggleButton, "interior-focus", &interiorFocus, NULL); - GtkStyle *gtkToggleButtonStyle = gtkToggleButtonStyle; int xt = interiorFocus ? gtkToggleButtonStyle->xthickness : 0; int yt = interiorFocus ? gtkToggleButtonStyle->ythickness : 0; if (focus && ((option->state & State_KeyboardFocusChange) || styleHint(SH_UnderlineShortcut, option, widget))) diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 3376c3cd52..ecb3e7f222 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -1836,6 +1836,7 @@ void QMacStylePrivate::animate() } if (!scrollBars.isEmpty()) { int i = 0; + const qint64 dt = QDateTime::currentMSecsSinceEpoch(); while (i < scrollBars.size()) { QWidget *maybeScroll = scrollBars.at(i); if (!maybeScroll) { @@ -1843,9 +1844,8 @@ void QMacStylePrivate::animate() } else { if (QScrollBar *sb = qobject_cast<QScrollBar *>(maybeScroll)) { const OverlayScrollBarInfo& info = scrollBarInfos[sb]; - const QDateTime dt = QDateTime::currentDateTime(); - const qreal elapsed = qMax(info.lastHovered.msecsTo(dt), - info.lastUpdate.msecsTo(dt)); + const qreal elapsed = qMax(dt - info.lastHovered, + dt - info.lastUpdate); const CGFloat opacity = 1.0 - qMax(0.0, (elapsed - ScrollBarFadeOutDelay) / ScrollBarFadeOutDuration); if ((opacity > 0.0 || !info.cleared) && (elapsed > ScrollBarFadeOutDelay)) { @@ -1888,7 +1888,8 @@ bool QMacStyle::eventFilter(QObject *o, QEvent *e) if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7 && [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay && scrollArea) { QMacStylePrivate::OverlayScrollBarInfo& info = d->scrollBarInfos[sb]; - const qreal elapsed = info.lastUpdate.msecsTo(QDateTime::currentDateTime()); + const qint64 dt = QDateTime::currentMSecsSinceEpoch(); + const qreal elapsed = dt - info.lastUpdate; const CGFloat opacity = 1.0 - qMax(0.0, (elapsed - QMacStylePrivate::ScrollBarFadeOutDelay) / QMacStylePrivate::ScrollBarFadeOutDuration); switch (e->type()) { @@ -1897,8 +1898,8 @@ bool QMacStyle::eventFilter(QObject *o, QEvent *e) // the fade out is stopped and it's set to 100% opaque if (opacity > 0.0) { info.hovered = true; - info.lastUpdate = QDateTime::currentDateTime(); - info.lastHovered = QDateTime::currentDateTime(); + info.lastUpdate = dt; + info.lastHovered = info.lastUpdate; sb->update(); break; } @@ -5113,6 +5114,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex } #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 + const qint64 dt = QDateTime::currentMSecsSinceEpoch(); if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_7 && [NSScroller preferredScrollerStyle] == NSScrollerStyleOverlay && scrollBarsScrollArea(qobject_cast<const QScrollBar *>(widget)) && @@ -5127,7 +5129,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex info.lastMinimum = slider->minimum; info.lastSize = slider->rect.size(); info.lastMaximum = slider->maximum; - info.lastUpdate = QDateTime::currentDateTime(); + info.lastUpdate = dt; showSiblings = true; } @@ -5139,18 +5141,18 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex d->scrollBarInfos.value(sibling).lastUpdate); info.cleared = false; if (d->scrollBarInfos.value(sibling).hovered) - info.lastUpdate = QDateTime::currentDateTime(); + info.lastUpdate = dt; } - qreal elapsed = info.lastHovered.msecsTo(QDateTime::currentDateTime()); + qreal elapsed = dt - info.lastHovered; CGFloat opacity = 1.0 - qMax(0.0, (elapsed - QMacStylePrivate::ScrollBarFadeOutDelay) / QMacStylePrivate::ScrollBarFadeOutDuration); const bool isHorizontal = slider->orientation == Qt::Horizontal; if (info.hovered) { - info.lastHovered = QDateTime::currentDateTime(); - info.lastUpdate = QDateTime::currentDateTime(); + info.lastHovered = dt; + info.lastUpdate = dt; opacity = 1.0; // if the current scroll bar is hovered, none of the others might fade out Q_FOREACH (const QScrollBar *sibling, siblings) { @@ -5206,7 +5208,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex // afterwards we draw the knob, since we cannot drow the know w/o the track, // we simulate a scrollbar with a knob from 0.0 to 1.0 - elapsed = info.lastUpdate.msecsTo(QDateTime::currentDateTime()); + elapsed = dt - info.lastUpdate; opacity = 1.0 - qMax(0.0, (elapsed - QMacStylePrivate::ScrollBarFadeOutDelay) / QMacStylePrivate::ScrollBarFadeOutDuration); info.cleared = opacity <= 0.0; diff --git a/src/widgets/styles/qmacstyle_mac_p.h b/src/widgets/styles/qmacstyle_mac_p.h index 2c129aa49d..ac482b8fc7 100644 --- a/src/widgets/styles/qmacstyle_mac_p.h +++ b/src/widgets/styles/qmacstyle_mac_p.h @@ -215,18 +215,18 @@ public: : lastValue(-1), lastMinimum(-1), lastMaximum(-1), - lastUpdate(QDateTime::currentDateTime()), + lastUpdate(QDateTime::currentMSecsSinceEpoch()), hovered(false), - lastHovered(QDateTime::fromTime_t(0)), + lastHovered(0), cleared(false) {} int lastValue; int lastMinimum; int lastMaximum; QSize lastSize; - QDateTime lastUpdate; + qint64 lastUpdate; bool hovered; - QDateTime lastHovered; + qint64 lastHovered; bool cleared; }; mutable QMap<const QWidget*, OverlayScrollBarInfo> scrollBarInfos; diff --git a/src/widgets/styles/qmotifstyle_p.h b/src/widgets/styles/qmotifstyle_p.h deleted file mode 100644 index 76f8c01119..0000000000 --- a/src/widgets/styles/qmotifstyle_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QMOTIFSTYLE_P_H -#define QMOTIFSTYLE_P_H -#include <qlist.h> -#include <qdatetime.h> -#include <qprogressbar.h> -#include "qmotifstyle.h" -#include "qcommonstyle_p.h" - -QT_BEGIN_NAMESPACE - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists for the convenience -// of qapplication_*.cpp, qwidget*.cpp and qfiledialog.cpp. This header -// file may change from version to version without notice, or even be removed. -// -// We mean it. -// - -// Private class -class QMotifStylePrivate : public QCommonStylePrivate -{ - Q_DECLARE_PUBLIC(QMotifStyle) -public: - QMotifStylePrivate(); - -public: -#ifndef QT_NO_PROGRESSBAR - QList<QProgressBar *> bars; - int animationFps; - int animateTimer; - QTime startTime; - int animateStep; -#endif // QT_NO_PROGRESSBAR -}; - -QT_END_NAMESPACE - -#endif //QMOTIFSTYLE_P_H |