29 |
30 |
30 @signal searchListChanged() emitted to indicate a change of the search list |
31 @signal searchListChanged() emitted to indicate a change of the search list |
31 """ |
32 """ |
32 searchListChanged = pyqtSignal() |
33 searchListChanged = pyqtSignal() |
33 |
34 |
34 def __init__(self, replace, vm, parent=None): |
35 def __init__(self, replace, vm, parent=None, sliding=False): |
35 """ |
36 """ |
36 Constructor |
37 Constructor |
37 |
38 |
38 @param replace flag indicating a replace widget is called |
39 @param replace flag indicating a replace widget is called |
39 @param vm reference to the viewmanager object |
40 @param vm reference to the viewmanager object |
40 @param parent parent widget of this widget (QWidget) |
41 @param parent parent widget of this widget (QWidget) |
|
42 @param sliding flag indicating the widget is embedded in the |
|
43 sliding widget (boolean) |
41 """ |
44 """ |
42 super().__init__(parent) |
45 super().__init__(parent) |
43 |
46 |
44 self.viewmanager = vm |
47 self.viewmanager = vm |
45 self.replace = replace |
48 self.replace = replace |
|
49 self.__sliding = sliding |
|
50 if sliding: |
|
51 self.__topWidget = parent |
46 |
52 |
47 self.findHistory = vm.getSRHistory('search') |
53 self.findHistory = vm.getSRHistory('search') |
48 if replace: |
54 if replace: |
49 self.replaceHistory = vm.getSRHistory('replace') |
55 self.replaceHistory = vm.getSRHistory('replace') |
50 self.ui = Ui_ReplaceWidget() |
56 self.ui = Ui_ReplaceWidget() |
668 if event.key() == Qt.Key_Escape: |
677 if event.key() == Qt.Key_Escape: |
669 aw = self.viewmanager.activeWindow() |
678 aw = self.viewmanager.activeWindow() |
670 if aw: |
679 if aw: |
671 aw.setFocus(Qt.ActiveWindowFocusReason) |
680 aw.setFocus(Qt.ActiveWindowFocusReason) |
672 event.accept() |
681 event.accept() |
673 self.close() |
682 if self.__sliding: |
|
683 self.__topWidget.close() |
|
684 else: |
|
685 self.close() |
|
686 |
|
687 |
|
688 class SearchReplaceSlidingWidget(QWidget): |
|
689 """ |
|
690 Class implementing the search and replace widget with sliding behavior. |
|
691 |
|
692 @signal searchListChanged() emitted to indicate a change of the search list |
|
693 """ |
|
694 searchListChanged = pyqtSignal() |
|
695 |
|
696 def __init__(self, replace, vm, parent=None): |
|
697 """ |
|
698 Constructor |
|
699 |
|
700 @param replace flag indicating a replace widget is called |
|
701 @param vm reference to the viewmanager object |
|
702 @param parent parent widget of this widget (QWidget) |
|
703 """ |
|
704 super().__init__(parent) |
|
705 |
|
706 self.__searchReplaceWidget = SearchReplaceWidget(replace, vm, self, True) |
|
707 srHeight = self.__searchReplaceWidget.height() |
|
708 |
|
709 self.__layout = QHBoxLayout(self) |
|
710 self.setLayout(self.__layout) |
|
711 self.__layout.setContentsMargins(0, 0, 0, 0) |
|
712 self.__layout.setAlignment(Qt.AlignTop) |
|
713 |
|
714 self.__leftButton = QToolButton(self) |
|
715 self.__leftButton.setArrowType(Qt.LeftArrow) |
|
716 self.__leftButton.setSizePolicy( |
|
717 QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) |
|
718 self.__leftButton.setAutoRepeat(True) |
|
719 |
|
720 self.__scroller = QScrollArea(self) |
|
721 self.__scroller.setWidget(self.__searchReplaceWidget) |
|
722 self.__scroller.setSizePolicy( |
|
723 QSizePolicy.Expanding, QSizePolicy.Minimum) |
|
724 self.__scroller.setMaximumHeight(srHeight) |
|
725 self.__scroller.setFrameShape(QFrame.NoFrame) |
|
726 self.__scroller.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) |
|
727 self.__scroller.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) |
|
728 self.__scroller.setWidgetResizable(False) |
|
729 |
|
730 self.__rightButton = QToolButton(self) |
|
731 self.__rightButton.setArrowType(Qt.RightArrow) |
|
732 self.__rightButton.setSizePolicy( |
|
733 QSizePolicy.Minimum, QSizePolicy.MinimumExpanding) |
|
734 self.__rightButton.setAutoRepeat(True) |
|
735 |
|
736 self.__layout.addWidget(self.__leftButton) |
|
737 self.__layout.addWidget(self.__scroller) |
|
738 self.__layout.addWidget(self.__rightButton) |
|
739 |
|
740 self.setMaximumHeight(srHeight) |
|
741 |
|
742 self.__searchReplaceWidget.searchListChanged.connect(self.searchListChanged) |
|
743 self.__leftButton.clicked[()].connect(self.__slideLeft) |
|
744 self.__rightButton.clicked[()].connect(self.__slideRight) |
|
745 |
|
746 def findNext(self): |
|
747 """ |
|
748 Public slot to find the next occurrence of text. |
|
749 """ |
|
750 self.__searchReplaceWidget.findNext() |
|
751 |
|
752 def findPrev(self): |
|
753 """ |
|
754 Public slot to find the next previous of text. |
|
755 """ |
|
756 self.__searchReplaceWidget.findPrev() |
|
757 |
|
758 def selectionChanged(self): |
|
759 """ |
|
760 Public slot tracking changes of selected text. |
|
761 """ |
|
762 editor = self.sender() |
|
763 self.__searchReplaceWidget.updateSelectionCheckBox(editor) |
|
764 |
|
765 @pyqtSlot(Editor) |
|
766 def updateSelectionCheckBox(self, editor): |
|
767 """ |
|
768 Public slot to update the selection check box. |
|
769 |
|
770 @param editor reference to the editor (Editor) |
|
771 """ |
|
772 self.__searchReplaceWidget.updateSelectionCheckBox(editor) |
|
773 |
|
774 def show(self, text=''): |
|
775 """ |
|
776 Overridden slot from QWidget. |
|
777 |
|
778 @param text text to be shown in the findtext edit (string) |
|
779 """ |
|
780 self.__searchReplaceWidget.show(text) |
|
781 super().show() |
|
782 |
|
783 def __slideLeft(self): |
|
784 """ |
|
785 Private slot to move the widget to the left, i.e. show contents to the right. |
|
786 """ |
|
787 self.__slide(True) |
|
788 |
|
789 def __slideRight(self): |
|
790 """ |
|
791 Private slot to move the widget to the right, i.e. show contents to the left. |
|
792 """ |
|
793 self.__slide(False) |
|
794 |
|
795 def __slide(self, toLeft): |
|
796 """ |
|
797 Private method to move the sliding widget. |
|
798 |
|
799 @param toLeft flag indicating to move to the left (boolean) |
|
800 """ |
|
801 scrollBar = self.__scroller.horizontalScrollBar() |
|
802 stepSize = scrollBar.singleStep() |
|
803 if toLeft: |
|
804 stepSize = -stepSize |
|
805 newValue = scrollBar.value() + stepSize |
|
806 if newValue < 0: |
|
807 newValue = 0 |
|
808 elif newValue > scrollBar.maximum(): |
|
809 newValue = scrollBar.maximum() |
|
810 scrollBar.setValue(newValue) |