|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2017 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to enter data to insert a hyperlink. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtCore import pyqtSlot |
|
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_HyperlinkMarkupDialog import Ui_HyperlinkMarkupDialog |
|
14 |
|
15 |
|
16 class HyperlinkMarkupDialog(QDialog, Ui_HyperlinkMarkupDialog): |
|
17 """ |
|
18 Class implementing a dialog to enter data to insert a hyperlink. |
|
19 """ |
|
20 def __init__(self, textMayBeEmpty, targetMayBeEmpty, noTitle=False, |
|
21 parent=None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param textMayBeEmpty flag indicating, that the link text may |
|
26 be empty |
|
27 @type bool |
|
28 @param targetMayBeEmpty flag indicating, that the link target may |
|
29 be empty |
|
30 @type bool |
|
31 @param noTitle flag indicating, that no title is supported |
|
32 @type bool |
|
33 @param parent reference to the parent widget |
|
34 @type QWidget |
|
35 """ |
|
36 super().__init__(parent) |
|
37 self.setupUi(self) |
|
38 |
|
39 self.__allowEmptyText = textMayBeEmpty |
|
40 self.__allowEmptyTarget = targetMayBeEmpty |
|
41 |
|
42 self.titelEdit.setEnabled(not noTitle) |
|
43 |
|
44 self.__updateOkButton() |
|
45 |
|
46 msh = self.minimumSizeHint() |
|
47 self.resize(max(self.width(), msh.width()), msh.height()) |
|
48 |
|
49 def __updateOkButton(self): |
|
50 """ |
|
51 Private method to update the state of the OK button. |
|
52 """ |
|
53 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
|
54 (bool(self.textEdit.text()) or self.__allowEmptyText) and |
|
55 (bool(self.targetEdit.text()) or self.__allowEmptyTarget) |
|
56 ) |
|
57 |
|
58 @pyqtSlot(str) |
|
59 def on_textEdit_textChanged(self, txt): |
|
60 """ |
|
61 Private slot handling a change of the link text. |
|
62 |
|
63 @param txt link text |
|
64 @type str |
|
65 """ |
|
66 self.__updateOkButton() |
|
67 |
|
68 @pyqtSlot(str) |
|
69 def on_targetEdit_textChanged(self, txt): |
|
70 """ |
|
71 Private slot handling a change of the link target. |
|
72 |
|
73 @param txt link target |
|
74 @type str |
|
75 """ |
|
76 self.__updateOkButton() |
|
77 |
|
78 def getData(self): |
|
79 """ |
|
80 Public method to get the entered data. |
|
81 |
|
82 @return tuple containing the link text, link target and the optional |
|
83 link title |
|
84 @rtype tuple of (str, str, str) |
|
85 """ |
|
86 return ( |
|
87 self.textEdit.text(), |
|
88 self.targetEdit.text(), |
|
89 self.titelEdit.text() |
|
90 ) |