Commit a9616756 authored by Dirk Wilden's avatar Dirk Wilden

keyBindings now also stored in ini file

+logfile crash also resolved

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@4623 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 6507389b
......@@ -394,6 +394,9 @@ Core::init() {
//register keyBinding for all scripting slots
coreWidget_->slotRegisterSlotKeyBindings();
//get keyAssignments from config files
restoreKeyBindings();
if ( OpenFlipper::Options::defaultToolboxMode( ) != "" )
coreWidget_->setViewMode( OpenFlipper::Options::defaultToolboxMode() );
else
......@@ -853,8 +856,11 @@ void Core::slotLogToFile(Logtype _type, QString _message){
return;
if (logStream_ == 0){
//check if a logfile has been specified
if (OpenFlipper::Options::logFile() == "")
//check if a logfile has been specified and if the path is valid
QFileInfo fi( OpenFlipper::Options::logFile() );
if (OpenFlipper::Options::logFile() == "" || !fi.dir().exists() )
OpenFlipper::Options::logFile(QDir::home().absolutePath() + OpenFlipper::Options::dirSeparator() + ".OpenFlipper" +
OpenFlipper::Options::dirSeparator() + "OpenFlipper.log");
......
......@@ -441,6 +441,9 @@ private:
/// Write Application options to ini file
void writeApplicationOptions(INIFile& _ini);
/// Restore key assignments from configs files
void restoreKeyBindings();
public slots:
/// Save the current options to the standard ini file
......
......@@ -352,6 +352,10 @@ void Core::writeApplicationOptions(INIFile& _ini) {
for (int i=0; i < entries.size(); i++)
_ini.add_entry("Options","ViewMode" + QString::number(i) ,entries[i]);
//save KeyBindings
if ( OpenFlipper::Options::gui() )
coreWidget_->saveKeyBindings(_ini);
//============================================================================
// Splash Screen
//============================================================================
......
......@@ -269,4 +269,47 @@ void Core::setupOptions() {
}
/// restore key Assignments that were saved in config files
void Core::restoreKeyBindings(){
QStringList optionFiles;
// ==============================================================
// Global ini file in the application directory
// ==============================================================
QFile globalIni(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
if ( globalIni.exists() )
optionFiles.push_back(OpenFlipper::Options::applicationDir().absolutePath() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
// ==============================================================
// Local ini file in the users home directory
// ==============================================================
QFile localIni(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
if ( localIni.exists() )
optionFiles.push_back(OpenFlipper::Options::configDirStr() + OpenFlipper::Options::dirSeparator() + "OpenFlipper.ini");
// Set the previously generated Optionfiles
OpenFlipper::Options::optionFiles(optionFiles);
// ==============================================================
// Load Application options from all files available
// ==============================================================
for ( int i = 0 ; i < (int)optionFiles.size(); ++i) {
INIFile _ini;
if ( ! _ini.connect(optionFiles[i],false) ) {
emit log(LOGERR,"Failed to connect to _ini file" + optionFiles[i]);
continue;
}
if ( OpenFlipper::Options::gui() )
coreWidget_->loadKeyBindings(_ini);
_ini.disconnect();
}
}
//=============================================================================
......@@ -78,6 +78,7 @@
#include <ACG/QtWidgets/QtSceneGraphWidget.hh>
#include <OpenFlipper/INIFile/INIFile.hh>
struct ViewMode{
QString name;
......@@ -219,14 +220,35 @@ public:
QList< SlotInfo >& coreSlots_;
private slots:
/** \brief key registration
*
* internal slot that registers a keyCombination to the sender() who emitted the registerKey() signal
* only after registering keyCombinations plugins receive keyEvents to the corresponding keyCombinations via KeyInterface.
*/
void slotRegisterKey(int _key, Qt::KeyboardModifiers _modifiers, QString _description,
bool _multiUse = false);
public slots:
/** \brief add a new key Mapping
*
* internal function that stores a new keyCombination assignment for an existing keyBinding
*/
void slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, QObject* _plugin, int _keyBindingID);
/** \brief register scripting slots to allow keyBindings
*
* internal function that registers all public slots without parameters of each plugin (or core)
* to the key management system. This allows the assignment of keyBindings for each of these slots.
*/
void slotRegisterSlotKeyBindings();
public:
///Load key assignments from a given INI file
void loadKeyBindings(INIFile& _ini);
///Store current key assignments to a given INI file
void saveKeyBindings(INIFile& _ini);
/** @} */
//===========================================================================
......
......@@ -336,6 +336,115 @@ void CoreWidget::slotAddKeyMapping(int _key, Qt::KeyboardModifiers _modifiers, Q
}
///Load key assignments from a given INI file
void CoreWidget::loadKeyBindings(INIFile& _ini){
QVector< int > keys;
QVector< int > modifiers;
QStringList pluginNames;
QVector< int > bindingIDs;
//first load everything from INI file
if ( !_ini.section_exists("KeyBindings") )
return;
int keyCount;
if (_ini.get_entry(keyCount,"KeyBindings","KeyCount") ){
int key;
int mod;
QString name;
int binding;
for (int i=0; i < keyCount; i++){
if (!_ini.get_entry(key, "KeyBindings","Key" + QString::number(i) ) ) continue;
if (!_ini.get_entry(mod, "KeyBindings","KeyModifiers" + QString::number(i) ) ) continue;
if (!_ini.get_entry(name, "KeyBindings","KeyTarget" + QString::number(i) ) ) continue;
if (!_ini.get_entry(binding, "KeyBindings","KeyBinding" + QString::number(i) ) ) continue;
keys.push_back( key );
modifiers.push_back( mod );
pluginNames.push_back( name );
bindingIDs.push_back( binding );
}
}
//add the keyMapping
for (int i=0; i < keys.count(); i++){
//first we need the plugin
QObject* plugin = 0;
if (pluginNames[i] != "Core" ){
//search for the plugin
for (uint i=0; i < plugins_.size(); i++)
if (plugins_[i].rpcName == pluginNames[i] ){
plugin = plugins_[i].plugin;
break;
}
if (plugin == 0)
continue; //because plugin was not found
}
slotAddKeyMapping( keys[i], (Qt::KeyboardModifiers) modifiers[i], plugin, bindingIDs[i] );
}
}
///Store current key assignments to a given INI file
void CoreWidget::saveKeyBindings(INIFile& _ini){
QVector< int > keys;
QVector< int > modifiers;
QStringList pluginNames;
QVector< int > bindingIDs;
//first get all keys with custom assignments
KeyMap::iterator it;
for (it=keys_.begin(); it != keys_.end(); ++it){
int key = (*it).first.first;
Qt::KeyboardModifiers mod = (*it).first.second;
QObject* plugin = (*it).second.first;
int bindingID = (*it).second.second;
KeyBinding binding = getKeyBinding(plugin, bindingID);
//check if current key assignment and original assignment differ
if (key != binding.key || mod != binding.modifiers){
//get the pluginName
QString name;
if (plugin == 0)
name = "Core";
else
name = getRPCName(plugin);
//store key assignment
keys.push_back( key );
modifiers.push_back( mod );
pluginNames.push_back( name );
bindingIDs.push_back( bindingID );
}
}
//finally store everything to INI file
if ( !_ini.section_exists("KeyBindings") )
_ini.add_section("KeyBindings");
_ini.add_entry("KeyBindings","KeyCount", keys.count());
for (int i=0; i < keys.count(); i++){
_ini.add_entry("KeyBindings","Key" + QString::number(i) , keys[i] );
_ini.add_entry("KeyBindings","KeyModifiers" + QString::number(i), modifiers[i] );
_ini.add_entry("KeyBindings","KeyTarget" + QString::number(i) , pluginNames[i] );
_ini.add_entry("KeyBindings","KeyBinding" + QString::number(i) , bindingIDs[i] );
}
}
/// if a keyPressEvent belongs to the core this functions is called
void CoreWidget::registerCoreKeys() {
......
......@@ -112,12 +112,48 @@ void OptionsWidget::applyShortcuts(){
int key = item->text(4).toInt();
Qt::KeyboardModifiers modi = (Qt::KeyboardModifiers) item->text(5).toInt();
emit addKeyMapping(key, modi, plugin, bindingID);
}
}
}
void OptionsWidget::restoreKeyPresets(){
//check if the shortcut already exists
for (int i=0; i < keyTree->topLevelItemCount(); i++)
for (int j=0; j < keyTree->topLevelItem(i)->childCount(); j++){
QTreeWidgetItem* item = keyTree->topLevelItem(i)->child(j);
QString key = item->text(1);
QString pluginName = item->parent()->text(0);
int bindingID = item->text(3).toInt();
if (pluginName == "Core"){
item->setText( 1, item->text(2) );
item->setText( 4, QString::number(coreKeys_[ bindingID ].key) );
item->setText( 5, QString::number(coreKeys_[ bindingID ].modifiers) );
} else {
//get the plugin object
int index = getPluginInfo(pluginName);
if (index == -1) //if pluginInfo was not found ->skip
continue;
item->setText( 1, item->text(2) );
item->setText( 4, QString::number(plugins_[index].keys[ bindingID ].key) );
item->setText( 5, QString::number(plugins_[index].keys[ bindingID ].modifiers) );
}
}
keyTree->setFocus(Qt::TabFocusReason);
keyTreeItemChanged(keyTree->currentItem(), 0);
}
/// init the TreeWidget containing the keyBindings
void OptionsWidget::initKeyTree(){
......@@ -150,7 +186,7 @@ void OptionsWidget::initKeyTree(){
else{
BaseInterface* basePlugin = qobject_cast< BaseInterface * >(plugin);
if (basePlugin)
name = basePlugin->name();
else{
......@@ -226,7 +262,7 @@ void OptionsWidget::initKeyTree(){
defaultStr = QKeySequence( defKey + defModi ).toString();
//and add the row
rows << description << keyString << defaultStr << QString::number(bindingID) << QString::number(key)
rows << description << keyString << defaultStr << QString::number(bindingID) << QString::number(key)
<< QString::number(modifiers) << QString::number(multiUse) << keyString;
QTreeWidgetItem* keyItem = new QTreeWidgetItem(parent, rows);
......
......@@ -180,7 +180,7 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
connect(shortcutButton, SIGNAL(keyChanged()), this, SLOT(updateShortcut()) );
connect(presetsButton, SIGNAL(clicked()), this, SLOT(restoreKeyPresets()) );
for (int i = 0 ; i < availDrawModes->count(); ++i )
availDrawModes->item( i )->setCheckState(Qt::Unchecked) ;
......
......@@ -88,6 +88,9 @@ private slots:
void slotShowPluginOptions(const QString& _pluginName );
///restore keyBinding Presets
void restoreKeyPresets();
protected:
void showEvent ( QShowEvent * event );
......
......@@ -22,7 +22,7 @@
<string/>
</property>
<property name="currentIndex" >
<number>2</number>
<number>4</number>
</property>
<property name="usesScrollButtons" >
<bool>true</bool>
......@@ -489,6 +489,36 @@ You can select multiple modes at the same time.</string>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12" >
<item>
<spacer name="horizontalSpacer_7" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>188</width>
<height>23</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="presetsButton" >
<property name="toolTip" >
<string>Restore default shortcuts</string>
</property>
<property name="statusTip" >
<string>Restore default shortcuts</string>
</property>
<property name="text" >
<string>Restore Presets</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="Updates" >
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment