forked from p0cisk/qNote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqnote_panel.py
More file actions
103 lines (79 loc) · 3.67 KB
/
Copy pathqnote_panel.py
File metadata and controls
103 lines (79 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# -*- coding: utf-8 -*-
from os import path
from qgis.PyQt import uic
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtGui import QAction, QFont, QIcon, QTextListFormat
from qgis.PyQt.QtWidgets import QDockWidget
pluginPath = path.dirname(path.abspath(__file__))
FORM_CLASS, _ = uic.loadUiType(path.join(pluginPath, 'ui/ui_panel.ui'))
class MainPanel(QDockWidget, FORM_CLASS):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
self.bold_action = QAction(QIcon(path.join(pluginPath, "icons/bold.png")), "Bold", self)
self.bold_action.triggered.connect(self.setBold)
self.toolbar.addAction(self.bold_action)
self.italic_action = QAction(QIcon(path.join(pluginPath, "icons/italic.png")), "Italic", self)
self.italic_action.triggered.connect(self.setItalic)
self.toolbar.addAction(self.italic_action)
self.underline_action = QAction(QIcon(path.join(pluginPath, "icons/underline.png")), "Underline", self)
self.underline_action.triggered.connect(self.setUnderline)
self.toolbar.addAction(self.underline_action)
self.strike_action = QAction(QIcon(path.join(pluginPath, "icons/strikethrough.png")), "Strike", self)
self.strike_action.triggered.connect(self.setStrike)
self.toolbar.addAction(self.strike_action)
self.toolbar.addSeparator()
self.bullet_list_action = QAction(
QIcon(path.join(pluginPath, "icons/bullet_list.png")),
"Insert bullet list",
self,
)
self.bullet_list_action.triggered.connect(self.setBulletList)
self.toolbar.addAction(self.bullet_list_action)
self.number_list_action = QAction(
QIcon(path.join(pluginPath, "icons/number_list.png")),
"Insert number list",
self,
)
self.number_list_action.triggered.connect(self.setNumberList)
self.toolbar.addAction(self.number_list_action)
self.toolbar.addSeparator()
self.add_hyperlink = QAction(
QIcon(path.join(pluginPath, "icons/hyperlink.jpg")),
"Add hyperlink",
self,
)
self.add_hyperlink.triggered.connect(self.addHyperlink)
self.toolbar.addAction(self.add_hyperlink)
self.toolbar.addSeparator()
self.undo = QAction(QIcon(path.join(pluginPath, "icons/undo.png")), "Undo", self)
self.undo.triggered.connect(self.edit.undo)
self.toolbar.addAction(self.undo)
self.edit.undoAvailable.connect(self.undo.setEnabled)
self.redo = QAction(QIcon(path.join(pluginPath, "icons/redo.png")), "Redo", self)
self.redo.triggered.connect(self.edit.redo)
self.toolbar.addAction(self.redo)
self.edit.redoAvailable.connect(self.redo.setEnabled)
def addHyperlink(self):
self.edit.showAddHyperLinkUi()
def setBold(self):
if self.edit.fontWeight() == QFont.Weight.Bold:
self.edit.setFontWeight(QFont.Weight.Normal)
else:
self.edit.setFontWeight(QFont.Weight.Bold)
def setItalic(self):
state = self.edit.fontItalic()
self.edit.setFontItalic(not state)
def setUnderline(self):
state = self.edit.fontUnderline()
self.edit.setFontUnderline(not state)
def setStrike(self):
fmt = self.edit.currentCharFormat()
fmt.setFontStrikeOut(not fmt.fontStrikeOut())
self.edit.setCurrentCharFormat(fmt)
def setBulletList(self):
cursor = self.edit.textCursor()
cursor.insertList(QTextListFormat.Style.ListDisc)
def setNumberList(self):
cursor = self.edit.textCursor()
cursor.insertList(QTextListFormat.Style.ListDecimal)