-
Notifications
You must be signed in to change notification settings - Fork 0
/
previewwidget.cpp
99 lines (87 loc) · 2.71 KB
/
previewwidget.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "previewwidget.h"
#include "ui_previewwidget.h"
#include <QEvent>
#include <QKeyEvent>
const static auto ZOOMING_KB_VALUE = 2 * ScrollAreaPannable::WheelStep;
PreviewWidget::PreviewWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::PreviewWidget)
{
ui->setupUi(this);
ui->scrollAreaZoom->installEventFilter(this);
}
PreviewWidget::~PreviewWidget()
{
delete ui;
}
void PreviewWidget::setImage(const QImage &image, const QString &tooltip)
{
getScrollArea()->setMaxZoom(image.size());
ui->lblZoomPix->setPixmap(QPixmap::fromImage(image));
ui->lblZoomPix->setStatusTip(tooltip);
}
void PreviewWidget::resetZoom() const
{
ui->scrollAreaZoom->zoomFitWindow();
ui->scrollAreaZoom->ensureVisible(0,0);
}
void PreviewWidget::zoomIn() const
{
ui->scrollAreaZoom->zoomBy(ZOOMING_KB_VALUE);
}
void PreviewWidget::zoomOut() const
{
ui->scrollAreaZoom->zoomBy(-ZOOMING_KB_VALUE);
}
QPointer<ScrollAreaPannable> PreviewWidget::getScrollArea() const
{
return QPointer<ScrollAreaPannable>(ui->scrollAreaZoom);
}
const QString& PreviewWidget::getKeyboardUsage()
{
const static QString zoomKbHintText = tr("LBM /arrows - pan, RBM - select, LBM + wheel(shift + wheel, +-, shift+up/down) - zoom. ctrl + L/R arrows to list files.");
return zoomKbHintText;
}
void PreviewWidget::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}
bool PreviewWidget::eventFilter(QObject *src, QEvent *e)
{
//mouse events for scrollzoom are overloaded in ScrollAreaPannable, do it there
//if you change shortcuts here, please fix hint string into on_tabsWidget_currentChanged(int index)
if (src == ui->scrollAreaZoom)
{
if (e->type() == QEvent::KeyPress)
{
const QKeyEvent *ke = static_cast<decltype (ke)>(e);
const auto key = ke->key();
if ((ke->modifiers() == Qt::ControlModifier) && (key == Qt::Key_Left || key == Qt::Key_Right))
{
if (key == Qt::Key_Left)
emit prevImageRequested();
else
emit nextImageRequested();
return true;
}
if (key == Qt::Key_Plus || key == Qt::Key_Equal || (key == Qt::Key_Up && ke->modifiers() == Qt::ShiftModifier))
{
zoomIn();
return true;
}
if (key == Qt::Key_Minus || (key == Qt::Key_Down && ke->modifiers() == Qt::ShiftModifier))
{
zoomOut();
return true;
}
}
}
return QWidget::eventFilter(src, e);
}