Ignore:
Timestamp:
May 3, 2016, 5:25:45 PM (9 years ago)
Author:
Silvan Scherrer
Message:

smplayer: update trunk to version 16.4

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/shortcutgetter.cpp

    r165 r176  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2014 Ricardo Villalba <rvm@users.sourceforge.net>
     2    Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    1515    along with this program; if not, write to the Free Software
    1616    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    17 */
    18 
    19 /*
     17
    2018    Note: The ShortcutGetter class is taken from the source code of Edyuk
    2119    (http://www.edyuk.org/), from file 3rdparty/qcumber/qshortcutdialog.cpp
     
    2422    License: GPL
    2523
    26         I've just made a little few changes on it.
     24    I modified it to support multiple shortcuts and some other few changes.
    2725*/
    2826
     
    4947
    5048#include "shortcutgetter.h"
     49#include "images.h"
    5150
    5251#include <QLayout>
     
    268267        setWindowTitle(tr("Modify shortcut"));
    269268
    270                        
    271269        QVBoxLayout *vbox = new QVBoxLayout(this);
    272270        vbox->setMargin(2);
    273271        vbox->setSpacing(4);
    274                        
     272
     273        // List and buttons added by rvm
     274        list = new QListWidget(this);
     275        connect(list, SIGNAL(currentRowChanged(int)), this, SLOT(rowChanged(int)));
     276        vbox->addWidget(list);
     277
     278        QHBoxLayout *hbox = new QHBoxLayout;
     279        addItem = new QPushButton(Images::icon("plus"), "", this);
     280        addItem->setToolTip(tr("Add shortcut"));
     281        connect(addItem, SIGNAL(clicked()), this, SLOT(addItemClicked()));
     282
     283        removeItem = new QPushButton(Images::icon("minus"), "", this);
     284        removeItem->setToolTip(tr("Remove shortcut"));
     285        connect(removeItem, SIGNAL(clicked()), this, SLOT(removeItemClicked()));
     286
     287        hbox->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding));
     288        hbox->addWidget(addItem);
     289        hbox->addWidget(removeItem);
     290
     291        vbox->addLayout(hbox);
     292
    275293        QLabel *l = new QLabel(this);
    276294        l->setText(tr("Press the key combination you want to assign"));
    277295        vbox->addWidget(l);
    278                        
     296
    279297        leKey = new QLineEdit(this);
     298        connect(leKey, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
    280299
    281300        leKey->installEventFilter(this);
     
    313332}
    314333
    315                
     334// Added by rvm
     335void ShortcutGetter::rowChanged(int row) {
     336        QString s = list->item(row)->text();
     337        leKey->setText(s);
     338        leKey->setFocus();
     339}
     340
     341// Added by rvm
     342void ShortcutGetter::textChanged(const QString & text) {
     343        list->item(list->currentRow())->setText(text);
     344}
     345
     346// Added by rvm
     347void ShortcutGetter::addItemClicked() {
     348        qDebug("ShortcutGetter::addItemClicked");
     349        list->addItem("");
     350        list->setCurrentRow( list->count()-1 ); // Select last item
     351}
     352
     353// Added by rvm
     354void ShortcutGetter::removeItemClicked() {
     355        qDebug("ShortcutGetter::removeItemClicked");
     356        if (list->count() > 1) {
     357                QListWidgetItem * i = list->takeItem( list->currentRow() );
     358                if (i) delete i;
     359        } else {
     360                list->setCurrentRow(0);
     361                leKey->setText("");
     362        }
     363}
     364
    316365QString ShortcutGetter::exec(const QString& s)
    317366{
     367        // Added by rvm
     368        QStringList shortcuts = s.split(", ");
     369        QString shortcut;
     370        foreach(shortcut, shortcuts) {
     371                list->addItem(shortcut.trimmed());
     372        }
     373        list->setCurrentRow(0);
     374
    318375        bStop = false;
    319         leKey->setText(s);
    320                        
    321         if ( QDialog::exec() == QDialog::Accepted )
    322                 return leKey->text();
    323                        
     376
     377        if (QDialog::exec() == QDialog::Accepted) {
     378                // Added by rvm
     379                QStringList l;
     380                for (int n = 0; n < list->count(); n++) {
     381                        QString shortcut = list->item(n)->text();
     382                        if (!shortcut.isEmpty()) {
     383                                //qDebug("ShortcutGetter::exec: shortcut: '%s'", shortcut.toUtf8().constData());
     384                                l << shortcut;
     385                        }
     386                }
     387                QString res = l.join(", ");
     388                if (res.isNull()) res = "";
     389                return res;
     390        }
     391
    324392        return QString();
    325393}
    326                
     394
    327395bool ShortcutGetter::event(QEvent *e)
    328396{
    329397        if (!capture) return QDialog::event(e);
    330 
    331398
    332399        QString key;
Note: See TracChangeset for help on using the changeset viewer.