"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bAnnote.cpp" (12 Feb 2021, 6534 Bytes) of package /linux/privat/cb2bib-2.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "c2bAnnote.cpp" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.0_vs_2.0.1.

    1 /***************************************************************************
    2  *   Copyright (C) 2004-2021 by Pere Constans
    3  *   constans@molspaces.com
    4  *   cb2Bib version 2.0.1. Licensed under the GNU GPL version 3.
    5  *   See the LICENSE file that comes with this distribution.
    6  ***************************************************************************/
    7 #include "c2bAnnote.h"
    8 
    9 #include "c2b.h"
   10 #include "c2bFileSystemWatcher.h"
   11 #include "c2bSettings.h"
   12 #include "c2bUtils.h"
   13 #include "c2bWebBrowser.h"
   14 
   15 #include <texToHtml.h>
   16 
   17 #include <QLabel>
   18 #include <QMessageBox>
   19 #include <QShortcut>
   20 #include <QStatusBar>
   21 
   22 
   23 /** \page c2bannote cb2Bib Annote
   24 
   25   The cb2Bib Annote module is named after the BibTeX key <tt>annote</tt>.
   26   Annote is not for a 'one reference annotation' though. Instead, Annote is for
   27   short notes that interrelate several references. Annote takes a plain text
   28   note, with minimal or no markup, inserts the bibliographic citations, and
   29   converts it to a HTML page with links to the referenced documents.
   30 
   31 
   32   From within cb2Bib, to write a note, type <tt>Alt+A</tt>, enter a filename,
   33   either new or existing, and once in Annote, type <tt>E</tt> to start the
   34   editor. Each time you save the document the viewer will be updated. For help
   35   on Annote's syntax type <tt>F1</tt>. If cb2Bib was compiled without Annote's
   36   Viewer, typing <tt>Alt+A</tt> will start the editor and HTML viewing will be
   37   committed to the default web browser.
   38 
   39 
   40   From the command line, typing
   41 \verbatim
   42 cb2bib --html-annote annote.tex
   43 \endverbatim
   44   will produce the HTML file <tt>annote.tex.html</tt>.
   45 
   46 
   47   See also \ref c2bconf_annote and \ref commandline.
   48 
   49 
   50 
   51 \section c2bannote_syntax Annote Syntax
   52 
   53   The resulting HTML file <tt>annote.tex.html</tt> can be seen at
   54 \htmlonly
   55 <a href="https://www.molspaces.com/cb2bib/doc/c2bannote/annote.tex.html" target="_blank">cb2Bib Annote</a>.
   56 \endhtmlonly
   57 
   58 \htmlonly
   59 <pre style="font-size: xx-small;">
   60 % annote.tex
   61 
   62 GET_C2BANNOTE_TEX_DOC
   63 \endhtmlonly
   64 
   65 */
   66 c2bAnnote::c2bAnnote(QWidget* parentw) : QMainWindow(parentw)
   67 {
   68     _view_port = new c2bWebBrowser(this);
   69     setCentralWidget(_view_port);
   70     QLabel* informationLabel = new QLabel(this);
   71     statusBar()->addWidget(informationLabel, 1);
   72     connect(_view_port, SIGNAL(windowTitleChanged(QString)), this, SLOT(setWindowTitle(QString)));
   73     connect(_view_port, SIGNAL(statusMessage(QString)), this, SLOT(showMessage(QString)));
   74 
   75     // Creating cb2Bib global resources
   76     c2b* c2b_resources = new c2b(this, this);
   77     connect(c2b_resources, SIGNAL(statusMessage(QString)), this, SLOT(showMessage(QString)));
   78 
   79     QAction* act = new QAction(QIcon(QString::fromUtf8(":/icons/icons/edit.png")), tr("Edit Note"), this);
   80     act->setShortcut(QKeySequence(Qt::Key_E));
   81     act->setStatusTip(tr("Edit TeX note"));
   82     c2bUtils::addSeparator(_view_port);
   83     _view_port->addAction(act);
   84     connect(act, SIGNAL(triggered()), this, SLOT(edit()));
   85 
   86     act = new QAction(QIcon(QString::fromUtf8(":/icons/icons/configure.png")), tr("Configure"), this);
   87     act->setShortcut(QKeySequence(Qt::Key_C));
   88     act->setStatusTip(tr("Configure cb2Bib Annote"));
   89     c2bUtils::addSeparator(_view_port);
   90     _view_port->addAction(act);
   91     connect(act, SIGNAL(triggered()), this, SLOT(configure()));
   92 
   93     _settingsP = c2bSettingsP;
   94     resize(_settingsP->value("c2bAnnote/size", size()).toSize());
   95     move(_settingsP->value("c2bAnnote/position", pos()).toPoint());
   96     loadSettings();
   97     connect(_settingsP, SIGNAL(newSettings()), this, SLOT(loadSettings()));
   98 
   99     _t2h = new texToHtml;
  100     _fsw = new c2bFileSystemWatcher(this);
  101     connect(_fsw, SIGNAL(fileChanged(QString)), this, SLOT(annote()));
  102     disconnect(_view_port->viewReloadAction, 0, 0, 0);
  103     connect(_view_port->viewReloadAction, SIGNAL(triggered()), this, SLOT(update()));
  104 
  105     QShortcut* help_shortcut = new QShortcut(QKeySequence(QKeySequence::HelpContents), this);
  106     connect(help_shortcut, SIGNAL(activated()), this, SLOT(help()));
  107 }
  108 
  109 c2bAnnote::~c2bAnnote()
  110 {
  111     delete _t2h;
  112     _settingsP->setValue("c2bAnnote/position", pos());
  113     _settingsP->setValue("c2bAnnote/size", size());
  114 }
  115 
  116 
  117 bool c2bAnnote::show()
  118 {
  119     _annote_filename = QDir::cleanPath(_settingsP->cl_annote_filename);
  120     const bool is_html = _annote_filename.endsWith(".html");
  121     if (is_html)
  122         _annote_filename.remove(QRegExp("\\.html$"));
  123     if (!QFileInfo::exists(_annote_filename))
  124     {
  125         QMessageBox::warning(this, tr("Warning - cb2Bib"),
  126                              tr("Unable to open the file %1 for reading.\nError: '%2'.")
  127                              .arg(QDir::toNativeSeparators(_annote_filename), "File does not exist"),
  128                              QMessageBox::Ok);
  129         return false;
  130     }
  131     _html_filename = _annote_filename + ".html";
  132     if (!is_html || !QFileInfo::exists(_html_filename))
  133         _t2h->toHtml(c2bUtils::fileToString(_annote_filename), _html_filename);
  134     _view_port->setHomePage(_html_filename);
  135     _fsw->addPath(_annote_filename);
  136     QMainWindow::show();
  137     return true;
  138 }
  139 
  140 void c2bAnnote::annote()
  141 {
  142     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
  143     _t2h->toHtml(c2bUtils::fileToString(_annote_filename), _html_filename);
  144     if (_html_filename == QDir::cleanPath(_view_port->url().toLocalFile()))
  145         _view_port->reload();
  146     QApplication::restoreOverrideCursor();
  147 }
  148 
  149 void c2bAnnote::update()
  150 {
  151     if (_html_filename == QDir::cleanPath(_view_port->url().toLocalFile()))
  152         annote();
  153     else
  154         _view_port->reload();
  155 }
  156 
  157 void c2bAnnote::edit()
  158 {
  159     c2bUtils::openFile(_annote_filename, this);
  160 }
  161 
  162 void c2bAnnote::configure()
  163 {
  164     // Attention: Currently c2bAnnote is page 0. Update here if c2bConfigure changes page ordering.
  165     c2b::configure(0);
  166 }
  167 
  168 void c2bAnnote::setWindowTitle(const QString& title)
  169 {
  170     if (title.isEmpty())
  171         QMainWindow::setWindowTitle("Annote - cb2Bib");
  172     else
  173         QMainWindow::setWindowTitle(title + " - cb2Bib");
  174     if (title == "New Note")
  175         showMessage(tr("Press E to Edit and %1 for Help.").arg(QKeySequence(QKeySequence::HelpContents).toString()));
  176 }
  177 
  178 void c2bAnnote::showMessage(const QString& ms)
  179 {
  180     statusBar()->showMessage(ms, C2B_MESSAGE_TIME);
  181 }
  182 
  183 void c2bAnnote::loadSettings()
  184 {
  185     _view_port->setFont(_settingsP->value("c2bAnnote/Font").value<QFont>());
  186     _view_port->setFixedFont(_settingsP->value("c2bAnnote/FixedFont").value<QFont>());
  187 }
  188 
  189 void c2bAnnote::help()
  190 {
  191     c2bUtils::displayHelp("https://www.molspaces.com/cb2bib/doc/c2bannote/");
  192 }