mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-09-10 18:46:11 -05:00
Improve preview frame visibilty of cursor condition
* Add transparent diagonal stripes to frame * Do not show frame if invalid selection was made
This commit is contained in:
37
src/utils/striped-frame.cpp
Normal file
37
src/utils/striped-frame.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "striped-frame.hpp"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
constexpr QColor stripeColor = QColor(255, 255, 255, 50);
|
||||
constexpr int stripeWidth = 30;
|
||||
constexpr int stripeSpacing = 30;
|
||||
constexpr qreal sqrtOf2 = 1.41421356237309;
|
||||
constexpr int painterVerticalOffset = stripeWidth / sqrtOf2 + 1;
|
||||
constexpr int rotatedPainterSpacing =
|
||||
(stripeWidth + stripeSpacing) / sqrtOf2 + 1;
|
||||
constexpr qreal horizontalMoveStep = stripeWidth + stripeSpacing;
|
||||
constexpr qreal verticalMoveStep = -horizontalMoveStep;
|
||||
|
||||
void StripedFrame::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QFrame::paintEvent(event);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setPen(Qt::NoPen);
|
||||
painter.setBrush(stripeColor);
|
||||
|
||||
const int biggerSideSize = width() > height() ? width() : height();
|
||||
const int numStripes = biggerSideSize / rotatedPainterSpacing + 1;
|
||||
|
||||
painter.translate(0, -painterVerticalOffset);
|
||||
painter.rotate(45);
|
||||
|
||||
const qreal diagonalLength =
|
||||
std::sqrt(width() * width() + height() * height());
|
||||
const qreal stripeLength = diagonalLength * 2;
|
||||
|
||||
for (int i = 0; i < numStripes; ++i) {
|
||||
painter.drawRect(0, 0, stripeWidth, stripeLength);
|
||||
painter.translate(horizontalMoveStep, verticalMoveStep);
|
||||
}
|
||||
}
|
||||
11
src/utils/striped-frame.hpp
Normal file
11
src/utils/striped-frame.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
#include <QFrame>
|
||||
#include <QPainter>
|
||||
|
||||
class StripedFrame : public QFrame {
|
||||
public:
|
||||
StripedFrame(QWidget *parent = nullptr) : QFrame(parent) {}
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *event) override;
|
||||
};
|
||||
Reference in New Issue
Block a user