aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Ui/skinned/hotkeyeditor.cpp
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2020-02-15 20:54:09 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2020-02-15 20:54:09 +0000
commite1017affecb9519173db73fefa6152b9bdef26e8 (patch)
treee90f8b4dc6bf8be3496991250f9021f6e186db66 /src/plugins/Ui/skinned/hotkeyeditor.cpp
parentd4a82b8c2c4a5662ad437046e8b20199a655be40 (diff)
downloadqmmp-e1017affecb9519173db73fefa6152b9bdef26e8.tar.gz
qmmp-e1017affecb9519173db73fefa6152b9bdef26e8.tar.bz2
qmmp-e1017affecb9519173db73fefa6152b9bdef26e8.zip
updated .ts files
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@9227 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Ui/skinned/hotkeyeditor.cpp')
0 files changed, 0 insertions, 0 deletions
le='author vovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38> 2007-06-23 16:48:01 +0000 committer vovanec <vovanec@90c681e8-e032-0410-971d-27865f9a5e38> 2007-06-23 16:48:01 +0000 moved into qmmp dir' href='/qmmp/commit/src/listwidget.cpp?h=main&id=2d622fd9bcb8da9dd3f3206e296cd6a701fc9d12'>2d622fd9b
11b7655bb
ecc137abe
7b17a2848
2d622fd9b
2d622fd9b


bdfdce731
fedd13511

2d622fd9b

11b7655bb

2d622fd9b


7b17a2848
a7732c0fc


2d622fd9b







ae75e5707
97c98d9d5
11b7655bb
013ee07b5
4cdf3ee86
11b7655bb
d03ac4cab
2d622fd9b



7abb96510
2d622fd9b
7b17a2848




2d622fd9b


013ee07b5
2d622fd9b

7b17a2848

2d622fd9b











2d622fd9b
2d622fd9b


7abb96510
2d622fd9b
4cdf3ee86
2d622fd9b
4cdf3ee86
2d622fd9b
4cdf3ee86

7abb96510

2d622fd9b
1f28f1893





7abb96510

1f28f1893

2d622fd9b





7abb96510

2d622fd9b
6d1217944

2d622fd9b
7abb96510

2d622fd9b

7abb96510

2d622fd9b

2d622fd9b

7abb96510
2d622fd9b
2d622fd9b
















7b17a2848

013ee07b5
2d622fd9b




4cdf3ee86


2d622fd9b
4cdf3ee86





2d622fd9b
4cdf3ee86
013ee07b5
4cdf3ee86


bdfdce731
2d622fd9b

4cdf3ee86
bdfdce731
2d622fd9b
bdfdce731
2d622fd9b
4cdf3ee86
2d622fd9b

bdfdce731
2d622fd9b
bdfdce731
2d622fd9b
4cdf3ee86
2d622fd9b

bdfdce731
4cdf3ee86

1f28f1893
4cdf3ee86
1f28f1893
4cdf3ee86
1f28f1893
4cdf3ee86
1f28f1893
4cdf3ee86

1f28f1893
4cdf3ee86
1f28f1893
2d622fd9b






7abb96510
013ee07b5
2d622fd9b

















11b7655bb
2d622fd9b


26da2f9c1

bc6a11535
26da2f9c1
bc6a11535










013ee07b5
bc6a11535


26da2f9c1



2d622fd9b











2d622fd9b
2d622fd9b





97c98d9d5

11b7655bb
2d622fd9b
d03ac4cab
2d622fd9b




f53bff4a5

97c98d9d5
f53bff4a5





2d622fd9b


a7732c0fc





















90d3aeb64
2d622fd9b
90d3aeb64

5e38daa8f
90d3aeb64
deeb74f4e
11b7655bb
d21deee70
deeb74f4e
5e38daa8f

2d622fd9b






013ee07b5
2d622fd9b


2d622fd9b



























2d622fd9b



24af8da3f
2d622fd9b

fedd13511






fedd13511


a0c457d7d
fedd13511
6d1217944





fedd13511
a0c457d7d

fedd13511


2d622fd9b

7b17a2848
2d622fd9b
7b17a2848






2d622fd9b
a7732c0fc







7b17a2848
2d622fd9b
7b17a2848


a7732c0fc









7b17a2848
a7732c0fc
7b17a2848


4cdf3ee86
7b17a2848
2d622fd9b
bc6a11535





2d622fd9b



4cdf3ee86
2d622fd9b


bdfdce731
11b7655bb
2d622fd9b


a7732c0fc

2d622fd9b


26da2f9c1
2d622fd9b
7abb96510
2d622fd9b
7abb96510

2d622fd9b



2d622fd9b







0fa5c6f14
2d622fd9b


0fa5c6f14
2d622fd9b
0fa5c6f14
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
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
                                                                            
                                                                            

























                                                                             
                     
                 

                                 
                               

                       
                        






                                       
                     
                              
                      
                 


                              
                               

                                                                            

                

                                


                                                                     
                           


                                                            







                               
                                                                 
                                                                                                   
                                                                                
                                                                            
                                                                           
                                                                            
 



                                             
                                                           
                     




                                         


        
                        

                                             

                                                             











                                                                  
                             


                                                   
                                 
 
                                              
     
                                                         
         

                                                                                               

                                                                            
         





                                                          

                                                                                

             





                                                 

                                                                                     
 

                                                           
         

                                              

                                      

                                                                                      

                                          

                                                    
                                                                                                 
     
















                                                       

                              
                    




                                                     


                                          
                                      





                                            
                                                                           
         
                                       


                                        
 

                                                 
                               
                                             
             
                                                                 
                 
                                                    

                 
                
             
                                                                 
                 
                                                    

                 
                                         

                                     
         
                                                       
             
                                                                     
             
                                           
             

                                                
             
                                         
         






                                             
                                                                 
                    

















                                                                       
                     


                 

                                  
                     
     










                                                                               
                        


                                           



                             











                                                                          
                                                                 





                                                                    

                                                   
                     
                 
                                                              




                                                                                

                         
                                         





                                                                                                   


             





















                                                                                                
                                                                           
 

                                                                     
                          
                       
                
                     
                      
                 

                                                                         






                                                    
                    


                 



























                                                                



                                                       
                                          

 






                                                                              


                                                           
                                                           
     





                                                              
                                                               

                                  


                        

                                               
                                      
     






                                      
 







                                           
                                
 


                                                                       









                                                                                            
                                                  
 


                                
                               
         
     





                                                                  



                                                  
                            


                                                 
                                     
                                    


                                

                     


                                  
                                  
 
                                                                      
     

                                                                                                       



                       







                                                            
                            


                                                         
                                                             
                                                 
                                                                 

     
/***************************************************************************
 *   Copyright (C) 2006-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 <QPixmap>
#include <QResizeEvent>
#include <QPainter>
#include <QFont>
#include <QFontMetrics>
#include <QSettings>
#include <QMenu>
#include <QUrl>
#include <QApplication>
#include <QHelpEvent>
#include <QTimer>
#include <qmmpui/playlistitem.h>
#include <qmmpui/playlistmodel.h>
#include <qmmpui/mediaplayer.h>
#include "listwidget.h"
#include "skin.h"
#include "popupwidget.h"
#include "playlist.h"

#define INVALID_ROW -1

ListWidget::ListWidget(QWidget *parent)
        : QWidget(parent)
{
    m_update = false;
    m_skin = Skin::instance();
    m_popupWidget = 0;
    loadColors();
    m_menu = new QMenu(this);
    m_scroll_direction = NONE;
    m_prev_y = 0;
    m_anchor_row = INVALID_ROW;
    m_player = MediaPlayer::instance();
    connect (m_player, SIGNAL(repeatableChanged(bool)), SLOT(updateList()));
    m_first = 0;
    m_rows = 0;
    m_scroll = false;
    m_select_on_release = false;
    readSettings();
    connect(m_skin, SIGNAL(skinChanged()), this, SLOT(updateSkin()));
    setAcceptDrops(true);
    setMouseTracking(true);
    m_timer = new QTimer(this);
    m_timer->setInterval(50);
    connect(m_timer, SIGNAL(timeout()), SLOT(autoscroll()));
}


ListWidget::~ListWidget()
{}

void ListWidget::readSettings()
{
    QSettings settings(Qmmp::configFile(), QSettings::IniFormat);
    m_font.fromString(settings.value("PlayList/Font", QApplication::font().toString()).toString());
    m_show_protocol = settings.value ("PlayList/show_protocol", false).toBool();
    m_show_number = settings.value ("PlayList/show_numbers", true).toBool();
    m_show_anchor = settings.value("PlayList/show_anchor", false).toBool();
    bool show_popup = settings.value("PlayList/show_popup", false).toBool();

    if (m_update)
    {
        delete m_metrics;
        m_metrics = new QFontMetrics(m_font);
        m_rows = height() / (m_metrics->lineSpacing() + 2);
        updateList();
        if(m_popupWidget)
        {
            m_popupWidget->deleteLater();
            m_popupWidget = 0;
        }
    }
    else
    {
        m_update = true;
        m_metrics = new QFontMetrics(m_font);
    }
    if(show_popup)
        m_popupWidget = new PlayListPopup::PopupWidget(this);
}

void ListWidget::loadColors()
{
    m_normal.setNamedColor(m_skin->getPLValue("normal"));
    m_current.setNamedColor(m_skin->getPLValue("current"));
    m_normal_bg.setNamedColor(m_skin->getPLValue("normalbg"));
    m_selected_bg.setNamedColor(m_skin->getPLValue("selectedbg"));
}

void ListWidget::paintEvent(QPaintEvent *)
{
    QPainter m_painter(this);
    m_painter.setFont(m_font);
    m_painter.setBrush(QBrush(m_normal_bg));
    m_painter.drawRect(-1,-1,width()+1,height()+1);
    int font_y = 0, old_size = 0;

    for (int i = 0; i < m_titles.size(); ++i )
    {
        if (m_show_anchor && i == m_anchor_row - m_first)
        {
            m_painter.setBrush(m_model->isSelected(i + m_first) ? m_selected_bg : m_normal_bg);
            m_painter.setPen(m_normal);
            m_painter.drawRect (6, i * (m_metrics->lineSpacing() + 2),
                                width() - 10, m_metrics->lineSpacing() + 1);
        }
        else
        {
            if (m_model->isSelected(i + m_first))
            {
                m_painter.setBrush(QBrush(m_selected_bg));
                m_painter.setPen(m_selected_bg);
                m_painter.drawRect (6, i * (m_metrics->lineSpacing() + 2),
                                    width() - 10, m_metrics->lineSpacing() + 1);
            }
        }

        if (m_model->currentRow() == i + m_first)
            m_painter.setPen(m_current);
        else
            m_painter.setPen(m_normal);  //243,58

        font_y = (i + 1) * (2 + m_metrics->lineSpacing()) - 2 - m_metrics->descent();
        m_painter.drawText(10, font_y, m_titles.at(i));

        QString extra_string = getExtraString(m_first + i);
        if(!extra_string.isEmpty())
        {
            old_size = m_font.pointSize();
            m_font.setPointSize(old_size - 1);
            m_painter.setFont(m_font);

            m_painter.drawText(width() - 10 - m_metrics->width(extra_string) -
                               m_metrics->width(m_times.at(i)), font_y, extra_string);
            m_font.setPointSize(old_size);
            m_painter.setFont(m_font);
            m_painter.setBrush(QBrush(m_normal_bg));
        }
        m_painter.drawText(width() - 7 - m_metrics->width(m_times.at(i)), font_y, m_times.at(i));
    }
}

void ListWidget::mouseDoubleClickEvent (QMouseEvent *e)
{
    int y = e->y();
    int row = rowAt(y);
    if (INVALID_ROW != row)
    {
        m_model->setCurrent(row);
        emit selectionChanged();
        update();
    }
}


void ListWidget::mousePressEvent(QMouseEvent *e)
{
    if(m_popupWidget)
        m_popupWidget->hide();
    m_scroll = true;
    int y = e->y();
    int row = rowAt(y);

    if (INVALID_ROW != row && m_model->count() > row)
    {
        m_pressed_row = row;
        if(e->button() == Qt::RightButton)
        {
            m_model->clearSelection();
            m_model->setSelected(row, true);
            m_anchor_row = m_pressed_row;
            QWidget::mousePressEvent(e);
            return;
        }

        if (m_model->isSelected(row) && (e->modifiers() == Qt::NoModifier))
        {
            m_select_on_release = true;
            QWidget::mousePressEvent(e);
            return;
        }

        if ((Qt::ShiftModifier & e->modifiers()))
        {
            bool select = true;
            if (m_pressed_row > m_anchor_row)
            {
                for (int j = m_anchor_row;j <= m_pressed_row;j++)
                {
                    m_model->setSelected(j, select);
                }
            }
            else
            {
                for (int j = m_anchor_row;j >= m_pressed_row;j--)
                {
                    m_model->setSelected(j, select);
                }
            }
            m_anchor_row = m_pressed_row;
        }
        else //ShiftModifier released
        {
            if ((Qt::ControlModifier & e->modifiers()))
            {
                m_model->setSelected(row, !m_model->isSelected(row));
            }
            else //ControlModifier released
            {
                m_model->clearSelection();
                m_model->setSelected(row, true);
            }
            m_anchor_row = m_pressed_row;
        }
        update();
    }
    QWidget::mousePressEvent(e);
}

void ListWidget::resizeEvent(QResizeEvent *e)
{
    m_rows = e->size().height() / (m_metrics->lineSpacing() + 2);
    m_scroll = true;
    updateList();
    QWidget::resizeEvent(e);
}

void ListWidget::wheelEvent (QWheelEvent *e)
{
    if (m_model->count() <= m_rows)
        return;
    if ((m_first == 0 && e->delta() > 0) ||
            ((m_first == m_model->count() - m_rows) && e->delta() < 0))
        return;
    m_first -= e->delta()/40;  //40*3 TODO: add step to config
    if (m_first < 0)
        m_first = 0;

    if (m_first > m_model->count() - m_rows)
        m_first = m_model->count() - m_rows;

    m_scroll = false;
    updateList();
}

bool ListWidget::event (QEvent *e)
{
    if(m_popupWidget)
    {
        if(e->type() == QEvent::ToolTip)
        {
            QHelpEvent *helpEvent = (QHelpEvent *) e;
            int row = rowAt(helpEvent->y());
            if(row < 0)
            {
                m_popupWidget->deactivate();
                return QWidget::event(e);
            }
            e->accept();
            m_popupWidget->prepare(m_model->item(row), helpEvent->globalPos());
            return true;
        }
        else if(e->type() == QEvent::Leave)
            m_popupWidget->deactivate();
    }
    return QWidget::event(e);
}

void ListWidget::updateList()
{
    if (m_model->count() < (m_rows+m_first+1) && m_rows< m_model->count())
    {
        m_first = m_model->count() - m_rows;
    }
    if (m_model->count() < m_rows + 1)
    {
        m_first = 0;
        emit positionChanged(0,0);
    }
    else
        emit positionChanged(m_first, m_model->count() - m_rows);
    if (m_model->count() <= m_first)
    {
        m_first = 0;
        emit positionChanged(0, qMax(0, m_model->count() - m_rows));
    }

    m_titles = m_model->getTitles(m_first, m_rows);
    m_times  = m_model->getTimes(m_first, m_rows);
    m_scroll = false;
    //add numbers
    for (int i = 0; i < m_titles.size() && m_show_number; ++i)
    {
        QString title = m_titles.at(i);
        m_titles.replace(i, title.prepend(QString("%1").arg(m_first+i+1)+". "));

    }
    //elide title
    QString extra_string;
    for (int i=0; i<m_titles.size(); ++i)
    {
        extra_string = getExtraString(m_first + i);
        int extra_string_space = extra_string.isEmpty() ? 0 : m_metrics->width(extra_string);
        m_titles.replace(i, m_metrics->elidedText (m_titles.at(i), Qt::ElideRight,
                            width() -  m_metrics->width(m_times.at(i)) - 22 - extra_string_space));
    }
    update();
}

void ListWidget::autoscroll()
{
    SimpleSelection sel = m_model->getSelection(m_pressed_row);
    if ((sel.m_top == 0 && m_scroll_direction == TOP && sel.count() > 1) ||
        (sel.m_bottom == m_model->count() - 1 && m_scroll_direction == DOWN && sel.count() > 1))
        return;

    if(m_scroll_direction == DOWN)
    {
        int row = m_first + m_rows;
        (m_first + m_rows < m_model->count()) ? m_first ++ : m_first;
        m_model->moveItems(m_pressed_row,row);
        m_pressed_row = row;
    }
    else if(m_scroll_direction == TOP && m_first > 0)
    {
        m_first --;
        m_model->moveItems(m_pressed_row, m_first);
        m_pressed_row = m_first;
    }
}

void ListWidget::setModel(PlayListModel *selected, PlayListModel *previous)
{
    if(previous)
        disconnect(previous, 0, this, 0); //disconnect previous model
    qApp->processEvents();
    m_model = selected;
    m_first = 0;
    m_scroll = false;
    recenterCurrent();
    updateList();
    connect (m_model, SIGNAL(currentChanged()), SLOT(recenterCurrent()));
    connect (m_model, SIGNAL(listChanged()), SLOT(updateList()));
}