diff --git a/Plugins/org.blueberry.ui.qt/src/application/berryQtWorkbenchAdvisor.cpp b/Plugins/org.blueberry.ui.qt/src/application/berryQtWorkbenchAdvisor.cpp index f51d8d24a7..a339e3f4e2 100755 --- a/Plugins/org.blueberry.ui.qt/src/application/berryQtWorkbenchAdvisor.cpp +++ b/Plugins/org.blueberry.ui.qt/src/application/berryQtWorkbenchAdvisor.cpp @@ -1,58 +1,60 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryQtWorkbenchAdvisor.h" #include "internal/berryQtGlobalEventFilter.h" #include "internal/berryWorkbenchPlugin.h" #include "berryQtPreferences.h" #include #include #include #include #include #include #include #include #include #include namespace berry { void QtWorkbenchAdvisor::Initialize(IWorkbenchConfigurer::Pointer configurer) { WorkbenchAdvisor::Initialize(configurer); IPreferencesService* prefService = WorkbenchPlugin::GetDefault()->GetPreferencesService(); IPreferences::Pointer prefs = prefService->GetSystemPreferences()->Node(QtPreferences::QT_STYLES_NODE); QString styleName = prefs->Get(QtPreferences::QT_STYLE_NAME, ""); + QString fontName = prefs->Get(QtPreferences::QT_FONT_NAME, ""); ctkServiceReference serviceRef = WorkbenchPlugin::GetDefault()->GetPluginContext()->getServiceReference(); if (serviceRef) { IQtStyleManager* styleManager = WorkbenchPlugin::GetDefault()->GetPluginContext()->getService(serviceRef); styleManager->SetStyle(styleName); + styleManager->SetFont(fontName); } QObject* eventFilter = new QtGlobalEventFilter(qApp); qApp->installEventFilter(eventFilter); } } diff --git a/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.cpp b/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.cpp index 197cbffd33..cb255011bc 100644 --- a/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.cpp +++ b/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.cpp @@ -1,28 +1,29 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryQtPreferences.h" #include namespace berry { const QString QtPreferences::QT_STYLES_NODE = "qtstyles"; const QString QtPreferences::QT_STYLE_NAME = "stylename"; const QString QtPreferences::QT_STYLE_SEARCHPATHS = "searchpaths"; const QString QtPreferences::QT_ICON_THEME = "icontheme"; +const QString QtPreferences::QT_FONT_NAME = "fontname"; } diff --git a/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.h b/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.h index 59b2a9d1f8..dbcf6a8111 100644 --- a/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.h +++ b/Plugins/org.blueberry.ui.qt/src/berryQtPreferences.h @@ -1,36 +1,37 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef BERRYQTPREFERENCES_H_ #define BERRYQTPREFERENCES_H_ #include #include namespace berry { struct BERRY_UI_QT QtPreferences { static const QString QT_STYLES_NODE; // = "qtstyles"; static const QString QT_STYLE_NAME; // = "stylename"; static const QString QT_STYLE_SEARCHPATHS; // = "searchpaths"; static const QString QT_ICON_THEME; // = "icontheme"; + static const QString QT_FONT_NAME; // = "fontname"; }; } #endif /* BERRYQTPREFERENCES_H_ */ diff --git a/Plugins/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp b/Plugins/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp index 839928566e..000270a575 100644 --- a/Plugins/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp +++ b/Plugins/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp @@ -1,269 +1,273 @@ /*=================================================================== BlueBerry Platform Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "berryQtStylePreferencePage.h" #include #include #include "berryWorkbenchPlugin.h" #include #include #include namespace berry { QtStylePreferencePage::QtStylePreferencePage() { } void QtStylePreferencePage::Init(IWorkbench::Pointer ) { } void QtStylePreferencePage::CreateQtControl(QWidget* parent) { mainWidget = new QWidget(parent); controls.setupUi(mainWidget); berry::IPreferencesService* prefService = berry::WorkbenchPlugin::GetDefault()->GetPreferencesService(); ctkPluginContext* context = berry::WorkbenchPlugin::GetDefault()->GetPluginContext(); ctkServiceReference styleManagerRef = context->getServiceReference(); if (styleManagerRef) { styleManager = context->getService(styleManagerRef); } m_StylePref = prefService->GetSystemPreferences()->Node(berry::QtPreferences::QT_STYLES_NODE); Update(); connect(controls.m_StylesCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(StyleChanged(int))); connect(controls.m_FontComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(FontChanged(int))); connect(controls.m_IconThemeComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(IconThemeChanged(int))); connect(controls.m_PathList, SIGNAL(itemSelectionChanged()), this, SLOT(UpdatePathListButtons())); connect(controls.m_AddButton, SIGNAL(clicked(bool)), this, SLOT(AddPathClicked(bool))); connect(controls.m_EditButton, SIGNAL(clicked(bool)), this, SLOT(EditPathClicked(bool))); connect(controls.m_RemoveButton, SIGNAL(clicked(bool)), this, SLOT(RemovePathClicked(bool))); } void QtStylePreferencePage::FillStyleCombo(const berry::IQtStyleManager::Style& currentStyle) { controls.m_StylesCombo->clear(); styles.clear(); styleManager->GetStyles(styles); qSort(styles); for (int i = 0; i < styles.size(); ++i) { controls.m_StylesCombo->addItem(styles.at(i).name, QVariant(styles.at(i).fileName)); } controls.m_StylesCombo->setCurrentIndex(styles.indexOf(currentStyle)); } void QtStylePreferencePage::FillFontCombo(const QString& currentFont) { controls.m_FontComboBox->clear(); QStringList fonts; styleManager->GetFonts(fonts); for (int i = 0; i < fonts.size(); ++i) { controls.m_FontComboBox->addItem(fonts.at(i)); } controls.m_FontComboBox->setCurrentIndex(fonts.indexOf(currentFont)); } void QtStylePreferencePage::FillIconThemeComboBox(const QString currentIconTheme) { controls.m_IconThemeComboBox->clear(); berry::IQtStyleManager::IconThemeList iconThemes; styleManager->GetIconThemes(iconThemes); qSort(iconThemes); for (int i = 0; i < iconThemes.size(); ++i) { controls.m_IconThemeComboBox->addItem(iconThemes.at(i).name); } QString currentTheme = currentIconTheme; if(currentTheme == QString("")) { currentTheme = QString("<>"); } controls.m_IconThemeComboBox->setCurrentIndex(iconThemes.indexOf( currentTheme )); } void QtStylePreferencePage::AddPath(const QString& path, bool updateCombo) { if (!controls.m_PathList->findItems(path, Qt::MatchCaseSensitive).isEmpty()) return; new QListWidgetItem(path, controls.m_PathList); styleManager->AddStyles(path); if (updateCombo) FillStyleCombo(oldStyle); } void QtStylePreferencePage::StyleChanged(int /*index*/) { QString fileName = controls.m_StylesCombo->itemData(controls.m_StylesCombo->currentIndex()).toString(); styleManager->SetStyle(fileName); } void QtStylePreferencePage::FontChanged(int /*index*/) { QString fontName = controls.m_FontComboBox->currentText(); styleManager->SetFont(fontName); } void QtStylePreferencePage::IconThemeChanged(int /*index*/) { QString themeName = controls.m_IconThemeComboBox->currentText(); styleManager->SetIconTheme(themeName); } void QtStylePreferencePage::AddPathClicked(bool /*checked*/) { QListWidgetItem* item = controls.m_PathList->currentItem(); QString initialDir; if (item) initialDir = item->text(); QString dir = QFileDialog::getExistingDirectory(mainWidget, "", initialDir); if (!dir.isEmpty()) this->AddPath(dir, true); } void QtStylePreferencePage::RemovePathClicked(bool /*checked*/) { QList selection = controls.m_PathList->selectedItems(); QListIterator it(selection); while (it.hasNext()) { QListWidgetItem* item = it.next(); QString dir = item->text(); controls.m_PathList->takeItem(controls.m_PathList->row(item)); delete item; styleManager->RemoveStyles(dir); } if (!styleManager->Contains(oldStyle.fileName)) { oldStyle = styleManager->GetDefaultStyle(); } FillStyleCombo(oldStyle); } void QtStylePreferencePage::EditPathClicked(bool checked) { QListWidgetItem* item = controls.m_PathList->currentItem(); QString initialDir = item->text(); QString dir = QFileDialog::getExistingDirectory(mainWidget, "", initialDir); if (!dir.isEmpty()) { this->RemovePathClicked(checked); this->AddPath(dir, true); } } void QtStylePreferencePage::UpdatePathListButtons() { int s = controls.m_PathList->selectedItems().size(); if (s == 0) { controls.m_EditButton->setEnabled(false); controls.m_RemoveButton->setEnabled(false); } else if (s == 1) { controls.m_EditButton->setEnabled(true); controls.m_RemoveButton->setEnabled(true); } else { controls.m_EditButton->setEnabled(false); controls.m_RemoveButton->setEnabled(true); } } QWidget* QtStylePreferencePage::GetQtControl() const { return mainWidget; } bool QtStylePreferencePage::PerformOk() { m_StylePref->Put(berry::QtPreferences::QT_STYLE_NAME, controls.m_StylesCombo->itemData(controls.m_StylesCombo->currentIndex()).toString()); QString paths; for (int i = 0; i < controls.m_PathList->count(); ++i) { QString path = controls.m_PathList->item(i)->text() + ";"; paths += path; } QString currentTheme = QIcon::themeName(); if(currentTheme.isEmpty()) { currentTheme = QString("<>"); } m_StylePref->Put(berry::QtPreferences::QT_STYLE_SEARCHPATHS, paths); m_StylePref->Put(berry::QtPreferences::QT_ICON_THEME, currentTheme); + m_StylePref->Put(berry::QtPreferences::QT_FONT_NAME, + controls.m_FontComboBox->currentText()); return true; } void QtStylePreferencePage::PerformCancel() { Update(); } void QtStylePreferencePage::Update() { styleManager->RemoveStyles(); QString paths = m_StylePref->Get(berry::QtPreferences::QT_STYLE_SEARCHPATHS, ""); QStringList pathList = paths.split(";", QString::SkipEmptyParts); QStringListIterator it(pathList); while (it.hasNext()) { AddPath(it.next(), false); } QString iconTheme = m_StylePref->Get(berry::QtPreferences::QT_ICON_THEME, "<>"); styleManager->SetIconTheme( iconTheme ); + FillIconThemeComboBox( iconTheme ); - QString name = m_StylePref->Get(berry::QtPreferences::QT_STYLE_NAME, ""); - styleManager->SetStyle(name); + QString styleName = m_StylePref->Get(berry::QtPreferences::QT_STYLE_NAME, ""); + styleManager->SetStyle(styleName); oldStyle = styleManager->GetStyle(); - FillStyleCombo(oldStyle); - FillIconThemeComboBox( iconTheme ); - FillFontCombo(styleManager->GetFont()); // TODO // TODO // TODO + + QString fontName = m_StylePref->Get(berry::QtPreferences::QT_FONT_NAME, ""); + styleManager->SetFont(fontName); + FillFontCombo(styleManager->GetFont()); } }