| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2002 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#include <Gui/Action.h> |
| 25 |
#include <Gui/Application.h> |
| 26 |
#include <Gui/MainWindow.h> |
| 27 |
|
| 28 |
#include "DlgSettingsMacroImp.h" |
| 29 |
#include "ui_DlgSettingsMacro.h" |
| 30 |
|
| 31 |
using namespace Gui::Dialog; |
| 32 |
|
| 33 |
/* TRANSLATOR Gui::Dialog::DlgSettingsMacroImp */ |
| 34 |
|
| 35 |
/** |
| 36 |
* Constructs a DlgSettingsMacroImp which is a child of 'parent', with the |
| 37 |
* name 'name' and widget flags set to 'f' |
| 38 |
*/ |
| 39 |
DlgSettingsMacroImp::DlgSettingsMacroImp(QWidget* parent) |
| 40 |
: PreferencePage(parent) |
| 41 |
, ui(new Ui_DlgSettingsMacro) |
| 42 |
{ |
| 43 |
ui->setupUi(this); |
| 44 |
|
| 45 |
// Was never implemented, so hide it |
| 46 |
ui->FileLogCheckBox->hide(); |
| 47 |
ui->MacroPath_2->hide(); |
| 48 |
|
| 49 |
if (ui->MacroPath->fileName().isEmpty()) { |
| 50 |
QDir d(QString::fromUtf8(App::GetApplication().getUserMacroDir().c_str())); |
| 51 |
ui->MacroPath->setFileName(d.path()); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Destroys the object and frees any allocated resources |
| 57 |
*/ |
| 58 |
DlgSettingsMacroImp::~DlgSettingsMacroImp() = default; |
| 59 |
|
| 60 |
/** Sets the size of the recent macros list from the user parameters. |
| 61 |
* @see RecentMacrosAction |
| 62 |
* @see StdCmdRecentMacros |
| 63 |
*/ |
| 64 |
void DlgSettingsMacroImp::setRecentMacroSize() |
| 65 |
{ |
| 66 |
auto recent = getMainWindow()->findChild<RecentMacrosAction*>(QLatin1String("recentMacros")); |
| 67 |
if (recent) { |
| 68 |
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentMacros"); |
| 69 |
recent->resizeList(hGrp->GetInt("RecentMacros", 4)); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
void DlgSettingsMacroImp::saveSettings() |
| 74 |
{ |
| 75 |
ui->PrefCheckBox_LocalEnv->onSave(); |
| 76 |
ui->MacroPath->onSave(); |
| 77 |
ui->PrefCheckBox_RecordGui->onSave(); |
| 78 |
ui->PrefCheckBox_GuiAsComment->onSave(); |
| 79 |
ui->PConsoleCheckBox->onSave(); |
| 80 |
ui->FileLogCheckBox->onSave(); |
| 81 |
ui->MacroPath_2->onSave(); |
| 82 |
ui->RecentMacros->onSave(); |
| 83 |
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentMacros"); |
| 84 |
hGrp->SetASCII("ShortcutModifiers", qPrintable(ui->ShortcutModifiers->text())); |
| 85 |
ui->ShortcutCount->onSave(); |
| 86 |
setRecentMacroSize(); |
| 87 |
} |
| 88 |
|
| 89 |
void DlgSettingsMacroImp::loadSettings() |
| 90 |
{ |
| 91 |
ui->PrefCheckBox_LocalEnv->onRestore(); |
| 92 |
ui->MacroPath->onRestore(); |
| 93 |
ui->PrefCheckBox_RecordGui->onRestore(); |
| 94 |
ui->PrefCheckBox_GuiAsComment->onRestore(); |
| 95 |
ui->PConsoleCheckBox->onRestore(); |
| 96 |
ui->FileLogCheckBox->onRestore(); |
| 97 |
ui->MacroPath_2->onRestore(); |
| 98 |
ui->RecentMacros->onRestore(); |
| 99 |
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentMacros"); |
| 100 |
ui->ShortcutModifiers->setText( |
| 101 |
QString::fromStdString(hGrp->GetASCII("ShortcutModifiers", "Ctrl+Shift+")) |
| 102 |
); |
| 103 |
ui->ShortcutCount->onRestore(); |
| 104 |
} |
| 105 |
|
| 106 |
void DlgSettingsMacroImp::resetSettingsToDefaults() |
| 107 |
{ |
| 108 |
ParameterGrp::handle hGrp; |
| 109 |
hGrp = WindowParameter::getDefaultParameter()->GetGroup("RecentMacros"); |
| 110 |
// reset "ShortcutModifiers" parameter |
| 111 |
hGrp->RemoveASCII("ShortcutModifiers"); |
| 112 |
|
| 113 |
// finally reset all the parameters associated to Gui::Pref* widgets |
| 114 |
PreferencePage::resetSettingsToDefaults(); |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Sets the strings of the subwidgets using the current language. |
| 119 |
*/ |
| 120 |
void DlgSettingsMacroImp::changeEvent(QEvent* e) |
| 121 |
{ |
| 122 |
if (e->type() == QEvent::LanguageChange) { |
| 123 |
ui->retranslateUi(this); |
| 124 |
} |
| 125 |
else { |
| 126 |
QWidget::changeEvent(e); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
#include "moc_DlgSettingsMacroImp.cpp" |