From kde-commits Wed Jul 02 08:50:25 2008 From: David Capel Date: Wed, 02 Jul 2008 08:50:25 +0000 To: kde-commits Subject: branches/work/soc-parley/parley/src/practice Message-Id: <1214988625.300663.9361.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=121498887512613 SVN commit 827077 by capel: Made the mc theme more usable Made shortcuts work in MC -- Alt+n and n both work (with n in [1,9]) This puts an upper limit of 9 answers for the number of MC answers. Return/Enter now functions similarly to how written works -- however, if you haven't selected an answer yet, it does nothing. Some general code cleanup. TODO: make MC prettier (maybe?); make Parley hide when parleypractice is shown. M +29 -3 input.cpp M +2 -0 input.h M +33 -2 parleypracticemainwindow.cpp M +9 -0 parleypracticeui.rc M themes/default_theme_mc.svgz --- branches/work/soc-parley/parley/src/practice/input.cpp #827076:827077 @@ -96,10 +96,38 @@ QRect bounds = m_renderer->boundsOnElement(elementId).toRect(); setGeometry(view->mapToScene(bounds).boundingRect().toRect()); + } +void MultipleChoiceInput::slotShortcutTriggered(int shortcutNumber) +{ + if (shortcutNumber > Prefs::numberMultipleChoiceAnswers()) + return; // bogus false positive + // Shortcut number 0 is triggered by return/enter and is used for activating the currently selected option. + // Therefore, we check if any buttons are checked, and if so, emit the signal + // if none are checked, we ignore this shortcut + if (shortcutNumber == 0) + // we emit only if a button is checked + foreach(QRadioButton* b, findChildren()) + if (b->isChecked()) + { + emit triggered(); + return; + } + foreach(QRadioButton* b, findChildren()) + { + if (b->text().startsWith(QString("&%1 ").arg(shortcutNumber))) + { + b->setChecked(true); + emit triggered(); + return; + } + } + // we didn't find anything. +} + void MultipleChoiceInput::slotSetAnswers(PracticeEntry* currentEntry, const QList source) { @@ -202,9 +230,7 @@ foreach(QRadioButton* b, findChildren()) if (b->isChecked()) { - kDebug() << "found it"; - // screw regexps ;) - emit signalAnswer(b->text().replace("&1 ", "").replace("&2 ", "").replace("&3 ", "").replace("&4 ", "").replace("&5 ", "").replace("&6 ", "").replace("&7 ", "").replace("&8 ", "").replace("&9 ", "")); + emit signalAnswer(b->text().remove(QRegExp("^&\\d "))); } emit signalAnswer(""); // none were selected. } --- branches/work/soc-parley/parley/src/practice/input.h #827076:827077 @@ -60,9 +60,11 @@ public slots: void slotEmitAnswer(); void slotSetAnswers(PracticeEntry*, QList); + void slotShortcutTriggered(int shortcutNumber); signals: void signalAnswer(const QString& answer); + void triggered(); private: KSvgRenderer* m_renderer; --- branches/work/soc-parley/parley/src/practice/parleypracticemainwindow.cpp #827076:827077 @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "practiceview.h" #include "input.h" @@ -201,6 +203,7 @@ if (!Prefs::showHints()) hintAction->setVisible(false); + KStandardAction::preferences(this, SLOT(slotCreatePreferencesDialog()), actionCollection()); @@ -316,8 +319,7 @@ StdButton * stdbutton = new StdButton(i18n("Check Answer"), m_renderer, m_view, "check_answer_and_continue_button"); m_scene->addWidget(stdbutton); - // TODO somehow get some form of keyboard input working. - // connect(input, SIGNAL(returnPressed()), stdbutton, SLOT(slotActivated())); + connect(input, SIGNAL(triggered()), stdbutton, SLOT(slotActivated())); connect(this, SIGNAL(signalCheckAnswerContinueActionsToggled(int)), stdbutton, SLOT(slotToggleText(int))); connect(stdbutton, SIGNAL(signalCheckAnswer()), actionCollection()->action("check answer"), SIGNAL(triggered())); connect(stdbutton, SIGNAL(signalContinue()), actionCollection()->action("continue"), SIGNAL(triggered())); @@ -342,4 +344,33 @@ connect(input, SIGNAL(signalInput(const QString&)), timer, SLOT(slotStop())); } + // setup shortcuts for multiple choice input + QSignalMapper * mapper = new QSignalMapper(this); + KAction * shortcut; + for(int n = 1; n < 10; ++n) + { + shortcut = new KAction(this); + shortcut->setText(i18n("Select Option %1", n)); + actionCollection()->addAction(QString("select option %1").arg(n), shortcut); + shortcut->setShortcut(KShortcut(QString("%1; Alt+%1").arg(n))); + mapper->setMapping(shortcut, n); + connect(shortcut, SIGNAL(triggered()), mapper, SLOT(map())); + if (n > Prefs::numberMultipleChoiceAnswers()) + shortcut->setVisible(false); // disable non-relevent shortcuts + } + + + // enter/return triggers shortcut 0, which means use the currently selected option + // if no option is selected, this is ignored. + QShortcut* accelerator = new QShortcut(Qt::Key_Enter, this); + accelerator->setAutoRepeat(false); + mapper->setMapping(accelerator, 0); + connect(accelerator, SIGNAL(activated()), mapper, SLOT(map())); + + accelerator = new QShortcut(Qt::Key_Return, this); + accelerator->setAutoRepeat(false); + mapper->setMapping(accelerator, 0); + connect(accelerator, SIGNAL(activated()), mapper, SLOT(map())); + + connect(mapper, SIGNAL(mapped(int)), input, SLOT(slotShortcutTriggered(int))); } --- branches/work/soc-parley/parley/src/practice/parleypracticeui.rc #827076:827077 @@ -8,6 +8,15 @@ + + + + + + + + + Hint