comparison libgui/src/shortcut-manager.cc @ 19861:19755f4fc851

maint: Cleanup C++ code to follow Octave coding conventions. Try to wrap long lines to < 80 characters. Use GNU style and don't indent first brace of function definition. "case" statement is aligned flush left with brace of switch stmt. Remove trailing '\' line continuation from the end of #define macros. Use 2 spaces for indent. * files-dock-widget.cc, history-dock-widget.cc, main-window.cc, octave-cmd.cc, octave-dock-widget.cc, octave-gui.cc, resource-manager.cc, settings-dialog.cc, shortcut-manager.cc, welcome-wizard.cc, workspace-view.cc, cellfun.cc, data.cc, debug.cc, debug.h, dirfns.cc, error.h, file-io.cc, gl-render.cc, gl-render.h, gl2ps-renderer.h, graphics.cc, graphics.in.h, help.cc, input.cc, load-path.cc, load-path.h, lookup.cc, lu.cc, oct-stream.cc, octave-default-image.h, ordschur.cc, pr-output.cc, qz.cc, strfns.cc, symtab.cc, symtab.h, sysdep.cc, variables.cc, zfstream.h, __fltk_uigetfile__.cc, __init_fltk__.cc, __magick_read__.cc, __osmesa_print__.cc, audiodevinfo.cc, ov-classdef.cc, ov-classdef.h, ov-fcn.h, ov-float.cc, ov-flt-complex.cc, ov-java.cc, ov-range.cc, ov-re-mat.cc, ov-usr-fcn.h, ov.cc, op-int.h, options-usage.h, pt-eval.cc, Array-C.cc, Array-fC.cc, Array.cc, Array.h, PermMatrix.cc, Sparse.cc, chMatrix.h, dSparse.cc, dim-vector.h, bsxfun-decl.h, bsxfun-defs.cc, oct-norm.cc, Sparse-op-defs.h, oct-inttypes.cc, oct-inttypes.h, main.in.cc, mkoctfile.in.cc: Cleanup C++ code to follow Octave coding conventions.
author Rik <rik@octave.org>
date Wed, 25 Feb 2015 11:55:49 -0800
parents 4197fc428c7d
children 62b73798a84f
comparison
equal deleted inserted replaced
19860:e8ccfc5d892b 19861:19755f4fc851
168 init (tr ("Documentation"), "main_window:doc", 168 init (tr ("Documentation"), "main_window:doc",
169 prefix + ctrl + Qt::Key_5); 169 prefix + ctrl + Qt::Key_5);
170 init (tr ("Reset Window Layout"), "main_window:reset", QKeySequence ()); 170 init (tr ("Reset Window Layout"), "main_window:reset", QKeySequence ());
171 171
172 // help 172 // help
173 init (tr ("Show Ondisk Documentation"), "main_help:ondisk_doc", QKeySequence ()); 173 init (tr ("Show Ondisk Documentation"), "main_help:ondisk_doc",
174 init (tr ("Show Online Documentation"), "main_help:online_doc", QKeySequence ()); 174 QKeySequence ());
175 init (tr ("Show Online Documentation"), "main_help:online_doc",
176 QKeySequence ());
175 init (tr ("Report a Bug"), "main_help:report_bug", QKeySequence ()); 177 init (tr ("Report a Bug"), "main_help:report_bug", QKeySequence ());
176 init (tr ("Octave Packages"), "main_help:packages", QKeySequence ()); 178 init (tr ("Octave Packages"), "main_help:packages", QKeySequence ());
177 init (tr ("Share Code"), "main_help:agora", QKeySequence ()); 179 init (tr ("Share Code"), "main_help:agora", QKeySequence ());
178 init (tr ("Contribute to Octave"), "main_help:contribute", QKeySequence ()); 180 init (tr ("Contribute to Octave"), "main_help:contribute", QKeySequence ());
179 init (tr ("Octave Developer Resources"), "main_help:developer", QKeySequence ()); 181 init (tr ("Octave Developer Resources"), "main_help:developer",
182 QKeySequence ());
180 init (tr ("About Octave"), "main_help:about", QKeySequence ()); 183 init (tr ("About Octave"), "main_help:about", QKeySequence ());
181 184
182 // news 185 // news
183 init (tr ("Release Notes"), "main_news:release_notes", QKeySequence ()); 186 init (tr ("Release Notes"), "main_news:release_notes", QKeySequence ());
184 init (tr ("Community News"), "main_news:community_news", QKeySequence ()); 187 init (tr ("Community News"), "main_news:community_news", QKeySequence ());
271 init (tr ("Preferences"), "editor_edit:preferences", QKeySequence ()); 274 init (tr ("Preferences"), "editor_edit:preferences", QKeySequence ());
272 init (tr ("Styles Preferences"), "editor_edit:styles_preferences", 275 init (tr ("Styles Preferences"), "editor_edit:styles_preferences",
273 QKeySequence ()); 276 QKeySequence ());
274 277
275 // view 278 // view
276 init (tr ("Show Line Numbers"), "editor_view:show_line_numbers", QKeySequence ()); 279 init (tr ("Show Line Numbers"), "editor_view:show_line_numbers",
277 init (tr ("Show White Spaces"), "editor_view:show_white_spaces", QKeySequence ()); 280 QKeySequence ());
281 init (tr ("Show White Spaces"), "editor_view:show_white_spaces",
282 QKeySequence ());
278 init (tr ("Show Line Endings"), "editor_view:show_eol_chars", QKeySequence ()); 283 init (tr ("Show Line Endings"), "editor_view:show_eol_chars", QKeySequence ());
279 init (tr ("Show Indentation Guides"), "editor_view:show_ind_guides", QKeySequence ()); 284 init (tr ("Show Indentation Guides"), "editor_view:show_ind_guides",
280 init (tr ("Show Long Line Marker"), "editor_view:show_long_line", QKeySequence ()); 285 QKeySequence ());
286 init (tr ("Show Long Line Marker"), "editor_view:show_long_line",
287 QKeySequence ());
281 init (tr ("Zoom In"), "editor_view:zoom_in", QKeySequence::ZoomIn); 288 init (tr ("Zoom In"), "editor_view:zoom_in", QKeySequence::ZoomIn);
282 init (tr ("Zoom Out"), "editor_view:zoom_out", QKeySequence::ZoomOut); 289 init (tr ("Zoom Out"), "editor_view:zoom_out", QKeySequence::ZoomOut);
283 #if defined (Q_OS_MAC) 290 #if defined (Q_OS_MAC)
284 init (tr ("Zoom Normal"), "editor_view:zoom_normal", 291 init (tr ("Zoom Normal"), "editor_view:zoom_normal",
285 QKeySequence (ctrl + Qt::Key_Underscore)); 292 QKeySequence (ctrl + Qt::Key_Underscore));
303 QKeySequence (prefix + Qt::Key_F5) ); 310 QKeySequence (prefix + Qt::Key_F5) );
304 init (tr ("Run Selection"), "editor_run:run_selection", 311 init (tr ("Run Selection"), "editor_run:run_selection",
305 QKeySequence (prefix + Qt::Key_F9) ); 312 QKeySequence (prefix + Qt::Key_F9) );
306 313
307 // help 314 // help
308 init (tr ("Help on Keyword"), "editor_help:help_keyword", QKeySequence::HelpContents); 315 init (tr ("Help on Keyword"), "editor_help:help_keyword",
309 init (tr ("Document on Keyword"), "editor_help:doc_keyword", QKeySequence (Qt::SHIFT + Qt::Key_F1)); 316 QKeySequence::HelpContents);
317 init (tr ("Document on Keyword"), "editor_help:doc_keyword",
318 QKeySequence (Qt::SHIFT + Qt::Key_F1));
310 } 319 }
311 320
312 void 321 void
313 shortcut_manager::init (QString description, QString key, QKeySequence def_sc) 322 shortcut_manager::init (QString description, QString key, QKeySequence def_sc)
314 { 323 {
315 QKeySequence actual_0 = QKeySequence (_settings->value ("shortcuts/"+key, def_sc).toString ()); 324 QKeySequence actual_0
316 QKeySequence actual_1 = QKeySequence (_settings->value ("shortcuts/"+key+"_1", def_sc).toString ()); 325 = QKeySequence (_settings->value ("shortcuts/"+key, def_sc).toString ());
326 QKeySequence actual_1
327 = QKeySequence (_settings->value ("shortcuts/"+key+"_1", def_sc).toString ());
317 328
318 // append the new shortcut to the list 329 // append the new shortcut to the list
319 shortcut_t shortcut_info; 330 shortcut_t shortcut_info;
320 shortcut_info.description = description; 331 shortcut_info.description = description;
321 shortcut_info.settings_key = key; 332 shortcut_info.settings_key = key;
326 _sc << shortcut_info; 337 _sc << shortcut_info;
327 338
328 // insert shortcut prepended by widget in order check for duplicates later 339 // insert shortcut prepended by widget in order check for duplicates later
329 QString widget = key.section ('_',0,0); // get widget that uses the shortcut 340 QString widget = key.section ('_',0,0); // get widget that uses the shortcut
330 if (! actual_0.isEmpty ()) 341 if (! actual_0.isEmpty ())
331 _shortcut_hash[widget + ":" + actual_0.toString ()] = _sc.count (); // offset of 1 to avoid 0 342 _shortcut_hash[widget + ":" + actual_0.toString ()] =
343 _sc.count (); // offset of 1 to avoid 0
332 if (! actual_1.isEmpty ()) 344 if (! actual_1.isEmpty ())
333 _shortcut_hash[widget + "_1:" + actual_1.toString ()] = _sc.count (); // offset of 1 to avoid 0 345 _shortcut_hash[widget + "_1:" + actual_1.toString ()] =
346 _sc.count (); // offset of 1 to avoid 0
334 _action_hash[key] = _sc.count (); // offset of 1 to avoid 0 347 _action_hash[key] = _sc.count (); // offset of 1 to avoid 0
335 } 348 }
336 349
337 void 350 void
338 shortcut_manager::do_fill_treewidget (QTreeWidget *tree_view) 351 shortcut_manager::do_fill_treewidget (QTreeWidget *tree_view)
417 430
418 } 431 }
419 432
420 // write one or all actual shortcut set(s) into a settings file 433 // write one or all actual shortcut set(s) into a settings file
421 void 434 void
422 shortcut_manager::do_write_shortcuts (int set, QSettings* settings, bool closing) 435 shortcut_manager::do_write_shortcuts (int set, QSettings* settings,
436 bool closing)
423 { 437 {
424 if (set) 438 if (set)
425 { 439 {
426 // set is not zero, only write the desired set (index = set-1) 440 // set is not zero, only write the desired set (index = set-1)
427 // into the settings file that the user has selected for this export 441 // into the settings file that the user has selected for this export
438 for (int i = 0; i < _sc.count (); i++) // loop over all shortcuts 452 for (int i = 0; i < _sc.count (); i++) // loop over all shortcuts
439 { 453 {
440 settings->setValue("shortcuts/"+_sc.at (i).settings_key, 454 settings->setValue("shortcuts/"+_sc.at (i).settings_key,
441 _sc.at (i).actual_sc[0].toString ()); 455 _sc.at (i).actual_sc[0].toString ());
442 settings->setValue("shortcuts/"+_sc.at (i).settings_key+"_1", 456 settings->setValue("shortcuts/"+_sc.at (i).settings_key+"_1",
443 _sc.at (i).actual_sc[1].toString ()); 457 _sc.at (i).actual_sc[1].toString ());
444 } 458 }
445 459
446 if (closing) 460 if (closing)
447 { 461 {
448 delete _dialog; // the dialog for key sequences can be removed now 462 delete _dialog; // the dialog for key sequences can be removed now
475 void 489 void
476 shortcut_manager::handle_double_clicked (QTreeWidgetItem* item, int col) 490 shortcut_manager::handle_double_clicked (QTreeWidgetItem* item, int col)
477 { 491 {
478 switch (col) 492 switch (col)
479 { 493 {
480 case 2: 494 case 2:
481 case 4: 495 case 4:
482 _selected_set = col/2 - 1; 496 _selected_set = col/2 - 1;
483 break; 497 break;
484 498
485 default: 499 default:
486 return; 500 return;
487 } 501 }
488 502
489 int i = _item_index_hash[item]; 503 int i = _item_index_hash[item];
490 if (i == 0) 504 if (i == 0)
491 return; // top-level-item clicked 505 return; // top-level-item clicked
509 "on the right button to reset the " 523 "on the right button to reset the "
510 "shortcut to its default.")); 524 "shortcut to its default."));
511 help->setWordWrap (true); 525 help->setWordWrap (true);
512 box->addWidget (help); 526 box->addWidget (help);
513 527
514 QCheckBox *direct = new QCheckBox (tr ("Enter shortcut directly by performing it")); 528 QCheckBox *direct = new QCheckBox (
529 tr ("Enter shortcut directly by performing it"));
515 direct->setCheckState (Qt::Checked); 530 direct->setCheckState (Qt::Checked);
516 box->addWidget (direct); 531 box->addWidget (direct);
517 532
518 QGridLayout *grid = new QGridLayout(); 533 QGridLayout *grid = new QGridLayout();
519 534
602 return; 617 return;
603 } 618 }
604 619
605 shortcut_t shortcut = _sc.at (_handled_index); 620 shortcut_t shortcut = _sc.at (_handled_index);
606 if (! shortcut.actual_sc[_selected_set].isEmpty ()) 621 if (! shortcut.actual_sc[_selected_set].isEmpty ())
607 _shortcut_hash.remove (widget + sep + shortcut.actual_sc[_selected_set].toString ()); 622 _shortcut_hash.remove (widget + sep +
623 shortcut.actual_sc[_selected_set].toString ());
608 shortcut.actual_sc[_selected_set] = _edit_actual->text(); 624 shortcut.actual_sc[_selected_set] = _edit_actual->text();
609 _sc.replace (_handled_index, shortcut); 625 _sc.replace (_handled_index, shortcut);
610 626
611 _index_item_hash[_handled_index]->setText ((_selected_set + 1)*2, 627 _index_item_hash[_handled_index]->setText ((_selected_set + 1)*2,
612 shortcut.actual_sc[_selected_set]); 628 shortcut.actual_sc[_selected_set]);
613 629
614 if (! shortcut.actual_sc[_selected_set].isEmpty ()) 630 if (! shortcut.actual_sc[_selected_set].isEmpty ())
615 _shortcut_hash[widget + sep + shortcut.actual_sc[_selected_set].toString ()] = 631 _shortcut_hash[widget + sep + shortcut.actual_sc[_selected_set].toString ()] =
616 _handled_index + 1; 632 _handled_index + 1;
617 } 633 }
618 634
619 void 635 void
620 shortcut_manager::shortcut_dialog_set_default () 636 shortcut_manager::shortcut_dialog_set_default ()
621 { 637 {
717 if (key == Qt::Key_unknown || key == 0) 733 if (key == Qt::Key_unknown || key == 0)
718 return; 734 return;
719 735
720 Qt::KeyboardModifiers modifiers = e->modifiers (); 736 Qt::KeyboardModifiers modifiers = e->modifiers ();
721 737
722 if(modifiers & Qt::ShiftModifier) 738 if (modifiers & Qt::ShiftModifier)
723 key += Qt::SHIFT; 739 key += Qt::SHIFT;
724 if(modifiers & Qt::ControlModifier) 740 if (modifiers & Qt::ControlModifier)
725 key += Qt::CTRL; 741 key += Qt::CTRL;
726 if(modifiers & Qt::AltModifier) 742 if (modifiers & Qt::AltModifier)
727 key += Qt::ALT; 743 key += Qt::ALT;
728 if(modifiers & Qt::MetaModifier) 744 if (modifiers & Qt::MetaModifier)
729 key += Qt::META; 745 key += Qt::META;
730 746
731 setText (QKeySequence(key)); 747 setText (QKeySequence(key));
732 } 748 }
733 } 749 }