Commit 8514867b authored by Victor Yacovlev's avatar Victor Yacovlev

DocBookViewer: context menu && copy example link

parent 20d365bb
......@@ -4,9 +4,9 @@
<context>
<name>DocBookViewer::ContentView</name>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="511"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="524"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1403"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="619"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="632"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1544"/>
<source>Table&amp;nbsp;%1. </source>
<translation>Таблица&amp;nbsp;%1. </translation>
</message>
......@@ -15,54 +15,64 @@
<translation type="obsolete">Контекст:</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="667"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="67"/>
<source>Copy</source>
<translation>Скопировать</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="493"/>
<source>Copy example</source>
<translation>Скопировать пример</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="775"/>
<source>See %1 for more details.</source>
<translation>Подробное описание см. в %1</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="687"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="706"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1402"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="795"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="814"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1543"/>
<source>Example&amp;nbsp;%1. </source>
<translation>Пример&amp;nbsp;%1. </translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="727"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="835"/>
<source>Algorithm </source>
<translation>Алгоритм</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="758"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="866"/>
<source>Synopsis:</source>
<translation>Синтаксис:</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="992"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1106"/>
<source>Figure&amp;nbsp;%1 </source>
<translation>Рисунок&amp;nbsp;%1. </translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1227"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1358"/>
<source>(see&amp;nbsp;&lt;a href=&quot;%1&quot;&gt;%2&lt;/a&gt;)</source>
<translation>(см.&amp;nbsp;&lt;a href=&quot;%1&quot;&gt;%2&lt;/a&gt;)</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1334"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1472"/>
<source>List of examples in &quot;%1&quot;</source>
<translation>Список примеров в &quot;%1&quot;</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1337"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1475"/>
<source>List of tables in &quot;%1&quot;</source>
<translation>Список таблиц в &quot;%1&quot;</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1341"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1479"/>
<source>List of Standard Library algorithms</source>
<translation>Список встроенных алгоритмов</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1343"/>
<location filename="../../../src/shared/docbookviewer/contentview.cpp" line="1481"/>
<source>List of algorithms of module &quot;%1&quot;</source>
<translation>Список алгоритмов исполнителя &quot;%1&quot;</translation>
</message>
......@@ -70,22 +80,22 @@
<context>
<name>DocBookViewer::DocBookViewImpl</name>
<message>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="80"/>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="84"/>
<source>Hide side bar</source>
<translation>Скрыть панель навигации</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="81"/>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="85"/>
<source>Show side bar</source>
<translation>Показать панель навигации</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="219"/>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="223"/>
<source>Toggle sidebar visible</source>
<translation>Показывать боковую панель</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="222"/>
<location filename="../../../src/shared/docbookviewer/docbookview_impl.cpp" line="226"/>
<source>Print...</source>
<translation>Печать...</translation>
</message>
......@@ -209,10 +219,10 @@
<translation>Алгоритмы</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="138"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="180"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="222"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="264"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="143"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="190"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="237"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.ui" line="284"/>
<source>Filter:</source>
<translation>&amp;Фильтр:</translation>
</message>
......@@ -235,17 +245,17 @@
<translation type="obsolete">Искать:</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/sidepanel.cpp" line="231"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.cpp" line="232"/>
<source>List of examples in &quot;%1&quot;</source>
<translation>Список примеров в &quot;%1&quot;</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/sidepanel.cpp" line="259"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.cpp" line="260"/>
<source>List of tables in &quot;%1&quot;</source>
<translation>Список таблиц в &quot;%1&quot;</translation>
</message>
<message>
<location filename="../../../src/shared/docbookviewer/sidepanel.cpp" line="279"/>
<location filename="../../../src/shared/docbookviewer/sidepanel.cpp" line="280"/>
<source>Standard Library functions</source>
<translation>Встроенные алгоритмы</translation>
</message>
......
......@@ -76,7 +76,7 @@ else()
endif()
add_library(DocBookViewer SHARED ${SOURCES} ${MOC_SOURCES} ${UI_SOURCES})
target_link_libraries(DocBookViewer ${QT_LIBRARIES} ExtensionSystem)
target_link_libraries(DocBookViewer ${QT_LIBRARIES} ExtensionSystem Widgets)
set_property(TARGET DocBookViewer APPEND PROPERTY COMPILE_DEFINITIONS LIBRARY_BUILD)
if(${BUILD_AS_PART_OF_KUMIR})
......
......@@ -3,6 +3,7 @@
#include "mathmlrenderer.h"
#include "extensionsystem/pluginmanager.h"
#include "widgets/iconprovider.h"
#include <QUrl>
#include <QtCore>
......@@ -59,6 +60,15 @@ ContentView::ContentView(QWidget *parent)
ExtraFontsLoaded_ = true;
}
#endif
contextMenu_ = new QMenu(this);
actionCopyToClipboard_ = contextMenu_->addAction(
Widgets::IconProvider::self()->iconForName("edit-copy"),
tr("Copy"),
this, SLOT(copy())
);
actionCopyToClipboard_->setEnabled(false);
connect(this, SIGNAL(copyAvailable(bool)), actionCopyToClipboard_, SLOT(setEnabled(bool)));
}
QSize ContentView::minimumSizeHint() const
......@@ -463,8 +473,27 @@ QString ContentView::programTextForLanguage(const QString &source,
QString ContentView::renderProgramListing(ModelPtr data) const
{
QString result = "<pre align='left' class='code'>";
QString result;
bool parentIsExample = false;
ModelPtr p = data->parent();
while (p) {
if (Example==p->modelType()) {
parentIsExample = true;
break;
}
p = p->parent();
}
const QString programText = renderChilds(data);
if (parentIsExample) {
const QByteArray b64Text = programText.toUtf8().toBase64();
const QString href = QString::fromLatin1("to_clipboard:%1")
.arg(QString::fromLatin1(b64Text));
result += "<div align='right'><a href='" + href + "'>";
result += "<img src='icon:edit-copy:16'/>&nbsp;";
result += tr("Copy example");
result += "</a></div>\n";
}
result += "<pre align='left' class='code'>";
result += programTextForLanguage(programText, data->role());
result += "</pre>\n";
return result;
......@@ -1189,6 +1218,21 @@ QVariant ContentView::loadResource(int type, const QUrl &name)
}
}
}
else if (link.startsWith("icon:")) {
const QStringList parts = link.split(":");
if (parts.count() > 1) {
QSize iconSize(16, 16);
if (parts.count() > 2) {
iconSize = QSize(parts[2].toInt(), parts[2].toInt());
}
const QIcon icon = Widgets::IconProvider::self()
->iconForName(parts[1]);
if (!icon.isNull()) {
ignore = false;
result = icon.pixmap(iconSize).toImage();
}
}
}
}
if (ignore) {
return QTextBrowser::loadResource(type, name);
......@@ -1535,6 +1579,13 @@ void ContentView::handleInternalLink(const QUrl &url)
ds >> ptr;
emit itemRequest(findModelByRawPtr(ptr));
}
else if (url.toEncoded().startsWith("to_clipboard:")) {
const QByteArray b64 = url.toEncoded().mid(13);
const QByteArray u8 = QByteArray::fromBase64(b64);
const QString text = QString::fromUtf8(u8).trimmed();
QClipboard * clipboard = QApplication::clipboard();
clipboard->setText(text);
}
}
ModelPtr ContentView::findModelByRawPtr(quintptr raw) const
......@@ -1687,6 +1738,12 @@ void ContentView::wheelEvent(QWheelEvent *e)
}
}
void ContentView::contextMenuEvent(QContextMenuEvent *e)
{
contextMenu_->exec(e->globalPos());
e->accept();
}
void ContentView::clearLastAnchorUrl()
{
if (!ignoreClearAnchorUrl_) {
......
......@@ -8,6 +8,9 @@
#include <QSharedPointer>
#include <QResizeEvent>
#include <QWheelEvent>
#include <QContextMenuEvent>
#include <QMenu>
#include <QAction>
namespace DocBookViewer {
......@@ -31,6 +34,7 @@ signals:
private:
void resizeEvent(QResizeEvent *e);
void wheelEvent(QWheelEvent *e);
void contextMenuEvent(QContextMenuEvent *e);
QString wrapHTML(const QString & body) const;
QString renderModel(ModelPtr data) const;
......@@ -135,6 +139,8 @@ private /*fields*/:
bool ignoreClearAnchorUrl_;
static bool ExtraFontsLoaded_;
QMenu * contextMenu_;
QAction * actionCopyToClipboard_;
private slots:
void clearLastAnchorUrl();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment