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
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
// $Id: mainControlPreferences.C,v 1.16.16.1 2007/03/25 22:02:03 oliver Exp $
//
#include <BALL/VIEW/DIALOGS/mainControlPreferences.h>
#include <BALL/VIEW/KERNEL/common.h>
#include <QtCore/QDir>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QStyleFactory>
#include <QtWidgets/QFontDialog>
#include <BALL/SYSTEM/path.h>
namespace BALL
{
namespace VIEW
{
MainControlPreferences::MainControlPreferences(QWidget* parent, const char* name, Qt::WindowFlags fl)
: QWidget(parent, fl),
Ui_MainControlPreferencesData(),
PreferencesEntry(),
last_index_(0)
{
setupUi(this);
setObjectName(name);
setINIFileSectionName("GENERAL");
Path p;
QStringList dpaths = QString(p.getDataPath().c_str()).split("\n");
languageComboBox_->addItem("English (default)", QVariant("en_US"));
Q_FOREACH(QString str, dpaths) {
QDir dir(str + "BALLView/translations");
QStringList tList = dir.entryList(QStringList("BALLView-*.qm"));
Q_FOREACH(QString entry, tList) {
entry.replace("BALLView-", "");
entry.replace(".qm", "");
languageComboBox_->addItem(QLocale::languageToString(QLocale(entry).language()), QVariant(entry));
}
}
style_box_->addItems(QStyleFactory::keys());
QString prefered_style = "Plastique";
#ifdef BALL_OS_WINDOWS
prefered_style = "WindowsXP";
#endif
#ifdef BALL_OS_DARWIN
prefered_style = "Macintosh (aqua)";
#endif
Index pos = style_box_->findText(prefered_style);
if (pos != -1) style_box_->setCurrentIndex(pos);
setWidgetStackName("General");
registerWidgets_();
unregisterObject_(style_box_);
unregisterObject_(languageComboBox_);
connect( font_button, SIGNAL( clicked() ), this, SLOT( selectFont() ) );
}
MainControlPreferences::~MainControlPreferences()
{
#ifdef BALL_VIEW_DEBUG
Log.error() << "Destructing object " << (void *)this
<< " of class MainControlPreferences" << std::endl;
#endif
}
QStyle* MainControlPreferences::setStyle()
{
if(!QApplication::style() || (QApplication::style()->objectName().compare(style_box_->currentText(), Qt::CaseInsensitive) != 0))
{
QStyle* new_style = QStyleFactory::create(style_box_->currentText());
QApplication::setStyle(new_style);
}
return QApplication::style();
}
QFont MainControlPreferences::getFont()
{
return font_label->font();
}
void MainControlPreferences::enableLoggingToFile(bool state)
{
if (state) logging_to_file->setChecked(true);
else logging_to_file->setChecked(false);
}
bool MainControlPreferences::loggingToFileEnabled() const
{
return logging_to_file->isChecked();
}
bool MainControlPreferences::getSkipDriverChecks() const
{
return skip_driver_checks->isChecked();
}
void MainControlPreferences::selectFont()
{
bool ok = true;
QFont font = QFontDialog::getFont(&ok, font_, 0);
if (!ok) return;
font_label->setFont(font);
font_ = font;
}
void MainControlPreferences::setFont(QFont font)
{
font_ = font;
font_label->setFont(font);
}
void MainControlPreferences::writePreferenceEntries(INIFile& inifile)
{
PreferencesEntry::writePreferenceEntries(inifile);
inifile.insertValue(inifile_section_name_, "style", ascii(style_box_->currentText()));
inifile.insertValue(inifile_section_name_, "language", ascii(languageComboBox_->currentData().toString()));
}
void MainControlPreferences::readPreferenceEntries(const INIFile& inifile)
{
PreferencesEntry::readPreferenceEntries(inifile);
if (inifile.hasEntry(inifile_section_name_, "style"))
{
String value = inifile.getValue(inifile_section_name_, "style");
int e = style_box_->findText(value.c_str());
if (e == -1) return;
style_box_->setCurrentIndex(e);
}
if (inifile.hasEntry(inifile_section_name_, "language"))
{
int e = languageComboBox_->findData(QString(inifile.getValue(inifile_section_name_, "language").c_str()));
if (e == -1) return;
last_index_ = e;
languageComboBox_->setCurrentIndex(e);
}
}
} } // namespaces
|