"Fossies" - the Fresh Open Source Software Archive

Member "cb2bib-2.0.1/src/c2bShortcutWidget.cpp" (12 Feb 2021, 4581 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 "c2bShortcutWidget.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 "c2bShortcutWidget.h"
    8 
    9 #include "c2bSettings.h"
   10 
   11 
   12 c2bShortcutWidget::c2bShortcutWidget(QWidget* parentw) : QWidget(parentw)
   13 {
   14     ui.setupUi(this);
   15     _settingsP = c2bSettingsP;
   16     _standard_keysequences.append(QKeySequence::Close);
   17     _standard_keysequences.append(QKeySequence::Copy);
   18     _standard_keysequences.append(QKeySequence::Cut);
   19     _standard_keysequences.append(QKeySequence::Find);
   20     _standard_keysequences.append(QKeySequence::FindNext);
   21     _standard_keysequences.append(QKeySequence::FindPrevious);
   22     _standard_keysequences.append(QKeySequence::HelpContents);
   23     _standard_keysequences.append(QKeySequence::Open);
   24     _standard_keysequences.append(QKeySequence::Paste);
   25     _standard_keysequences.append(QKeySequence::Redo);
   26     _standard_keysequences.append(QKeySequence::Refresh);
   27     _standard_keysequences.append(QKeySequence::Save);
   28     _standard_keysequences.append(QKeySequence::SelectAll);
   29     _standard_keysequences.append(QKeySequence::Undo);
   30     _standard_keysequences.append(QKeySequence::ZoomIn);
   31     _standard_keysequences.append(QKeySequence::ZoomOut);
   32     _standard_keysequences.append(Qt::Key_F2);
   33     _standard_keysequences.append(QKeySequence::Quit);
   34     _standard_keysequences.append(QKeySequence::SaveAs);
   35 
   36     connect(ui.Clear, SIGNAL(clicked()), ui.Shortcut, SLOT(clear()));
   37     connect(ui.Reset, SIGNAL(clicked()), ui.Shortcut, SLOT(reset()));
   38 }
   39 
   40 
   41 void c2bShortcutWidget::setShortcutNames(const QString& path, const QStringList& fullnames)
   42 {
   43     disconnect(ui.Shortcut, SIGNAL(shortcutChanged(QKeySequence,QKeySequence)), this,
   44                SLOT(shortcutChanged(QKeySequence,QKeySequence)));
   45     disconnect(ui.Description, SIGNAL(currentIndexChanged(QString)), this, SLOT(currentIndexChanged(QString)));
   46     _modified_keysequences.clear();
   47 
   48     _shortcut_path = path;
   49     _fullnames = fullnames.filter(path);
   50     const int n(_fullnames.count());
   51     const int p(path.length());
   52     for (int i = 0; i < n; ++i)
   53         if (_fullnames.at(i).startsWith(path))
   54             ui.Description->addItem(_fullnames.at(i).mid(p));
   55 
   56     ui.Shortcut->setKeysequence(_settingsP->keysequence(_shortcut_path + ui.Description->currentText()));
   57     ui.Shortcut->setDefaultKeysequence(_settingsP->defaultKeysequence(_shortcut_path + ui.Description->currentText()));
   58 
   59     connect(ui.Shortcut, SIGNAL(shortcutChanged(QKeySequence,QKeySequence)), this,
   60             SLOT(shortcutChanged(QKeySequence,QKeySequence)));
   61     connect(ui.Description, SIGNAL(currentIndexChanged(QString)), this, SLOT(currentIndexChanged(QString)));
   62 }
   63 
   64 void c2bShortcutWidget::currentIndexChanged(const QString& name)
   65 {
   66     const QString fullname(_shortcut_path + name);
   67     if (_modified_keysequences.contains(fullname))
   68         ui.Shortcut->setKeysequence(_modified_keysequences.value(fullname));
   69     else
   70         ui.Shortcut->setKeysequence(_settingsP->keysequence(fullname));
   71     ui.Shortcut->setDefaultKeysequence(_settingsP->defaultKeysequence(fullname));
   72 }
   73 
   74 void c2bShortcutWidget::shortcutChanged(const QKeySequence& oldks, const QKeySequence& newks)
   75 {
   76     const QString fullname(_shortcut_path + ui.Description->currentText());
   77     if (!newks.isEmpty())
   78     {
   79         if (_standard_keysequences.contains(newks))
   80         {
   81             ui.Shortcut->setKeysequence(oldks);
   82             ui.Shortcut->setChecked(true);
   83             emit statusMessage(
   84                 tr("Key sequence %1 is used by standard shortcuts").arg(newks.toString(QKeySequence::NativeText)));
   85             return;
   86         }
   87         if (_modified_keysequences.size() == 0)
   88         {
   89             const int n(_fullnames.count());
   90             for (int i = 0; i < n; ++i)
   91                 _modified_keysequences.insert(_fullnames.at(i), _settingsP->keysequence(_fullnames.at(i)));
   92         }
   93         if (_modified_keysequences.values().contains(newks) && _modified_keysequences.value(fullname) != newks)
   94         {
   95             ui.Shortcut->setKeysequence(oldks);
   96             ui.Shortcut->setChecked(true);
   97             emit statusMessage(tr("Key sequence %1 is already assigned").arg(newks.toString(QKeySequence::NativeText)));
   98             return;
   99         }
  100     }
  101     _modified_keysequences[fullname] = newks;
  102     emit statusMessage(QString());
  103 }