mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-24 02:05:24 -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:
@@ -268,6 +268,8 @@ target_sources(
|
||||
src/utils/slider-spinbox.hpp
|
||||
src/utils/source-selection.cpp
|
||||
src/utils/source-selection.hpp
|
||||
src/utils/striped-frame.cpp
|
||||
src/utils/striped-frame.hpp
|
||||
src/utils/transition-selection.cpp
|
||||
src/utils/transition-selection.hpp
|
||||
src/utils/utility.cpp
|
||||
|
||||
@@ -334,18 +334,20 @@ void MacroConditionCursorEdit::SetupFrame()
|
||||
Qt::WindowStaysOnTopHint);
|
||||
_frame.setAttribute(Qt::WA_TranslucentBackground, true);
|
||||
|
||||
if (_entryData) {
|
||||
QRect rect(_entryData->_minX, _entryData->_minY,
|
||||
_entryData->_maxX - _entryData->_minX,
|
||||
_entryData->_maxY - _entryData->_minY);
|
||||
|
||||
if (rect.size().height() == 0 || rect.size().width() == 0) {
|
||||
_frame.setGeometry(0, 0, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
_frame.setGeometry(getScreenUnionRect().intersected(rect));
|
||||
if (!_entryData) {
|
||||
return;
|
||||
}
|
||||
|
||||
QRect rect(_entryData->_minX, _entryData->_minY,
|
||||
_entryData->_maxX - _entryData->_minX,
|
||||
_entryData->_maxY - _entryData->_minY);
|
||||
|
||||
if (rect.size().height() <= 0 || rect.size().width() <= 0) {
|
||||
_frame.setGeometry(0, 0, 1, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
_frame.setGeometry(getScreenUnionRect().intersected(rect));
|
||||
}
|
||||
|
||||
void MacroConditionCursorEdit::UpdateEntryData()
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#pragma once
|
||||
#include "macro.hpp"
|
||||
#include "striped-frame.hpp"
|
||||
|
||||
#include <QSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QPushButton>
|
||||
#include <QTimer>
|
||||
#include <QFrame>
|
||||
|
||||
class MacroConditionCursor : public MacroCondition {
|
||||
public:
|
||||
@@ -86,6 +86,6 @@ private:
|
||||
void SetWidgetVisibility();
|
||||
void SetupFrame();
|
||||
QTimer _timer;
|
||||
QFrame _frame;
|
||||
StripedFrame _frame;
|
||||
bool _loading = true;
|
||||
};
|
||||
|
||||
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