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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/VIEW/DIALOGS/pythonSettings.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QFileDialog>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QStackedWidget>
#include <QtWidgets/QTableWidgetItem>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QFontDialog>
namespace BALL
{
namespace VIEW
{
ComboBoxDelegate::ComboBoxDelegate(QObject* parent)
: QItemDelegate(parent)
{
sl_modifier_ << "None" << "Shift" << "Ctrl";
for (Position p = 2; p < 13; p++)
{
sl_keys_ << (String(tr("F")) + String(p)).c_str();
}
}
QWidget *ComboBoxDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem& option,
const QModelIndex& index) const
{
Position c = index.column();
if (c >= 2) return QItemDelegate::createEditor(parent, option, index);
QComboBox* editor = new QComboBox(parent);
if (c == 0) editor->addItems(sl_modifier_);
else editor->addItems(sl_keys_);
editor->setEditable(false);
editor->setFrame(false);
editor->setDuplicatesEnabled(false);
editor->installEventFilter(const_cast<ComboBoxDelegate*>(this));
editor->showPopup();
return editor;
}
void ComboBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
if (index.column() >= 2)
{
QItemDelegate::setEditorData(editor, index);
return;
}
QString data = index.model()->data(index, Qt::DisplayRole).toString();
QComboBox* cb = static_cast<QComboBox*>(editor);
cb->setCurrentIndex(cb->findText(data));
}
void ComboBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
if (index.column() >= 2)
{
QItemDelegate::setModelData(editor, model, index);
return;
}
QComboBox* cb = static_cast<QComboBox*>(editor);
QString data = cb->currentText();
model->setData(index, data);
}
void ComboBoxDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
void PythonSettings::rowSelected()
{
remove_button->setEnabled(table->currentRow() >= 0);
}
const list<Hotkey> PythonSettings::getContent() const
{
return table->getContent();
}
void PythonSettings::setContent(const list<Hotkey>& hotkeys)
{
table->setContent(hotkeys);
}
// =============================================================
PythonSettings::PythonSettings(QWidget* parent, const char* name)
: QWidget(parent),
Ui_PythonSettingsData(),
PreferencesEntry()
{
setINIFileSectionName("PYTHON");
setupUi(this);
setObjectName(name);
// signals and slots connections
connect( choose_button, SIGNAL( clicked() ), this, SLOT( fileSelected() ) );
connect( clear_button, SIGNAL( clicked() ), this, SLOT( clearStartupScript() ) );
connect( font_button, SIGNAL( clicked() ), this, SLOT( selectFont() ) );
connect(new_button, SIGNAL(pressed()), table, SLOT(addEmptyRow()));
connect(remove_button, SIGNAL(pressed()), table, SLOT(removeSelection()));
setWidgetStackName("Python");
setWidgetStack(widget_stack);
registerWidgets_();
}
void PythonSettings::fileSelected()
{
QString s = QFileDialog::getOpenFileName(
0,
tr("Choose a Startup Python Script"),
getMainControl()->getWorkingDir().c_str(),
tr("Python scripts") + " (*.py)");
if (s == QString::null) return;
script_edit->setText(s);
QWidget::update();
}
void PythonSettings::setFilename(const String& filename)
{
script_edit->setText(filename.c_str());
QWidget::update();
}
void PythonSettings::clearStartupScript()
{
script_edit->setText("");
}
String PythonSettings::getFilename() const
{
return ascii(script_edit->text());
}
void PythonSettings::selectFont()
{
bool ok = true;
QFont font = QFontDialog::getFont(&ok, font_, 0);
if (!ok) return;
font_label->setFont(font);
font_ = font;
}
void PythonSettings::writePreferenceEntries(INIFile& inifile)
{
PreferencesEntry::writePreferenceEntries(inifile);
// the font size
inifile.insertValue("PYTHON", "font", ascii(font_.toString()));
}
void PythonSettings::readPreferenceEntries(const INIFile& inifile)
{
PreferencesEntry::readPreferenceEntries(inifile);
if (inifile.hasEntry("PYTHON", "font"))
{
font_.fromString(inifile.getValue("PYTHON", "font").c_str());
}
else
{
font_ = QFont("Helvetica", 12);
}
font_label->setFont(font_);
}
// NAMESPACE
} }
|