diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/python/main.py | 29 | ||||
-rw-r--r-- | src/main/python/utils/app.py | 12 | ||||
-rw-r--r-- | src/main/python/utils/dialogs.py | 1 | ||||
-rw-r--r-- | src/main/python/utils/fileWindow.py | 14 | ||||
-rw-r--r-- | src/main/python/utils/tabs.py | 22 | ||||
-rw-r--r-- | src/main/python/utils/toolbar.py | 40 | ||||
-rw-r--r-- | src/main/resources/base/app.qss | 187 | ||||
-rw-r--r-- | src/main/resources/base/ui/close.svg | 60 |
8 files changed, 288 insertions, 77 deletions
diff --git a/src/main/python/main.py b/src/main/python/main.py index ed64570..9def7fb 100644 --- a/src/main/python/main.py +++ b/src/main/python/main.py @@ -60,11 +60,6 @@ class appWindow(QMainWindow): # self.resize(1280, 720) #set collapse dim self.mdi.subWindowActivated.connect(self.tabSwitched) self.readSettings() - - def updateMenuBar(self): - # used to update menu bar undo-redo buttons to current scene - self.undo.triggered.connect(self.activeScene.painter.undoAction.trigger()) - self.redo.triggered.connect(self.activeScene.painter.redoAction.trigger()) def createToolbar(self): #place holder for toolbar with fixed width, layout may change @@ -76,13 +71,14 @@ class appWindow(QMainWindow): self.toolbar.populateToolbar() def toolButtonClicked(self, object): - currentDiagram = self.mdi.currentSubWindow().tabber.currentWidget().painter - if currentDiagram: - graphic = getattr(shapes, object['object'])(*map(lambda x: int(x) if x.isdigit() else x, object['args'])) - # graphic.setPen(QPen(Qt.black, 2)) - # graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable) - currentDiagram.addItemPlus(graphic) - graphic.setPos(20, 20) + if self.mdi.currentSubWindow(): + currentDiagram = self.mdi.currentSubWindow().tabber.currentWidget().painter + if currentDiagram: + graphic = getattr(shapes, object['object'])(*map(lambda x: int(x) if x.isdigit() else x, object['args'])) + # graphic.setPen(QPen(Qt.black, 2)) + # graphic.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsMovable) + currentDiagram.addItemPlus(graphic) + graphic.setPos(20, 20) def newProject(self): #call to create a new file inside mdi area @@ -93,7 +89,6 @@ class appWindow(QMainWindow): project.newDiagram() #create a new tab in the new file # project.resizeHandler() project.fileCloseEvent.connect(self.fileClosed) #closed file signal to switch to sub window view - project.tabChangeEvent.connect(self.updateMenuBar) if self.count > 1: #switch to tab view if needed self.mdi.setViewMode(QMdiArea.TabbedView) project.show() @@ -110,7 +105,6 @@ class appWindow(QMainWindow): project.__setstate__(projectData) project.resizeHandler() project.fileCloseEvent.connect(self.fileClosed) - project.tabChangeEvent.connect(self.updateMenuBar) project.show() if self.count > 1: # self.tabSpace.setVisible(True) @@ -218,12 +212,7 @@ class appWindow(QMainWindow): else: return event.accept() - - elif event.key() == Qt.Key_Delete or event.key() == Qt.Key_Backspace: - for item in reversed(self.mdi.activeSubWindow().tabber.currentWidget().painter.selectedItems()): - # self.mdi.currentSubWindow().tabber.currentWidget().deleteItem(item) - pass - #donot delete, to manage undo redo + if __name__ == '__main__': # 1. Instantiate ApplicationContext diff --git a/src/main/python/utils/app.py b/src/main/python/utils/app.py index 4cc8228..96a45b0 100644 --- a/src/main/python/utils/app.py +++ b/src/main/python/utils/app.py @@ -3,7 +3,9 @@ Declare fbs application so that it can be imported in other modules. """ from fbs_runtime.application_context.PyQt5 import ApplicationContext -from PyQt5.QtCore import QSettings +from PyQt5.QtCore import QSettings, pyqtProperty +from PyQt5.QtGui import QIcon +from PyQt5.QtWidgets import QWidget from json import JSONEncoder, dumps, loads, dump, load from os.path import join @@ -15,6 +17,9 @@ def fileImporter(*file): # Helper function to fetch files from src/main/resources return app.get_resource(join(*file)) +with open(fileImporter("app.qss"), "r") as stylesheet: + app.app.setStyleSheet(stylesheet.read()) + class JSON_Encoder: def _encode(obj): @@ -52,6 +57,9 @@ class JSON_Typer(JSONEncoder): def encode(self, obj): return super(JSON_Typer, self).encode(self._encode(obj)) - + + +importer = pyqtProperty(str, fileImporter) + shapeGrips = {} lines = {}
\ No newline at end of file diff --git a/src/main/python/utils/dialogs.py b/src/main/python/utils/dialogs.py index 79685c5..f2c4eb9 100644 --- a/src/main/python/utils/dialogs.py +++ b/src/main/python/utils/dialogs.py @@ -58,7 +58,6 @@ class paperDims(QDialog): super(paperDims, self).exec_() self.deleteLater() #remove from memory #if ok was pressed return value else return None - print(self.landscapeCheckBox.isChecked()) return (self.returnCanvasSize, self.returnCanvasPPI, self.landscapeCheckBox.isChecked()) if self.result() else None class sideViewSwitchDialog(QDialog): diff --git a/src/main/python/utils/fileWindow.py b/src/main/python/utils/fileWindow.py index e0f5652..ba0b6e9 100644 --- a/src/main/python/utils/fileWindow.py +++ b/src/main/python/utils/fileWindow.py @@ -61,20 +61,6 @@ class fileWindow(QMdiSubWindow): self.sideView.setInteractive(False) self.sideViewCloseButton = QPushButton('×', self.sideView) self.sideViewCloseButton.setFlat(True) - self.sideViewCloseButton.setStyleSheet("""QPushButton{ - background: rgba(214, 54, 40, 50%); - border: 1px groove white; - border-radius: 2px; - font-size: 18px; - font-weight: Bold; - padding: 1px 2px 3px 3px; - color: rgba(255, 255, 255, 50%); - } - QPushButton:Hover{ - background: rgba(214, 54, 40, 90%); - color: rgba(255, 255, 255, 90%); - } - """) self.sideViewCloseButton.setFixedSize(20, 20) self.moveSideViewCloseButton() self.sideViewCloseButton.clicked.connect(lambda: setattr(self, 'sideViewTab', None)) diff --git a/src/main/python/utils/tabs.py b/src/main/python/utils/tabs.py index 5196557..1431db2 100644 --- a/src/main/python/utils/tabs.py +++ b/src/main/python/utils/tabs.py @@ -41,19 +41,9 @@ class customTabWidget(QTabWidget): self.plusButton = QPushButton('+', self) #create the new tab button #style the new tab button self.plusButton.setFlat(True) - self.plusButton.setStyleSheet(""" - QPushButton{ - background: rgba(230, 230, 227, 0%); - padding: 1px; - border: 0px solid #E6E6E3; - - } - QPushButton:hover{ - background: rgba(230, 230, 227, 60%); - }""") #and parent it to the widget to add it at 0, 0 - self.plusButton.setFixedSize(35, 25) #set dimensions + self.plusButton.setFixedSize(25, 25) #set dimensions self.plusButton.clicked.connect(self.plusClicked.emit) #emit signal on click #set flags self.setMovable(True) @@ -64,23 +54,17 @@ class customTabWidget(QTabWidget): self.tab.nameChanged.connect(self.changeWidgetName) #set custom stylesheet for the widget area - self.setStyleSheet("""QTabWidget::pane { - margin: 0px,1px,1px,1px; - border: 2px solid #E6E6E3; - border-radius: 7px; - padding: 1px; - background-color: #E6E6E3;}""") def movePlusButton(self): #move the new tab button to correct location size = sum([self.tab.tabRect(i).width() for i in range(self.tab.count())]) # calculate width of all tabs - h = max(self.tab.geometry().bottom() - self.plusButton.height(), 0) #align with bottom of tabbar + h = max(self.tab.geometry().bottom() - self.plusButton.height()-10, -5) #align with bottom of tabbar w = self.tab.width() if size > w: #if all the tabs do not overflow the tab bar, add at the end self.plusButton.move(w-self.plusButton.width(), h) else: - self.plusButton.move(size-3, h) + self.plusButton.move(size+5, h) def changeWidgetName(self, index, newName): self.widget(index).setObjectName(newName)
\ No newline at end of file diff --git a/src/main/python/utils/toolbar.py b/src/main/python/utils/toolbar.py index 90b46fb..beac867 100644 --- a/src/main/python/utils/toolbar.py +++ b/src/main/python/utils/toolbar.py @@ -2,11 +2,11 @@ from fbs_runtime.application_context.PyQt5 import ApplicationContext from PyQt5.QtCore import QSize, Qt, pyqtSignal, QMimeData from PyQt5.QtGui import QIcon, QDrag from PyQt5.QtWidgets import (QBoxLayout, QDockWidget, QGridLayout, QLineEdit, - QScrollArea, QToolButton, QWidget, QApplication, QStyle, QLabel) + QScrollArea, QToolButton, QWidget, QStyle, QLabel) from re import search, IGNORECASE from .data import toolbarItems -from .app import fileImporter +from .app import fileImporter, app from .layout import flowLayout # resourceManager = ApplicationContext() #Used to load images, mainly toolbar icons @@ -39,14 +39,14 @@ class toolbar(QDockWidget): #create a scrollable area to house all buttons self.diagArea = QScrollArea(self) - self.diagArea.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) + self.diagArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded) self.diagArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.diagArea.setWidgetResizable(True) self.layout.addWidget(self.diagArea, stretch=1) self.diagAreaWidget = QWidget(self.diagArea) #inner widget for scroll area #custom layout for inner widget self.diagAreaLayout = flowLayout(self.diagAreaWidget) - + self.diagAreaLayout.setSizeConstraint(flowLayout.SetMinimumSize) self.setWidget(self.widget) #set main widget to dockwidget def clearLayout(self): @@ -81,18 +81,25 @@ class toolbar(QDockWidget): parent = self.parentWidget() #used to get parent dimensions self.layout.setDirection(QBoxLayout.TopToBottom) # here so that a horizontal toolbar can be implemented later # self.setFixedHeight(self.height()) #span available height - width = self.width() - QApplication.style().pixelMetric(QStyle.PM_ScrollBarExtent) + self.searchBox.setMinimumWidth(.15*parent.width()) + width = self.width() + scrollBar = self.diagArea.verticalScrollBar() + height = self.diagAreaLayout.heightForWidth(width) + if scrollBar.isVisible(): + width -= app.app.style().pixelMetric(QStyle.PM_ScrollBarExtent) # the following line, sets the required height for the current width, so that blank space doesnt occur - self.diagAreaWidget.setMinimumHeight(self.diagAreaLayout.heightForWidth(width)) - self.setMinimumWidth(.17*parent.width()) #12% of parent width + self.diagAreaWidget.setMinimumHeight(height) + self.setMinimumWidth(.18*parent.width()) #12% of parent width # self.setMinimumWidth(self.diagAreaLayout.minimumSize().width()) #12% of parent width self.diagAreaWidget.setLayout(self.diagAreaLayout) self.diagArea.setWidget(self.diagAreaWidget) for _, label in self.toolbarLabelDict.items(): - label.setFixedSize(width, 20) - + label.setFixedWidth(width) + + def resizeEvent(self, event): + self.resize() def toolbarItems(self, itemClasses): #helper functions to create required buttons @@ -139,7 +146,7 @@ class toolbarButton(QToolButton): #handles drag if not (event.buttons() and Qt.LeftButton): return #ignore if left click is not held - if (event.pos() - self.dragStartPosition).manhattanLength() < QApplication.startDragDistance(): + if (event.pos() - self.dragStartPosition).manhattanLength() < app.app.startDragDistance(): return #check if mouse was dragged enough, manhattan length is a rough and quick method in qt drag = QDrag(self) #create drag object @@ -155,17 +162,8 @@ class toolbarButton(QToolButton): def minimumSizeHint(self): #defines button size return QSize(40, 40) - + class sectionLabel(QLabel): def __init__(self, *args): - super(sectionLabel, self).__init__(*args) - self.setAlignment(Qt.AlignHCenter) - self.setStyleSheet(""" - QLabel{ - background-color: #E6E6E3; - border: 2px solid gray; - border-left: 0px; - background-clip: padding; - } - """)
\ No newline at end of file + super(sectionLabel, self).__init__(*args)
\ No newline at end of file diff --git a/src/main/resources/base/app.qss b/src/main/resources/base/app.qss new file mode 100644 index 0000000..0d6e912 --- /dev/null +++ b/src/main/resources/base/app.qss @@ -0,0 +1,187 @@ +QLineEdit { + color: #ffffff; + background-color: #b6b6b6; + selection-color: black; + selection-background-color: #5e90fa; + /* Padding and margin defined */ + border-style: solid; + border: 1px solid #b6b6b6; /* border top color defined after QAbstractSpinBox, QLineEdit and QComboBox */ + border-top-color: #a2a2a0; /* Creates an inset effect inside the elements */ + padding: 2px 6px 2px 6px; /* This makes text colour work on QComboBox */ + margin: 0px 2px 0px 2px; + border-radius: 3px; +} + +QLineEdit:focus{ + border-color: #7cabf9; +} + +QTabBar { + qproperty-drawBase: 0; + left: 5px; + background-color: transparent; +} + +QTabBar:focus { + border: 0px transparent black; +} + +QTabBar::close-button { + padding: 0px; + margin: 0px; + border-radius: 2px; + background-image: url("src/main/resources/base/ui/close.svg"); + background-position: center center; + background-repeat: none; +} + +QTabBar::close-button:hover { + background-color: #7cabf9; +} + +QTabBar::close-button:pressed { + background-color: #adc5ed; +} + +QTabBar::scroller { /* the width of the scroll buttons */ + width: 20px; +} + +QTabBar::tab:top, +QTabBar::tab:bottom { + color: black; + border: 1px solid #b6b6b6; + border-left-color: #e6e6e6; + border-right-width: 0px; + background-color: white; + padding:0px 15px; +} + +QTabBar::tab:top:first, +QTabBar::tab:bottom:first { + border-top-left-radius: 6px; + border-bottom-left-radius: 6px; +} + +QTabBar::tab:top:last, +QTabBar::tab:bottom:last { + border-top-right-radius: 6px; + border-bottom-right-radius: 6px; + border-right-width: 1px; +} + +QTabBar::tab:top:selected, +QTabBar::tab:bottom:selected { + color: black; + background-color: qlineargradient(spread:pad, x1:1, y1:0.545, x2:1, y2:0, stop:0 #3874f2, stop:1 #5e90fa); + border-color: #3874f2; +} + +QTabBar::tab:top:!selected:hover, +QTabBar::tab:bottom:!selected:hover { + color: black; +} + +QTabBar::tab:top:only-one , +QTabBar::tab:bottom:only-one { + border: 1px solid #1b3774; + border-radius: 6px; +} + +QDockWidget { + color: #828282; + border: 1px solid #e6e6e6; +} + +QDockWidget::float-button { + border: 1px transparent #e6e6e6; + border-radius: 2px; + background: transparent; + subcontrol-origin: padding; + subcontrol-position: right center; +} +QDockWidget::float-button { + right: 4px; +} + +QDockWidget::float-button:hover { + background: #f5f5f5; +} + +QDockWidget::float-button:pressed { + /*padding: 1px -1px -1px 1px;*/ + background-color: #e0e0e0; +} + +QToolButton { + color: #f2f2f2; + text-align: center; + background-color: rgba(213, 213, 213, 0); + border: 1px solid #828282; + outline: none; +} + +QToolButton:hover, +QToolButton:focus { + color: black; + background-color: qlineargradient(spread:pad, x1:1, y1:0.545, x2:1, y2:0, stop:0 #3874f2, stop:1 #5e90fa); + border-color: #3874f2; +} + +QToolButton:disabled, +QToolButton:disabled:checked { + color: #b6b6b6; + background-color: #e6e6e6; + border-color: #b6b6b6; +} + +QToolButton:pressed { + border-color: #7cabf9; +} + +QToolButton:checked { + background-color: #5e90fa; + border-color: #3874f2; +} + +sectionLabel{ + border-style: solid; + border-color: grey; + padding-bottom: 3px; + margin-bottom: 3px; + margin-top: 5px; + text-align: left; + border-width: 0px 0px 2px 0px; +} + +customView QPushButton{ + background: rgba(214, 54, 40, 50%); + border: 1px groove white; + border-radius: 2px; + font-size: 18px; + font-weight: Bold; + padding: 1px 2px 3px 3px; + color: rgba(255, 255, 255, 50%); +} +customView QPushButton:Hover{ + background: rgba(214, 54, 40, 90%); + color: rgba(255, 255, 255, 90%); +} + +customTabWidget QPushButton{ + background: rgba(230, 230, 227, 0%); + padding: 1px; + border: 0px solid #E6E6E3; + border-radius: 10px; + top: -5px; +} +customTabWidget QPushButton:hover{ + background: rgba(230, 230, 227, 60%); +} + +customTabWidget::pane { + margin: 0px,1px,1px,1px; + border: 2px solid #E6E6E3; + border-radius: 7px; + padding: 1px; + background-color: #E6E6E3;} diff --git a/src/main/resources/base/ui/close.svg b/src/main/resources/base/ui/close.svg new file mode 100644 index 0000000..cb1c174 --- /dev/null +++ b/src/main/resources/base/ui/close.svg @@ -0,0 +1,60 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + inkscape:version="1.0 (4035a4fb49, 2020-05-01)" + sodipodi:docname="close.svg" + id="svg4" + version="1.1" + viewBox="0 0 10 10"><metadata + id="metadata10"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + </cc:Work> + </rdf:RDF> +</metadata> +<defs + id="defs8" /> +<sodipodi:namedview + inkscape:current-layer="svg4" + inkscape:window-maximized="1" + inkscape:window-y="-9" + inkscape:window-x="-9" + inkscape:cy="7.585194" + inkscape:cx="2.5623729" + inkscape:zoom="42.1" + showgrid="false" + id="namedview6" + inkscape:window-height="1013" + inkscape:window-width="1920" + inkscape:pageshadow="2" + inkscape:pageopacity="0" + guidetolerance="10" + gridtolerance="10" + objecttolerance="10" + borderopacity="1" + bordercolor="#666666" + pagecolor="#ffffff" /> +<text + id="text2" /> +2 y=8>×<text + id="text837" + y="11.016971" + x="-2.6576188" + style="font-style:normal;font-weight:normal;font-size:18.834px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.470852" + xml:space="preserve"><tspan + style="stroke-width:0.470852" + y="11.016971" + x="-2.6576188" + id="tspan835" + sodipodi:role="line">×</tspan></text> +</svg> |