Skip to content

Commit

Permalink
Re-enable antialiasing for Oculars panel border
Browse files Browse the repository at this point in the history
It was broken by the switch to a non-multisampled final framebuffer, so
now the implementation uses a QPixmap rendered with QPainter.
  • Loading branch information
10110111 committed Jan 12, 2025
1 parent 90101de commit 70b3790
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 23 deletions.
58 changes: 36 additions & 22 deletions plugins/Oculars/src/gui/OcularsGuiPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ OcularsGuiPanel::OcularsGuiPanel(Oculars* plugin,
Qt::WindowFlags wFlags):
QGraphicsWidget(parent, wFlags),
ocularsPlugin(plugin),
parentWidget(parent),
borderPath(Q_NULLPTR)
parentWidget(parent)
{
setContentsMargins(0, 0, 0, 0);

Expand Down Expand Up @@ -174,8 +173,8 @@ OcularsGuiPanel::OcularsGuiPanel(Oculars* plugin,

updateRotationButtons();

borderPath = new QGraphicsPathItem(parentWidget);
borderPath->setZValue(100);
bgPixmap.reset(new QGraphicsPixmapItem(parentWidget));
bgPixmap->setZValue(100);

updateLayout();

Expand All @@ -197,9 +196,6 @@ OcularsGuiPanel::OcularsGuiPanel(Oculars* plugin,

OcularsGuiPanel::~OcularsGuiPanel()
{
if (borderPath)
delete borderPath;

delete buttonCrosshairs; buttonCrosshairs = Q_NULLPTR;
delete buttonCcd; buttonCcd = Q_NULLPTR;
delete buttonTelrad; buttonTelrad = Q_NULLPTR;
Expand Down Expand Up @@ -274,20 +270,37 @@ void OcularsGuiPanel::updatePosition()
qreal xPos = parentWidget->size().width() - size().width();
qreal yPos = 0;
setPos(xPos, yPos);
bgPixmap->setPos(xPos - 1, yPos);

if (bgPixmap->pixmap().size() != size().toSize())
updateBackgroundPixmap();
}

//Update border/shading
QPainterPath newBorderPath;
double cornerRadius = 12.0;
QPointF verticalBorderStart = geometry().topLeft() + QPointF(-0.5,0.5);
QPointF horizontalBorderEnd = geometry().bottomRight() + QPointF(-0.5,0.5);
QPointF cornerArcStart(verticalBorderStart.x(),
horizontalBorderEnd.y() - cornerRadius);
newBorderPath.moveTo(verticalBorderStart);
newBorderPath.lineTo(cornerArcStart);
newBorderPath.arcTo(cornerArcStart.x(), cornerArcStart.y(), cornerRadius, cornerRadius, 180, 90);
newBorderPath.lineTo(horizontalBorderEnd);
newBorderPath.lineTo(horizontalBorderEnd.x(), verticalBorderStart.y());
borderPath->setPath(newBorderPath);
void OcularsGuiPanel::updateBackgroundPixmap()
{
const double cornerRadius = 12.0;
const QPointF verticalBorderStart = geometry().topLeft();
const QPointF horizontalBorderEnd = geometry().bottomRight();
const QPointF cornerArcStart(verticalBorderStart.x(),
horizontalBorderEnd.y() - cornerRadius);
QPainterPath path;
path.moveTo(verticalBorderStart);
path.lineTo(cornerArcStart);
path.arcTo(cornerArcStart.x(), cornerArcStart.y(), cornerRadius, cornerRadius, 180, 90);
path.lineTo(horizontalBorderEnd);
path.lineTo(horizontalBorderEnd.x(), verticalBorderStart.y());

QPixmap pix(size().toSize() + QSize(1,1));
pix.fill(Qt::transparent);
{
QPainter p(&pix);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(borderPen);
p.setBrush(bgBrush);
p.translate(QPointF(0.5,0.5)-verticalBorderStart);
p.drawPath(path);
}
bgPixmap->setPixmap(pix);
}

void OcularsGuiPanel::updateOcularControls()
Expand Down Expand Up @@ -1169,9 +1182,10 @@ void OcularsGuiPanel::setControlsFont(const QFont& font)
void OcularsGuiPanel::setColorScheme(const QString &schemeName)
{
Q_UNUSED(schemeName)
borderPath->setPen(QColor::fromRgbF(0.7,0.7,0.7,0.5));
borderPath->setBrush(QColor::fromRgbF(0.15, 0.16, 0.19, 0.2));
borderPen = QPen(QColor::fromRgbF(0.7,0.7,0.7,0.5));
bgBrush = QBrush(QColor::fromRgbF(0.15, 0.16, 0.19, 0.2));
setControlsColor(QColor::fromRgbF(0.9, 0.91, 0.95, 0.9));
updateBackgroundPixmap();
}

void OcularsGuiPanel::updateRotationButtons()
Expand Down
7 changes: 6 additions & 1 deletion plugins/Oculars/src/gui/OcularsGuiPanel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
#define OCULARSGUIPANEL_HPP

#include <QGraphicsWidget>
#include <QPen>
#include <QBrush>

class Oculars;
class StelButton;
Expand Down Expand Up @@ -72,6 +74,7 @@ private slots:

void updateLayout();
void updateRotationButtons();
void updateBackgroundPixmap();

private:
Oculars* ocularsPlugin;
Expand All @@ -81,7 +84,9 @@ private slots:

QGraphicsLinearLayout* mainLayout;

QGraphicsPathItem* borderPath;
QPen borderPen;
QBrush bgBrush;
std::unique_ptr<QGraphicsPixmapItem> bgPixmap;

//! Mini-toolbar holding StelButtons
QGraphicsWidget* buttonBar;
Expand Down

0 comments on commit 70b3790

Please sign in to comment.