Exemplo n.º 1
0
Palette* MuseScore::newNoteHeadsPalette()
      {
      Palette* sp = new Palette;
      sp->setName(QT_TRANSLATE_NOOP("Palette", "Note Heads"));
      sp->setMag(1.3);
      sp->setGrid(33, 36);
      sp->setDrawGrid(true);

      for (int i = 0; i < int(NoteHead::Group::HEAD_GROUPS); ++i) {
            SymId sym = Note::noteHead(0, NoteHead::Group(i), NoteHead::Type::HEAD_HALF);
            // HEAD_BREVIS_ALT shows up only for brevis value
            if (i == int(NoteHead::Group::HEAD_BREVIS_ALT) )
                  sym = Note::noteHead(0, NoteHead::Group(i), NoteHead::Type::HEAD_BREVIS);
            NoteHead* nh = new NoteHead(gscore);
            nh->setSym(sym);
            sp->append(nh, Sym::id2userName(sym));
            }
      Icon* ik = new Icon(gscore);
      ik->setIconType(IconType::BRACKETS);
      Shortcut* s = Shortcut::getShortcut("add-brackets");
      QAction* action = s->action();
      QIcon icon(action->icon());
      ik->setAction("add-brackets", icon);
      sp->append(ik, s->help());
      return sp;
      }
Exemplo n.º 2
0
void PluginManager::init()
      {
      //
      // initialize local shortcut table
      //    we need a deep copy to be able to rewind all
      //    changes on "Abort"
      //
      qDeleteAll(localShortcuts);
      localShortcuts.clear();
      foreach(const Shortcut* s, Shortcut::shortcuts())
            localShortcuts[s->key()] = new Shortcut(*s);
      shortcutsChanged = false;

      preferences.updatePluginList();
      int n = preferences.pluginList.size();
      pluginList->clear();
      for (int i = 0; i < n; ++i) {
            PluginDescription& d = preferences.pluginList[i];
            Shortcut* s = &d.shortcut;
            localShortcuts[s->key()] = new Shortcut(*s);

            QListWidgetItem* item = new QListWidgetItem(QFileInfo(d.path).completeBaseName(),  pluginList);
            item->setFlags(item->flags() | Qt::ItemIsEnabled);
            item->setCheckState(d.load ? Qt::Checked : Qt::Unchecked);
            item->setData(Qt::UserRole, i);
            }
      prefs = preferences;
      if (n) {
            pluginList->setCurrentRow(0);
            pluginListItemChanged(pluginList->item(0), 0);
            }
      connect(pluginList, SIGNAL(itemChanged(QListWidgetItem*)), SLOT(pluginLoadToggled(QListWidgetItem*)));
      connect(pluginList, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)),
         SLOT(pluginListItemChanged(QListWidgetItem*, QListWidgetItem*)));
      }
Exemplo n.º 3
0
void QmlPlugin::cmd(const QString& s)
      {
      Shortcut* sc = Shortcut::getShortcut(qPrintable(s));
      if (sc)
            msc->cmd(sc->action());
      else
            qDebug("QmlPlugin:cmd: not found <%s>", qPrintable(s));
      }
Exemplo n.º 4
0
void QmlPlugin::cmd(const QString& s)
      {
      Shortcut* sc = Shortcut::getShortcut(s.toLatin1().data());
      if (sc)
            msc->cmd(sc->action());
      else
            printf("QmlPlugin:cmd: not found <%s>\n", qPrintable(s));
      }
Exemplo n.º 5
0
void Shortcut::resetToDefault()
      {
      QList<Shortcut1*> sl = loadDefaultShortcuts();
      foreach(Shortcut1* sc, sl) {
            Shortcut* s = getShortcut(sc->key);
            if (s) {
                  s->setKeys(sc->keys);
                  s->setStandardKey(sc->standardKey);
                  }
            }
Exemplo n.º 6
0
void Shortcut::load()
      {
      QFile f(dataPath + "/shortcuts.xml");
      if (!f.exists())
            f.setFileName(":/data/shortcuts.xml");
      if (!f.open(QIODevice::ReadOnly)) {
            qDebug("Cannot open shortcuts <%s>", qPrintable(f.fileName()));
            return;
            }
      if (MScore::debugMode)
            qDebug("read shortcuts from <%s>", qPrintable(f.fileName()));

      XmlReader e(&f);

      while (e.readNextStartElement()) {
            if (e.name() == "Shortcuts") {
                  while (e.readNextStartElement()) {
                        if (e.name() == "SC") {
                              Shortcut* sc = 0;
                              while (e.readNextStartElement()) {
                                    const QStringRef& tag(e.name());
                                    if (tag == "key") {
                                          QString val(e.readElementText());
                                          sc = getShortcut(val.toLatin1().data());
                                          if (!sc)
                                                qDebug("cannot find shortcut <%s>", qPrintable(val));
                                          else
                                                sc->clear();
                                          }
                                    else if (tag == "std") {
                                          int i = e.readInt();
                                          if(sc)
                                                sc->_standardKey = QKeySequence::StandardKey(i);
                                          }
                                    else if (tag == "seq") {
                                          QString s = e.readElementText();
                                          if(sc)
                                                sc->_keys.append(Shortcut::keySeqFromString(s, QKeySequence::PortableText));
//                                          sc->_keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
                                          }
                                    else
                                          e.unknown();
                                    }
                              }
                        else
                              e.unknown();
                        }
                  }
            else
                  e.unknown();
            }
      dirty = false;
      }
Exemplo n.º 7
0
void Shortcut::load()
      {
      QFile f(dataPath + "/shortcuts.xml");
      if (!f.exists())
            f.setFileName(":/data/shortcuts.xml");
      if (!f.open(QIODevice::ReadOnly)) {
            printf("cannot open shortcuts\n");
            return;
            }
      QDomDocument doc;
      int line, column;
      QString err;
      if (!doc.setContent(&f, false, &err, &line, &column)) {
            printf("error reading shortcuts.xml at line %d column %d: %s\n",
               line, column, qPrintable(err));
            return;
            }
      f.close();

      QString key;
      for (QDomElement e = doc.documentElement(); !e.isNull(); e = e.nextSiblingElement()) {
            if (e.tagName() == "Shortcuts") {
                  for (QDomElement ee = e.firstChildElement(); !ee.isNull(); ee = ee.nextSiblingElement()) {
                        if (ee.tagName() == "SC") {
                              Shortcut* sc = 0;
                              for (QDomElement eee = ee.firstChildElement(); !eee.isNull(); eee = eee.nextSiblingElement()) {
                                    const QString& tag(eee.tagName());
                                    const QString& val(eee.text());
                                    if (tag == "key") {
                                          sc = getShortcut(val.toAscii().data());
                                          if (!sc) {
                                                printf("cannot find shortcut <%s>\n", qPrintable(val));
                                                break;
                                                }
                                          sc->clear();
                                          }
                                    else if (tag == "std")
                                          sc->_standardKey = QKeySequence::StandardKey(val.toInt());
                                    else if (tag == "seq")
                                          sc->_keys.append(QKeySequence::fromString(val, QKeySequence::PortableText));
                                    else
                                          domError(eee);
                                    }
                              }
                        else
                              domError(ee);
                        }
                  }
            else
                  domError(e);
            }
      dirty = false;
      }
Exemplo n.º 8
0
Accelerator* add_keyboard_shortcut_to_quicktool(const char* shortcut_string, tools::Tool* tool)
{
    Shortcut* shortcut = get_keyboard_shortcut_for_quicktool(tool);
    if (!shortcut) {
        shortcut = new Shortcut(Shortcut::Type::EditorQuicktool);
        shortcut->tool = tool;

        shortcuts->push_back(shortcut);
    }

    shortcut->add_shortcut(shortcut_string);
    return shortcut->accel;
}
Exemplo n.º 9
0
Accelerator* add_keyboard_shortcut_to_spriteeditor(const char* shortcut_string, const char* action_name)
{
    Shortcut* shortcut = get_keyboard_shortcut_for_spriteeditor(action_name);
    if (!shortcut) {
        shortcut = new Shortcut(Shortcut::Type::SpriteEditor);
        shortcut->action = action_name;

        shortcuts->push_back(shortcut);
    }

    shortcut->add_shortcut(shortcut_string);
    return shortcut->accel;
}
Exemplo n.º 10
0
void populateIconPalette(Palette* p, const IconAction* a)
      {
      while (a->subtype != IconType::NONE) {
            Icon* ik = new Icon(gscore);
            ik->setIconType(a->subtype);
            Shortcut* s = Shortcut::getShortcut(a->action);
            QAction* action = s->action();
            QIcon icon(action->icon());
            ik->setAction(a->action, icon);
            p->append(ik, s->help());
            ++a;
            }
      }
Exemplo n.º 11
0
Accelerator* add_keyboard_shortcut_to_execute_command(const char* shortcut_string,
        const char* command_name, Params* params, KeyContext keyContext)
{
    Shortcut* shortcut = get_keyboard_shortcut_for_command(command_name, params);
    if (!shortcut) {
        shortcut = new Shortcut(Shortcut::Type::ExecuteCommand);
        shortcut->command = CommandsModule::instance()->getCommandByName(command_name);
        shortcut->params = params ? params->clone(): new Params;
        shortcut->keycontext = keyContext;
        shortcuts->push_back(shortcut);
    }
    shortcut->add_shortcut(shortcut_string);
    return shortcut->accel;
}
Exemplo n.º 12
0
void Shortcut::load()
      {
      QFile f(dataPath + "/shortcuts.xml");
      if (!f.exists())
            f.setFileName(":/data/shortcuts.xml");
      if (!f.open(QIODevice::ReadOnly)) {
            printf("cannot open shortcuts\n");
            return;
            }

      XmlReader e(&f);

      QString key;
      while (e.readNextStartElement()) {
            if (e.name() == "Shortcuts") {
                  while (e.readNextStartElement()) {
                        if (e.name() == "SC") {
                              Shortcut* sc = 0;
                              while (e.readNextStartElement()) {
                                    const QStringRef& tag(e.name());
                                    if (tag == "key") {
                                          QString val(e.readElementText());
                                          sc = getShortcut(val.toLatin1().data());
                                          if (!sc) {
                                                printf("cannot find shortcut <%s>\n", qPrintable(val));
                                                break;
                                                }
                                          sc->clear();
                                          }
                                    else if (tag == "std")
                                          sc->_standardKey = QKeySequence::StandardKey(e.readInt());
                                    else if (tag == "seq")
                                          sc->_keys.append(QKeySequence::fromString(e.readElementText(), QKeySequence::PortableText));
                                    else if (tag == "code")
                                          sc->_keys.append(QKeySequence(e.readInt()));
                                    else
                                          e.unknown();
                                    }
                              }
                        else
                              e.unknown();
                        }
                  }
            else
                  e.unknown();
            }
      dirty = false;
      }
Exemplo n.º 13
0
/*!
    Removes the knowledge about a shortcut under the specified \a id.

    Usually you do not need to unregister shortcuts. The only valid use case for unregistering
    shortcuts, is for shortcuts that represent user definable actions. If the user removes such an action,
    a corresponding shortcut also has to be unregistered from the action manager,
    to make it disappear from shortcut settings etc.
*/
void ActionManager::unregisterShortcut(Id id)
{
    Shortcut *sc = 0;
    CommandPrivate *c = d->m_idCmdMap.value(id, 0);
    QTC_ASSERT(c, return);
    sc = qobject_cast<Shortcut *>(c);
    if (!sc) {
        qWarning() << "unregisterShortcut: id" << id.name()
                   << "is registered with a different command type.";
        return;
    }
    delete sc->shortcut();
    d->m_idCmdMap.remove(id);
    delete sc;
    emit m_instance->commandListChanged();
}
Exemplo n.º 14
0
void Shortcut::Init(){
	lastkb = NULL;

	// install defaults
	InstallDefaults();

	YPreferences prefs(SETTINGS_DIR"/KeyBindings");
	if(prefs.InitCheck() == B_OK){
		// Init from prefs file
		const char *ID = NULL;
		int32 key, keyAlt;
		int32 mod, modAlt;
		uint32 message;
		bool menuItem;
		int32 i = 0;
		while(prefs.FindString("IkbID",i,&ID) == B_OK){
			if(prefs.FindInt32("IkbKey",i,&key) != B_OK)			key = 0;
			if(prefs.FindInt32("IkbMod",i,&mod) != B_OK)					mod = 0;
			if(prefs.FindInt32("IkbKeyAlt",i,&keyAlt) != B_OK)		keyAlt = 0;
			if(prefs.FindInt32("IkbModAlt",i,&modAlt) != B_OK)				modAlt = 0;
			if(prefs.FindInt32("IkbMessage",i,(int32*)&message) != B_OK)	message = 0;
			if(prefs.FindBool("IkbMenu",i,&menuItem) != B_OK)				menuItem = 0;

			char *I = new char[strlen(ID)+1]; strcpy(I,ID);
			KeyBind.Install(menuItem, I, key, mod, keyAlt, modAlt, message);
			i++;
		}
	}
}
Exemplo n.º 15
0
void Shortcut::save()
      {
      QFile f(dataPath + "/shortcuts.xml");
      if (!f.open(QIODevice::WriteOnly)) {
            qDebug("cannot save shortcuts");
            return;
            }
      Xml xml(&f);
      xml.header();
      xml.stag("Shortcuts");
      for (unsigned i = 0;; ++i) {
            Shortcut* s = &sc[i];
            if (s->_key == 0)
                  break;
            s->write(xml);
            }
      xml.etag();
      f.close();
      }
Exemplo n.º 16
0
tools::Tool* get_selected_quicktool(tools::Tool* currentTool)
{
    if (currentTool && currentTool->getInk(0)->isSelection()) {
        Accelerator* copyselection_accel = get_accel_to_copy_selection();
        if (copyselection_accel && copyselection_accel->checkFromAllegroKeyArray())
            return NULL;
    }

    tools::ToolBox* toolbox = App::instance()->getToolBox();

    // Iterate over all tools
    for (tools::ToolIterator it = toolbox->begin(); it != toolbox->end(); ++it) {
        Shortcut* shortcut = get_keyboard_shortcut_for_quicktool(*it);

        // Collect all tools with the pressed keyboard-shortcut
        if (shortcut && shortcut->is_pressed_from_key_array()) {
            return *it;
        }
    }

    return NULL;
}
Exemplo n.º 17
0
Command *ActionManagerPrivate::registerShortcut(QShortcut *shortcut, const QString &id, const QList<int> &context)
{
    Shortcut *sc = 0;
    int uid = UniqueIDManager::instance()->uniqueIdentifier(id);

    if (CommandPrivate * c = m_idCmdMap.value(uid, 0)) {
        sc = qobject_cast<Shortcut *>(c);
        if (!sc) {
            qWarning() << "registerShortcut: id" << id << "is registered with a different command type.";
            return c;
        }
    } else {
        sc = new Shortcut(uid);
        m_idCmdMap.insert(uid, sc);
    }

    if (sc->shortcut()) {
        qWarning() << "registerShortcut: action already registered (id" << id << ".";
        return sc;
    }

    if (!hasContext(context)) {
        shortcut->setEnabled(false);
    }
    shortcut->setObjectName(id);
    shortcut->setParent(m_mainWnd);
    sc->setShortcut(shortcut);

    if (context.isEmpty()) {
        sc->setContext(QList<int>() << 0);
    } else {
        sc->setContext(context);
    }

    sc->setKeySequence(shortcut->key());
    sc->setDefaultKeySequence(QKeySequence());

    return sc;
}
/*!
    \brief Makes a \a shortcut known to the system under the specified \a id.

    Returns a command object that represents the shortcut in the application and is
    owned by the ActionManager. You can registered several shortcuts with the
    same \a id as long as the \a context is different. In this case
    a trigger of the actual shortcut is forwarded to the registered QShortcut
    for the currently active context.
    A scriptable shortcut can be called from a script without the need for the user
    to interact with it.
*/
Command *ActionManager::registerShortcut(QShortcut *shortcut, const Id &id, const Context &context, bool scriptable)
{
    Shortcut *sc = 0;
    if (CommandPrivate *c = m_instance->d->m_idCmdMap.value(id, 0)) {
        sc = qobject_cast<Shortcut *>(c);
        if (!sc) {
            qWarning() << "registerShortcut: id" << id.name()
                       << "is registered with a different command type.";
            return c;
        }
    } else {
        sc = new Shortcut(id);
        m_instance->d->m_idCmdMap.insert(id, sc);
    }

    if (sc->shortcut()) {
        qWarning() << "registerShortcut: action already registered, id" << id.name() << ".";
        return sc;
    }

    if (!m_instance->d->hasContext(context))
        shortcut->setEnabled(false);
    shortcut->setObjectName(id.toString());
    shortcut->setParent(ICore::mainWindow());
    sc->setShortcut(shortcut);
    sc->setScriptable(scriptable);

    if (context.isEmpty())
        sc->setContext(Context(0));
    else
        sc->setContext(context);

    emit m_instance->commandListChanged();
    emit m_instance->commandAdded(id.toString());

    if (isPresentationModeEnabled())
        connect(sc->shortcut(), SIGNAL(activated()), m_instance->d, SLOT(shortcutTriggered()));
    return sc;
}
Exemplo n.º 19
0
void Kernel::bindShortcut(string argument) {

    unsigned int argDelim = argument.find_first_of('+');
    if (argDelim == string::npos) {
        return;
    }
    string bind = argument.substr(0, argDelim);
    string keys = argument.substr(argDelim + 1);

    Action *action = Util::get(actionBindings_, bind);

    if (action) {
        Shortcut *oldShortcut = action->shortcut();
        if (oldShortcut) {
            bool doUngrab = true;
            for (MBindings::iterator it = actionBindings_->begin();
                    it != actionBindings_->end(); it++)
            {
                Action *action = (*it).second;
                Shortcut *s = action->listenOn();
                if (s &&
                    (s->modMask() == oldShortcut->modMask()) &&
                    (s->keyCode() == oldShortcut->keyCode()) &&
                    (s->button() == oldShortcut->button()))
                {
                    doUngrab = false;
                    break;
                }
            }
            if (doUngrab) {
                ungrabShortcutOnAllMonitors(oldShortcut);
            }
            delete oldShortcut;
        }

        string prefix;
        switch (action->type()) {
        case Action::INTERN:
            prefix = "intern.";
            break;
        case Action::EXTERN:
            prefix = "extern.";
            break;
        case Action::SEQUENCE:
            prefix = "chain.";
            break;
        case Action::UNKNOWN:
            prefix = "unknown.";
            break;
        }

        if (keys == "") {
            Util::remove(actionSettings_, prefix + bind + ".keys");
            return;
        }
        action->setShortcut(Shortcut::shortcut(keys));

        (*actionSettings_)[prefix + bind + ".keys"] = keys;
        if (action->listenOn()) {
            grabShortcutOnAllMonitors(action->listenOn());
        }
    }
}
Exemplo n.º 20
0
// Manager event handler.
bool CustomizedGuiManager::onProcessMessage(Message* msg)
{
    switch (msg->type()) {

    case kCloseAppMessage:
    {
        // Execute the "Exit" command.
        Command* command = CommandsModule::instance()->getCommandByName(CommandId::Exit);
        UIContext::instance()->executeCommand(command);
    }
    break;

    case kDropFilesMessage:
    {
        // If the main window is not the current foreground one. We
        // discard the drop-files event.
        if (getForegroundWindow() != App::instance()->getMainWindow())
            break;

        const DropFilesMessage::Files& files = static_cast<DropFilesMessage*>(msg)->files();

        // Open all files
        Command* cmd_open_file =
            CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
        Params params;

        for (DropFilesMessage::Files::const_iterator
                it = files.begin(); it != files.end(); ++it) {
            params.set("filename", it->c_str());
            UIContext::instance()->executeCommand(cmd_open_file, &params);
        }
    }
    break;

    case kQueueProcessingMessage:
        gui_feedback();
        break;

    case kKeyDownMessage: {
        Window* toplevel_window = getTopWindow();

        // If there is a foreground window as top level...
        if (toplevel_window &&
                toplevel_window != App::instance()->getMainWindow() &&
                toplevel_window->isForeground()) {
            // We just do not process keyboard shortcuts for menus and tools
            break;
        }

        for (Shortcut* shortcut : *shortcuts) {
            if (shortcut->is_pressed(msg)) {
                // Cancel menu-bar loops (to close any popup menu)
                App::instance()->getMainWindow()->getMenuBar()->cancelMenuLoop();

                switch (shortcut->type) {

                case Shortcut::Type::ChangeTool: {
                    tools::Tool* current_tool = UIContext::instance()->settings()->getCurrentTool();
                    tools::Tool* select_this_tool = shortcut->tool;
                    tools::ToolBox* toolbox = App::instance()->getToolBox();
                    std::vector<tools::Tool*> possibles;

                    // Iterate over all tools
                    for (tools::ToolIterator it = toolbox->begin(); it != toolbox->end(); ++it) {
                        Shortcut* shortcut = get_keyboard_shortcut_for_tool(*it);

                        // Collect all tools with the pressed keyboard-shortcut
                        if (shortcut && shortcut->is_pressed(msg))
                            possibles.push_back(*it);
                    }

                    if (possibles.size() >= 2) {
                        bool done = false;

                        for (size_t i=0; i<possibles.size(); ++i) {
                            if (possibles[i] != current_tool &&
                                    ToolBar::instance()->isToolVisible(possibles[i])) {
                                select_this_tool = possibles[i];
                                done = true;
                                break;
                            }
                        }

                        if (!done) {
                            for (size_t i=0; i<possibles.size(); ++i) {
                                // If one of the possibilities is the current tool
                                if (possibles[i] == current_tool) {
                                    // We select the next tool in the possibilities
                                    select_this_tool = possibles[(i+1) % possibles.size()];
                                    break;
                                }
                            }
                        }
                    }

                    ToolBar::instance()->selectTool(select_this_tool);
                    return true;
                }

                case Shortcut::Type::ExecuteCommand: {
                    Command* command = shortcut->command;

                    // Commands are executed only when the main window is
                    // the current window running at foreground.
                    UI_FOREACH_WIDGET(getChildren(), it) {
                        Window* child = static_cast<Window*>(*it);

                        // There are a foreground window executing?
                        if (child->isForeground()) {
                            break;
                        }
                        // Is it the desktop and the top-window=
                        else if (child->isDesktop() && child == App::instance()->getMainWindow()) {
                            // OK, so we can execute the command represented
                            // by the pressed-key in the message...
                            UIContext::instance()->executeCommand(command, shortcut->params);
                            return true;
                        }
                    }
                    break;
                }

                case Shortcut::Type::EditorQuicktool: {
                    // Do nothing, it is used in the editor through the
                    // get_selected_quicktool() function.
                    break;
                }

                }
                break;
            }
        }
        break;
    }
Exemplo n.º 21
0
QAction* getAction(const char* id)
      {
      Shortcut* s = Shortcut::getShortcut(id);
      return s->action();
      }