Merge progress bars into single source file

This commit is contained in:
Veronica Berglyd Olsen
2024-06-16 16:14:11 +02:00
parent 45ad0f8c20
commit 43cdc8420c
4 changed files with 28 additions and 58 deletions
@@ -1,9 +1,10 @@
"""
novelWriter Custom Widget: Progress Circle
============================================
novelWriter Custom Widget: Progress Bars
==========================================
File History:
Created: 2023-06-07 [2.1b1]
Created: 2023-06-07 [2.1b1] NProgressCircle
Created: 2023-06-09 [2.1b1] NProgressSimple
This file is a part of novelWriter
Copyright 20182024, Veronica Berglyd Olsen
@@ -101,3 +102,25 @@ class NProgressCircle(QProgressBar):
painter.setPen(self._tColor)
painter.drawText(self._cRect, QtAlignCenter, self._text or f"{progress:.1f} %")
return
class NProgressSimple(QProgressBar):
"""Extension: Simple Progress Widget
A custom widget that paints a plain bar with no other styling.
"""
def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent)
return
def paintEvent(self, event: QPaintEvent) -> None:
"""Custom painter for the progress bar."""
if (value := self.value()) > 0:
progress = ceil(self.width()*float(value)/self.maximum())
painter = QPainter(self)
painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self.palette().highlight().color())
painter.setBrush(self.palette().highlight())
painter.drawRect(0, 0, progress, self.height())
return
-53
View File
@@ -1,53 +0,0 @@
"""
novelWriter Custom Widget: Progress Simple
============================================
File History:
Created: 2023-06-09 [2.1b1]
This file is a part of novelWriter
Copyright 20182024, Veronica Berglyd Olsen
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from __future__ import annotations
from math import ceil
from PyQt5.QtGui import QPainter, QPaintEvent
from PyQt5.QtWidgets import QProgressBar, QWidget
from novelwriter.types import QtPaintAnitAlias
class NProgressSimple(QProgressBar):
"""Extension: Simple Progress Widget
A custom widget that paints a plain bar with no other styling.
"""
def __init__(self, parent: QWidget) -> None:
super().__init__(parent=parent)
return
def paintEvent(self, event: QPaintEvent) -> None:
"""Custom painter for the progress bar."""
if (value := self.value()) > 0:
progress = ceil(self.width()*float(value)/self.maximum())
painter = QPainter(self)
painter.setRenderHint(QtPaintAnitAlias, True)
painter.setPen(self.palette().highlight().color())
painter.setBrush(self.palette().highlight())
painter.drawRect(0, 0, progress, self.height())
return