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
|
/***************************************************************************
* Copyright (C) 2008-2009 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)
: QFrame(parent)
{
setWindowFlags(Qt::X11BypassWindowManagerHint |
Qt::WindowStaysOnTopHint | Qt::Dialog | Qt::FramelessWindowHint);
setFrameStyle(QFrame::Box | QFrame::Plain);
setAttribute(Qt::WA_QuitOnClose, FALSE);
m_lastItem = 0;
QHBoxLayout *hlayout = new QHBoxLayout(this); //layout
m_pixlabel = new QLabel(this);
m_pixlabel->setPixmap(QPixmap(":/32x32/qmmp.png"));
m_pixlabel->setFixedSize(32,32);
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();
settings.endGroup();
//timer
m_timer = new QTimer(this);
m_timer->setInterval(10000);
m_timer->setSingleShot (TRUE);
connect(m_timer, SIGNAL(timeout ()), SLOT(hide()));
}
PopupWidget::~PopupWidget()
{}
void PopupWidget::mousePressEvent (QMouseEvent *)
{
deleteLater();
}
void PopupWidget::popup(PlayListItem *item, QPoint pos)
{
if(m_lastItem == item)
{
show();
m_timer->start();
return;
}
m_timer->stop();
m_lastItem = item;
move(pos);
QString title = m_template;
if (item->length() > 0)
{
int l = item->length();
title.replace("%l",QString("%1:%2").arg(l/60).arg(l%60, 2, 10, QChar('0')));
}
else
title.replace("%l","");
MetaDataFormatter f(title);
title = f.parse(item->metaData());
m_label1->setText(title);
QPixmap pix = MetaDataManager::instance()->getCover(item->url());
if(!pix.isNull())
{
m_pixlabel->setFixedSize(m_coverSize,m_coverSize);
m_pixlabel->setPixmap(pix.scaled(m_coverSize,m_coverSize));
}
else
{
m_pixlabel->setPixmap(QPixmap(":/notifier_icon.png"));
m_pixlabel->setFixedSize(32,32);
}
qApp->processEvents();
resize(sizeHint());
qApp->processEvents();
show();
m_timer->start();
}
|