1 /***************************************************************************
2 * Copyright (C) 2005-2018 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
23 #include <QApplication>
25 #include <QDesktopServices>
26 #include <QFontMetrics>
27 #include <QGraphicsSceneMouseEvent>
30 #include <QTextLayout>
33 #include "buffermodel.h"
34 #include "bufferview.h"
36 #include "chatlinemodel.h"
38 #include "contextmenuactionprovider.h"
42 #include "qtuistyle.h"
44 ChatItem::ChatItem(const QRectF &boundingRect, ChatLine *parent)
46 _boundingRect(boundingRect),
47 _selectionMode(NoSelection),
60 ChatLine *ChatItem::chatLine() const
66 ChatScene *ChatItem::chatScene() const
68 return chatLine()->chatScene();
72 ChatView *ChatItem::chatView() const
74 return chatScene()->chatView();
78 const QAbstractItemModel *ChatItem::model() const
80 return chatLine()->model();
84 int ChatItem::row() const
86 return chatLine()->row();
90 QPointF ChatItem::mapToLine(const QPointF &p) const
96 QPointF ChatItem::mapFromLine(const QPointF &p) const
102 // relative to the ChatLine
103 QPointF ChatItem::mapToScene(const QPointF &p) const
105 return chatLine()->mapToScene(p /* + pos() */);
109 QPointF ChatItem::mapFromScene(const QPointF &p) const
111 return chatLine()->mapFromScene(p) /* - pos() */;
115 QVariant ChatItem::data(int role) const
117 QModelIndex index = model()->index(row(), column());
118 if (!index.isValid()) {
119 qWarning() << "ChatItem::data(): model index is invalid!" << index;
122 return model()->data(index, role);
126 QTextLayout *ChatItem::layout() const
129 return _cachedLayout;
131 _cachedLayout = new QTextLayout;
132 initLayout(_cachedLayout);
133 chatView()->setHasCache(chatLine());
134 return _cachedLayout;
138 void ChatItem::clearCache()
140 delete _cachedLayout;
145 void ChatItem::initLayoutHelper(QTextLayout *layout, QTextOption::WrapMode wrapMode, Qt::Alignment alignment) const
149 layout->setText(data(MessageModel::DisplayRole).toString());
152 option.setWrapMode(wrapMode);
153 option.setAlignment(alignment);
154 layout->setTextOption(option);
156 QList<QTextLayout::FormatRange> formatRanges
157 = QtUi::style()->toTextLayoutList(formatList(), layout->text().length(), data(ChatLineModel::MsgLabelRole).value<UiStyle::MessageLabel>());
158 layout->setAdditionalFormats(formatRanges);
162 void ChatItem::initLayout(QTextLayout *layout) const
164 initLayoutHelper(layout, QTextOption::NoWrap);
169 void ChatItem::doLayout(QTextLayout *layout) const
171 layout->beginLayout();
172 QTextLine line = layout->createLine();
173 if (line.isValid()) {
174 line.setLineWidth(width());
175 line.setPosition(QPointF(0, 0));
181 UiStyle::FormatList ChatItem::formatList() const
183 return data(MessageModel::FormatRole).value<UiStyle::FormatList>();
187 qint16 ChatItem::posToCursor(const QPointF &posInLine) const
189 QPointF pos = mapFromLine(posInLine);
190 if (pos.y() > height())
191 return data(MessageModel::DisplayRole).toString().length();
195 for (int l = layout()->lineCount() - 1; l >= 0; l--) {
196 QTextLine line = layout()->lineAt(l);
197 if (pos.y() >= line.y()) {
198 return line.xToCursor(pos.x(), QTextLine::CursorOnCharacter);
205 void ChatItem::paintBackground(QPainter *painter)
208 if (_selectionMode == FullSelection)
209 bgBrush = data(ChatLineModel::SelectedBackgroundRole);
211 bgBrush = data(ChatLineModel::BackgroundRole);
212 if (bgBrush.isValid())
213 painter->fillRect(boundingRect(), bgBrush.value<QBrush>());
217 // NOTE: This is not the most time-efficient implementation, but it saves space by not caching unnecessary data
218 // This is a deliberate trade-off. (-> selectFmt creation, data() call)
219 void ChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
221 Q_UNUSED(option); Q_UNUSED(widget);
223 painter->setClipRect(boundingRect());
224 paintBackground(painter);
226 layout()->draw(painter, pos(), additionalFormats(), boundingRect());
228 // layout()->draw(painter, QPointF(0,0), formats, boundingRect());
231 // uncomment partially or all of the following stuff:
233 // 0) alternativ painter color for debug stuff
235 // painter->setPen(Qt::red);
237 // painter->setPen(Qt::blue);
238 // 1) draw wordwrap points in the first line
239 // if(column() == 2) {
240 // ChatLineModel::WrapList wrapList = data(ChatLineModel::WrapListRole).value<ChatLineModel::WrapList>();
241 // foreach(ChatLineModel::Word word, wrapList) {
242 // if(word.endX > width())
244 // painter->drawLine(word.endX, 0, word.endX, height());
247 // 2) draw MsgId over the time column
248 // if(column() == 0) {
249 // QString msgIdString = QString::number(data(MessageModel::MsgIdRole).value<MsgId>().toLongLong());
250 // QPointF bottomPoint = boundingRect().bottomLeft();
251 // bottomPoint.ry() -= 2;
252 // painter->drawText(bottomPoint, msgIdString);
254 // 3) draw bounding rect
255 // painter->drawRect(_boundingRect.adjusted(0, 0, -1, -1));
261 void ChatItem::overlayFormat(UiStyle::FormatList &fmtList, quint16 start, quint16 end, UiStyle::FormatType overlayFmt) const
263 for (size_t i = 0; i < fmtList.size(); i++) {
264 int fmtStart = fmtList.at(i).first;
265 int fmtEnd = (i < fmtList.size()-1 ? fmtList.at(i+1).first : data(MessageModel::DisplayRole).toString().length());
272 // split the format if necessary
273 if (fmtStart < start) {
274 fmtList.insert(fmtList.begin() + i, fmtList.at(i));
275 fmtList[++i].first = start;
278 fmtList.insert(fmtList.begin() + i, fmtList.at(i));
279 fmtList[i+1].first = end;
282 fmtList[i].second.type |= overlayFmt;
287 QVector<QTextLayout::FormatRange> ChatItem::additionalFormats() const
289 return selectionFormats();
293 QVector<QTextLayout::FormatRange> ChatItem::selectionFormats() const
296 return QVector<QTextLayout::FormatRange>();
299 if (_selectionMode == FullSelection) {
301 end = data(MessageModel::DisplayRole).toString().length();
304 start = qMin(_selectionStart, _selectionEnd);
305 end = qMax(_selectionStart, _selectionEnd);
308 UiStyle::FormatList fmtList = formatList();
310 while (fmtList.size() > 1 && fmtList.at(1).first <= start)
311 fmtList.erase(fmtList.begin());
313 fmtList.front().first = start;
315 while (fmtList.size() > 1 && fmtList.back().first >= end)
318 return QtUi::style()->toTextLayoutList(fmtList, end, data(ChatLineModel::MsgLabelRole).value<UiStyle::MessageLabel>()|UiStyle::MessageLabel::Selected).toVector();
322 bool ChatItem::hasSelection() const
324 if (_selectionMode == NoSelection)
326 if (_selectionMode == FullSelection)
329 return _selectionStart != _selectionEnd;
333 QString ChatItem::selection() const
335 if (_selectionMode == FullSelection)
336 return data(MessageModel::DisplayRole).toString();
337 if (_selectionMode == PartialSelection)
338 return data(MessageModel::DisplayRole).toString().mid(qMin(_selectionStart, _selectionEnd), qAbs(_selectionStart - _selectionEnd));
343 void ChatItem::setSelection(SelectionMode mode, qint16 start, qint16 end)
345 _selectionMode = mode;
346 _selectionStart = start;
348 chatLine()->update();
352 void ChatItem::setFullSelection()
354 if (_selectionMode != FullSelection) {
355 _selectionMode = FullSelection;
356 chatLine()->update();
361 void ChatItem::clearSelection()
363 if (_selectionMode != NoSelection) {
364 _selectionMode = NoSelection;
365 chatLine()->update();
370 void ChatItem::continueSelecting(const QPointF &pos)
372 _selectionMode = PartialSelection;
373 _selectionEnd = posToCursor(pos);
374 chatLine()->update();
378 bool ChatItem::isPosOverSelection(const QPointF &pos) const
380 if (_selectionMode == FullSelection)
382 if (_selectionMode == PartialSelection) {
383 int cursor = posToCursor(pos);
384 return cursor >= qMin(_selectionStart, _selectionEnd) && cursor <= qMax(_selectionStart, _selectionEnd);
390 QList<QRectF> ChatItem::findWords(const QString &searchWord, Qt::CaseSensitivity caseSensitive)
392 QList<QRectF> resultList;
393 const QAbstractItemModel *model_ = model();
397 QString plainText = model_->data(model_->index(row(), column()), MessageModel::DisplayRole).toString();
398 QList<int> indexList;
399 int searchIdx = plainText.indexOf(searchWord, 0, caseSensitive);
400 while (searchIdx != -1) {
401 indexList << searchIdx;
402 searchIdx = plainText.indexOf(searchWord, searchIdx + 1, caseSensitive);
405 foreach(int idx, indexList) {
406 QTextLine line = layout()->lineForTextPosition(idx);
407 qreal x = line.cursorToX(idx);
408 qreal width = line.cursorToX(idx + searchWord.count()) - x;
409 qreal height = line.height();
410 qreal y = height * line.lineNumber();
411 resultList << QRectF(x, y, width, height);
418 void ChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clickMode)
420 // single clicks are already handled by the scene (for clearing the selection)
421 if (clickMode == ChatScene::DragStartClick) {
422 chatScene()->setSelectingItem(this);
423 _selectionStart = _selectionEnd = posToCursor(pos);
424 _selectionMode = NoSelection; // will be set to PartialSelection by mouseMoveEvent
425 chatLine()->update();
430 void ChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
432 if (event->buttons() == Qt::LeftButton) {
433 if (boundingRect().contains(event->pos())) {
434 qint16 end = posToCursor(event->pos());
435 if (end != _selectionEnd) {
437 _selectionMode = (_selectionStart != _selectionEnd ? PartialSelection : NoSelection);
438 chatLine()->update();
443 chatScene()->startGlobalSelection(this, event->pos());
453 void ChatItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
455 if (event->buttons() == Qt::LeftButton)
462 void ChatItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
464 if (_selectionMode != NoSelection && event->button() == Qt::LeftButton) {
465 chatScene()->selectionToClipboard(QClipboard::Selection);
473 void ChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos)
477 GraphicalUi::contextMenuActionProvider()->addActions(menu, chatScene()->filter(), data(MessageModel::BufferIdRole).value<BufferId>());
481 // ************************************************************
483 // ************************************************************
485 void SenderChatItem::initLayout(QTextLayout *layout) const
487 initLayoutHelper(layout, QTextOption::ManualWrap, Qt::AlignRight);
492 void SenderChatItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
494 Q_UNUSED(option); Q_UNUSED(widget);
496 painter->setClipRect(boundingRect());
497 paintBackground(painter);
499 qreal layoutWidth = layout()->minimumWidth();
501 if (chatScene()->senderCutoffMode() == ChatScene::CutoffLeft)
502 offset = qMin(width() - layoutWidth, (qreal)0);
504 offset = qMax(layoutWidth - width(), (qreal)0);
506 if (layoutWidth > width()) {
507 // Draw a nice gradient for longer items
508 // Qt's text drawing with a gradient brush sucks, so we use compositing instead
509 QPixmap pixmap(layout()->boundingRect().toRect().size());
510 pixmap.fill(Qt::transparent);
512 QPainter pixPainter(&pixmap);
513 layout()->draw(&pixPainter, QPointF(qMax(offset, (qreal)0), 0), additionalFormats());
515 // Create alpha channel mask
516 QLinearGradient gradient;
518 gradient.setStart(0, 0);
519 gradient.setFinalStop(12, 0);
520 gradient.setColorAt(0, Qt::transparent);
521 gradient.setColorAt(1, Qt::white);
524 gradient.setStart(width()-10, 0);
525 gradient.setFinalStop(width(), 0);
526 gradient.setColorAt(0, Qt::white);
527 gradient.setColorAt(1, Qt::transparent);
529 pixPainter.setCompositionMode(QPainter::CompositionMode_DestinationIn); // gradient's alpha gets applied to the pixmap
530 pixPainter.fillRect(pixmap.rect(), gradient);
531 painter->drawPixmap(pos(), pixmap);
534 layout()->draw(painter, pos(), additionalFormats(), boundingRect());
540 void SenderChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clickMode)
542 if (clickMode == ChatScene::DoubleClick) {
543 BufferInfo curBufInfo = Client::networkModel()->bufferInfo(data(MessageModel::BufferIdRole).value<BufferId>());
544 QString nick = data(MessageModel::EditRole).toString();
545 // check if the nick is a valid ircUser
546 if (!nick.isEmpty() && Client::network(curBufInfo.networkId())->ircUser(nick))
547 Client::bufferModel()->switchToOrStartQuery(curBufInfo.networkId(), nick);
550 ChatItem::handleClick(pos, clickMode);
554 // ************************************************************
556 // ************************************************************
558 ContentsChatItem::ActionProxy ContentsChatItem::_actionProxy;
560 ContentsChatItem::ContentsChatItem(const QPointF &pos, const qreal &width, ChatLine *parent)
561 : ChatItem(QRectF(pos, QSizeF(width, 0)), parent),
565 setGeometryByWidth(width);
569 QFontMetricsF *ContentsChatItem::fontMetrics() const
571 return QtUi::style()->fontMetrics(data(ChatLineModel::FormatRole).value<UiStyle::FormatList>().at(0).second.type, UiStyle::MessageLabel::None);
575 ContentsChatItem::~ContentsChatItem()
581 void ContentsChatItem::clearCache()
585 ChatItem::clearCache();
589 ContentsChatItemPrivate *ContentsChatItem::privateData() const
592 ContentsChatItem *that = const_cast<ContentsChatItem *>(this);
593 that->_data = new ContentsChatItemPrivate(ClickableList::fromString(data(ChatLineModel::DisplayRole).toString()), that);
599 qreal ContentsChatItem::setGeometryByWidth(qreal w)
601 // We use this for reloading layout info as well, so we can't bail out if the width doesn't change
605 WrapColumnFinder finder(this);
606 while (finder.nextWrapColumn(w) > 0)
608 qreal spacing = qMax(fontMetrics()->lineSpacing(), fontMetrics()->height()); // cope with negative leading()
609 qreal h = lines * spacing;
613 if (w != width() || h != height())
620 void ContentsChatItem::initLayout(QTextLayout *layout) const
622 initLayoutHelper(layout, QTextOption::WrapAtWordBoundaryOrAnywhere);
627 void ContentsChatItem::doLayout(QTextLayout *layout) const
629 ChatLineModel::WrapList wrapList = data(ChatLineModel::WrapListRole).value<ChatLineModel::WrapList>();
630 if (!wrapList.count()) return; // empty chatitem
633 qreal spacing = qMax(fontMetrics()->lineSpacing(), fontMetrics()->height()); // cope with negative leading()
634 WrapColumnFinder finder(this);
635 layout->beginLayout();
637 QTextLine line = layout->createLine();
641 int col = finder.nextWrapColumn(width());
643 col = layout->text().length();
644 int num = col - line.textStart();
646 line.setNumColumns(num);
648 // Sometimes, setNumColumns will create a line that's too long (cf. Qt bug 238249)
649 // We verify this and try setting the width again, making it shorter each time until the lengths match.
650 // Dead fugly, but seems to work…
651 for (int i = line.textLength()-1; i >= 0 && line.textLength() > num; i--) {
652 line.setNumColumns(i);
654 if (num != line.textLength()) {
655 qWarning() << "WARNING: Layout engine couldn't workaround Qt bug 238249, please report!";
656 // qDebug() << num << line.textLength() << t.mid(line.textStart(), line.textLength()) << t.mid(line.textStart() + line.textLength());
659 line.setPosition(QPointF(0, h));
666 Clickable ContentsChatItem::clickableAt(const QPointF &pos) const
668 return privateData()->clickables.atCursorPos(posToCursor(pos));
672 UiStyle::FormatList ContentsChatItem::formatList() const
674 UiStyle::FormatList fmtList = ChatItem::formatList();
675 for (int i = 0; i < privateData()->clickables.count(); i++) {
676 Clickable click = privateData()->clickables.at(i);
677 if (click.type() == Clickable::Url) {
678 overlayFormat(fmtList, click.start(), click.start() + click.length(), UiStyle::FormatType::Url);
685 QVector<QTextLayout::FormatRange> ContentsChatItem::additionalFormats() const
687 QVector<QTextLayout::FormatRange> fmt = ChatItem::additionalFormats();
688 // mark a clickable if hovered upon
689 if (privateData()->currentClickable.isValid()) {
690 Clickable click = privateData()->currentClickable;
691 QTextLayout::FormatRange f;
692 f.start = click.start();
693 f.length = click.length();
694 f.format.setFontUnderline(true);
701 void ContentsChatItem::endHoverMode()
704 if (privateData()->currentClickable.isValid()) {
705 chatLine()->unsetCursor();
706 privateData()->currentClickable = Clickable();
709 chatLine()->update();
714 void ContentsChatItem::handleClick(const QPointF &pos, ChatScene::ClickMode clickMode)
716 if (clickMode == ChatScene::SingleClick) {
717 qint16 idx = posToCursor(pos);
718 Clickable foo = privateData()->clickables.atCursorPos(idx);
720 NetworkId networkId = Client::networkModel()->networkId(data(MessageModel::BufferIdRole).value<BufferId>());
721 QString text = data(ChatLineModel::DisplayRole).toString();
722 foo.activate(networkId, text);
725 else if (clickMode == ChatScene::DoubleClick) {
726 chatScene()->setSelectingItem(this);
727 setSelectionMode(PartialSelection);
728 Clickable click = clickableAt(pos);
729 if (click.isValid()) {
730 setSelectionStart(click.start());
731 setSelectionEnd(click.start() + click.length());
734 // find word boundary
735 QString str = data(ChatLineModel::DisplayRole).toString();
736 qint16 cursor = posToCursor(pos);
737 qint16 start = str.lastIndexOf(QRegExp("\\W"), cursor) + 1;
738 qint16 end = qMin(str.indexOf(QRegExp("\\W"), cursor), str.length());
739 if (end < 0) end = str.length();
740 setSelectionStart(start);
741 setSelectionEnd(end);
743 chatLine()->update();
745 else if (clickMode == ChatScene::TripleClick) {
746 setSelection(PartialSelection, 0, data(ChatLineModel::DisplayRole).toString().length());
748 ChatItem::handleClick(pos, clickMode);
752 void ContentsChatItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
754 // mouse move events always mean we're not hovering anymore...
756 ChatItem::mouseMoveEvent(event);
760 void ContentsChatItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
767 void ContentsChatItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
769 bool onClickable = false;
770 Clickable click = clickableAt(event->pos());
771 if (click.isValid()) {
772 if (click.type() == Clickable::Url) {
774 showWebPreview(click);
776 else if (click.type() == Clickable::Channel) {
777 QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
778 // don't make clickable if it's our own name
779 BufferId myId = data(MessageModel::BufferIdRole).value<BufferId>();
780 if (Client::networkModel()->bufferName(myId) != name)
784 chatLine()->setCursor(Qt::PointingHandCursor);
785 privateData()->currentClickable = click;
786 chatLine()->update();
790 if (!onClickable) endHoverMode();
795 void ContentsChatItem::addActionsToMenu(QMenu *menu, const QPointF &pos)
797 if (privateData()->currentClickable.isValid()) {
798 Clickable click = privateData()->currentClickable;
799 switch (click.type()) {
801 privateData()->activeClickable = click;
802 menu->addAction(icon::get("edit-copy"), tr("Copy Link Address"),
803 &_actionProxy, SLOT(copyLinkToClipboard()))->setData(QVariant::fromValue<void *>(this));
805 case Clickable::Channel:
807 // Remove existing menu actions, they confuse us when right-clicking on a clickable
809 QString name = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
810 GraphicalUi::contextMenuActionProvider()->addActions(menu, chatScene()->filter(), data(MessageModel::BufferIdRole).value<BufferId>(), name);
818 // Buffer-specific actions
819 ChatItem::addActionsToMenu(menu, pos);
824 void ContentsChatItem::copyLinkToClipboard()
826 Clickable click = privateData()->activeClickable;
827 if (click.isValid() && click.type() == Clickable::Url) {
828 QString url = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
829 if (!url.contains("://"))
830 url = "http://" + url;
831 chatScene()->stringToClipboard(url);
836 /******** WEB PREVIEW *****************************************************************************/
838 void ContentsChatItem::showWebPreview(const Clickable &click)
840 #if !defined HAVE_WEBKIT && !defined HAVE_WEBENGINE
843 QTextLine line = layout()->lineForTextPosition(click.start());
844 qreal x = line.cursorToX(click.start());
845 qreal width = line.cursorToX(click.start() + click.length()) - x;
846 qreal height = line.height();
847 qreal y = height * line.lineNumber();
849 QPointF topLeft = mapToScene(pos()) + QPointF(x, y);
850 QRectF urlRect = QRectF(topLeft.x(), topLeft.y(), width, height);
852 QString urlstr = data(ChatLineModel::DisplayRole).toString().mid(click.start(), click.length());
853 if (!urlstr.contains("://"))
854 urlstr = "http://" + urlstr;
855 QUrl url = QUrl::fromEncoded(urlstr.toUtf8(), QUrl::TolerantMode);
856 chatScene()->loadWebPreview(this, url, urlRect);
861 void ContentsChatItem::clearWebPreview()
863 #if defined HAVE_WEBKIT || defined HAVE_WEBENGINE
864 chatScene()->clearWebPreview(this);
869 /*************************************************************************************************/
871 ContentsChatItem::WrapColumnFinder::WrapColumnFinder(const ChatItem *_item)
873 wrapList(item->data(ChatLineModel::WrapListRole).value<ChatLineModel::WrapList>()),
881 ContentsChatItem::WrapColumnFinder::~WrapColumnFinder()
886 qint16 ContentsChatItem::WrapColumnFinder::nextWrapColumn(qreal width)
888 if (wordidx >= wrapList.count())
892 qreal targetWidth = lineCount * width + choppedTrailing;
894 qint16 start = wordidx;
895 qint16 end = wrapList.count() - 1;
897 // check if the whole line fits
898 if (wrapList.at(end).endX <= targetWidth) // || start == end)
901 // check if we have a very long word that needs inter word wrap
902 if (wrapList.at(start).endX > targetWidth) {
903 if (!line.isValid()) {
904 item->initLayoutHelper(&layout, QTextOption::NoWrap);
905 layout.beginLayout();
906 line = layout.createLine();
909 return line.xToCursor(targetWidth, QTextLine::CursorOnCharacter);
913 if (start + 1 == end) {
915 const ChatLineModel::Word &lastWord = wrapList.at(start); // the last word we were able to squeeze in
917 // both cases should be cought preliminary
918 Q_ASSERT(lastWord.endX <= targetWidth); // ensure that "start" really fits in
919 Q_ASSERT(end < wrapList.count()); // ensure that start isn't the last word
921 choppedTrailing += lastWord.trailing - (targetWidth - lastWord.endX);
922 return wrapList.at(wordidx).start;
925 qint16 pivot = (end + start) / 2;
926 if (wrapList.at(pivot).endX > targetWidth) {
938 /*************************************************************************************************/