--- a/E5Gui/E5TextEditSearchWidget.py Fri Nov 03 17:24:01 2017 +0100 +++ b/E5Gui/E5TextEditSearchWidget.py Sun Nov 05 11:35:32 2017 +0100 @@ -9,35 +9,38 @@ from __future__ import unicode_literals -from PyQt5.QtCore import pyqtSlot, Qt +from PyQt5.QtCore import pyqtSlot, Qt, QMetaObject, QSize from PyQt5.QtGui import QPalette, QBrush, QColor, QTextDocument, QTextCursor -from PyQt5.QtWidgets import QWidget +from PyQt5.QtWidgets import QWidget, QVBoxLayout, QHBoxLayout, QLabel, \ + QComboBox, QCheckBox, QToolButton, QSizePolicy -from .Ui_E5TextEditSearchWidget import Ui_E5TextEditSearchWidget +from E5Gui.E5ComboBox import E5ClearableComboBox import UI.PixmapCache -class E5TextEditSearchWidget(QWidget, Ui_E5TextEditSearchWidget): +class E5TextEditSearchWidget(QWidget): """ Class implementing a horizontal search widget for QTextEdit. """ - def __init__(self, parent=None): + def __init__(self, parent=None, widthForHeight=True): """ Constructor - @param parent reference to the parent widget (QWidget) + @param parent reference to the parent widget + @type QWidget + @param widthForHeight flag indicating to prefer width for height. + If this parameter is False, some widgets are shown in a third + line. + @type bool """ super(E5TextEditSearchWidget, self).__init__(parent) - self.setupUi(self) + self.__setupUi(widthForHeight) self.__textedit = None self.__texteditType = "" self.__findBackwards = True - self.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow.png")) - self.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow.png")) - self.__defaultBaseColor = \ self.findtextCombo.lineEdit().palette().color(QPalette.Base) self.__defaultTextColor = \ @@ -54,6 +57,97 @@ self.setFocusProxy(self.findtextCombo) + def __setupUi(self, widthForHeight): + """ + Private method to generate the UI. + + @param widthForHeight flag indicating to prefer width for height + @type bool + """ + self.setObjectName("E5TextEditSearchWidget") + + self.verticalLayout = QVBoxLayout(self) + self.verticalLayout.setObjectName("verticalLayout") + self.verticalLayout.setContentsMargins(0, 0, 0, 0) + + # row 1 of widgets + self.horizontalLayout1 = QHBoxLayout() + self.horizontalLayout1.setObjectName("horizontalLayout1") + + self.label = QLabel(self) + self.label.setObjectName("label") + self.label.setText(self.tr("Find:")) + self.horizontalLayout1.addWidget(self.label) + + self.findtextCombo = E5ClearableComboBox(self) + sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth( + self.findtextCombo.sizePolicy().hasHeightForWidth()) + self.findtextCombo.setSizePolicy(sizePolicy) + self.findtextCombo.setMinimumSize(QSize(200, 0)) + self.findtextCombo.setEditable(True) + self.findtextCombo.setInsertPolicy(QComboBox.InsertAtTop) + self.findtextCombo.setDuplicatesEnabled(False) + self.findtextCombo.setObjectName("findtextCombo") + self.horizontalLayout1.addWidget(self.findtextCombo) + + # row 2 (maybe) of widgets + self.horizontalLayout2 = QHBoxLayout() + self.horizontalLayout2.setObjectName("horizontalLayout2") + + self.caseCheckBox = QCheckBox(self) + self.caseCheckBox.setObjectName("caseCheckBox") + self.caseCheckBox.setText(self.tr("Match case")) + self.horizontalLayout2.addWidget(self.caseCheckBox) + + self.wordCheckBox = QCheckBox(self) + self.wordCheckBox.setObjectName("wordCheckBox") + self.wordCheckBox.setText(self.tr("Whole word")) + self.horizontalLayout2.addWidget(self.wordCheckBox) + + # layout for the navigation buttons + self.horizontalLayout3 = QHBoxLayout() + self.horizontalLayout3.setSpacing(0) + self.horizontalLayout3.setObjectName("horizontalLayout3") + + self.findPrevButton = QToolButton(self) + self.findPrevButton.setObjectName("findPrevButton") + self.findPrevButton.setToolTip(self.tr( + "Press to find the previous occurrence")) + self.findPrevButton.setIcon(UI.PixmapCache.getIcon("1leftarrow.png")) + self.horizontalLayout3.addWidget(self.findPrevButton) + + self.findNextButton = QToolButton(self) + self.findNextButton.setObjectName("findNextButton") + self.findNextButton.setToolTip(self.tr( + "Press to find the next occurrence")) + self.findNextButton.setIcon(UI.PixmapCache.getIcon("1rightarrow.png")) + self.horizontalLayout3.addWidget(self.findNextButton) + + self.horizontalLayout2.addLayout(self.horizontalLayout3) + + # info label (in row 2 or 3) + self.infoLabel = QLabel(self) + self.infoLabel.setText("") + self.infoLabel.setObjectName("infoLabel") + + # place everything together + self.verticalLayout.addLayout(self.horizontalLayout1) + if widthForHeight: + self.horizontalLayout1.addLayout(self.horizontalLayout2) + else: + self.verticalLayout.addLayout(self.horizontalLayout2) + self.verticalLayout.addWidget(self.infoLabel) + + QMetaObject.connectSlotsByName(self) + + self.setTabOrder(self.findtextCombo, self.caseCheckBox) + self.setTabOrder(self.caseCheckBox, self.wordCheckBox) + self.setTabOrder(self.wordCheckBox, self.findPrevButton) + self.setTabOrder(self.findPrevButton, self.findNextButton) + def attachTextEdit(self, textedit, editType="QTextEdit"): """ Public method to attach a QTextEdit widget.