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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/***************************************************************************
* Copyright (C) 2008-2010 by Ilya Kotov *
* forkotov02@hotmail.ru *
* *
* 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 2 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, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <QVBoxLayout>
#include <QLabel>
#include <QApplication>
#include <QTimer>
#include <QSettings>
#include <QApplication>
#include <qmmp/soundcore.h>
#include <qmmp/metadatamanager.h>
#include <qmmpui/metadataformatter.h>
#include <qmmpui/playlistitem.h>
#include "popupwidget.h"
using namespace PlayListPopup;
PopupWidget::PopupWidget(QWidget *parent)
: QWidget(parent)
{
setWindowFlags(Qt::X11BypassWindowManagerHint | Qt::Dialog | Qt::FramelessWindowHint);
//setFrameStyle(QFrame::Box | QFrame::Plain);
setAttribute(Qt::WA_QuitOnClose, FALSE);
m_item = 0;
QHBoxLayout *hlayout = new QHBoxLayout(this); //layout
m_pixlabel = new QLabel(this);
hlayout->addWidget(m_pixlabel);
m_label1 = new QLabel(this);
hlayout->addWidget (m_label1);
//settings
QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
settings.beginGroup("PlayList");
setWindowOpacity(settings.value("popup_opacity", 1.0).toDouble());
m_coverSize = settings.value("popup_cover_size", 48).toInt();
m_template = settings.value("popup_template",DEFAULT_TEMPLATE).toString();
int delay = settings.value("popup_delay", 2500).toInt();
bool show_cover = settings.value("popup_show_cover",true).toBool();
settings.endGroup();
//timer
m_timer = new QTimer(this);
m_timer->setInterval(delay);
m_timer->setSingleShot (true);
if(show_cover)
connect(m_timer, SIGNAL(timeout ()), SLOT(loadCover()));
else
m_pixlabel->hide();
connect(m_timer, SIGNAL(timeout ()), SLOT(show()));
setMouseTracking(true);
}
PopupWidget::~PopupWidget()
{}
void PopupWidget::mousePressEvent (QMouseEvent *)
{
hide();
}
void PopupWidget::mouseMoveEvent (QMouseEvent *)
{
hide();
}
void PopupWidget::prepare(PlayListItem *item, QPoint pos)
{
pos += QPoint(15,10);
m_item = item;
hide();
if(!item)
{
m_timer->stop();
return;
}
move(pos);
QString title = m_template;
MetaDataFormatter f(title);
title = f.parse(item);
m_label1->setText(title);
qApp->processEvents();
updateGeometry ();
qApp->processEvents();
m_timer->start();
}
void PopupWidget::deactivate()
{
m_timer->stop();
hide();
}
PlayListItem *PopupWidget::item()
{
return m_item;
}
void PopupWidget::loadCover()
{
if(!m_item)
return;
QPixmap pix = MetaDataManager::instance()->getCover(m_item->url());
if(pix.isNull())
pix = QPixmap(":/ui_no_cover.png");
m_pixlabel->setFixedSize(m_coverSize,m_coverSize);
m_pixlabel->setPixmap(pix.scaled(m_coverSize,m_coverSize));
}
|