comparison main/MainWindow.cpp @ 36:da7a3828727f

* Pull alphabetical categorisation code out into a SubdividingMenu class
author Chris Cannam
date Mon, 25 Sep 2006 11:21:12 +0000
parents 8ad306d8a568
children 8cd725696138
comparison
equal deleted inserted replaced
35:06787742542a 36:da7a3828727f
35 #include "widgets/PropertyBox.h" 35 #include "widgets/PropertyBox.h"
36 #include "widgets/PropertyStack.h" 36 #include "widgets/PropertyStack.h"
37 #include "widgets/AudioDial.h" 37 #include "widgets/AudioDial.h"
38 #include "widgets/LayerTree.h" 38 #include "widgets/LayerTree.h"
39 #include "widgets/ListInputDialog.h" 39 #include "widgets/ListInputDialog.h"
40 #include "widgets/SubdividingMenu.h"
40 #include "audioio/AudioCallbackPlaySource.h" 41 #include "audioio/AudioCallbackPlaySource.h"
41 #include "audioio/AudioCallbackPlayTarget.h" 42 #include "audioio/AudioCallbackPlayTarget.h"
42 #include "audioio/AudioTargetFactory.h" 43 #include "audioio/AudioTargetFactory.h"
43 #include "data/fileio/AudioFileReaderFactory.h" 44 #include "data/fileio/AudioFileReaderFactory.h"
44 #include "data/fileio/DataFileReaderFactory.h" 45 #include "data/fileio/DataFileReaderFactory.h"
598 TransformFactory::getInstance()->getAllTransformTypes(); 599 TransformFactory::getInstance()->getAllTransformTypes();
599 600
600 map<QString, map<QString, QMenu *> > categoryMenus; 601 map<QString, map<QString, QMenu *> > categoryMenus;
601 map<QString, map<QString, QMenu *> > makerMenus; 602 map<QString, map<QString, QMenu *> > makerMenus;
602 603
603 map<QString, QMenu *> byPluginNameMenus; 604 map<QString, SubdividingMenu *> byPluginNameMenus;
604 map<QString, map<QString, QMenu *> > pluginNameMenus; 605 map<QString, map<QString, QMenu *> > pluginNameMenus;
605 606
606 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms")); 607 m_recentTransformsMenu = m_transformsMenu->addMenu(tr("&Recent Transforms"));
607 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu); 608 m_rightButtonTransformsMenu->addMenu(m_recentTransformsMenu);
608 connect(&m_recentTransforms, SIGNAL(recentChanged()), 609 connect(&m_recentTransforms, SIGNAL(recentChanged()),
656 } 657 }
657 } 658 }
658 } 659 }
659 660
660 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i); 661 QString byPluginNameLabel = tr("%1 by Plugin Name").arg(*i);
661 byPluginNameMenus[*i] = m_transformsMenu->addMenu(byPluginNameLabel); 662 byPluginNameMenus[*i] = new SubdividingMenu(byPluginNameLabel);
663 m_transformsMenu->addMenu(byPluginNameMenus[*i]);
662 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]); 664 m_rightButtonTransformsMenu->addMenu(byPluginNameMenus[*i]);
663 665
664 QString byMakerLabel = tr("%1 by Maker").arg(*i); 666 QString byMakerLabel = tr("%1 by Maker").arg(*i);
665 QMenu *byMakerMenu = m_transformsMenu->addMenu(byMakerLabel); 667 QMenu *byMakerMenu = m_transformsMenu->addMenu(byMakerLabel);
666 m_rightButtonTransformsMenu->addMenu(byMakerMenu); 668 m_rightButtonTransformsMenu->addMenu(byMakerMenu);
677 makerMenus[*i][maker] = byMakerMenu->addMenu(maker); 679 makerMenus[*i][maker] = byMakerMenu->addMenu(maker);
678 } 680 }
679 } 681 }
680 682
681 map<QString, set<QString> > pluginNameLists; 683 map<QString, set<QString> > pluginNameLists;
682 map<QString, map<QString, QMenu *> > pluginNameToChunkMenuMap;
683 684
684 for (unsigned int i = 0; i < transforms.size(); ++i) { 685 for (unsigned int i = 0; i < transforms.size(); ++i) {
685 QString description = transforms[i].description; 686 QString description = transforms[i].description;
686 if (description == "") description = transforms[i].name; 687 if (description == "") description = transforms[i].name;
687 QString type = transforms[i].type; 688 QString type = transforms[i].type;
688 QString pluginName = description.section(": ", 0, 0); 689 QString pluginName = description.section(": ", 0, 0);
689 pluginNameLists[type].insert(pluginName); 690 pluginNameLists[type].insert(tr("%1").arg(pluginName));
690 } 691 }
691 692
692 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) { 693 for (vector<QString>::iterator i = types.begin(); i != types.end(); ++i) {
693 694 byPluginNameMenus[*i]->setEntries(pluginNameLists[*i]);
694 size_t total = pluginNameLists[*i].size();
695 size_t chunk = 14;
696
697 if (total < (chunk * 3) / 2) continue;
698
699 size_t count = 0;
700 QMenu *chunkMenu = new QMenu();
701
702 QString firstNameInChunk;
703 QChar firstInitialInChunk;
704 bool discriminateStartInitial = false;
705
706 for (set<QString>::iterator j = pluginNameLists[*i].begin();
707 j != pluginNameLists[*i].end();
708 ++j) {
709
710 pluginNameToChunkMenuMap[*i][*j] = chunkMenu;
711
712 set<QString>::iterator k = j;
713 ++k;
714
715 QChar initial = (*j)[0];
716
717 if (count == 0) {
718 firstNameInChunk = *j;
719 firstInitialInChunk = initial;
720 }
721
722 bool lastInChunk = (k == pluginNameLists[*i].end() ||
723 (count >= chunk-1 &&
724 (count == (5*chunk) / 2 ||
725 (*k)[0] != initial)));
726
727 ++count;
728
729 if (lastInChunk) {
730
731 bool discriminateEndInitial = (k != pluginNameLists[*i].end() &&
732 (*k)[0] == initial);
733
734 bool initialsEqual = (firstInitialInChunk == initial);
735
736 QString from = QString("%1").arg(firstInitialInChunk);
737 if (discriminateStartInitial ||
738 (discriminateEndInitial && initialsEqual)) {
739 from = firstNameInChunk.left(3);
740 }
741
742 QString to = QString("%1").arg(initial);
743 if (discriminateEndInitial ||
744 (discriminateStartInitial && initialsEqual)) {
745 to = j->left(3);
746 }
747
748 QString menuText;
749
750 if (from == to) menuText = from;
751 else menuText = tr("%1 - %2").arg(from).arg(to);
752
753 discriminateStartInitial = discriminateEndInitial;
754
755 chunkMenu->setTitle(menuText);
756
757 byPluginNameMenus[*i]->addMenu(chunkMenu);
758
759 chunkMenu = new QMenu();
760
761 count = 0;
762 }
763 }
764
765 if (count == 0) delete chunkMenu;
766 } 695 }
767 696
768 for (unsigned int i = 0; i < transforms.size(); ++i) { 697 for (unsigned int i = 0; i < transforms.size(); ++i) {
769 698
770 QString description = transforms[i].description; 699 QString description = transforms[i].description;
813 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl; 742 // cerr << "Transform: \"" << name.toStdString() << "\": plugin name \"" << pluginName.toStdString() << "\"" << endl;
814 743
815 if (pluginNameMenus[type].find(pluginName) == 744 if (pluginNameMenus[type].find(pluginName) ==
816 pluginNameMenus[type].end()) { 745 pluginNameMenus[type].end()) {
817 746
818 QMenu *parentMenu = pluginNameToChunkMenuMap[type][pluginName]; 747 SubdividingMenu *parentMenu = byPluginNameMenus[type];
819 if (!parentMenu) parentMenu = byPluginNameMenus[type];
820 748
821 if (output == "") { 749 if (output == "") {
822 parentMenu->addAction(action); 750 parentMenu->addAction(pluginName, action);
823 } else { 751 } else {
824 pluginNameMenus[type][pluginName] = 752 pluginNameMenus[type][pluginName] =
825 parentMenu->addMenu(pluginName); 753 parentMenu->addMenu(pluginName);
826 connect(this, SIGNAL(canAddLayer(bool)), 754 connect(this, SIGNAL(canAddLayer(bool)),
827 pluginNameMenus[type][pluginName], 755 pluginNameMenus[type][pluginName],