-
-
Notifications
You must be signed in to change notification settings - Fork 582
Expand file tree
/
Copy pathcurveimagewidget.cpp
More file actions
100 lines (87 loc) · 2.6 KB
/
Copy pathcurveimagewidget.cpp
File metadata and controls
100 lines (87 loc) · 2.6 KB
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
100
/*
* Copyright (C) EdgeTX
*
* Based on code named
* opentx - https://github.com/opentx/opentx
* th9x - http://code.google.com/p/th9x
* er9x - http://code.google.com/p/er9x
* gruvin9x - http://code.google.com/p/gruvin9x
*
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include "curveimagewidget.h"
#include "curveimage.h"
#include "curvedialog.h"
#include "compounditemmodels.h"
#include "modeldata.h"
#include "eeprominterface.h"
CurveImageWidget::CurveImageWidget(QWidget * parent) :
QLabel(parent)
{
setToolTip(tr("Double click to edit"));
}
void CurveImageWidget::set(ModelData * model, Firmware * firmware, CompoundItemModelFactory * sharedItemModels, int index, QColor penColor, qreal penWidth)
{
this->model = model;
this->firmware = firmware;
this->sharedItemModels = sharedItemModels;
this->penWidth = penWidth;
this->penColor = penColor;
setIndex(index);
setGrid();
}
void CurveImageWidget::setIndex(int index)
{
this->index = index;
}
void CurveImageWidget::setGrid(QColor color, qreal width)
{
gridColor = color;
gridWidth = width;
}
void CurveImageWidget::setPen(QColor color, qreal width)
{
penColor = color;
penWidth = width;
}
int CurveImageWidget::edit()
{
int ret = 0;
if (abs(index) > 0 && abs(index) <= CPN_MAX_CURVES) {
CurveDialog *dlg = new CurveDialog(this, *model, abs(index) - 1, firmware, sharedItemModels);
ret = dlg->exec();
delete dlg;
}
return ret;
}
void CurveImageWidget::draw()
{
if (abs(index) > 0 && abs(index) <= CPN_MAX_CURVES) {
CurveImage *curveImage = new CurveImage(gridColor, gridWidth);
curveImage->drawCurve(model->curves[abs(index) - 1], penColor, penWidth);
QImage image = curveImage->get();
if (index < 0)
image = image.mirrored(true, false);
setPixmap(QPixmap::fromImage(image.scaled(height(), width())));
delete curveImage;
}
else {
CurveImage *curveImage = new CurveImage(gridColor, gridWidth);
QImage image = curveImage->get();
setPixmap(QPixmap::fromImage(image.scaled(height(), width())));
}
}
void CurveImageWidget::mouseDoubleClickEvent(QMouseEvent * event)
{
QLabel::mouseDoubleClickEvent(event);
emit doubleClicked();
}