Changeset 846 for trunk/src/gui/widgets/qlabel.cpp
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/src/gui/widgets/qlabel.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 54 54 #include "qlabel_p.h" 55 55 #include "private/qstylesheetstyle_p.h" 56 #include <qmath.h> 56 57 57 58 QT_BEGIN_NAMESPACE … … 635 636 #endif 636 637 else if (isTextLabel) { 637 int align = QStyle::visualAlignment( q->layoutDirection(), QFlag(this->align));638 int align = QStyle::visualAlignment(textDirection(), QFlag(this->align)); 638 639 // Add indentation 639 640 int m = indent; … … 662 663 control->setTextWidth(-1); 663 664 } 664 br = QRect(QPoint(0, 0), control->size().toSize()); 665 666 QSizeF controlSize = control->size(); 667 br = QRect(QPoint(0, 0), QSize(qCeil(controlSize.width()), qCeil(controlSize.height()))); 665 668 666 669 // restore state … … 680 683 bool tryWidth = (w < 0) && (align & Qt::TextWordWrap); 681 684 if (tryWidth) 682 w = fm.averageCharWidth() * 80;685 w = qMin(fm.averageCharWidth() * 80, q->maximumSize().width()); 683 686 else if (w < 0) 684 687 w = 2000; … … 782 785 } 783 786 787 /*! 788 Selects text from position \a start and for \a length characters. 789 790 \sa selectedText() 791 792 \bold{Note:} The textInteractionFlags set on the label need to include 793 either TextSelectableByMouse or TextSelectableByKeyboard. 794 795 \since 4.7 796 */ 797 void QLabel::setSelection(int start, int length) 798 { 799 Q_D(QLabel); 800 if (d->control) { 801 d->ensureTextPopulated(); 802 QTextCursor cursor = d->control->textCursor(); 803 cursor.setPosition(start); 804 cursor.setPosition(start + length, QTextCursor::KeepAnchor); 805 d->control->setTextCursor(cursor); 806 } 807 } 808 809 /*! 810 \property QLabel::hasSelectedText 811 \brief whether there is any text selected 812 813 hasSelectedText() returns true if some or all of the text has been 814 selected by the user; otherwise returns false. 815 816 By default, this property is false. 817 818 \sa selectedText() 819 820 \bold{Note:} The textInteractionFlags set on the label need to include 821 either TextSelectableByMouse or TextSelectableByKeyboard. 822 823 \since 4.7 824 */ 825 bool QLabel::hasSelectedText() const 826 { 827 Q_D(const QLabel); 828 if (d->control) 829 return d->control->textCursor().hasSelection(); 830 return false; 831 } 832 833 /*! 834 \property QLabel::selectedText 835 \brief the selected text 836 837 If there is no selected text this property's value is 838 an empty string. 839 840 By default, this property contains an empty string. 841 842 \sa hasSelectedText() 843 844 \bold{Note:} The textInteractionFlags set on the label need to include 845 either TextSelectableByMouse or TextSelectableByKeyboard. 846 847 \since 4.7 848 */ 849 QString QLabel::selectedText() const 850 { 851 Q_D(const QLabel); 852 if (d->control) 853 return d->control->textCursor().selectedText(); 854 return QString(); 855 } 856 857 /*! 858 selectionStart() returns the index of the first selected character in the 859 label or -1 if no text is selected. 860 861 \sa selectedText() 862 863 \bold{Note:} The textInteractionFlags set on the label need to include 864 either TextSelectableByMouse or TextSelectableByKeyboard. 865 866 \since 4.7 867 */ 868 int QLabel::selectionStart() const 869 { 870 Q_D(const QLabel); 871 if (d->control && d->control->textCursor().hasSelection()) 872 return d->control->textCursor().selectionStart(); 873 return -1; 874 } 875 784 876 /*!\reimp 785 877 */ … … 863 955 } 864 956 ev->accept(); 865 menu-> exec(ev->globalPos());866 delete menu;957 menu->setAttribute(Qt::WA_DeleteOnClose); 958 menu->popup(ev->globalPos()); 867 959 #endif 868 960 } … … 968 1060 QRect cr = contentsRect(); 969 1061 cr.adjust(d->margin, d->margin, -d->margin, -d->margin); 970 int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align)); 1062 int align = QStyle::visualAlignment(d->isTextLabel ? d->textDirection() 1063 : layoutDirection(), QFlag(d->align)); 971 1064 972 1065 #ifndef QT_NO_MOVIE … … 1028 1121 painter.restore(); 1029 1122 } else { 1030 int flags = align; 1123 int flags = align | (d->textDirection() == Qt::LeftToRight ? Qt::TextForceLeftToRight 1124 : Qt::TextForceRightToLeft); 1031 1125 if (d->hasShortcut) { 1032 1126 flags |= Qt::TextShowMnemonic; … … 1356 1450 } else if (ev->type() == QEvent::ContentsRectChange) { 1357 1451 d->updateLabel(); 1358 } else if (ev->type() == QEvent::LayoutDirectionChange) {1359 if (d->isTextLabel && d->control) {1360 d->sendControlEvent(ev);1361 }1362 1452 } 1363 1453 QFrame::changeEvent(ev); … … 1395 1485 } 1396 1486 1487 Qt::LayoutDirection QLabelPrivate::textDirection() const 1488 { 1489 if (control) { 1490 QTextOption opt = control->document()->defaultTextOption(); 1491 return opt.textDirection(); 1492 } 1493 1494 return text.isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight; 1495 } 1397 1496 1398 1497 /*! … … 1412 1511 QRect cr = q->contentsRect(); 1413 1512 cr.adjust(margin, margin, -margin, -margin); 1414 const int align = QStyle::visualAlignment(q->layoutDirection(), QFlag(this->align)); 1513 const int align = QStyle::visualAlignment(isTextLabel ? textDirection() 1514 : q->layoutDirection(), QFlag(this->align)); 1415 1515 int m = indent; 1416 1516 if (m < 0 && q->frameWidth()) // no indent, but we do have a frame … … 1473 1573 return; 1474 1574 ensureTextPopulated(); 1475 Q_Q(const QLabel);1476 1575 if (control) { 1477 1576 QTextDocument *doc = control->document(); … … 1484 1583 else 1485 1584 opt.setWrapMode(QTextOption::ManualWrap); 1486 1487 opt.setTextDirection(q->layoutDirection());1488 1585 1489 1586 doc->setDefaultTextOption(opt);
Note:
See TracChangeset
for help on using the changeset viewer.