Warning, file /office/calligra/libs/text/InsertTextReferenceAction.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) 2007 Thomas Zander <zander@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "InsertTextReferenceAction_p.h"
0021 #include "KoTextLocator.h"
0022 #include "KoTextReference.h"
0023 #include "KoInlineTextObjectManager.h"
0024 
0025 #include <KoCanvasBase.h>
0026 
0027 #include <klocalizedstring.h>
0028 #include <kmessagebox.h>
0029 #include <kpagedialog.h>
0030 #include <QVBoxLayout>
0031 #include <QListWidget>
0032 #include <QLabel>
0033 
0034 InsertTextReferenceAction::InsertTextReferenceAction(KoCanvasBase *canvas, const KoInlineTextObjectManager *manager)
0035         : InsertInlineObjectActionBase(canvas, i18n("Text Reference")),
0036         m_manager(manager)
0037 {
0038 }
0039 
0040 KoInlineObject *InsertTextReferenceAction::createInlineObject()
0041 {
0042     const QList<KoTextLocator*> textLocators = m_manager->textLocators();
0043     if (textLocators.isEmpty()) {
0044         KMessageBox::information(m_canvas->canvasWidget(), i18n("Please create an index to reference first."));
0045         return 0;
0046     }
0047 
0048     QWidget *widget = new QWidget();
0049     QVBoxLayout *lay = new QVBoxLayout(widget);
0050     widget->setLayout(lay);
0051     lay->setMargin(0);
0052 
0053     QLabel *label = new QLabel(i18n("Select the index you want to reference"), widget);
0054     lay->addWidget(label);
0055     QStringList selectionList;
0056     foreach(KoTextLocator* locator, textLocators)
0057         selectionList << locator->word() + '(' + QString::number(locator->pageNumber()) + ')';
0058     QListWidget *list = new QListWidget(widget);
0059     lay->addWidget(list);
0060     list->addItems(selectionList);
0061 
0062     KPageDialog dialog(m_canvas->canvasWidget());
0063     dialog.setWindowTitle(i18n("%1 Options", i18n("Text Reference"))); // reuse the text passed in the constructor
0064     dialog.addPage(widget, QString());
0065 
0066     KoVariable *variable = 0;
0067     if (dialog.exec() == KPageDialog::Accepted && list->currentRow() >= 0) {
0068         KoTextLocator *locator = textLocators[list->currentRow()];
0069         Q_ASSERT(locator);
0070         variable = new KoTextReference(locator->id());
0071     }
0072     return variable;
0073 }