Changeset 176 for smplayer/trunk/src/shortcutgetter.cpp
- Timestamp:
- May 3, 2016, 5:25:45 PM (9 years ago)
- Location:
- smplayer/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
smplayer/trunk
- Property svn:mergeinfo changed
/smplayer/vendor/current merged: 175
- Property svn:mergeinfo changed
-
smplayer/trunk/src/shortcutgetter.cpp
r165 r176 1 1 /* smplayer, GUI front-end for mplayer. 2 Copyright (C) 2006-201 4Ricardo Villalba <rvm@users.sourceforge.net>2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net> 3 3 4 4 This program is free software; you can redistribute it and/or modify … … 15 15 along with this program; if not, write to the Free Software 16 16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 */ 18 19 /* 17 20 18 Note: The ShortcutGetter class is taken from the source code of Edyuk 21 19 (http://www.edyuk.org/), from file 3rdparty/qcumber/qshortcutdialog.cpp … … 24 22 License: GPL 25 23 26 I've just made a little few changes on it.24 I modified it to support multiple shortcuts and some other few changes. 27 25 */ 28 26 … … 49 47 50 48 #include "shortcutgetter.h" 49 #include "images.h" 51 50 52 51 #include <QLayout> … … 268 267 setWindowTitle(tr("Modify shortcut")); 269 268 270 271 269 QVBoxLayout *vbox = new QVBoxLayout(this); 272 270 vbox->setMargin(2); 273 271 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 275 293 QLabel *l = new QLabel(this); 276 294 l->setText(tr("Press the key combination you want to assign")); 277 295 vbox->addWidget(l); 278 296 279 297 leKey = new QLineEdit(this); 298 connect(leKey, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &))); 280 299 281 300 leKey->installEventFilter(this); … … 313 332 } 314 333 315 334 // Added by rvm 335 void ShortcutGetter::rowChanged(int row) { 336 QString s = list->item(row)->text(); 337 leKey->setText(s); 338 leKey->setFocus(); 339 } 340 341 // Added by rvm 342 void ShortcutGetter::textChanged(const QString & text) { 343 list->item(list->currentRow())->setText(text); 344 } 345 346 // Added by rvm 347 void ShortcutGetter::addItemClicked() { 348 qDebug("ShortcutGetter::addItemClicked"); 349 list->addItem(""); 350 list->setCurrentRow( list->count()-1 ); // Select last item 351 } 352 353 // Added by rvm 354 void 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 316 365 QString ShortcutGetter::exec(const QString& s) 317 366 { 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 318 375 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 324 392 return QString(); 325 393 } 326 394 327 395 bool ShortcutGetter::event(QEvent *e) 328 396 { 329 397 if (!capture) return QDialog::event(e); 330 331 398 332 399 QString key;
Note:
See TracChangeset
for help on using the changeset viewer.