Warning, file /office/calligra/libs/textlayout/KoPointedAt.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* This file is part of the KDE project
0002  * Copyright (C) 2011 C. Boemann, KO GmbH <cbo@kogmbh.com>
0003  * Copyright (C) 2011 C. Boemann <cbo@boemann.dk>
0004  *
0005  * This library is free software; you can redistribute it and/or
0006  * modify it under the terms of the GNU Library General Public
0007  * License as published by the Free Software Foundation; either
0008  * version 2 of the License, or (at your option) any later version.
0009  *
0010  * This library is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013  * Library General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU Library General Public License
0016  * along with this library; see the file COPYING.LIB.  If not, write to
0017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019  */
0020 
0021 #include "KoPointedAt.h"
0022 
0023 #include <KoInlineNote.h>
0024 #include <KoInlineTextObjectManager.h>
0025 #include <KoTextRangeManager.h>
0026 
0027 #include <TextLayoutDebug.h>
0028 
0029 #include <QTextCursor>
0030 
0031 KoPointedAt::KoPointedAt()
0032     : position(-1)
0033     , bookmark(0)
0034     , note(0)
0035     , noteReference(-1)
0036     , table(0)
0037     , tableHit(None)
0038 {
0039 }
0040 
0041 KoPointedAt::KoPointedAt(KoPointedAt *other)
0042 {
0043     position = other->position;
0044     bookmark = other->bookmark;
0045     note = other->note;
0046     noteReference = other->noteReference;
0047     externalHRef = other->externalHRef;
0048     tableHit = other->tableHit;
0049     tableRowDivider = other->tableRowDivider;
0050     tableColumnDivider = other->tableColumnDivider;
0051     tableLeadSize = other->tableLeadSize;
0052     tableTrailSize = other->tableTrailSize;
0053     table = other->table;
0054 }
0055 
0056 void KoPointedAt::fillInLinks(const QTextCursor &cursor, KoInlineTextObjectManager *inlineManager, KoTextRangeManager *rangeManager)
0057 {
0058     bookmark = 0;
0059     externalHRef.clear();
0060     note = 0;
0061 
0062     if (!inlineManager)
0063         return;
0064 
0065     // Is there an href here ?
0066     if (cursor.charFormat().isAnchor()) {
0067         QString href = cursor.charFormat().anchorHref();
0068         // local href starts with #
0069         if (href.startsWith('#')) {
0070             // however bookmark does not contain it, so strip it
0071             href = href.right(href.size() - 1);
0072 
0073             if (!href.isEmpty()) {
0074                 bookmark = rangeManager->bookmarkManager()->bookmark(href);
0075             }
0076             return;
0077         } else {
0078             // Nope, then it must be external;
0079             externalHRef = href;
0080         }
0081     } else {
0082         note = dynamic_cast<KoInlineNote*>(inlineManager->inlineTextObject(cursor));
0083     }
0084 }