diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp index e6d42122c4..a82637097f 100644 --- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp +++ b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.cpp @@ -1,246 +1,247 @@ /*=================================================================== 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 #include namespace berry { QtStylePreferencePage::QtStylePreferencePage() { } QtStylePreferencePage::QtStylePreferencePage(const QtStylePreferencePage& other) { Q_UNUSED(other) } void QtStylePreferencePage::Init(IWorkbench::Pointer ) { } void QtStylePreferencePage::CreateQtControl(QWidget* parent) { mainWidget = new QWidget(parent); controls.setupUi(mainWidget); berry::IPreferencesService::Pointer prefService = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IPreferencesService::ID); styleManager = berry::Platform::GetServiceRegistry() .GetServiceById(berry::IQtStyleManager::ID); 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_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::FillIconThemeComboBox() +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 = QIcon::themeName(); + 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::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().toStdString()); std::string paths; for (int i = 0; i < controls.m_PathList->count(); ++i) { QString path = controls.m_PathList->item(i)->text() + ";"; paths += path.toStdString(); } QString currentTheme = QIcon::themeName(); if(currentTheme == QString("")) { currentTheme = QString("<>"); } m_StylePref->Put(berry::QtPreferences::QT_STYLE_SEARCHPATHS, paths); m_StylePref->Put(berry::QtPreferences::QT_ICON_THEME, currentTheme.toStdString()); return true; } void QtStylePreferencePage::PerformCancel() { Update(); } void QtStylePreferencePage::Update() { styleManager->RemoveStyles(); QString paths = QString::fromStdString(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 = QString::fromStdString(m_StylePref->Get(berry::QtPreferences::QT_ICON_THEME, "<>")); styleManager->SetIconTheme( iconTheme ); std::string name = m_StylePref->Get(berry::QtPreferences::QT_STYLE_NAME, ""); styleManager->SetStyle(QString::fromStdString(name)); oldStyle = styleManager->GetStyle(); FillStyleCombo(oldStyle); - FillIconThemeComboBox(); + FillIconThemeComboBox( iconTheme ); } } diff --git a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.h b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.h index 124458db09..8568d6f300 100644 --- a/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.h +++ b/BlueBerry/Bundles/org.blueberry.ui.qt/src/internal/berryQtStylePreferencePage.h @@ -1,83 +1,83 @@ /*=================================================================== 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 BERRYQTSTYLEPREFERENCEPAGE_H_ #define BERRYQTSTYLEPREFERENCEPAGE_H_ #include #include #include #include #include namespace berry { class QtStylePreferencePage : public QObject, public IQtPreferencePage { Q_OBJECT Q_INTERFACES(berry::IPreferencePage) public: QtStylePreferencePage(); QtStylePreferencePage(const QtStylePreferencePage& other); void Init(IWorkbench::Pointer workbench); void CreateQtControl(QWidget* parent); QWidget* GetQtControl() const; bool PerformOk(); void PerformCancel(); void Update(); protected: void AddPath(const QString& path, bool updateCombo); void FillStyleCombo(const berry::IQtStyleManager::Style& currentStyle); - void FillIconThemeComboBox(); + void FillIconThemeComboBox(const QString currentIconTheme); protected slots: void StyleChanged(int /*index*/); void IconThemeChanged(int /*index*/); void AddPathClicked(bool /*checked*/); void RemovePathClicked(bool /*checked*/); void EditPathClicked(bool checked); void UpdatePathListButtons(); private: berry::IQtStyleManager::Pointer styleManager; Ui::QtStylePreferencePageUI controls; berry::IPreferences::Pointer m_StylePref; berry::IQtStyleManager::Style oldStyle; berry::IQtStyleManager::StyleList styles; QWidget* mainWidget; }; } #endif /* BERRYQTSTYLEPREFERENCEPAGE_H_ */