That's better

This commit is contained in:
ArsenArsen 2017-06-24 23:03:00 +02:00
parent e573f3d014
commit 909944d04c
2 changed files with 17 additions and 7 deletions

View File

@ -7,6 +7,12 @@
#include <QTimer>
#include <hotkeying.hpp>
QSize max(300, 300);
inline bool sizeGreater(QSize one, QSize two) {
return one.height() > two.height() || one.width() > two.width();
}
RecordingPreview::RecordingPreview(QRect area, QWidget *parent) : QWidget(parent) {
recordingArea = area;
setStyleSheet("background-color: rgba(0, 0, 0, 0.7);");
@ -16,23 +22,26 @@ RecordingPreview::RecordingPreview(QRect area, QWidget *parent) : QWidget(parent
QTimer::singleShot(0, [&] {
adjustSize();
move(0, 0);
if (rect().intersects(recordingArea)) // Formatter please
if (frameGeometry().intersects(recordingArea)) // Formatter please
move(QApplication::primaryScreen()->size().width() - rect().width(), 0);
if (rect().intersects(recordingArea)) // Formatter please
if (frameGeometry().intersects(recordingArea)) // Formatter please
move(0, QApplication::primaryScreen()->size().height() - rect().height());
if (rect().intersects(recordingArea))
if (frameGeometry().intersects(recordingArea))
move(QApplication::primaryScreen()->size().width() - rect().width(),
QApplication::primaryScreen()->size().height() - rect().height());
if (!rect().intersects(recordingArea)) show();
if (!frameGeometry().intersects(recordingArea)) show();
});
label = new QLabel;
hintLabel = new QLabel;
auto ly = new QGridLayout(this);
setLayout(ly);
auto size = recordingArea.size().scaled(QSize(300, 300), Qt::KeepAspectRatio);
size = sizeGreater(recordingArea.size(), max) ? recordingArea.size().scaled(max, Qt::KeepAspectRatio) :
recordingArea.size();
label->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
label->setMaximumSize(size);
label->resize(size);
QPixmap empty(size);
empty.fill(Qt::transparent);
label->setPixmap(empty);
layout()->addWidget(hintLabel);
layout()->addWidget(label);
hintLabel->setText(QString("Time: 00:00\nFrame: 0\nStop key: ") + hotkeying::sequence("recordingstop"));
@ -45,7 +54,7 @@ RecordingPreview::~RecordingPreview() {
}
void RecordingPreview::setPixmap(QPixmap map) {
label->setPixmap(map.scaled(label->maximumSize()));
label->setPixmap(map.scaled(size));
}
void RecordingPreview::setTime(QString time, int frame) {
if (isVisible())

View File

@ -17,6 +17,7 @@ public:
private:
QLabel *label;
QLabel *hintLabel;
QSize size;
QRect recordingArea;
};