comparison main/MainWindow.cpp @ 37:8cd725696138

* Add a friendlier setup mechanism to SubdividingMenu, and use it for all the plugin menus, not just the by-name and by-maker ones
author Chris Cannam
date Mon, 25 Sep 2006 12:05:41 +0000
parents da7a3828727f
children 5c20bb3e6c94
comparison
equal deleted inserted replaced
36:da7a3828727f 37:8cd725696138
596 TransformFactory::getInstance()->getAllTransforms(); 596 TransformFactory::getInstance()->getAllTransforms();
597 597
598 vector<QString> types = 598 vector<QString> types =
599 TransformFactory::getInstance()->getAllTransformTypes(); 599 TransformFactory::getInstance()->getAllTransformTypes();
600 600
601 map<QString, map<QString, QMenu *> > categoryMenus; 601 map<QString, map<QString, SubdividingMenu *> > categoryMenus;
602 map<QString, map<QString, QMenu *> > makerMenus; 602 map<QString, map<QString, SubdividingMenu *> > makerMenus;
603 603
604 map<QString, SubdividingMenu *> byPluginNameMenus; 604 map<QString, SubdividingMenu *> byPluginNameMenus;
605 map<QString, map<QString, QMenu *> > pluginNameMenus; 605 map<QString, map<QString, QMenu *> > pluginNameMenus;
606
607 set<SubdividingMenu *> pendingMenus;
606 608
607 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms")); 609 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
608 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu); 610 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
609 connect(&m_recentTransforms, SIGNAL(recentChanged()), 611 connect(&m_recentTransforms, SIGNAL(recentChanged()),
610 this, SLOT(setupRecentTransformsMenu())); 612 this, SLOT(setupRecentTransformsMenu()));
618 m_transformsMenu->addSeparator(); 620 m_transformsMenu->addSeparator();
619 m_rightButtonTransformsMenu->addSeparator(); 621 m_rightButtonTransformsMenu->addSeparator();
620 } 622 }
621 623
622 QString byCategoryLabel = tr("%1 by Category").arg(*i); 624 QString byCategoryLabel = tr("%1 by Category").arg(*i);
623 QMenu *byCategoryMenu = m_transformsMenu->addMenu(byCategoryLabel); 625 SubdividingMenu *byCategoryMenu = new SubdividingMenu(byCategoryLabel,
626 20, 40);
627 m_transformsMenu->addMenu(byCategoryMenu);
624 m_rightButtonTransformsMenu->addMenu(byCategoryMenu); 628 m_rightButtonTransformsMenu->addMenu(byCategoryMenu);
629 pendingMenus.insert(byCategoryMenu);
625 630
626 vector<QString> categories = 631 vector<QString> categories =
627 TransformFactory::getInstance()->getTransformCategories(*i); 632 TransformFactory::getInstance()->getTransformCategories(*i);
628 633
629 for (vector<QString>::iterator j = categories.begin(); 634 for (vector<QString>::iterator j = categories.begin();
646 QString parentKey = key; 651 QString parentKey = key;
647 if (key != "") key += " > "; 652 if (key != "") key += " > ";
648 key += *k; 653 key += *k;
649 654
650 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) { 655 if (categoryMenus[*i].find(key) == categoryMenus[*i].end()) {
656 SubdividingMenu *m = new SubdividingMenu(*k, 20, 40);
657 pendingMenus.insert(m);
658 categoryMenus[*i][key] = m;
651 if (parentKey == "") { 659 if (parentKey == "") {
652 categoryMenus[*i][key] = byCategoryMenu->addMenu(*k); 660 byCategoryMenu->addMenu(m);
653 } else { 661 } else {
654 categoryMenus[*i][key] = 662 categoryMenus[*i][parentKey]->addMenu(m);
655 categoryMenus[*i][parentKey]->addMenu(*k);
656 } 663 }
657 } 664 }
658 } 665 }
659 } 666 }
660 667
661 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i); 668 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
662 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel); 669 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
663 m_transformsMenu->addMenu(byPluginNameMenus[*i]); 670 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
664 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]); 671 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
672 pendingMenus.insert(byPluginNameMenus[*i]);
665 673
666 QString byMakerLabel = tr("%1 by Maker").arg(*i); 674 QString byMakerLabel = tr("%1 by Maker").arg(*i);
667 QMenu *byMakerMenu = m_transformsMenu->addMenu(byMakerLabel); 675 SubdividingMenu *byMakerMenu = new SubdividingMenu(byMakerLabel, 20, 40);
676 m_transformsMenu->addMenu(byMakerMenu);
668 m_rightButtonTransformsMenu->addMenu(byMakerMenu); 677 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
678 pendingMenus.insert(byMakerMenu);
669 679
670 vector<QString> makers = 680 vector<QString> makers =
671 TransformFactory::getInstance()->getTransformMakers(*i); 681 TransformFactory::getInstance()->getTransformMakers(*i);
672 682
673 for (vector<QString>::iterator j = makers.begin(); 683 for (vector<QString>::iterator j = makers.begin();
674 j != makers.end(); ++j) { 684 j != makers.end(); ++j) {
675 685
676 QString maker = *j; 686 QString maker = *j;
677 if (maker == "") maker = tr("Unknown"); 687 if (maker == "") maker = tr("Unknown");
678 688
679 makerMenus[*i][maker] = byMakerMenu->addMenu(maker); 689 makerMenus[*i][maker] = new SubdividingMenu(maker, 30, 40);
690 byMakerMenu->addMenu(makerMenus[*i][maker]);
691 pendingMenus.insert(makerMenus[*i][maker]);
680 } 692 }
681 } 693 }
682 694
683 map<QString, set<QString> > pluginNameLists;
684
685 for (unsigned int i = 0; i < transforms.size(); ++i) {
686 QString description = transforms[i].description;
687 if (description == "") description = transforms[i].name;
688 QString type = transforms[i].type;
689 QString pluginName = description.section(": ", 0, 0);
690 pluginNameLists[type].insert(tr("%1").arg(pluginName));
691 }
692
693 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
694 byPluginNameMenus[*i]->setEntries(pluginNameLists[*i]);
695 }
696
697 for (unsigned int i = 0; i < transforms.size(); ++i) { 695 for (unsigned int i = 0; i < transforms.size(); ++i) {
698 696
699 QString description = transforms[i].description; 697 QString description = transforms[i].description;
700 if (description == "") description = transforms[i].name; 698 if (description == "") description = transforms[i].name;
701 699
729 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: " 727 std::cerr << "WARNING: MainWindow::setupMenus: Internal error: "
730 << "No maker menu for transform \"" 728 << "No maker menu for transform \""
731 << description.toStdString() << "\" (maker = \"" 729 << description.toStdString() << "\" (maker = \""
732 << maker.toStdString() << "\")" << std::endl; 730 << maker.toStdString() << "\")" << std::endl;
733 } else { 731 } else {
734 makerMenus[type][maker]->addAction(action); 732 makerMenus[type][maker]->addAction(pluginName, action);
735 } 733 }
736 734
737 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this); 735 action = new QAction(tr("%1...").arg(output == "" ? pluginName : output), this);
738 connect(action, SIGNAL(triggered()), this, SLOT(addLayer())); 736 connect(action, SIGNAL(triggered()), this, SLOT(addLayer()));
739 m_transformActions[action] = transforms[i].name; 737 m_transformActions[action] = transforms[i].name;
759 757
760 if (pluginNameMenus[type].find(pluginName) != 758 if (pluginNameMenus[type].find(pluginName) !=
761 pluginNameMenus[type].end()) { 759 pluginNameMenus[type].end()) {
762 pluginNameMenus[type][pluginName]->addAction(action); 760 pluginNameMenus[type][pluginName]->addAction(action);
763 } 761 }
762 }
763
764 for (set<SubdividingMenu *>::iterator i = pendingMenus.begin();
765 i != pendingMenus.end(); ++i) {
766 (*i)->entriesAdded();
764 } 767 }
765 768
766 setupRecentTransformsMenu(); 769 setupRecentTransformsMenu();
767 770
768 menu = m_paneMenu; 771 menu = m_paneMenu;