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
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/VIEW/DIALOGS/shortcutDialog.h>
#include <BALL/VIEW/KERNEL/shortcutRegistry.h>
#include <BALL/VIEW/KERNEL/common.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <BALL/SYSTEM/path.h>
#include <QtWidgets/QFileDialog>
namespace BALL
{
namespace VIEW
{
ShortcutDialog::ShortcutDialog(QWidget* parent, const char* name, Qt::WindowFlags)
: QWidget(parent),
Ui_ShortcutDialogData(),
ModularWidget(name),
PreferencesEntry()
{
// apply the dialogs layout
setupUi(this);
// define the dialogs section name in the INIFile
setINIFileSectionName("BALLVIEWSHORTCUTS");
setObjectName(name);
// defines the dialogs Entry name
setWidgetStackName(String(tr("Shortcuts")));
registerWidgets_();
//The shortcut registry has should be saved along with the other options for shortcuts
registerObject_(ShortcutRegistry::getInstance(0));
//The search should not be stored from session to session
unregisterObject_(searchEdit);
hide();
connect(browse_export_button, SIGNAL(clicked()), this, SLOT(browseExportFile_()));
connect(browse_import_button, SIGNAL(clicked()), this, SLOT(browseImportFile_()));
connect(tableView, SIGNAL(shortcutChanged()), this, SLOT(shortcutChanged_()));
}
ShortcutDialog::~ShortcutDialog()
{
}
void ShortcutDialog::initializeWidget(MainControl&)
{
PreferencesEntry::restoreValues();
}
void ShortcutDialog::searchTextChanged(QString filter)
{
tableView->setFilter(filter);
}
void ShortcutDialog::browseImportFile_()
{
Path p;
String filename = p.find("shortcuts_15.txt");
QString s = QFileDialog::getOpenFileName(
0,
tr("Choose a file to import shortcuts from"),
filename.c_str(),
"Text files (*)");
if (s.isEmpty())
{
// TODO this method should not occure if the dialog was canceled
Log.warn()<< (String)tr("Could not import shortcuts from file ") << ascii(s) << std::endl;
return;
}
else
{
loadShortcutsFromFile_(ascii(s));
}
}
void ShortcutDialog:: browseExportFile_()
{
Path p;
String filename = p.find("shortcuts_13.txt");
QString s = QFileDialog::getSaveFileName(
0,
tr("Choose a File to export Shortcuts"),
filename.c_str(),
"Text files (*.*)");
if (s.isEmpty()) return;
bool ret = ShortcutRegistry::getInstance(0)->writeShortcutsToFile(ascii(s));
if (!ret)
{
// TODO this method should not occure if the dialog was canceled
Log.warn()<< (String)tr("Could not export shortcuts to file ") << ascii(s) << std::endl;
}
}
void ShortcutDialog::loadPredefinedShortcuts_(QString entry)
{
Path p;
String filename;
if (entry == tr("Default Shortcuts (Version 1.5)"))
{
filename = p.find("BALLView/shortcuts_15.txt");
}
else if (entry == tr("Legacy Shortcuts (Version 1.2)"))
{
filename = p.find("BALLView/shortcuts_12.txt");
}
else if (entry == tr("Custom"))
{
return;
}
if (filename.isEmpty())
{
setStatusbarText((String)tr("Could not load legacy shortcuts."));
return;
}
loadShortcutsFromFile_(filename);
}
void ShortcutDialog::shortcutChanged_()
{
predefined_combo_box->setCurrentIndex(2);
}
void ShortcutDialog::loadShortcutsFromFile_(const String& filename)
{
ShortcutRegistry* registry = ShortcutRegistry::getInstance(0);
registry->clearKeySequences();
bool ret = registry->readShortcutsFromFile(filename);
if (!ret)
{
String description = (String)tr("Could not load shortcuts from file ") + filename + ".";
setStatusbarText(description);
}
else
{
String description = (String)tr("Successfully loaded shortcuts from file ") + filename + ".";
setStatusbarText(description);
}
}
}//namespace VIEW
}//namespace BALL
|