-
Notifications
You must be signed in to change notification settings - Fork 5
/
LogoWidget.cpp
98 lines (83 loc) · 2.55 KB
/
LogoWidget.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
#include "LogoWidget.h"
#include "common/Common.h"
#include <QPainter>
LogoWidget::LogoWidget(QWidget *parent) : BaseWidget(parent)
{
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
m_pOpenFile = new SOpenFileButton(this);
QImage image(Common::getImagePath(":/Image/OpenFileButton.png"));
m_pOpenFile->setFixedHeight(image.height());
m_pOpenFile->setFixedWidth(image.width()/4);
m_pOpenFile->AppendImage(image);
m_pOpenFile->setToolTip(tr("Open file"));
createCentralButtonMenu();
connect(m_pOpenFile, SIGNAL(Signal_Clicked()), this
, SIGNAL(onOpenLocalFileButtonClicked()));
connect(m_pOpenFile, SIGNAL(onArrowButtonClicked()), this, SLOT(onShowPopupMenu()));
}
LogoWidget::~LogoWidget()
{
if (m_pCentralButtonMenu)
{
m_pCentralButtonMenu->close();
delete m_pCentralButtonMenu;
m_pCentralButtonMenu = NULL;
}
}
void LogoWidget::onShowPopupMenu()
{
if (!m_pCentralButtonMenu)
{
return;
}
QPoint pt = m_pOpenFile->rect().bottomLeft();
m_pCentralButtonMenu->exec(m_pOpenFile->mapToGlobal(QPoint(pt.x(), pt.y() + 1)));
}
void LogoWidget::SetLogoImage(const QString &imageFilePath)
{
m_logoImage = QImage(imageFilePath);
update();
}
void LogoWidget::paintEvent(QPaintEvent *event)
{
if (!m_logoImage.isNull())
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawImage(QPoint(0,0),m_logoImage.scaled(size()));
}
BaseWidget::paintEvent(event);
}
void LogoWidget::resizeEvent(QResizeEvent *event)
{
m_pOpenFile->move(rect().center().x() - m_pOpenFile->width()/2,rect().center().y() + m_pOpenFile->height()+10);
BaseWidget::resizeEvent(event);
}
void LogoWidget::createCentralButtonMenu()
{
m_pCentralButtonMenu = new QMenu(this);
QAction *openLocalFileAction = m_pCentralButtonMenu->addAction(tr("Open file"));
connect(openLocalFileAction, SIGNAL(triggered()), this
, SIGNAL(onOpenLocalFileButtonClicked()));
QAction *openURLAction = m_pCentralButtonMenu->addAction(tr("Open URL"));
connect(openURLAction, SIGNAL(triggered()), this, SIGNAL(onOpenURLButtonClicked()));
}
SOpenFileButton::SOpenFileButton(QWidget *parent) : SButton(parent)
{
}
SOpenFileButton::~SOpenFileButton()
{
}
void SOpenFileButton::mouseReleaseEvent(QMouseEvent *event)
{
if (event->pos().x() > 94)
{
this->ResetButtonState();
this->update();
emit onArrowButtonClicked();
}
else
{
SButton::mouseReleaseEvent(event);
}
}