[go: up one dir, main page]

Menu

[r9]: / drawingarea.cpp  Maximize  Restore  History

Download this file

100 lines (85 with data), 2.9 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
/*
Copyright (C) 2011 Arnaud Champenois arthelion92@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "drawingarea.h"
#include <QPainter>
#include <QMouseEvent>
DrawingArea::DrawingArea(MainWindow *parent) :
QWidget(parent)
{
mRubberPt = NULL;
mMainWindow = parent;
mInLogo = false;
}
DrawingArea::~DrawingArea()
{
delete mRubberPt;
}
void DrawingArea::mousePressEvent ( QMouseEvent * event )
{
if(event->button() != Qt::LeftButton)
return;
if(mImage.isNull()) return;
mInLogo = true;
mOrigin = event->pos();
if (!mRubberPt)
mRubberPt = new QRubberBand(QRubberBand::Rectangle, this);
mRubberPt->setGeometry(QRect(mOrigin, QSize()));
mRubberPt->show();
}
void DrawingArea::mouseReleaseEvent ( QMouseEvent * event )
{
if(mImage.isNull()) return;
mInLogo = false;
QRect anImageRect = mImage.rect();
mLogoArea = anImageRect.intersect(QRect(mOrigin, event->pos()).normalized());
mRubberPt->hide();
repaint();
if(mLogoArea.isValid() && mLogoArea.width()>3 && mLogoArea.height()>3)
mMainWindow->SetLogo(mLogoArea,mImage.copy(mLogoArea));
}
void DrawingArea::mouseMoveEvent ( QMouseEvent * event )
{
if(mImage.isNull()) return;
QRect anImageRect = mImage.rect();
anImageRect = anImageRect.intersect(QRect(mOrigin, event->pos()).normalized());
mRubberPt->setGeometry(anImageRect);
}
void DrawingArea::paintEvent(QPaintEvent* event)
{
QPainter p(this);
p.drawImage(0,0,mImage);
if(mMainWindow->HasLogo())
{
p.setPen(QColor(255,0,0));
p.setBrush(QColor(255,0,0,50));
p.drawRect(mLogoArea);
}
else if(!mMainWindow->IsClosed() && !mInLogo)
{
p.setFont(QFont("Times",14,10,false));
p.setPen(QColor(255,0,0));
p.drawText(QRect(0,0,800,60),tr("Drag mouse pressing left button\nto select channel logo"));
}
else if(mMainWindow->IsClosed())
{
p.setFont(QFont("Times",18,10,false));
p.setPen(QColor(255,0,0));
p.drawText(QRect(0,0,800,30),tr("Drop an mpeg ts video here"));
}
}
void DrawingArea::SetImage(const QImage&anImage)
{
mImage = anImage;
repaint();
}