Mercurial > octave-nkf
diff gui/src/qtinfo/webinfo.cc @ 15055:48ae6a7c69c1 gui
Integrated texinfo browser from QtOctave.
* documentation-dockwidget.cc: Added new dock widget for the documentation.
* documentation-dockwidget.h: Added new dock widget for the documentation.
* bookmark.png: New icon file.
* question.png: New icon file.
* star.png: New icon file.
* stop.png: New icon file.
* zoom-in.png: New icon file.
* zoom-out.png: New icon file.
* parser.cc: Added file from QtOctave, refactored code.
* parser.h: Added file from QtOctave, refactored code.
* webinfo.cc: Added file from QtOctave, refactored code.
* webinfo.h: Added file from QtOctave, refactored code.
* main-window.cc: Added menu entries to handle documentation and integrated new documentation dock widget.
* main-window.h: Including header for documentation dock widget and added member variable.
* resource.qrc: Added icon entries for new icon files.
* src.pro: Added file entries for new file added to the project.
author | Jacob Dawid <jacob.dawid@gmail.com> |
---|---|
date | Mon, 30 Jul 2012 19:27:14 +0200 |
parents | |
children | 4c4f2fb07a50 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gui/src/qtinfo/webinfo.cc Mon Jul 30 19:27:14 2012 +0200 @@ -0,0 +1,209 @@ +/* Copyright (C) 2009 P.L. Lucas + * Copyright (C) 2012 Jacob Dawid <jacob.dawid@gmail.com> + * + * This program 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 2 of the License, or + * (at your option) any later version. + * + * This program 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 this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "webinfo.h" +#include <QVBoxLayout> +#include <QHBoxLayout> + + +webinfo::webinfo (QWidget *parent) + :QWidget (parent) +{ + _font_web = font (); + + QVBoxLayout *layout = new QVBoxLayout (); + setLayout (layout); + + QHBoxLayout *hboxLayout = new QHBoxLayout (); + layout->addLayout (hboxLayout); + + _close_tab_button = new QPushButton (this); + _close_tab_button->setSizePolicy (QSizePolicy::Fixed,QSizePolicy::Preferred); + _close_tab_button->setIcon (QIcon (":/actions/icons/stop.png")); + hboxLayout->addWidget (_close_tab_button); + + _tab_bar = new QTabBar (this); + _tab_bar->setSizePolicy (QSizePolicy::Preferred,QSizePolicy::Preferred); + _tab_bar->setExpanding (false); + hboxLayout->addWidget (_tab_bar); + + _zoom_in_button = new QToolButton (this); + _zoom_in_button->setSizePolicy (QSizePolicy::Fixed,QSizePolicy::Preferred); + _zoom_in_button->setIcon (QIcon (":/actions/icons/zoom-in.png")); + hboxLayout->addWidget (_zoom_in_button); + + _zoom_out_button = new QToolButton (this); + _zoom_out_button->setSizePolicy (QSizePolicy::Fixed,QSizePolicy::Preferred); + _zoom_out_button->setIcon (QIcon (":/actions/icons/zoom-out.png")); + hboxLayout->addWidget (_zoom_out_button); + + _stacked_widget = new QStackedWidget (this); + layout->addWidget (_stacked_widget); + + hboxLayout = new QHBoxLayout (); + layout->addLayout (hboxLayout); + + _search_line_edit = new QLineEdit(this); + _search_line_edit->setPlaceholderText (tr ("Type here and press \'Return\' to search")); + hboxLayout->addWidget (_search_line_edit); + + _search_check_box = new QCheckBox (tr ("Global search")); + hboxLayout->addWidget (_search_check_box); + + connect (_close_tab_button, SIGNAL (clicked ()), this, SLOT (close_tab ())); + 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 ())); + + resize (500, 300); + + set_info_path ("../../doc/interpreter/octave.info"); +} + +void +webinfo::set_info_path (QString info_path) +{ + _parser.set_info_path (info_path); + load_node ("Top"); +} + +void +webinfo::load_node (QString node_name) +{ + //Check if node has been already opened. + for (int i = 0;i < _tab_bar->count (); i++) + { + if (node_name == _tab_bar->tabText (i)) + { + _tab_bar->setCurrentIndex (i); + return; + } + } + + QString text = _parser.search_node (node_name); + int i = _parser.is_ref (node_name); + _text_browser = addNewTab (node_name); + _text_browser->setHtml (_parser.node_text_to_html (text, i - 1, "anchor")); + + if (i != -1) + { + _text_browser->scrollToAnchor ("anchor"); + } +} + +void +webinfo::link_clicked (const QUrl & link) +{ + QString node = link.toString (); + load_node (node); +} + +void +webinfo::current_tab_changed (int index) +{ + QVariant data = _tab_bar->tabData (index); + _text_browser = (QTextBrowser*) (data.value<void*> ()); + + _stacked_widget->setCurrentIndex (_stacked_widget->indexOf (_text_browser)); + + if (_text_browser->font () != _font_web) + { + _text_browser->setFont (_font_web); + } +} + +QTextBrowser * +webinfo::addNewTab(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 data; + data.setValue ( (void*)_text_browser); + _tab_bar->setTabData (nt, data); + + connect (_tab_bar, SIGNAL (currentChanged (int)), this, SLOT (current_tab_changed (int))); + + if (_text_browser->font () != _font_web) + { + _text_browser->setFont (_font_web); + } + return _text_browser; +} + +void +webinfo::close_tab () +{ + int index = _tab_bar->currentIndex (); + if (_tab_bar->tabText (index) != "Top") + closeTab (index); +} + +void +webinfo::closeTab (int index) +{ + QVariant data = _tab_bar->tabData (index); + QWidget *w = (QWidget*) (data.value<void*> ()); + _stacked_widget->removeWidget (w); + delete w; + + _tab_bar->removeTab (index); +} + +void +webinfo::search () +{ + 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 () +{ + _font_web.setPointSize (_font_web.pointSize() + 1); + _text_browser->setFont (_font_web); +} + +void +webinfo::zoom_out () +{ + _font_web.setPointSize (_font_web.pointSize() - 1); + _text_browser->setFont (_font_web); +} +