aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/CommandLineOptions/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/CommandLineOptions/CMakeLists.txt')
0 files changed, 0 insertions, 0 deletions
mmitter trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> 2008-07-04 08:39:23 +0000 improved text scroller' href='/qmmp/commit/src/ui/textscroller.cpp?id=8b6b8eba5ecd95826cf07071f8f63a97d34796a8'>8b6b8eba5
aa5224151
ae75e5707
09d1eb079

047d5bb26

2d622fd9b
b1a02c986
2d622fd9b
2d622fd9b
09d1eb079
76cf6ceec
2d622fd9b
b1a02c986
2d622fd9b
09d1eb079

3d3847f97
09d1eb079
96cfa27dc
09d1eb079

c6802d917
09d1eb079

eb25fd643

09d1eb079
8b6b8eba5
b1a02c986

09d1eb079
b1a02c986
37f66aa3c
09d1eb079

09d1eb079

02051aa43
2d622fd9b

2d622fd9b
8b6b8eba5
ae75e5707
fa1e4194b
b1a02c986
3d3847f97

8b6b8eba5
2d622fd9b
09d1eb079
2d622fd9b
09d1eb079

2d622fd9b

09d1eb079
2d622fd9b
09d1eb079





2d622fd9b
09d1eb079

2d622fd9b
09d1eb079





8b6b8eba5
2d622fd9b



26da2f9c1
36dc7e509
09d1eb079
fa1e4194b
c6802d917
aa5224151
7ea7dcc4f
09d1eb079
2d622fd9b
2d622fd9b
b1a02c986
fa1e4194b
b1a02c986

3d3847f97
02051aa43
2d622fd9b
eb25fd643
23c468df4

09d1eb079

23c468df4

8b6b8eba5
eb25fd643



8b6b8eba5
eb25fd643
09d1eb079
8b6b8eba5
eb25fd643
8b6b8eba5
3fe88a875
7ea7dcc4f















8b6b8eba5

09d1eb079

8b6b8eba5
09d1eb079

8b6b8eba5

ff33b2edc
8b6b8eba5





09d1eb079
7ea7dcc4f
a09f7ea6f
09d1eb079

7ea7dcc4f

8b6b8eba5


a09f7ea6f

09d1eb079
a09f7ea6f
09d1eb079
a09f7ea6f
7ea7dcc4f
a09f7ea6f
09d1eb079
a09f7ea6f



09d1eb079
7ea7dcc4f
09d1eb079




a09f7ea6f
7ea7dcc4f

a09f7ea6f

09d1eb079
047d5bb26













09d1eb079

































09d1eb079

96cfa27dc
09d1eb079











c6802d917
09d1eb079





c6802d917
b1a02c986


36dc7e509
09d1eb079


640da1ded
09d1eb079







c6802d917
b1a02c986


36dc7e509
09d1eb079


































c6802d917
09d1eb079




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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
                                                                            
                                                                            














                                                                            
                                                                            



                                                                             



                      
                       
                      

                                     

                                   
                 
                          
                         
 
                            
                                                                            
 
                                                               
 

                      
                  
                                                         
                                        

                                   
                              

                                

                             
 
                             

                                                                                                     
                                       
                                             
                                                                       

                                                               

                                                                                        
                 

 
                             
 
                                                                 
                                                                         
                                                                                          

                         
 
 
                                               
 

                        

 
                          
 





                              
     

                        
     





                                 
             



                               
                                                     
                                                        
                                                                 
                                                                     
                              
                                                                                                     
                                
                  
                         
        
     
                                                                                        

                                                                                                         
                                         
                 
 
 

                                            

                                                      

 
                                           



                    
                                           
 
                 
                         
 
 
                                                                                          















                                                        

                                             

                         
     

                                           

        
                                        





                                                   
                                                       
     
                        

                                    

        


                                    

                                                     
                                     
                                     
                                                       
                         
        
                                      
                     



                                                  
                  
     




                                              
                 

        

                                   
 













                                                              

































                                                                                

                                        
                                                                                      











                                                                                                    
                                                 





                                                
                                              


                                              
                                                                      


                                     
                   







                                                               
                                                   


                                             
                                                                     


































                                                                
                                                    




                                       
/***************************************************************************
 *   Copyright (C) 2006-2015 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 <QTimer>
#include <QSettings>
#include <QAction>
#include <QMenu>
#include <QMouseEvent>
#include <QSettings>
#include <QApplication>
#include <qmmp/qmmp.h>
#include <qmmp/soundcore.h>
#include <qmmpui/metadataformatter.h>
#include <qmmpui/playlistmanager.h>
#include <qmmpui/playlistmodel.h>
#include "skin.h"
#include "actionmanager.h"
#include "textscroller.h"

#define SCROLL_SEP "   *** "
#define TITLE_FORMAT "%p%if(%p&%t, - ,)%t%if(%p,,%if(%t,,%f))%if(%l, - %l,)"

TextScroller::TextScroller (QWidget *parent) : QWidget (parent)
{
    m_pressed = false;
    m_press_pos = 0;
    m_metrics = 0;
    m_defautText = QString("Qmmp ") + Qmmp::strVersion();
    m_formater.setPattern(TITLE_FORMAT);
    m_core = SoundCore::instance();
    m_skin = Skin::instance();
    m_ratio = m_skin->ratio();

    m_timer = new QTimer (this);
    m_timer->setInterval(50);
    m_timer->start();

    m_menu = new QMenu(this);
    m_scrollAction = m_menu->addAction(tr("Autoscroll Songname"), this, SLOT(updateText()));
    m_transparencyAction = m_menu->addAction(tr("Transparent Background"), this, SLOT(updateText()));
    m_scrollAction->setCheckable(true);
    m_transparencyAction->setCheckable(true);
    connect(m_scrollAction, SIGNAL(toggled(bool)), SLOT(updateText()));
    connect(m_timer, SIGNAL (timeout()), SLOT (addOffset()));
    connect(m_skin, SIGNAL(skinChanged()), SLOT(updateSkin()));
    connect(m_core, SIGNAL(stateChanged(Qmmp::State)), SLOT(processState(Qmmp::State)));
    connect(m_core, SIGNAL(metaDataChanged()), SLOT(processMetaData()));
    updateSkin();
}

TextScroller::~TextScroller()
{
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    settings.setValue("Skinned/autoscroll", m_scrollAction->isChecked());
    settings.setValue("Skinned/scroller_transparency", m_transparencyAction->isChecked());
    if(m_metrics)
        delete m_metrics;
}

void TextScroller::setText(const QString &text)
{
    m_sliderText = text;
    updateText();
}

void TextScroller::clear()
{
    setText(QString());
}

void TextScroller::addOffset()
{
    if(!m_scroll)
    {
        m_timer->stop();
        return;
    }
    m_x1--;
    m_x2--;
    if(m_x1 < - m_pixmap.width())
        m_x1 = m_pixmap.width();
    if(m_x2 < - m_pixmap.width())
        m_x2 = m_pixmap.width();
    update();
}

void TextScroller::updateSkin()
{
    setCursor(m_skin->getCursor(Skin::CUR_SONGNAME));
    m_color = m_skin->getMainColor(Skin::MW_FOREGROUND);
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    m_bitmap = settings.value("Skinned/bitmap_font", false).toBool();
    m_ratio = m_skin->ratio();
    QString fontname = settings.value("Skinned/mw_font", QApplication::font().toString()).toString();
    m_font.fromString(fontname);
    if (m_metrics)
        delete m_metrics;
    else
    {
        m_scrollAction->setChecked(settings.value("Skinned/autoscroll", true).toBool());
        m_transparencyAction->setChecked(settings.value("Skinned/scroller_transparency", true).toBool());
    }
    m_metrics = new QFontMetrics(m_font);
    updateText();
}

void TextScroller::setProgress(int progress)
{
    m_bufferText = tr("Buffering: %1%").arg(progress);
    updateText();
}

void TextScroller::hideEvent (QHideEvent *)
{
    m_timer->stop();
}

void TextScroller::showEvent (QShowEvent *)
{
    if (m_scroll)
        m_timer->start();
}

inline void drawBitmapText(int x, int y, const QString &text, QPainter *paint, Skin *skin)
{
    QString lowertext = text.toLower();
    int chwidth, ypix;
    {
        QPixmap samplechar = skin->getLetter('a');
        chwidth = samplechar.width();
        ypix = y - samplechar.height();
    }
    for (int i = 0; i < lowertext.size(); i++)
    {
        QPixmap pixchar = skin->getLetter(lowertext[i]);
        paint->drawPixmap(x, ypix, pixchar);
        x += chwidth;
    }
}

void TextScroller::paintEvent (QPaintEvent *)
{
    QPainter paint(this);
    if(m_scroll)
    {
        paint.drawPixmap(m_x1,0, m_pixmap);
        paint.drawPixmap(m_x2,0, m_pixmap);
    }
    else
        paint.drawPixmap(0,0, m_pixmap);
}

void TextScroller::mousePressEvent (QMouseEvent *e)
{
    if (e->button() == Qt::RightButton)
        m_menu->exec(e->globalPos());
    else if (e->button() == Qt::LeftButton && m_scroll)
    {
        m_timer->stop();
        m_press_pos = e->x() - m_x1;
        m_pressed = true;
    }
    else
        QWidget::mousePressEvent(e);
}

void TextScroller::mouseReleaseEvent (QMouseEvent *e)
{
   if(e->button() == Qt::RightButton)
        m_menu->exec(e->globalPos());
    else if (e->button() == Qt::LeftButton && m_scroll)
        m_timer->start();
    else
        QWidget::mouseReleaseEvent(e);
   m_pressed = false;
}

void TextScroller::mouseMoveEvent (QMouseEvent *e)
{
    if (m_pressed)
    {
        int bound = m_pixmap.width();
        m_x1 = (e->x() - m_press_pos) % bound;
        if (m_x1 > 0)
            m_x1 -= bound;
        m_x2 = m_x1 + m_pixmap.width();
        update();
    }
    else
        QWidget::mouseMoveEvent(e);
}

void TextScroller::mouseDoubleClickEvent(QMouseEvent *e)
{
   if(e->button() == Qt::LeftButton)
   {
       PlayListManager *manager = PlayListManager::instance();
       PlayListModel *model = manager->currentPlayList();
       model->showDetailsForCurrent(this);
   }
   else
   {
       QWidget::mouseDoubleClickEvent(e);
   }
}

void TextScroller::processState(Qmmp::State state)
{
    switch(state)
    {
    case Qmmp::Buffering:
    {
        connect(m_core, SIGNAL(bufferingProgress(int)), SLOT(setProgress(int)));
        break;
    }
    case Qmmp::Playing:
    {
        disconnect(m_core, SIGNAL(bufferingProgress(int)), this, 0);
        m_bufferText.clear();
        updateText();
        break;
    }
    case Qmmp::Paused:
    {
        break;
    }
    case Qmmp::Stopped:
    {
        m_bufferText.clear();
        m_titleText.clear();
        updateText();
        break;
    }
    default:
        break;
    }
}

void TextScroller::processMetaData()
{
    if(m_core->state() == Qmmp::Playing)
    {
        m_titleText = m_formater.format(m_core->metaData(), m_core->totalTime()/1000);
        updateText();
    }
}

void TextScroller::preparePixmap(const QString &text, bool scrollable)
{
    m_scroll = scrollable;
    bool bitmap = m_bitmap && (text.toLatin1() == text.toLocal8Bit()); //use bitmap font if possible
    if(scrollable)
    {
         int textWidth = m_bitmap ? QString(text + SCROLL_SEP).size() * 5
                                  : m_metrics->width(text + SCROLL_SEP);
         int count = 150*m_ratio / textWidth + 1;
         int width = count * textWidth;
         QString fullText;
         for(int i = 0; i < count; ++i)
         {
             fullText.append(text + SCROLL_SEP);
         }
         m_pixmap = QPixmap(width,15*m_ratio);
         if(m_transparencyAction->isChecked())
             m_pixmap.fill(Qt::transparent);
         else
             m_pixmap.fill(m_skin->getMainColor(Skin::MW_BACKGROUND));
         QPainter painter(&m_pixmap);
         painter.setPen(m_color);
         painter.setFont(m_font);
         if(bitmap)
             drawBitmapText (0,12, fullText, &painter, m_skin);
         else
             painter.drawText (0,12, fullText);
         m_x1 = 0;
         m_x2 = m_pixmap.width();
    }
    else
    {
        m_pixmap = QPixmap(150*m_ratio,15*m_ratio);
        if(m_transparencyAction->isChecked())
            m_pixmap.fill(Qt::transparent);
        else
            m_pixmap.fill(m_skin->getMainColor(Skin::MW_BACKGROUND));
        QPainter painter(&m_pixmap);
        painter.setPen(m_color);
        painter.setFont(m_font);
        if(bitmap)
            drawBitmapText (0,12, text, &painter, m_skin);
        else
            painter.drawText (0,12, text);
    }
}

void TextScroller::updateText() //draw text according priority
{
    if(!m_sliderText.isEmpty())
    {
        preparePixmap(m_sliderText);
        m_timer->stop();
    }
    else if(!m_bufferText.isEmpty())
    {
        preparePixmap(m_bufferText);
        m_timer->stop();
    }
    else if (!m_titleText.isEmpty())
    {
        preparePixmap(m_titleText, m_scrollAction->isChecked());
        m_timer->start();
    }
    else if(!m_defautText.isEmpty())
    {
        preparePixmap(m_defautText);
        m_timer->stop();
    }
    else
    {
        m_timer->stop();
        m_pixmap = QPixmap (150*m_ratio,15*m_ratio);
        m_pixmap.fill(Qt::transparent);
        m_scroll = false;
    }
    update();
}