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/actionseditor.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
     
    3737#include <QApplication>
    3838#include <QAction>
     39#include <QDebug>
    3940
    4041#include "images.h"
     
    103104        }
    104105
     106        //qDebug("ActionsEditor::shortcutsToString: accelText: '%s'", accelText.toUtf8().constData());
     107
    105108        return accelText;
    106109}
     
    109112        QList <QKeySequence> shortcuts_list;
    110113
    111         QStringList l = shortcuts.split(',');
     114        QStringList l = shortcuts.split(", ");
    112115
    113116        for (int n=0; n < l.count(); n++) {
     
    121124                QString s = QKeySequence( l[n].simplified() );
    122125#endif
    123                
     126
    124127                //Work-around for Simplified-Chinese
    125128                s.replace( QString::fromUtf8("å·Š"), "Left");
     
    147150        latest_dir = Paths::shortcutsPath();
    148151
    149     actionsTable = new QTableWidget(0, COL_NAME +1, this);
     152        actionsTable = new QTableWidget(0, COL_NAME +1, this);
    150153        actionsTable->setSelectionMode( QAbstractItemView::SingleSelection );
    151154        actionsTable->verticalHeader()->hide();
     
    154157        actionsTable->horizontalHeader()->setSectionResizeMode(COL_DESC, QHeaderView::Stretch);
    155158        actionsTable->horizontalHeader()->setSectionResizeMode(COL_NAME, QHeaderView::Stretch);
     159        actionsTable->horizontalHeader()->setSectionResizeMode(COL_CONFLICTS, QHeaderView::ResizeToContents);
    156160#else
    157161        actionsTable->horizontalHeader()->setResizeMode(COL_DESC, QHeaderView::Stretch);
    158162        actionsTable->horizontalHeader()->setResizeMode(COL_NAME, QHeaderView::Stretch);
     163        actionsTable->horizontalHeader()->setResizeMode(COL_CONFLICTS, QHeaderView::ResizeToContents);
    159164#endif
    160165
     
    254259        actionsTable->setRowCount( actionsList.count() );
    255260
    256     QAction *action;
     261        QAction *action;
    257262        QString accelText;
    258263
     
    283288                // Shortcut column
    284289                QTableWidgetItem * i_shortcut = new QTableWidgetItem(accelText);
     290                int column_height = i_shortcut->sizeHint().height();
     291                i_shortcut->setSizeHint(QSize(150, column_height));
    285292
    286293                // Set flags
     
    372379
    373380                if (!result.isNull()) {
    374                     QString accelText = QKeySequence(result).toString(QKeySequence::PortableText);
     381                        //qDebug("ActionsEditor::editShortcut: result: '%s'", result.toUtf8().constData());
     382                        QString accelText = QKeySequence(result).toString(QKeySequence::PortableText);
    375383                        i->setText(accelText);
    376384                        if (hasConflicts()) qApp->beep();
     
    387395}
    388396
     397bool ActionsEditor::containsShortcut(const QString & accel, const QString & shortcut) {
     398        QStringList shortcut_list = accel.split(", ");
     399        QString s;
     400        foreach(s, shortcut_list) {
     401                s = s.trimmed();
     402                //qDebug("ActionsEditor::containsShortcut: comparing '%s' with '%s'", s.toUtf8().constData(), shortcut.toUtf8().constData());
     403                if (s == shortcut) return true;
     404        }
     405        return false;
     406}
     407
    389408int ActionsEditor::findActionAccel(const QString & accel, int ignoreRow) {
    390         for (int row=0; row < actionsTable->rowCount(); row++) {
     409        QStringList shortcuts = accel.split(", ");
     410        QString shortcut;
     411
     412        for (int row = 0; row < actionsTable->rowCount(); row++) {
    391413                QTableWidgetItem * i = actionsTable->item(row, COL_SHORTCUT);
    392                 if ( (i) && (i->text() == accel) ) {
    393                         if (ignoreRow == -1) return row;
    394                         else
    395                         if (ignoreRow != row) return row;
     414                if (i && row != ignoreRow) {
     415                        if (!i->text().isEmpty()) {
     416                                foreach(shortcut, shortcuts) {
     417                                        if (containsShortcut(i->text(), shortcut.trimmed())) {
     418                                                return row;
     419                                        }
     420                                }
     421                        }
    396422                }
    397423        }
     
    406432        QTableWidgetItem *i;
    407433
    408         for (int n=0; n < actionsTable->rowCount(); n++) {
     434        for (int n = 0; n < actionsTable->rowCount(); n++) {
    409435                //actionsTable->setText( n, COL_CONFLICTS, " ");
    410436                i = actionsTable->item( n, COL_CONFLICTS );
     
    416442                        if (!accelText.isEmpty()) {
    417443                                found = findActionAccel( accelText, n );
    418                                 if ( (found != -1) && (found != n) ) {
     444                                if ( (found != -1) /*&& (found != n)*/ ) {
    419445                                        conflict = true;
    420446                                        //actionsTable->setText( n, COL_CONFLICTS, "!");
     
    497523
    498524bool ActionsEditor::loadActionsTable(const QString & filename) {
    499         qDebug("ActionsEditor::loadActions: '%s'", filename.toUtf8().data());
    500 
    501         QRegExp rx("^(.*)\\t(.*)");
     525        qDebug() << "ActionsEditor::loadActions:" <<  filename;
     526
    502527        int row;
    503528
    504     QFile f( filename );
    505     if ( f.open( QIODevice::ReadOnly ) ) {
     529        QFile f( filename );
     530        if ( f.open( QIODevice::ReadOnly ) ) {
    506531
    507532#if !USE_SHORTCUTGETTER
     
    509534#endif
    510535
    511         QTextStream stream( &f );
     536                QTextStream stream( &f );
    512537                stream.setCodec("UTF-8");
    513538
    514         QString line;
    515         while ( !stream.atEnd() ) {
    516             line = stream.readLine();
    517                         qDebug("line: '%s'", line.toUtf8().data());
    518                         if (rx.indexIn(line) > -1) {
    519                                 QString name = rx.cap(1);
    520                                 QString accelText = rx.cap(2);
    521                                 qDebug(" name: '%s' accel: '%s'", name.toUtf8().data(), accelText.toUtf8().data());
     539                QString line;
     540                while ( !stream.atEnd() ) {
     541                        line = stream.readLine().trimmed();
     542                        qDebug() << "ActionsEditor::loadActions: line:" << line;
     543                        QString name;
     544                        QString accelText;
     545                        int pos = line.indexOf(QRegExp("\\t|\\s"));
     546                        //qDebug() << "ActionsEditor::loadActions: pos:" << pos;
     547                        if (pos == -1) {
     548                                name = line;
     549                        } else {
     550                                name = line.left(pos);
     551                                accelText = line.mid(pos+1).trimmed();
     552                        }
     553                        qDebug() << "ActionsEditor::loadActions: name:" << name << "accel:" << accelText;
     554                        if (!name.isEmpty()) {
    522555                                row = findActionName(name);
    523556                                if (row > -1) {
    524                                         qDebug("Action found!");
     557                                        qDebug() << "ActionsEditor::loadActions: action found!";
    525558                                        actionsTable->item(row, COL_SHORTCUT)->setText(accelText);
    526                                 }                               
     559                                }
    527560                        } else {
    528                                 qDebug(" wrong line");
     561                                qDebug() << "ActionsEditor::loadActions: error in line";
    529562                        }
    530563                }
Note: See TracChangeset for help on using the changeset viewer.