-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectionwindow.cpp
More file actions
37 lines (31 loc) · 915 Bytes
/
selectionwindow.cpp
File metadata and controls
37 lines (31 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "selectionwindow.h"
#include <QApplication>
#include <QKeyEvent>
#include <QPixmap>
#include <QScreen>
namespace shutter {
SelectionWindow::SelectionWindow() : QGraphicsView() {
m_pix = qApp->primaryScreen()->grabWindow();
m_scene = new QGraphicsScene(this);
setScene(m_scene);
m_scene->addPixmap(m_pix);
// this is not exactly what we want, but good enough for prototype
setDragMode(QGraphicsView::RubberBandDrag);
}
void SelectionWindow::keyPressEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_Escape) {
close();
} else {
QGraphicsView::keyPressEvent(event);
}
}
void SelectionWindow::mouseReleaseEvent(QMouseEvent* event) {
m_pix = QPixmap::fromImage(m_pix.toImage().copy(rubberBandRect()));
setDragMode(DragMode::NoDrag);
m_scene->clear();
m_scene->addPixmap(m_pix);
showNormal();
resize(m_pix.size());
QGraphicsView::mouseReleaseEvent(event);
}
} // namespace shutter