aboutsummaryrefslogtreecommitdiff
path: root/src/ui/logscale.cpp
blob: 921004fd972ef0b2986bb93e29dd6ce19bdb32a2 (plain) (blame)
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
// Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com>
//
// Use, modification and distribution is allowed without limitation,
// warranty, or liability of any kind.
//

#include "logscale.h"

#include <math.h>
#include <stdio.h>


LogScale::LogScale(int maxscale, int maxrange)
    : indices(0), s(0), r(0)
{
    setMax(maxscale, maxrange);
}


LogScale::~LogScale()
{
    if (indices)
	delete [] indices;
}


void LogScale::setMax(int maxscale, int maxrange)
{
    if (maxscale == 0 || maxrange == 0)
	return;

    s = maxscale;
    r = maxrange;

    if (indices)
	delete [] indices;

    double alpha;
    int i, scaled;
    double domain = double(maxscale),
	    range = double(maxrange),
		x = 1.0,
	       dx = 1.0,
		y = 0.0,
	       yy = 0.0,
		t = 0.0,
	       e4 = double(1.0E-8);

    indices = new int[maxrange];
    for (i = 0; i < maxrange; i++)
	indices[i] = 0;

    // initialize log scale
    while (fabs(dx) > e4) {
	t = log((domain + x) / x);
	y = (x * t) - range;
	yy = t - (domain / (x + domain));
	dx = y / yy;
	x -= dx;
    }

    alpha = x;
    for (i = 1; i < (int) domain; i++) {
	scaled = (int) floor(0.5 + (alpha * log((double(i) + alpha) / alpha)));
	if (indices[scaled - 1] < i)
	    indices[scaled - 1] = i;
    }
}


int LogScale::operator[](int index)
{
    return indices[index];
}
er vovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38> 2007-06-23 16:48:01 +0000 moved into qmmp dir' href='/qmmp/commit/src/timeindicator.cpp?id=2d622fd9bcb8da9dd3f3206e296cd6a701fc9d12'>2d622fd9b
97c98d9d5
2d622fd9b
6f2cb48f2
2d622fd9b

178b0feca
029b517f5

97c98d9d5



2d622fd9b
97c98d9d5
2d622fd9b




97c98d9d5


2d622fd9b

97c98d9d5
2d622fd9b
080507d3a
2d622fd9b


2d622fd9b
080507d3a
2d622fd9b














97c98d9d5
2d622fd9b





ae75e5707
fa1e4194b

2d622fd9b


2d622fd9b

ae75e5707
fa1e4194b

2d622fd9b


2d622fd9b


6f2cb48f2



2d622fd9b







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
127
128
129
130
131
132
133
134
135
136
137
138
139
                                                                            
                                                                            














                                                                            
                                                                            


                                                                             
                      
                 
                      



                          

                                              
 
                              
                                                                   




                                
            
                                                                     

                               
                                  
                                                      

 
                                   

               


                                    



                               
                                                      
     
              

              
                 

                



                                                         
 
                         




                           


                                    

 
                                                   
 
                                                         


                                             
     
                                     














                                          
                                                                   





                                  
                                                                 

                                                              


                        

                                   
                                                                 

                                                


                        


                                                



                         







                                                    
/***************************************************************************
 *   Copyright (C) 2006-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.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 ***************************************************************************/
#include <QPainter>
#include <QSettings>
#include <QMouseEvent>
#include <QTimer>
#include <qmmp/qmmp.h>

#include "skin.h"
#include "timeindicator.h"

TimeIndicator::TimeIndicator (QWidget *parent)
        : PixmapWidget (parent)
{
    m_skin = Skin::instance();
    m_pixmap = QPixmap (65 * m_skin->ratio(),13 * m_skin->ratio());
    m_elapsed = true;
    m_time = m_songDuration = 0;
    readSettings();
    m_needToShowTime = false;
    updateSkin();
    reset();
    connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin()));
    m_timer = new QTimer(this);
    m_timer->setInterval(125);
    m_timer->setSingleShot (true);
    connect(m_timer, SIGNAL(timeout()),SLOT(reset()));
}

void TimeIndicator::setTime (int t)
{
    m_time = t;
    m_pixmap.fill (Qt::transparent);
    int r = m_skin->ratio();
    QPainter paint (&m_pixmap);

    if (!m_elapsed)
    {
        t = m_songDuration - t;
        paint.drawPixmap(r*2,0,m_skin->getNumber(10));
    }
    if (t < 0)
        t = 0;

    if(t >= 3600)
        t /= 60;

    paint.drawPixmap(r*13,0,m_skin->getNumber(t/600%10));
    paint.drawPixmap(r*26,0,m_skin->getNumber(t/60%10));
    paint.drawPixmap(r*43,0,m_skin->getNumber(t%60/10));
    paint.drawPixmap(r*56,0,m_skin->getNumber(t%60%10));

    setPixmap (m_pixmap);

}

void TimeIndicator::reset()
{
    m_pixmap.fill (Qt::transparent);
    QPainter paint (&m_pixmap);
    setPixmap (m_pixmap );
}

void TimeIndicator::mousePressEvent(QMouseEvent* e)
{
    if (m_needToShowTime && e->button() & Qt::LeftButton)
    {
        m_elapsed = m_elapsed ? false : true;
        setTime(m_time);
    }
    PixmapWidget::mousePressEvent(e);
}

void TimeIndicator::setSongDuration(int d)
{
    m_songDuration = d;
}

TimeIndicator::~TimeIndicator()
{
    writeSettings();
}


void TimeIndicator::updateSkin()
{
    m_pixmap = QPixmap (65 * m_skin->ratio(),13 * m_skin->ratio());
    if (m_needToShowTime)
        setTime(m_time);
}

void TimeIndicator::readSettings()
{
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    settings.beginGroup("Skinned");
    m_elapsed  = settings.value("disp_elapsed",true).toBool();
    settings.endGroup();
}

void TimeIndicator::writeSettings()
{
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    settings.beginGroup("Skinned");
    settings.setValue("disp_elapsed",m_elapsed);
    settings.endGroup();
}

void TimeIndicator::setNeedToShowTime(bool need)
{
    m_needToShowTime = need;
    if (!need)
        m_timer->start();
    else
        m_timer->stop();
}

void TimeIndicator::mouseMoveEvent(QMouseEvent *)
{}

void TimeIndicator::mouseReleaseEvent(QMouseEvent *)
{}