Changeset View
Changeset View
Standalone View
Standalone View
src/widgets/structurewidget.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | |||||
60 | #include <QClipboard> | 60 | #include <QClipboard> | ||
61 | #include <QFileInfo> | 61 | #include <QFileInfo> | ||
62 | #include <QIcon> | 62 | #include <QIcon> | ||
63 | #include <QHeaderView> | 63 | #include <QHeaderView> | ||
64 | #include <QMimeDatabase> | 64 | #include <QMimeDatabase> | ||
65 | #include <QMimeType> | 65 | #include <QMimeType> | ||
66 | #include <QRegExp> | 66 | #include <QRegExp> | ||
67 | #include <QScrollBar> | 67 | #include <QScrollBar> | ||
68 | #include <QSignalMapper> | | |||
69 | #include <QUrl> | 68 | #include <QUrl> | ||
70 | 69 | | |||
71 | #include <KLocalizedString> | 70 | #include <KLocalizedString> | ||
72 | #include <KMessageBox> | 71 | #include <KMessageBox> | ||
73 | #include <KRun> | 72 | #include <KRun> | ||
74 | 73 | | |||
75 | #include "documentinfo.h" | 74 | #include "documentinfo.h" | ||
76 | #include "errorhandler.h" | 75 | #include "errorhandler.h" | ||
▲ Show 20 Lines • Show All 666 Lines • ▼ Show 20 Line(s) | |||||
743 | // all popup items get different id's, so that we can see, what item is activated | 742 | // all popup items get different id's, so that we can see, what item is activated | ||
744 | // - label: 1 - 6 | 743 | // - label: 1 - 6 | ||
745 | // - sectioning: 10 - 16 | 744 | // - sectioning: 10 - 16 | ||
746 | // - graphics: 100ff | 745 | // - graphics: 100ff | ||
747 | void StructureWidget::viewContextMenuEvent(StructureView *view, QContextMenuEvent *event) | 746 | void StructureWidget::viewContextMenuEvent(StructureView *view, QContextMenuEvent *event) | ||
748 | { | 747 | { | ||
749 | KILE_DEBUG_MAIN << "\tcalled"; | 748 | KILE_DEBUG_MAIN << "\tcalled"; | ||
750 | 749 | | |||
751 | QSignalMapper signalMapper; | | |||
752 | connect(&signalMapper, SIGNAL(mapped(int)), this, SLOT(slotPopupActivated(int))); | | |||
753 | QMenu popup; | 750 | QMenu popup; | ||
754 | QAction *action = Q_NULLPTR; | | |||
755 | m_showingContextMenu = Q_NULLPTR; | 751 | m_showingContextMenu = Q_NULLPTR; | ||
756 | 752 | | |||
757 | m_popupItem = dynamic_cast<StructureViewItem*>(view->itemAt(event->pos())); | 753 | m_popupItem = dynamic_cast<StructureViewItem*>(view->itemAt(event->pos())); | ||
758 | if(!m_popupItem) { | 754 | if(!m_popupItem) { | ||
759 | KILE_DEBUG_MAIN << "not a pointer to a StructureViewItem object."; | 755 | KILE_DEBUG_MAIN << "not a pointer to a StructureViewItem object."; | ||
760 | return; | 756 | return; | ||
761 | } | 757 | } | ||
762 | 758 | | |||
763 | bool hasLabel = !(m_popupItem->label().isEmpty()); | 759 | bool hasLabel = !(m_popupItem->label().isEmpty()); | ||
764 | 760 | | |||
765 | if(m_popupItem->type() == KileStruct::Sect) { | 761 | if(m_popupItem->type() == KileStruct::Sect) { | ||
766 | if(hasLabel) { | 762 | if(hasLabel) { | ||
767 | popup.addSection(i18n("Sectioning")); | 763 | popup.addSection(i18n("Sectioning")); | ||
768 | } | 764 | } | ||
769 | action = popup.addAction(i18n("Cu&t"), &signalMapper, SLOT(map())); | 765 | popup.addAction(i18n("Cu&t"), this, [this] { slotPopupSectioning(SectioningCut); }); | ||
770 | signalMapper.setMapping(action, SectioningCut); | 766 | popup.addAction(i18n("&Copy"), this, [this] { slotPopupSectioning(SectioningCopy); }); | ||
771 | action = popup.addAction(i18n("&Copy"), &signalMapper, SLOT(map())); | 767 | popup.addAction(i18n("&Paste below"), this, [this] { slotPopupSectioning(SectioningPaste); }); | ||
772 | signalMapper.setMapping(action, SectioningCopy); | | |||
773 | action = popup.addAction(i18n("&Paste below"), &signalMapper, SLOT(map())); | | |||
774 | signalMapper.setMapping(action, SectioningPaste); | | |||
775 | popup.addSeparator(); | 768 | popup.addSeparator(); | ||
776 | action = popup.addAction(i18n("&Select"), &signalMapper, SLOT(map())); | 769 | popup.addAction(i18n("&Select"), this, [this] { slotPopupSectioning(SectioningSelect); }); | ||
777 | signalMapper.setMapping(action, SectioningSelect); | 770 | popup.addAction(i18n("&Delete"), this, [this] { slotPopupSectioning(SectioningDelete); }); | ||
778 | action = popup.addAction(i18n("&Delete"), &signalMapper, SLOT(map())); | | |||
779 | signalMapper.setMapping(action, SectioningDelete); | | |||
780 | popup.addSeparator(); | 771 | popup.addSeparator(); | ||
781 | action = popup.addAction(i18n("C&omment"), &signalMapper, SLOT(map())); | 772 | popup.addAction(i18n("C&omment"), this, [this] { slotPopupSectioning(SectioningComment); }); | ||
782 | signalMapper.setMapping(action, SectioningComment); | | |||
783 | popup.addSeparator(); | 773 | popup.addSeparator(); | ||
784 | action = popup.addAction(i18n("Run QuickPreview"), &signalMapper, SLOT(map())); | 774 | popup.addAction(i18n("Run QuickPreview"), this, [this] { slotPopupSectioning(SectioningPreview); }); | ||
785 | signalMapper.setMapping(action, SectioningPreview); | | |||
786 | } | 775 | } | ||
787 | else if(m_popupItem->type() == KileStruct::Graphics) { | 776 | else if(m_popupItem->type() == KileStruct::Graphics) { | ||
788 | m_popupInfo = m_popupItem->title(); | 777 | m_popupInfo = m_popupItem->title(); | ||
789 | 778 | | |||
790 | if(!QDir::isAbsolutePath(m_popupInfo)) { | 779 | if(!QDir::isAbsolutePath(m_popupInfo)) { | ||
791 | QString fn = m_ki->getCompileName(); | 780 | QString fn = m_ki->getCompileName(); | ||
792 | m_popupInfo = QFileInfo(fn).path() + '/' + m_popupInfo; | 781 | m_popupInfo = QFileInfo(fn).path() + '/' + m_popupInfo; | ||
793 | } | 782 | } | ||
794 | 783 | | |||
795 | QFileInfo fi(m_popupInfo); | 784 | QFileInfo fi(m_popupInfo); | ||
796 | if(fi.isReadable()) { | 785 | if(fi.isReadable()) { | ||
797 | QUrl url; | 786 | QUrl url; | ||
798 | url.setPath(m_popupInfo); | 787 | url.setPath(m_popupInfo); | ||
799 | 788 | | |||
800 | QMimeDatabase db; | 789 | QMimeDatabase db; | ||
801 | m_offerList = KMimeTypeTrader::self()->query(db.mimeTypeForUrl(url).name(), "Application"); | 790 | m_offerList = KMimeTypeTrader::self()->query(db.mimeTypeForUrl(url).name(), "Application"); | ||
802 | for(int i = 0; i < m_offerList.count(); ++i) { | 791 | for(int i = 0; i < m_offerList.count(); ++i) { | ||
803 | action = popup.addAction(QIcon::fromTheme(m_offerList[i]->icon()), m_offerList[i]->name(), | 792 | popup.addAction(QIcon::fromTheme(m_offerList[i]->icon()), m_offerList[i]->name(), | ||
804 | &signalMapper, SLOT(map())); | 793 | this, [this, i] { slotPopupGraphics(i + SectioningGraphicsOfferlist); }); | ||
805 | signalMapper.setMapping(action, i + SectioningGraphicsOfferlist); | | |||
806 | } | 794 | } | ||
807 | popup.addSeparator(); | 795 | popup.addSeparator(); | ||
808 | action = popup.addAction(i18n("Other..."), &signalMapper, SLOT(map())); | 796 | popup.addAction(i18n("Other..."), this, [this] { slotPopupGraphics(SectioningGraphicsOther); }); | ||
809 | signalMapper.setMapping(action, SectioningGraphicsOther); | | |||
810 | } | 797 | } | ||
811 | } | 798 | } | ||
812 | 799 | | |||
813 | if(hasLabel) { | 800 | if(hasLabel) { | ||
814 | popup.addSection(i18n("Insert Label")); | 801 | popup.addSection(i18n("Insert Label")); | ||
815 | action = popup.addAction(i18n("As &reference"), &signalMapper, SLOT(map())); | 802 | popup.addAction(i18n("As &reference"), this, [this] { emit(sendText("\\ref{" + m_popupItem->label() + '}')); }); | ||
816 | signalMapper.setMapping(action, 1); | 803 | popup.addAction(i18n("As &page reference"), this, [this] { emit(sendText("\\pageref{" + m_popupItem->label() + '}')); }); | ||
817 | action = popup.addAction(i18n("As &page reference"), &signalMapper, SLOT(map())); | 804 | popup.addAction(i18n("Only the &label"), this, [this] { emit(sendText(m_popupItem->label())); }); | ||
818 | signalMapper.setMapping(action, 2); | | |||
819 | action = popup.addAction(i18n("Only the &label"), &signalMapper, SLOT(map())); | | |||
820 | signalMapper.setMapping(action, 3); | | |||
821 | popup.addSeparator(); | 805 | popup.addSeparator(); | ||
822 | popup.addSection(i18n("Copy Label to Clipboard")); | 806 | popup.addSection(i18n("Copy Label to Clipboard")); | ||
823 | action = popup.addAction(i18n("As reference"), &signalMapper, SLOT(map())); | 807 | popup.addAction(i18n("As reference"), this, [this] { QApplication::clipboard()->setText("\\ref{" + m_popupItem->label() + '}'); }); | ||
824 | signalMapper.setMapping(action, 4); | 808 | popup.addAction(i18n("As page reference"), this, [this] { QApplication::clipboard()->setText("\\pageref{" + m_popupItem->label() + '}'); }); | ||
825 | action = popup.addAction(i18n("As page reference"), &signalMapper, SLOT(map())); | 809 | popup.addAction(i18n("Only the label"), this, [this] { QApplication::clipboard()->setText(m_popupItem->label()); }); | ||
826 | signalMapper.setMapping(action, 5); | | |||
827 | action = popup.addAction(i18n("Only the label"), &signalMapper, SLOT(map())); | | |||
828 | signalMapper.setMapping(action, 6); | | |||
829 | } | 810 | } | ||
830 | 811 | | |||
831 | if(!popup.isEmpty()) { | 812 | if(!popup.isEmpty()) { | ||
832 | m_showingContextMenu = &popup; | 813 | m_showingContextMenu = &popup; | ||
833 | popup.exec(event->globalPos()); | 814 | popup.exec(event->globalPos()); | ||
834 | m_showingContextMenu = Q_NULLPTR; | 815 | m_showingContextMenu = Q_NULLPTR; | ||
835 | } | 816 | } | ||
836 | } | 817 | } | ||
837 | 818 | | |||
838 | void StructureWidget::slotPopupActivated(int id) | | |||
839 | { | | |||
840 | KILE_DEBUG_MAIN << "id: " << id; | | |||
841 | if(id >= 1 && id <= 6) { | | |||
842 | slotPopupLabel(id); | | |||
843 | } | | |||
844 | else if(id >= SectioningCut && id <= SectioningPreview) { | | |||
845 | slotPopupSectioning(id); | | |||
846 | } | | |||
847 | else if(id >= SectioningGraphicsOther && id <= SectioningGraphicsOfferlist + m_offerList.count()) { | | |||
848 | slotPopupGraphics(id); | | |||
849 | } | | |||
850 | } | | |||
851 | | ||||
852 | // id's 1..6 (already checked) | | |||
853 | void StructureWidget::slotPopupLabel(int id) | | |||
854 | { | | |||
855 | KILE_DEBUG_MAIN << "\tStructureWidget::slotPopupLabel (" << id << ")"<< endl; | | |||
856 | | ||||
857 | QString s = m_popupItem->label(); | | |||
858 | if(id == 1 || id == 4) { | | |||
859 | s = "\\ref{" + s + '}'; | | |||
860 | } | | |||
861 | else if(id == 2 || id == 5) { | | |||
862 | s = "\\pageref{" + s + '}'; | | |||
863 | } | | |||
864 | | ||||
865 | if(id <= 3) { | | |||
866 | emit(sendText(s)); | | |||
867 | } | | |||
868 | else { | | |||
869 | QApplication::clipboard()->setText(s); | | |||
870 | } | | |||
871 | } | | |||
872 | | ||||
873 | // id's 10..16 (already checked) | 819 | // id's 10..16 (already checked) | ||
874 | void StructureWidget::slotPopupSectioning(int id) | 820 | void StructureWidget::slotPopupSectioning(int id) | ||
875 | { | 821 | { | ||
876 | KILE_DEBUG_MAIN << "\tStructureWidget::slotPopupSectioning (" << id << ")"<< endl; | 822 | KILE_DEBUG_MAIN << "\tStructureWidget::slotPopupSectioning (" << id << ")"<< endl; | ||
877 | if(m_popupItem->level() >= 1 && m_popupItem->level() <= 7) { | 823 | if(m_popupItem->level() >= 1 && m_popupItem->level() <= 7) { | ||
878 | emit(sectioningPopup(m_popupItem, id)); | 824 | emit(sectioningPopup(m_popupItem, id)); | ||
879 | } | 825 | } | ||
880 | } | 826 | } | ||
▲ Show 20 Lines • Show All 212 Lines • Show Last 20 Lines |