Area selection dialog
This commit is contained in:
parent
869c2d0031
commit
09e670bf23
@ -47,7 +47,8 @@ SOURCES += main.cpp\
|
||||
cropeditor/drawing/lineitem.cpp \
|
||||
cropeditor/drawing/textitem.cpp \
|
||||
colorpicker/colorpickerscene.cpp \
|
||||
worker/worker.cpp
|
||||
worker/worker.cpp \
|
||||
screenareaselector/screenareaselector.cpp
|
||||
|
||||
HEADERS += mainwindow.hpp \
|
||||
cropeditor/cropeditor.hpp \
|
||||
@ -76,7 +77,8 @@ HEADERS += mainwindow.hpp \
|
||||
colorpicker/colorpickerscene.hpp \
|
||||
platformbackend.hpp \
|
||||
gif-h/gif.h \
|
||||
worker/worker.hpp
|
||||
worker/worker.hpp \
|
||||
screenareaselector/screenareaselector.hpp
|
||||
|
||||
mac {
|
||||
SOURCES += $$PWD/platformspecifics/mac/macbackend.cpp
|
||||
|
2
main.cpp
2
main.cpp
@ -5,6 +5,7 @@
|
||||
#include <QtGlobal>
|
||||
#include <iostream>
|
||||
#include <notifications.hpp>
|
||||
#include <screenareaselector/screenareaselector.hpp>
|
||||
#include <stdio.h>
|
||||
#include <worker/worker.hpp>
|
||||
|
||||
@ -62,5 +63,6 @@ int main(int argc, char *argv[]) {
|
||||
Worker::init();
|
||||
a.connect(&a, &QApplication::aboutToQuit, Worker::end);
|
||||
if (!parser.isSet(h)) w.show();
|
||||
(new ScreenAreaSelector())->show();
|
||||
return a.exec();
|
||||
}
|
||||
|
38
screenareaselector/screenareaselector.cpp
Normal file
38
screenareaselector/screenareaselector.cpp
Normal file
@ -0,0 +1,38 @@
|
||||
#include "screenareaselector.hpp"
|
||||
#include <QCloseEvent>
|
||||
#include <QPalette>
|
||||
#include <QTimer>
|
||||
#include <settings.hpp>
|
||||
|
||||
ScreenAreaSelector::ScreenAreaSelector() {
|
||||
setAttribute(Qt::WA_TranslucentBackground);
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
setStyleSheet("background:transparent;");
|
||||
setWindowTitle("KShare: Select Area (By resizig this window)");
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ScreenAreaSelector::~ScreenAreaSelector() {
|
||||
}
|
||||
|
||||
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::closeEvent(QCloseEvent *) {
|
||||
QRect r = QRect(pos(), rect().size());
|
||||
settings::settings().setValue("screenareaselector/rect", r);
|
||||
}
|
19
screenareaselector/screenareaselector.hpp
Normal file
19
screenareaselector/screenareaselector.hpp
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef SCREENAREASELECTOR_HPP
|
||||
#define SCREENAREASELECTOR_HPP
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class ScreenAreaSelector : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScreenAreaSelector();
|
||||
~ScreenAreaSelector();
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
void keyPressEvent(QKeyEvent *) override;
|
||||
signals:
|
||||
void selectedArea(QRect area);
|
||||
};
|
||||
|
||||
#endif // SCREENAREASELECTOR_HPP
|
Loading…
Reference in New Issue
Block a user