Mercurial > octave
changeset 25610:828d3a7b5da7
remove unused qtinfo source files
* texinfo-parser.cc, texinfo-parser.h, webinfo.cc, webinfo.h: Delete.
* libgui/src/module.mk: Update.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 13 Jul 2018 15:51:39 -0400 |
parents | 506419b5f817 |
children | e9372127fe91 |
files | libgui/src/module.mk libgui/src/qtinfo/texinfo-parser.cc libgui/src/qtinfo/texinfo-parser.h libgui/src/qtinfo/webinfo.cc libgui/src/qtinfo/webinfo.h |
diffstat | 5 files changed, 0 insertions(+), 1284 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/module.mk Fri Jul 13 14:32:23 2018 -0400 +++ b/libgui/src/module.mk Fri Jul 13 15:51:39 2018 -0400 @@ -127,8 +127,6 @@ %reldir%/moc-variable-editor-model.cc \ %reldir%/moc-find-files-dialog.cc \ %reldir%/moc-find-files-model.cc \ - %reldir%/qtinfo/moc-texinfo-parser.cc \ - %reldir%/qtinfo/moc-webinfo.cc \ %reldir%/moc-octave-dock-widget.cc octave_gui_MOC += \ @@ -172,8 +170,6 @@ %reldir%/octave-gui.h \ %reldir%/octave-cmd.h \ %reldir%/octave-qt-link.h \ - %reldir%/qtinfo/texinfo-parser.h \ - %reldir%/qtinfo/webinfo.h \ %reldir%/resource-manager.h \ %reldir%/settings-dialog.h \ %reldir%/shortcut-manager.h \ @@ -207,8 +203,6 @@ %reldir%/octave-dock-widget.cc \ %reldir%/octave-gui.cc \ %reldir%/octave-qt-link.cc \ - %reldir%/qtinfo/texinfo-parser.cc \ - %reldir%/qtinfo/webinfo.cc \ %reldir%/resource-manager.cc \ %reldir%/settings-dialog.cc \ %reldir%/shortcut-manager.cc \ @@ -236,7 +230,6 @@ -I$(srcdir)/libgui/qterminal/libqterminal \ -Ilibgui/src -I$(srcdir)/libgui/src \ -I$(srcdir)/%reldir%/m-editor \ - -I$(srcdir)/%reldir%/qtinfo \ -I$(srcdir)/libgui/graphics \ -Iliboctave \ -I$(srcdir)/liboctave/array \
--- a/libgui/src/qtinfo/texinfo-parser.cc Fri Jul 13 14:32:23 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,634 +0,0 @@ -/* - -Copyright (C) 2012-2018 Jacob Dawid -Copyright (C) 2009 P. L. Lucas - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -// Author: P. L. Lucas -// Author: Jacob Dawid <jacob.dawid@cybercatalyst.com> - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include "texinfo-parser.h" -#include "procstream.h" -#include <QFileInfo> -#include <QDir> -#include <QFile> -#include <QUrl> -#include <QRegExp> -#include <QBuffer> - -texinfo_parser::texinfo_parser (QObject *p) - : QObject(p) -{ - _compressors_map.insert ( "bz2", R"(bzip2 -dc "%1")" ); - _compressors_map.insert ( "gz", R"(gzip -dc "%1")" ); - _compressors_map.insert ( "lzma", R"(lzma -dc "%1")" ); - _compressors_map.insert ( "xz", R"(xz -dc "%1")" ); - _compressors_map.insert ( "Z", R"(gunzip -c "%1")" ); -} - -bool -texinfo_parser::set_info_path (const QString& infoPath) -{ - this->_info_path = infoPath; - - _info_files.clear (); - - QFileInfo info (infoPath); - - bool info_file_exists = info.exists (); - QHash<QString, QString>::iterator it; - for (it = _compressors_map.begin (); it != _compressors_map.end (); it++) - { - if (info_file_exists) - break; - info_file_exists = QFileInfo (info.absoluteFilePath () + '.' + - it.key ()).exists (); - } - - if (info_file_exists) - { - QString path = info.absolutePath (); - QString fileName = info.fileName (); - - QDir infoDir (path); - QStringList filter; - filter.append (fileName + '*'); - - _info_files = infoDir.entryInfoList (filter, QDir::Files); - - parse_info_map (); - - return true; - } - else - return false; -} - -QString -texinfo_parser::get_info_path () -{ - return _info_path; -} - -QIODevice * -texinfo_parser::open_file (QFileInfo & file_info) -{ - QIODevice *iodevice = nullptr; - if (_compressors_map.contains (file_info.suffix ())) - { - QString command = _compressors_map.value (file_info.suffix ()).arg ( - file_info.absoluteFilePath ()); - iprocstream ips (command.toStdString ()); - - if (ips.bad ()) - return nullptr; - - QByteArray result; - char buffer[1024]; - - while (! ips.eof ()) - { - ips.read (buffer, sizeof (buffer)); - result.append (buffer, ips.gcount ()); - } - - QBuffer *io = new QBuffer (this); - io->setData (result); - - if (! io->open (QIODevice::ReadOnly | QIODevice::Text)) - return nullptr; - - iodevice = io; - } - else - { - QFile *io = new QFile (file_info.absoluteFilePath ()); - if (! io->open (QIODevice::ReadOnly | QIODevice::Text)) - return nullptr; - iodevice = io; - } - - return iodevice; -} - -QString -texinfo_parser::find_reference (const QString& ref_name) -{ - QString xref_name = "XREF" + ref_name; - xref_name.remove (' '); // Delete spaces as XREF uses no whitespace - - if (_ref_map.contains (xref_name)) - return xref_name; - else if (_node_map.contains ("The " + ref_name + " Statement")) - { - // See, for example "The while Statement" which has no XREF. - return "The " + ref_name + " Statement"; - } - else - return "Top"; -} - -bool -texinfo_parser::is_reference (const QString& ref) -{ - return _ref_map.contains (ref); -} - -QString -texinfo_parser::search_node (const QString& node_arg) -{ - QString node = node_arg; - QString text = ""; - - // If node_arg was a reference, translate to node. - if (_ref_map.contains (node_arg)) - node = _ref_map [node_arg]._node_name; - - if (_node_map.contains (node)) - { - QFileInfo file_info; - int real_pos; - real_position (_node_map [node].pos, file_info, real_pos); - - QIODevice* io = open_file (file_info); - if (! io) - return text; - - seek (io, real_pos); - - text = get_next_node (io); - - io->close (); - delete io; - } - - return text; -} - -void -texinfo_parser::append_line (QString *text, const char *line) -{ - QString line_converted = QString::fromLatin1 (line); - int len = line_converted.length (); - line_converted = QString::fromUtf8 (line); - for (int i = len - line_converted.length (); i > 0; i--) - line_converted.insert (line_converted.size () - 1, QByteArray (" ")); - text->append (line_converted); -} - -QString -texinfo_parser::get_next_node (QIODevice *io) -{ - QString text; - QByteArray line, line_buffer; - char c; - int i; - - while (! io->atEnd ()) - { - io->getChar (&c); - if (c) - { - // first char is not equal 0 - io->ungetChar (c); - line = io->readLine (); - } - else - { - // 0 was read -> image -> handle text replacement (length changes) - line_buffer = io->readLine (); // start of image tag -> drop it - int len = line_buffer.size (); - line = io->readLine (); // get first line of its text - line_buffer = line; // and store it - append_line (&text, line); - line = io->readLine (); // get next line of text - append_line (&text, line); - line = io->readLine (); // drop last line (unneeded chars) - line = line_buffer; // and take the first instead - // now correct the size of the dropped line and 5 additional chars - for (i = 1; i < len + 6; i++) - line.insert (line.size ()-1, QByteArray (" ")); // adding blanks - } - - if (line.at(0) == 31) - break; - else - append_line (&text, line); - } - return text; -} - -static QString -get_first_line (const QString& text) -{ - int n = text.indexOf ("\n"); - - if (n < 0) - return QString (); - - QString first_line = text.left (n); - return first_line; -} - -static QString -texinfo_parser_node (const QString& text, const QString& node_name) -{ - QString firstLine = get_first_line (text); - QStringList nodes = firstLine.split (","); - for (int i = 0; i < nodes.size (); i++) - { - QString node = nodes.at (i).trimmed (); - - if (node.startsWith (node_name)) - return node.remove (0, node_name.size ()).trimmed (); - } - return QString (); -} - -QString -texinfo_parser::get_node_name (const QString& text) -{ - return texinfo_parser_node (text, "Node:"); -} - -QString -texinfo_parser::get_node_up (const QString& text) -{ - return texinfo_parser_node (text, "Up:"); -} - -QString -texinfo_parser::get_node_next (const QString& text) -{ - return texinfo_parser_node (text, "Next:"); -} - -QString -texinfo_parser::get_node_prev (const QString& text) -{ - return texinfo_parser_node (text, "Prev:"); -} - -static void -replace_links (QString& text) -{ - QRegExp re ("(\\*[N|n]ote|\n\\*)([ |\n]+)([^:]+):([^:\\.,]*)([:,\\.]+)"); - int i = 0, f; - - while ((i = re.indexIn (text, i)) != -1) - { - QString type = re.cap (1); - QString note = re.cap (3); - QString url_link = re.cap (4); - QString term = re.cap (5); - - if (url_link.isEmpty ()) - url_link = note; - - term.replace (":", ""); - note.replace (":", ""); - note.replace (QRegExp ("`([^']+)'"),"\\1"); // no extra format in links - - QRegExp re_break ("(\n[ ]*)"); - - if (note == "fig" || note == "tab") - url_link.prepend ("#"); - - QString href; - if (type == "\n*") - href = "\n"; - - if (re_break.indexIn (url_link) != -1) - term += re_break.cap (1); - else if (re_break.indexIn (re.cap (2)) != -1) - href = re_break.cap (1) + ' '; - else if (re_break.indexIn (note) != -1) - term += re_break.cap (1); - note.replace (re_break," "); - - url_link = url_link.trimmed (); - url_link.replace ("\n", " "); - url_link.replace (QRegExp (" +"), " "); - url_link.replace ("<b>", ""); - url_link.replace ("</b>", ""); - - href += R"(<font style="color:DarkGray; font-weight:bold;">»</font>)"; - href += " <a href='" + url_link + "'>" + note + "</a>" + term; - f = re.matchedLength (); - text.replace (i, f, href); - i += href.size (); - } -} - -static void -replace_colons (QString& text) -{ - QRegExp re ("`([^']+)'"); - int i = 0, f; - while ((i = re.indexIn (text, i)) != -1) - { - QString t = re.cap (1); - QString bold = R"(<font style="color:SteelBlue;font-weight:bold">)" + t + - "</font>"; - - f = re.matchedLength (); - text.replace (i, f, bold); - i += bold.size (); - } -} - -static void -info_to_html (QString& text) -{ - text.replace ("&", "&"); - text.replace ("<", "<"); - text.replace (">", ">"); - - text.replace ("\n* Menu:", - "\n<font style=\"color:DarkRed;font-weight:bold\">Menu:</font>"); - text.replace ("See also:", - R"(<font style="color:DarkRed;font-style:italic;font-weight:bold">See also:</font>)"); - replace_links (text); - replace_colons (text); -} - -QString -texinfo_parser::node_as_html (const QString& node, const QString& anchor) -{ - QString text = search_node (node); - - QString nodeName = get_node_name (text); - QString nodeUp = get_node_up (text); - QString nodeNext = get_node_next (text); - QString nodePrev = get_node_prev (text); - - // Insert anchor, if node is a XREF-reference - if (is_reference (node)) - { - node_position ref = _ref_map[node]; - int anchor_pos = ref.pos - _node_map[ref._node_name].pos; - - QString text1 = text.left (anchor_pos); - QString text2 = text.mid (anchor_pos); - - text1.remove (0, text1.indexOf ("\n")); - - info_to_html (text1); - info_to_html (text2); - - text = text1 + "<a name='" + anchor - + R"('/><font style="color:DarkBlue; font: bold monospace large;">♦</font><br> )" - + text2; - } - else - { - text.remove (0, text.indexOf ("\n")); - info_to_html (text); - } - - QString navigationLinks = QString ( - R"(<b>Section:</b> <font style="color:DarkRed">%1</font><br>)" - "<b>Previous Section:</b> <a href='%2'>%3</a><br>" - "<b>Next Section:</b> <a href='%4'>%5</a><br>" - "<b>Up:</b> <a href='%6'>%7</a><br>\n" - ) - .arg (nodeName, nodePrev, nodePrev, nodeNext, nodeNext, nodeUp, nodeUp); - - text.prepend ("<hr>\n<pre style=\"font-family:monospace\">"); - text.append ("</pre>\n<hr><hr>\n"); - text.prepend (navigationLinks); - text.append (navigationLinks); - text.prepend ("<html><body>\n"); - text.append ("</body></html>\n"); - - return text; -} - -void -texinfo_parser::parse_info_map () -{ - QRegExp re ("(Node|Ref): ([^\\0177]+)\\0177(\\d+)\n"); - QRegExp re_files ("([^:]+): (\\d+)\n"); - int foundCount = 0; - - for (int i = 0; i < _info_files.size (); i++) - { - QFileInfo fileInfo = _info_files.at (i); - - QIODevice *io = open_file (fileInfo); - if (! io) - continue; - - QString nodeText; - while (! (nodeText = get_next_node (io)).isEmpty () && foundCount < 2) - { - QString first_line = get_first_line (nodeText); - if (first_line.startsWith ("Tag")) - { - foundCount++; - int pos = 0; - QString last_node; - - while ((pos = re.indexIn (nodeText, pos)) != -1) - { - QString type = re.cap (1); - QString node = re.cap (2); - int index = re.cap (3).toInt (); - - if (type == "Node") - { - node_map_item item; - item.pos = index; - _node_map [node] = item; - last_node = node; - } - else if (type == "Ref") - { - node_position item; - item._node_name = last_node; - item.pos = index; - _ref_map [node] = item; - } - pos += re.matchedLength (); - } - break; - } - else if (first_line.startsWith ("Indirect:")) - { - foundCount++; - int pos = 0; - - while ((pos = re_files.indexIn (nodeText, pos)) != -1) - { - QString fileCap = re_files.cap (1).trimmed (); - int index = re_files.cap (2).toInt (); - - info_file_item item; - for (int j = 0; j < _info_files.size (); j++) - { - QFileInfo info = _info_files.at (j); - if (info.fileName ().startsWith (fileCap)) - { - item.file_info = info; - break; - } - } - item.real_size = index; - _info_file_real_size_list.append (item); - pos += re_files.matchedLength (); - } - } - } - io->close (); - delete io; - } -} - -void -texinfo_parser::real_position (int pos, QFileInfo& file_info, int& real_pos) -{ - int header = -1; - int sum = 0; - for (int i = 0; i < _info_file_real_size_list.size (); i++) - { - info_file_item item = _info_file_real_size_list.at (i); - if (header == -1) - { - file_info = item.file_info; - header = item.real_size; - } - - if (pos < item.real_size) - { - break; - } - - file_info = item.file_info; - sum = item.real_size; - } - real_pos = pos - sum + header + 2; -} - -void -texinfo_parser::seek (QIODevice *io, int pos) -{ - char ch; - while (! io->atEnd () && pos > 0) - { - io->getChar (&ch); - pos--; - } -} - -QString -texinfo_parser::global_search (const QString& text, int max_results) -{ - QString results; - QStringList words = text.split (" ", QString::SkipEmptyParts); - - QString re_program ('(' + QRegExp::escape (words.at (0))); - for (int i = 1; i < words.size (); i++) - re_program += '|' + QRegExp::escape (words.at (i)); - re_program += ')'; - - QRegExp re (re_program, Qt::CaseInsensitive); - - results.append ("<html><body>\n<h1>Search results</h1>\n<b>Results for:</b> "); - results.append (text); - results.append ("<br>\n"); - - for (int i = 0; i < _info_files.size (); i++) - { - QFileInfo file_info = _info_files.at (i); - QIODevice *io = open_file (file_info); - if (! io) - continue; - - QString node_text; - while (! (node_text = get_next_node (io)).isEmpty ()) - { - QString firstLine = get_first_line (node_text); - QString node = get_node_name (node_text); - if (node.isEmpty ()) - continue; - - node_text.remove (0, node_text.indexOf ("\n")); - - int pos = 0; - int founds = 0; - - for (; founds < words.size () - && node_text.indexOf (words.at (founds), 0,Qt::CaseInsensitive) - >= 0; - founds++) - { } - - if (founds < words.size ()) - continue; - - founds = 0; - - while ((pos = re.indexIn (node_text, pos)) != -1 - && founds < max_results) - { - if (founds == 0) - { - results.append( - "<br>\n<font style=\"color:DarkGray; font-weight:bold;\">»</font> <a href='" - + node + - "'>"); - results.append (node); - results.append ("</a><br>\n"); - } - - // Replace text found with BOLD TEXT in search results - int line_start, line_end; - line_start = node_text.lastIndexOf ("\n", pos); - line_end = node_text.indexOf ("\n", pos); - QString line = node_text.mid (line_start, - line_end - line_start); - - int pos2 = pos - line_start; - int len = re.matchedLength (); - - QString ptn = line.mid (pos2, len); - QString repl ("<b>%1</b>"); - repl = repl.arg (ptn); - line.remove (pos2, len); - line.insert (pos2, repl); - line = line.trimmed (); - results.append (line); - results.append ("<br>\n"); - - pos += len; - founds++; - } - } - io->close (); - delete io; - } - - results.append ("</body></html>"); - return results; -}
--- a/libgui/src/qtinfo/texinfo-parser.h Fri Jul 13 14:32:23 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,157 +0,0 @@ -/* - -Copyright (C) 2012-2018 Jacob Dawid -Copyright (C) 2009 P.L. Lucas - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -// Author: P. L. Lucas -// Author: Jacob Dawid <jacob.dawid@cybercatalyst.com> - -#if ! defined (octave_texinfo_parser_h) -#define octave_texinfo_parser_h 1 - -#include <QStringList> -#include <QIODevice> -#include <QFileInfoList> -#include <QHash> - -//! This class processes Texinfo `*.info`-files and their contained nodes -//! for searching and translation to HTML. -//! -//! Texinfo files are structured by nodes and contain a map with the -//! `position` of each node. The nodes themselves hold the actual -//! documentation. -//! -//! If you make a queue with info files, `position` will be the number of -//! bytes from begining to a node position. -//! -//! But is not so easy. There is headers, and qtinfo must not take these -//! headers into account. - -class texinfo_parser - : public QObject -{ - Q_OBJECT - -public: - - //! Ctor. - - texinfo_parser (QObject *parent = nullptr); - - //! Sets the path of the Texinfo files to @p info_path. - //! - //! @returns true, if successful, otherwise false. - - bool set_info_path (const QString& info_path); - - //! Returns the path of the Texinfo files. - - QString get_info_path (); - - //! Search for the text of @p node. - - QString search_node (const QString& node); - - //! Search for string @p text with @p max_results search results. - - QString global_search (const QString& text, int max_results); - - //! Find reference @p ref. - //! - //! @returns A valid XREF-reference, if @p ref exists. - //! Otherwise node "Top" is returned. - - QString find_reference (const QString& ref); - - //! Checks if @p ref is a XREF-reference. - - bool is_reference (const QString& ref); - - //! Get a HTML representation of @p node. - //! - //! If @p node is a XREF-reference, an HTML anchor `<a name="anchor">` is - //! inserted at the position of the XREF-reference to navigate to it. - //! - //! @param anchor Name of the anchor. - //! - //! @returns HTML string. - - QString node_as_html (const QString& node, - const QString& anchor = QString ()); - -private: - - struct node_position - { - QString _node_name; - int pos; - }; - - struct node_map_item - { - int pos; - }; - - struct info_file_item - { - QFileInfo file_info; - int real_size; - }; - - QString get_next_node (QIODevice* io); - QString get_node_name (const QString& text); - QString get_node_up (const QString& text); - QString get_node_next (const QString& text); - QString get_node_prev (const QString& text); - - //! Append @p line to @p text. - - void append_line (QString *text, const char *line); - - //! Parse `*.info` file and generate map of nodes and their positions. - - void parse_info_map (); - - //! Open compressed `*.info` file @p fileInfo. - - QIODevice* open_file (QFileInfo& fileInfo); - - //! Calculates real position of nodes. - //! - //! @param pos Position from info file. - //! @param file_info Returns file that contains @p pos. - //! @param real_pos Returns real position inside @p file_info. - - void real_position (int pos, QFileInfo& file_info, int& real_pos); - - //! Seeks in @p io to position @p pos. - - void seek (QIODevice *io, int pos); - - QString _info_path; - QFileInfoList _info_files; - QHash<QString, node_map_item> _node_map; - QHash<QString, node_position> _ref_map; - QList<info_file_item> _info_file_real_size_list; - QHash<QString, QString> _compressors_map; -}; - -#endif
--- a/libgui/src/qtinfo/webinfo.cc Fri Jul 13 14:32:23 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,377 +0,0 @@ -/* - -Copyright (C) 2012-2018 Jacob Dawid -Copyright (C) 2009 P. L. Lucas - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -// Author: P. L. Lucas -// Author: Jacob Dawid <jacob.dawid@cybercatalyst.com> - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include "webinfo.h" -#include <QVBoxLayout> -#include <QHBoxLayout> -#include <QApplication> -#include <QClipboard> - -#include "file-ops.h" -#include "help.h" -#include "resource-manager.h" -#include "shortcut-manager.h" - -namespace octave -{ - webinfo::webinfo (QWidget *p) - : QWidget (p) - { - _font_web = font (); - - QVBoxLayout *vbox_layout = new QVBoxLayout (); - vbox_layout->setMargin (0); - setLayout (vbox_layout); - - QHBoxLayout *hbox_layout = new QHBoxLayout (); - hbox_layout->setMargin (0); - hbox_layout->setSpacing (0); - vbox_layout->addLayout (hbox_layout); - - _tab_bar = new tab_bar (this); - _tab_bar->setSizePolicy (QSizePolicy::Preferred,QSizePolicy::Preferred); - _tab_bar->setExpanding (false); - _tab_bar->setTabsClosable (true); -#if defined (HAVE_QTABWIDGET_SETMOVABLE) - _tab_bar->setMovable (true); -#endif - hbox_layout->addWidget (_tab_bar); - - _zoom_in_button = new QToolButton (this); - _zoom_in_button->setIcon (resource_manager::icon ("zoom-in")); - hbox_layout->addWidget (_zoom_in_button); - - _zoom_out_button = new QToolButton (this); - _zoom_out_button->setIcon (resource_manager::icon ("zoom-out")); - hbox_layout->addWidget (_zoom_out_button); - - _stacked_widget = new QStackedWidget (this); - vbox_layout->addWidget (_stacked_widget); - - hbox_layout = new QHBoxLayout (); - vbox_layout->addLayout (hbox_layout); - - _search_line_edit = new QLineEdit (this); -#if defined (HAVE_QLINEEDIT_SETPLACEHOLDERTEXT) - _search_line_edit->setPlaceholderText ( - tr ("Type here and press \'Return\' to search")); -#endif - hbox_layout->addWidget (_search_line_edit); - - _search_check_box = new QCheckBox (tr ("Global search")); - hbox_layout->addWidget (_search_check_box); - - _close_action = add_action (_tab_bar->get_context_menu (), - resource_manager::icon ("window-close",false), tr ("&Close"), - this, SLOT (request_close_tab (bool))); - _close_others_action = add_action (_tab_bar->get_context_menu (), - resource_manager::icon ("window-close",false), tr ("Close &Other Tabs"), - this, SLOT (request_close_other_tabs (bool))); - _close_action->setEnabled (false); - _close_others_action->setEnabled (false); - - connect (_tab_bar, SIGNAL (close_current_tab_signal (bool)), - this, SLOT (request_close_tab (bool))); - connect (_tab_bar, SIGNAL (tabCloseRequested (int)), - this, SLOT (close_tab (int))); - connect (_tab_bar, SIGNAL (currentChanged (int)), this, - SLOT (current_tab_changed (int))); - connect (_zoom_in_button, SIGNAL (clicked ()), this, SLOT (zoom_in ())); - connect (_zoom_out_button, SIGNAL (clicked ()), this, SLOT (zoom_out ())); - connect (_search_line_edit, SIGNAL (returnPressed ()), this, SLOT (search ())); - - // Actions for tab navigation - m_switch_left_tab_action - = add_action (nullptr, QIcon (), "", - _tab_bar, SLOT (switch_left_tab (void))); - m_switch_right_tab_action - = add_action (nullptr, QIcon (), "", - _tab_bar, SLOT (switch_right_tab (void))); - m_move_tab_left_action - = add_action (nullptr, QIcon (), "", - _tab_bar, SLOT (move_tab_left (void))); - m_move_tab_right_action - = add_action (nullptr, QIcon (), "", - _tab_bar, SLOT (move_tab_right (void))); - - resize (500, 300); - } - - // Add an action to a menu or the widget itself - QAction* webinfo::add_action (QMenu *menu, const QIcon& icon, - const QString& text, - QWidget* receiver, const char *member) - { - QAction *a; - - if (menu) - a = menu->addAction (icon, text, receiver, member); - else - { - a = new QAction (this); - connect (a, SIGNAL (triggered ()), receiver, member); - } - - addAction (a); // important for shortcut context - a->setShortcutContext (Qt::WidgetWithChildrenShortcut); - - return a; - } - - // Slot for the close tab action - void webinfo::request_close_tab (bool) - { - close_tab (_tab_bar->currentIndex ()); - } - - // Slot for the close other tabs action - void webinfo::request_close_other_tabs (bool) - { - int current = _tab_bar->currentIndex (); - - for (int index = _tab_bar->count ()-1; index >= 0; index--) - { - if (current != index) - close_tab (index); - } - } - - void webinfo::load_info_file (const QString& info_file) - { - if (! set_info_path (info_file)) - { - // Info file does not exist - _search_check_box->setEnabled (false); - _search_line_edit->setEnabled (false); - - QTextBrowser *msg = addNewTab (tr ("Error")); - QString msg_text = QString ( - "<html><body><br><br><center><b>%1</b></center></body></html>"). - arg (tr ("The info file<p>%1<p>or compressed versions do not exist"). - arg (info_file)); - msg->setHtml (msg_text); - } - } - - bool webinfo::set_info_path (const QString& info_path) - { - if (_parser.set_info_path (info_path)) - { - load_node ("Top"); - return true; - } - else - return false; - } - - void webinfo::load_node (const QString& node_name) - { - // no XREF in the tabs - QString tab_text = node_name; - tab_text.replace ("XREF", ""); - - //Check if node has been already opened. - for (int i = 0; i < _tab_bar->count (); i++) - { - if (tab_text == _tab_bar->tabText (i)) - { - _tab_bar->setCurrentIndex (i); - return; - } - } - - _text_browser = addNewTab (tab_text); - _text_browser->setHtml (_parser.node_as_html (node_name, "anchor")); - - if (_parser.is_reference (node_name)) - _text_browser->scrollToAnchor ("anchor"); - } - - void webinfo::link_clicked (const QUrl& link) - { - QString node = link.toString (); - if (node.at (0) != '#') - load_node (node); - else - _text_browser->scrollToAnchor (node); - } - - void webinfo::tab_state_changed (void) - { - _close_action->setEnabled (_tab_bar->count () > 1); - _close_others_action->setEnabled (_tab_bar->count () > 1); - setFocusProxy (_stacked_widget->currentWidget ()); - } - - void webinfo::current_tab_changed (int index) - { - QVariant tab_data = _tab_bar->tabData (index); - _text_browser = static_cast<QTextBrowser *> (tab_data.value<void*> ()); - - _stacked_widget->setCurrentIndex (_stacked_widget->indexOf (_text_browser)); - - if (_text_browser->font () != _font_web) - _text_browser->setFont (_font_web); - - tab_state_changed (); - } - - QTextBrowser * webinfo::addNewTab (const QString& name) - { - _text_browser = new QTextBrowser (this); - _text_browser->setOpenLinks (false); - _text_browser->show (); - - connect (_text_browser, SIGNAL (anchorClicked (const QUrl&)), this, - SLOT (link_clicked (const QUrl&))); - disconnect (_tab_bar, SIGNAL (currentChanged (int)), this, - SLOT (current_tab_changed (int))); - - int ns = _stacked_widget->addWidget (_text_browser); - _stacked_widget->setCurrentIndex (ns); - - int nt = _tab_bar->addTab (name); - _tab_bar->setCurrentIndex (nt); - QVariant tab_data; - tab_data.setValue (static_cast<void *> (_text_browser)); - _tab_bar->setTabData (nt, tab_data); - - connect (_tab_bar, SIGNAL (currentChanged (int)), this, - SLOT (current_tab_changed (int))); - - tab_state_changed (); - - if (_text_browser->font () != _font_web) - _text_browser->setFont (_font_web); - - return _text_browser; - } - - void webinfo::close_tab (int index) - { - if (_tab_bar->count () > 1) - { - QVariant tab_data = _tab_bar->tabData (index); - QWidget *w = static_cast<QWidget *> (tab_data.value<void*> ()); - _stacked_widget->removeWidget (w); - delete w; - - _tab_bar->removeTab (index); - } - - tab_state_changed (); - - setFocus (); - } - - void webinfo::load_ref (const QString& ref_name) - { - // Will load "Top", if ref_name was not found. - load_node (_parser.find_reference (ref_name)); - - if (_text_browser) - _text_browser->setFocus (); - } - - void webinfo::search (void) - { - if (_search_line_edit->text ().trimmed ().isEmpty ()) - return; // do nothing if search field is empty or only has whitespaces - - if (_search_check_box->isChecked ()) - { - // Global search - QString results = _parser.global_search (_search_line_edit->text (), 5); - _text_browser=addNewTab ("Results for: " + _search_line_edit->text ()); - _text_browser->setHtml (results); - } - else - { - // Local search - _text_browser->find (_search_line_edit->text ()); - } - } - - void webinfo::zoom_in (void) - { - _font_web.setPointSize (_font_web.pointSize () + 1); - _text_browser->setFont (_font_web); - } - - void webinfo::zoom_out (void) - { - _font_web.setPointSize (_font_web.pointSize () - 1); - _text_browser->setFont (_font_web); - } - - void webinfo::copyClipboard (void) - { - if (_search_line_edit->hasFocus () && _search_line_edit->hasSelectedText ()) - { - QClipboard *clipboard = QApplication::clipboard (); - - clipboard->setText (_search_line_edit->selectedText ()); - } - - if (_text_browser->hasFocus ()) - _text_browser->copy (); - } - - void webinfo::selectAll (void) - { - if (_search_line_edit->hasFocus ()) - _search_line_edit->selectAll (); - - if (_text_browser->hasFocus ()) - _text_browser->selectAll (); - } - - void webinfo::pasteClipboard (void) - { - if (_search_line_edit->hasFocus ()) - { - QClipboard *clipboard = QApplication::clipboard (); - QString str = clipboard->text (); - if (str.length () > 0) - _search_line_edit->insert (str); - } - } - - void webinfo::notice_settings (const QSettings *) - { - shortcut_manager::set_shortcut (_close_action, "editor_file:close"); - shortcut_manager::set_shortcut (_close_others_action, "editor_file:close_other"); - shortcut_manager::set_shortcut (m_switch_left_tab_action, "editor_tabs:switch_left_tab"); - shortcut_manager::set_shortcut (m_switch_right_tab_action, "editor_tabs:switch_right_tab"); - shortcut_manager::set_shortcut (m_move_tab_left_action, "editor_tabs:move_tab_left"); - shortcut_manager::set_shortcut (m_move_tab_right_action, "editor_tabs:move_tab_right"); - } -} -
--- a/libgui/src/qtinfo/webinfo.h Fri Jul 13 14:32:23 2018 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -/* - -Copyright (C) 2012-2018 Jacob Dawid -Copyright (C) 2009 P. L. Lucas - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -// Author: P. L. Lucas -// Author: 2012 Jacob Dawid <jacob.dawid@cybercatalyst.com> - -#if ! defined (octave_webinfo_h) -#define octave_webinfo_h 1 - -#include <QTextBrowser> -#include "texinfo-parser.h" -#include <QStackedWidget> -#include <QTabBar> -#include <QPushButton> -#include <QLineEdit> -#include <QCheckBox> -#include <QToolButton> -#include <QMenu> -#include <QAction> -#include <QMouseEvent> -#include <QSettings> - -#include "tab-bar.h" - -namespace octave -{ - // The webinfo class - class webinfo : public QWidget - { - Q_OBJECT - - public: - - webinfo (QWidget *parent = nullptr); - - bool set_info_path (const QString& info_path); - void load_node (const QString& node_name); - void load_ref (const QString& ref_name); - void notice_settings (const QSettings *settings); - - void load_info_file (const QString& info_file); - - public slots: - - void link_clicked (const QUrl& link); - void current_tab_changed (int index); - void close_tab (int index); - void search (void); - void zoom_in (void); - void zoom_out (void); - - void copyClipboard (void); - void pasteClipboard (void); - void selectAll (void); - - void request_close_tab (bool); - void request_close_other_tabs (bool); - - private: - - QAction *_close_action; - QAction *_close_others_action; - QAction *m_switch_left_tab_action; - QAction *m_switch_right_tab_action; - QAction *m_move_tab_left_action; - QAction *m_move_tab_right_action; - - QTextBrowser *_text_browser; - tab_bar *_tab_bar; - QStackedWidget *_stacked_widget; - QLineEdit *_search_line_edit; - QCheckBox *_search_check_box; - QToolButton *_zoom_in_button; - QToolButton *_zoom_out_button; - - texinfo_parser _parser; - QFont _font_web; - - QTextBrowser * addNewTab (const QString& name); - - QAction * add_action (QMenu *menu, const QIcon& icon, const QString& text, - QWidget *receiver, const char *member); - - void tab_state_changed (void); - - }; -} - -#endif