"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bBibMenu.cpp" (12 Feb 2021, 5747 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 "c2bBibMenu.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 "c2bBibMenu.h"
    8 
    9 #include <cb2bib_parameters.h>
   10 
   11 #include <QKeyEvent>
   12 
   13 
   14 c2bBibMenu::c2bBibMenu(QWidget* parentw) : QMenu(parentw), _keyboard_selection(0), _was_plus_pressed(false)
   15 {
   16     _title_action = addAction("Title");
   17     _title_action->setData("title");
   18     _author_action = addAction("Author");
   19     _author_action->setData("author");
   20     _add_author_action = addAction("Add authors");
   21     _add_author_action->setIcon(QIcon(C2B_ICON_DIR + "add.png"));
   22     _journal_action = addAction("Journal");
   23     _journal_action->setData("journal");
   24     addSeparator();
   25 
   26     _pages_action = addAction("Pages");
   27     _pages_action->setData("pages");
   28     _volume_action = addAction("Volume");
   29     _volume_action->setData("volume");
   30     _number_action = addAction("Number");
   31     _number_action->setData("number");
   32     _year_action = addAction("Year");
   33     _year_action->setData("year");
   34     addSeparator();
   35 
   36     _abstract_action = addAction("Abstract");
   37     _abstract_action->setData("abstract");
   38     _keywords_action = addAction("Keywords");
   39     _keywords_action->setData("keywords");
   40     _file_action = addAction("File");
   41     _file_action->setData("file");
   42 
   43     QMenu* submenu = new QMenu("Other fields...", this);
   44     _address_action = submenu->addAction("Address");
   45     _address_action->setData("address");
   46     _annote_action = submenu->addAction("Annote");
   47     _annote_action->setData("annote");
   48     _booktitle_action = submenu->addAction("Booktitle");
   49     _booktitle_action->setData("booktitle");
   50     _chapter_action = submenu->addAction("Chapter");
   51     _chapter_action->setData("chapter");
   52     _doi_action = submenu->addAction("DOI");
   53     _doi_action->setData("doi");
   54     _edition_action = submenu->addAction("Edition");
   55     _edition_action->setData("edition");
   56     _editor_action = submenu->addAction("Editor");
   57     _editor_action->setData("editor");
   58     _add_editor_action = submenu->addAction("Add editors");
   59     _add_editor_action->setIcon(QIcon(C2B_ICON_DIR + "add.png"));
   60     _eprint_action = submenu->addAction("Eprint");
   61     _eprint_action->setData("eprint");
   62     _institution_action = submenu->addAction("Institution");
   63     _institution_action->setData("institution");
   64     _isbn_action = submenu->addAction("ISBN");
   65     _isbn_action->setData("isbn");
   66     _issn_action = submenu->addAction("ISSN");
   67     _issn_action->setData("issn");
   68     _month_action = submenu->addAction("Month");
   69     _month_action->setData("month");
   70     _note_action = submenu->addAction("Note");
   71     _note_action->setData("note");
   72     _organization_action = submenu->addAction("Organization");
   73     _organization_action->setData("organization");
   74     _publisher_action = submenu->addAction("Publisher");
   75     _publisher_action->setData("publisher");
   76     _school_action = submenu->addAction("School");
   77     _school_action->setData("school");
   78     _series_action = submenu->addAction("Series");
   79     _series_action->setData("series");
   80     _url_action = submenu->addAction("URL");
   81     _url_action->setData("url");
   82 
   83     addSeparator();
   84     addMenu(submenu);
   85     addSeparator();
   86     _any_pattern_action = addAction(QString());
   87 }
   88 
   89 QAction* c2bBibMenu::exec(const QPoint& p)
   90 {
   91     _keyboard_selection = 0;
   92     _was_plus_pressed = false;
   93     QAction* a = QMenu::exec(p);
   94     if (a)
   95         return a;
   96     else
   97         return _keyboard_selection;
   98 }
   99 
  100 void c2bBibMenu::keyPressEvent(QKeyEvent* qevent)
  101 {
  102     switch (qevent->key())
  103     {
  104     case Qt::Key_A:
  105         if (_was_plus_pressed)
  106             _keyboard_selection = _add_author_action;
  107         else
  108             _keyboard_selection = _author_action;
  109         break;
  110     case Qt::Key_B:
  111         _keyboard_selection = _booktitle_action;
  112         break;
  113     case Qt::Key_C:
  114         _keyboard_selection = _chapter_action;
  115         break;
  116     case Qt::Key_D:
  117         _keyboard_selection = _doi_action;
  118         break;
  119     case Qt::Key_E:
  120         if (_was_plus_pressed)
  121             _keyboard_selection = _add_editor_action;
  122         else
  123             _keyboard_selection = _editor_action;
  124         break;
  125     case Qt::Key_F:
  126         _keyboard_selection = _file_action;
  127         break;
  128     case Qt::Key_I:
  129         _keyboard_selection = _isbn_action;
  130         break;
  131     case Qt::Key_J:
  132         _keyboard_selection = _journal_action;
  133         break;
  134     case Qt::Key_K:
  135         _keyboard_selection = _keywords_action;
  136         break;
  137     case Qt::Key_M:
  138         _keyboard_selection = _month_action;
  139         break;
  140     case Qt::Key_N:
  141         _keyboard_selection = _number_action;
  142         break;
  143     case Qt::Key_O:
  144         _keyboard_selection = _organization_action;
  145         break;
  146     case Qt::Key_P:
  147         _keyboard_selection = _pages_action;
  148         break;
  149     case Qt::Key_S:
  150         _keyboard_selection = _series_action;
  151         break;
  152     case Qt::Key_T:
  153         _keyboard_selection = _title_action;
  154         break;
  155     case Qt::Key_U:
  156         _keyboard_selection = _url_action;
  157         break;
  158     case Qt::Key_V:
  159         _keyboard_selection = _volume_action;
  160         break;
  161     case Qt::Key_Y:
  162         _keyboard_selection = _year_action;
  163         break;
  164     case Qt::Key_Plus:
  165         _was_plus_pressed = true;
  166         break;
  167     default:
  168         _keyboard_selection = 0;
  169         _was_plus_pressed = false;
  170     }
  171     if (_keyboard_selection)
  172     {
  173         qevent->accept();
  174         hide();
  175         _keyboard_selection->trigger();
  176     }
  177     else
  178         QMenu::keyPressEvent(qevent);
  179 }