KShare/screenareaselector/screenareaselector.cpp

53 lines
1.7 KiB
C++
Raw Normal View History

2017-05-31 17:24:17 +02:00
#include "screenareaselector.hpp"
#include <QCloseEvent>
#include <QLabel>
2017-05-31 17:24:17 +02:00
#include <QPalette>
#include <QStackedLayout>
2017-05-31 17:24:17 +02:00
#include <QTimer>
#include <settings.hpp>
ScreenAreaSelector::ScreenAreaSelector() {
setAttribute(Qt::WA_TranslucentBackground);
setAttribute(Qt::WA_DeleteOnClose);
2017-06-07 10:37:40 +02:00
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
setStyleSheet("background-color: rgba(0, 0, 0, 0.5);");
2017-05-31 23:46:27 +02:00
setWindowTitle("KShare: Select Area (By resizing this window)");
2017-05-31 17:24:17 +02:00
QTimer::singleShot(0, [&] {
QVariant val = settings::settings().value("screenareaselector/rect");
if (val.canConvert<QRect>()) {
QRect rect = val.value<QRect>();
resize(rect.size());
move(rect.topLeft());
}
hintLabel->setText(QString::number(width()) + "x" + QString::number(height()));
show();
2017-05-31 17:24:17 +02:00
});
setLayout(new QStackedLayout());
hintLabel = new QLabel();
hintLabel->setAlignment(Qt::AlignCenter);
layout()->addWidget(hintLabel);
2017-05-31 17:24:17 +02:00
}
ScreenAreaSelector::~ScreenAreaSelector() {
delete hintLabel;
2017-05-31 17:24:17 +02:00
}
void ScreenAreaSelector::keyPressEvent(QKeyEvent *event) {
event->accept();
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
QRect r = QRect(pos(), rect().size());
emit selectedArea(r);
close();
} else if (event->key() == Qt::Key_Escape)
close();
}
void ScreenAreaSelector::resizeEvent(QResizeEvent *) {
hintLabel->setText(QString::number(width()) + "x" + QString::number(height()));
}
2017-05-31 17:24:17 +02:00
void ScreenAreaSelector::closeEvent(QCloseEvent *) {
QRect r = QRect(pos(), rect().size());
settings::settings().setValue("screenareaselector/rect", r);
}