void switchToNextMode(ClickRecognizerRef recognizer, void *context) { if (currentMode == ModeIdle || currentMode == ModePause) { switchToMode(ModePrepare); } else if (currentMode == ModePrepare || currentMode == ModeSport) { switchToMode(ModeIdle); } }
void restartPrepare(ClickRecognizerRef recognizer, void *context) { if (currentMode == ModePrepare || currentMode == ModeSport) { switchToMode(ModePrepare); } else if (currentMode == ModePause) { currentTimer += sportLength; updateClock(); } }
void ModeSwitchPlugin::update(ViewerPtr viewer) { if ( isFocused() ) { if ( mSwitchButton() ) { unsigned int new_mode(0); if ( mMaxMode != 0 ) { new_mode = (mCurrentMode + 1) % (mMaxMode + 1); } switchToMode(new_mode, viewer); } } typedef std::vector<PluginData>::iterator iter_type; for ( iter_type i = mPlugins.begin(); i != mPlugins.end(); ++i ) { (*i).mPlugin->update(viewer); } }
UBTeacherGuidePageZeroWidget::UBTeacherGuidePageZeroWidget(UBTGModel* pModel, QWidget* parent, const char* name) : QWidget(parent) , mpLayout(NULL) , mpButtonTitleLayout(NULL) , mpContainerWidgetLayout(NULL) , mpModePushButton(NULL) , mpPageNumberLabel(NULL) , mpScrollArea(NULL) , mpContainerWidget(NULL) , mpSessionTitle(NULL) , mpSeparatorSessionTitle(NULL) , mpAuthorsLabel(NULL) , mpAuthors(NULL) , mpSeparatorAuthors(NULL) , mpCreationLabel(NULL) , mpLastModifiedLabel(NULL) , mpObjectivesLabel(NULL) , mpObjectives(NULL) , mpSeparatorObjectives(NULL) , mpIndexLabel(NULL) , mpKeywordsLabel(NULL) , mpKeywords(NULL) , mpSchoolLevelItemLabel(NULL) , mpSchoolLevelBox(NULL) , mpSchoolLevelValueLabel(NULL) , mpSchoolSubjectsItemLabel(NULL) , mpSchoolSubjectsBox(NULL) , mpSchoolSubjectsValueLabel(NULL) , mpSchoolTypeItemLabel(NULL) , mpSchoolTypeBox(NULL) , mpSchoolTypeValueLabel(NULL) , mpSeparatorIndex(NULL) , mpLicenceLabel(NULL) , mpLicenceBox( NULL) , mpLicenceIcon(NULL) , mpLicenceLayout(NULL) , mpModel(pModel) //, mpSceneItemSessionTitle(NULL) { QWidget::setObjectName(name); QString chapterStyle("QLabel {font-size:16px; font-weight:bold;}"); mpLayout = new QVBoxLayout(0); setLayout(mpLayout); mpPageNumberLabel = new QLabel(this); mpPageNumberLabel->setAlignment(Qt::AlignRight); mpPageNumberLabel->setObjectName("UBTGPageNumberLabel"); mpPageNumberLabel->setText(tr("Title page")); mpLayout->addWidget(mpPageNumberLabel); mpScrollArea = new QScrollArea(); mpScrollArea->setFocusPolicy(Qt::NoFocus); mpContainerWidget = new QWidget(); mpContainerWidget->setFocusPolicy(Qt::NoFocus); mpContainerWidgetLayout = new QVBoxLayout(); mpLayout->addWidget(mpScrollArea); mpScrollArea->setWidget(mpContainerWidget); mpScrollArea->setWidgetResizable(true); mpScrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mpContainerWidget->setLayout(mpContainerWidgetLayout); mpButtonTitleLayout = new QHBoxLayout(0); mpModePushButton = new QPushButton(this); mpModePushButton->setIcon(QIcon(":images/teacherGuide/pencil.svg")); mpModePushButton->setMaximumWidth(32); mpModePushButton->installEventFilter(this); mpButtonTitleLayout->addWidget(mpModePushButton); connect(mpModePushButton, SIGNAL(clicked()), this, SLOT(switchToMode())); mpSessionTitle = new UBTGAdaptableText(0, this, "UBTGSessionTitle"); mpSessionTitle->setPlaceHolderText(tr("Type session title here ...")); mpSessionTitle->setMaximumLength(1000); mpButtonTitleLayout->addWidget(mpSessionTitle); connect(this, SIGNAL(resized()), mpSessionTitle, SLOT(onTextChanged())); mpContainerWidgetLayout->addLayout(mpButtonTitleLayout); mpSeparatorSessionTitle = new QFrame(this); mpSeparatorSessionTitle->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorSessionTitle->setObjectName("UBTGSeparator"); mpContainerWidgetLayout->addWidget(mpSeparatorSessionTitle); mpAuthorsLabel = new QLabel(this); mpAuthorsLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpAuthorsLabel->setText(tr("Author(s)")); mpAuthorsLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpAuthorsLabel); mpAuthors = new UBTGAdaptableText(0, this); mpAuthors->setObjectName("UBTGZeroPageInputText"); mpAuthors->setPlaceHolderText(tr("Type authors here ...")); mpContainerWidgetLayout->addWidget(mpAuthors); connect(this, SIGNAL(resized()), mpAuthors, SLOT(onTextChanged())); mpCreationLabel = new QLabel(this); mpCreationLabel->setObjectName("UBTGZeroPageDateLabel"); mpCreationLabel->setText(tr("Creation date:")); mpContainerWidgetLayout->addWidget(mpCreationLabel); mpLastModifiedLabel = new QLabel(this); mpLastModifiedLabel->setObjectName("UBTGZeroPageDateLabel"); mpLastModifiedLabel->setText(tr("Last Modified:")); mpContainerWidgetLayout->addWidget(mpLastModifiedLabel); mpSeparatorAuthors = new QFrame(this); mpSeparatorAuthors->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorAuthors->setObjectName("UBTGSeparator"); mpContainerWidgetLayout->addWidget(mpSeparatorAuthors); mpObjectivesLabel = new QLabel(this); mpObjectivesLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpObjectivesLabel->setText(tr("Objective(s)")); mpObjectivesLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpObjectivesLabel); mpObjectives = new UBTGAdaptableText(0, this); mpObjectives->setObjectName("UBTGZeroPageInputText"); mpObjectives->setPlaceHolderText(tr("Type objectives here...")); mpContainerWidgetLayout->addWidget(mpObjectives); connect(this, SIGNAL(resized()), mpObjectives, SLOT(onTextChanged())); mpSeparatorObjectives = new QFrame(this); mpSeparatorObjectives->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorObjectives->setObjectName("UBTGSeparator"); mpContainerWidgetLayout->addWidget(mpSeparatorObjectives); mpIndexLabel = new QLabel(this); mpIndexLabel->setObjectName("UBTGZeroPageEditionModeTitle"); mpIndexLabel->setText(tr("Resource indexing")); mpIndexLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpIndexLabel); mpKeywordsLabel = new QLabel(this); mpKeywordsLabel->setObjectName("UBTGZeroPageItemLabel"); mpKeywordsLabel->setText(tr("Keywords:")); mpKeywordsLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpKeywordsLabel); mpKeywords = new UBTGAdaptableText(0, this); mpKeywords->setPlaceHolderText(tr("Type keywords here ...")); mpContainerWidgetLayout->addWidget(mpKeywords); connect(this, SIGNAL(resized()), mpKeywords, SLOT(onTextChanged())); mpSchoolLevelItemLabel = new QLabel(this); mpSchoolLevelItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolLevelItemLabel->setText(tr("Level:")); mpSchoolLevelItemLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpSchoolLevelItemLabel); mpSchoolLevelBox = new QComboBox(this); mpSchoolLevelBox->setMinimumHeight(22); mpSchoolLevelBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpSchoolLevelBox->setObjectName("DockPaletteWidgetComboBox"); connect(mpSchoolLevelBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(onSchoolLevelChanged(QString))); mpContainerWidgetLayout->addWidget(mpSchoolLevelBox); mpSchoolLevelValueLabel = new QLabel(this); mpContainerWidgetLayout->addWidget(mpSchoolLevelValueLabel); mpSchoolSubjectsItemLabel = new QLabel(this); mpSchoolSubjectsItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolSubjectsItemLabel->setText(tr("Subjects:")); mpSchoolSubjectsItemLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpSchoolSubjectsItemLabel); mpSchoolSubjectsBox = new QComboBox(this); mpSchoolSubjectsBox->setMinimumHeight(22); mpSchoolSubjectsBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpSchoolSubjectsBox->setObjectName("DockPaletteWidgetComboBox"); mpContainerWidgetLayout->addWidget(mpSchoolSubjectsBox); mpSchoolSubjectsValueLabel = new QLabel(this); mpContainerWidgetLayout->addWidget(mpSchoolSubjectsValueLabel); mpSchoolTypeItemLabel = new QLabel(this); mpSchoolTypeItemLabel->setObjectName("UBTGZeroPageItemLabel"); mpSchoolTypeItemLabel->setText(tr("Type:")); mpSchoolTypeItemLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpSchoolTypeItemLabel); mpSchoolTypeBox = new QComboBox(this); mpSchoolTypeBox->setMinimumHeight(22); mpSchoolTypeBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpSchoolTypeBox->setObjectName("DockPaletteWidgetComboBox"); mpContainerWidgetLayout->addWidget(mpSchoolTypeBox); mpSchoolTypeValueLabel = new QLabel(this); mpContainerWidgetLayout->addWidget(mpSchoolTypeValueLabel); mpSeparatorIndex = new QFrame(this); mpSeparatorIndex->setFixedHeight(UBTG_SEPARATOR_FIXED_HEIGHT); mpSeparatorIndex->setObjectName("UBTGSeparator"); mpContainerWidgetLayout->addWidget(mpSeparatorIndex); mpLicenceLabel = new QLabel(this); mpLicenceLabel->setObjectName("UBTGZeroPageItemLabel"); mpLicenceLabel->setText(tr("Licence")); mpLicenceLabel->setStyleSheet(chapterStyle); mpContainerWidgetLayout->addWidget(mpLicenceLabel); mpLicenceBox = new QComboBox(this); mpLicenceBox->setMinimumHeight(22); mpLicenceBox->setMinimumWidth(LOWER_RESIZE_WIDTH); mpLicenceBox->setObjectName("DockPaletteWidgetComboBox"); mpContainerWidgetLayout->addWidget(mpLicenceBox); mpLicenceLayout = new QHBoxLayout(0); mpLicenceIcon = new QLabel(this); mpLicenceIcon->setMinimumWidth(LOWER_RESIZE_WIDTH/2); mpLicenceLayout->addWidget(mpLicenceIcon); mpLicenceValueLabel = new QLabel(this); mpLicenceValueLabel->setMinimumWidth(LOWER_RESIZE_WIDTH/2); mpLicenceLayout->addWidget(mpLicenceValueLabel); mpContainerWidgetLayout->addLayout(mpLicenceLayout); mpContainerWidgetLayout->addStretch(1); //connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), this, SLOT(onActiveSceneChanged())); fillComboBoxes(); // Register the metadatas // addMetaData(nameSpace(), UBSettings::sessionTitle, mpSessionTitle->text()); // addMetaData(nameSpace(), UBSettings::sessionAuthors, mpAuthors->text()); // addMetaData(nameSpace(), UBSettings::sessionObjectives, mpObjectives->text()); // addMetaData(nameSpace(), UBSettings::sessionKeywords, mpKeywords->text()); // addMetaData(nameSpace(), UBSettings::sessionGradeLevel, mpSchoolLevelBox->currentText()); // addMetaData(nameSpace(), UBSettings::sessionSubjects, mpSchoolSubjectsBox->currentText()); // addMetaData(nameSpace(), UBSettings::sessionType, mpSchoolTypeBox->currentText()); // addMetaData(nameSpace(), UBSettings::sessionLicence, QString("%0").arg(mpLicenceBox->currentIndex())); // UBApplication::documentController->currentDocument()->registerMetaDataProvider(this); }
viewer::PluginPtr ModeSwitchPlugin::init(ViewerPtr viewer) { const std::string plugin_path_prop("plugin_path"); const std::string plugins_prop("plugins"); const std::string mode_names_prop("mode_names"); const std::string swap_button_prop("swap_button_nums"); const std::string mode_plugin_type("mode_plugin_def"); const std::string active_modes_prop("active_modes"); const std::string plugin_prop("plugin"); const unsigned int req_cfg_version(2); InterfaceTrader& if_trader = viewer->getUser()->getInterfaceTrader(); mWandInterface = if_trader.getWandInterface(); // -- Configure -- // std::string elt_type_name = getElementType(); jccl::ConfigElementPtr elt = viewer->getConfiguration().getConfigElement(elt_type_name); if ( ! elt ) { throw PluginException("ModeSwitchPlugin not find its configuration.", VRKIT_LOCATION); } vprASSERT(elt->getID() == getElementType()); // Check for correct version of plug-in configuration. if ( elt->getVersion() < req_cfg_version ) { std::ostringstream msg; msg << "ModeSwitchPlugin: Configuration failed. Required cfg version: " << req_cfg_version << " found:" << elt->getVersion(); throw PluginException(msg.str(), VRKIT_LOCATION); } // ---- Process configuration --- // mMaxMode = 0; // -- Setup the plug-in search path -- // std::vector<std::string> search_path; const unsigned int num_paths(elt->getNum(plugin_path_prop)); for ( unsigned int i = 0; i < num_paths; ++i ) { search_path.push_back( elt->getProperty<std::string>(plugin_path_prop, i) ); } const std::vector<vpr::LibraryPtr> modules = plugin::findModules(search_path); std::for_each( modules.begin(), modules.end(), boost::bind(&ModeSwitchPlugin::registerModule, this, _1, viewer) ); // Get the button for swapping mSwitchButton.configure(elt->getProperty<std::string>(swap_button_prop), mWandInterface); // Get mode names const unsigned int num_mode_names(elt->getNum(mode_names_prop)); mMaxMode = num_mode_names - 1; for ( unsigned int i = 0; i < num_mode_names; ++i ) { mModeNames.push_back(elt->getProperty<std::string>(mode_names_prop, i)); } // --- Load the managed plug-ins --- // const unsigned int num_plugins(elt->getNum(plugins_prop)); VRKIT_STATUS << "[Mode Switch Plug-in] Found " << num_plugins << " plug-ins to load." << std::endl; plugin::RegistryPtr plugin_registry = viewer->getPluginRegistry(); // Attempt to load each plug-in // - Get creator and create plug-in // - Push onto plug-in list for ( unsigned int i = 0; i < num_plugins; ++i ) { PluginData plugin_data; jccl::ConfigElementPtr plg_elt = elt->getProperty<jccl::ConfigElementPtr>(plugins_prop, i); plugin_data.mName = plg_elt->getProperty<std::string>(plugin_prop); try { std::cout << " Loading plug-in: " << plugin_data.mName << " ... " << std::flush; std::vector<AbstractPluginPtr> deps; AbstractPluginPtr p = plugin_registry->makeInstance(plugin_data.mName, deps); std::vector<PluginData> plugins; plugins.reserve(deps.size() + 1); typedef std::vector<AbstractPluginPtr>::iterator iter_type; for ( iter_type d = deps.begin(); d != deps.end(); ++d ) { viewer::PluginPtr cur_dep = boost::dynamic_pointer_cast<viewer::Plugin>(*d); if ( cur_dep ) { PluginData dep_data; dep_data.mName = cur_dep->getInfo().getName(); dep_data.mPlugin = cur_dep; plugins.push_back(dep_data); } } plugin_data.mPlugin = boost::dynamic_pointer_cast<Plugin>(p); if ( ! plugin_data.mPlugin ) { std::ostringstream msg_stream; msg_stream << "Invalid plug-in type '" << p->getInfo().getFullName() << "' given as plug-in for the Mode Switch Plug-in!"; throw PluginException(msg_stream.str(), VRKIT_LOCATION); } plugins.push_back(plugin_data); const unsigned int num_active_modes = plg_elt->getNum(active_modes_prop); for ( unsigned int m = 0; m < num_active_modes; ++m ) { const unsigned int mode_num = plg_elt->getProperty<unsigned int>(active_modes_prop, m); if ( mode_num > mMaxMode ) { mMaxMode = mode_num; } typedef std::vector<PluginData>::iterator piter_type; for ( piter_type p = plugins.begin(); p != plugins.end(); ++p ) { (*p).mActiveModes.push_back(mode_num); } } mPlugins.insert(mPlugins.end(), plugins.begin(), plugins.end()); std::cout << "[OK]" << std::endl; } catch (std::runtime_error& ex) { std::cerr << "[FAILED]\n" << "WARNING: ModeSwitchPlugin failed to load plug-in '" << plugin_data.mName << "': " << ex.what() << std::endl; } } // Make sure we have enough mode names to match up with the number of modes. if ( mMaxMode >= mModeNames.size() ) { mModeNames.resize(mMaxMode + 1, std::string("Unknown Mode")); } switchToMode(0, viewer); return shared_from_this(); }