📄 preferencespagethemes.cpp
字号:
/* * Roadnav * PreferencesPageThemes.cpp * * Copyright (c) 2004 - 2006 Richard L. Lynch <rllynch@users.sourceforge.net> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *////////////////////////////////////////////////////////////////////////////////// \file////// Contains the Themes page of the preferences dialog box./////////////////////////////////////////////////////////////////////////////////#ifdef HAVE_CONFIG_H# include <config.h>#endif#ifdef _MSC_VER#pragma warning(disable: 4786)#pragma warning(disable: 4800)#endif#include <wx/wx.h>#include "App.h"#include "PreferencesPageThemes.h"#include "Frame.h"#include "ThemeManager.h"#include "EditThemeDialog.h"//////////////////////////////////////////////////////////////////////////////////// IDs for PreferencesPageThemes.cpp/////////////////////////////////////////////////////////////////////////////////enum{ idThemes, idAdd, idEdit, idRemove, idNightTheme, idDayTheme, idPhotoTheme};//////////////////////////////////////////////////////////////////////////////////// PreferencesPageThemes event table/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(PreferencesPageThemes, wxPanel) EVT_BUTTON(idAdd,PreferencesPageThemes::OnAdd) EVT_BUTTON(idEdit,PreferencesPageThemes::OnEdit) EVT_BUTTON(idRemove,PreferencesPageThemes::OnRemove)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// PreferencesPageThemes constructor - create and initialize controls/////////////////////////////////////////////////////////////////////////////////PreferencesPageThemes::PreferencesPageThemes(wxWindow *parent) : wxPanel(parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL){ MapApp& app = wxGetApp(); MapFrame* pFrame = (MapFrame *) app.GetTopWindow(); m_ThemeManager = pFrame->GetThemeManager(); m_iDefaultDetailLevel = pFrame->GetMapControl()->GetDetailLevel(); wxFlexGridSizer* psizerGrid = new wxFlexGridSizer(1, 3, 0, 0); ////////////////////////////////////////////////////////////////////////// // List of themes ////////////////////////////////////////////////////////////////////////// wxBoxSizer* psizerThemeList = new wxBoxSizer(wxVERTICAL); psizerThemeList->Add( new wxStaticText(this, -1, wxT("Manage Themes")), 0, wxALL, 5 ); m_pctlThemeList = new wxListBox(this, idThemes, wxDefaultPosition, wxDefaultSize, 0, NULL, wxLB_SINGLE|wxLB_SORT); psizerThemeList->Add(m_pctlThemeList, 1, wxALL|wxEXPAND, 5); psizerGrid->Add(psizerThemeList, 1, wxEXPAND, 0); ////////////////////////////////////////////////////////////////////////// // Command buttons ////////////////////////////////////////////////////////////////////////// wxBoxSizer* psizerCommandButtons = new wxBoxSizer(wxVERTICAL); psizerCommandButtons->Add(20,20,0,wxALL,5); psizerCommandButtons->Add( new wxButton(this, idAdd, wxT("Add...")), 0, wxALL, 5); psizerCommandButtons->Add( new wxButton(this, idEdit, wxT("Edit...")), 0, wxALL, 5); psizerCommandButtons->Add( new wxButton(this, idRemove, wxT("Remove")), 0, wxALL, 5); psizerGrid->Add(psizerCommandButtons, 1, wxEXPAND, 0); ////////////////////////////////////////////////////////////////////////// // Active themes ////////////////////////////////////////////////////////////////////////// wxString strings(wxT("Default")); wxBoxSizer* psizerActiveThemes = new wxBoxSizer(wxVERTICAL); psizerActiveThemes->Add( new wxStaticText(this,-1,wxT("Nighttime Theme")), 0, wxALL, 5); m_pctlNightTheme = new wxComboBox(this,idNightTheme,wxT(""),wxDefaultPosition,wxDefaultSize,0,NULL,wxCB_READONLY); psizerActiveThemes->Add( m_pctlNightTheme, 1, wxALL | wxEXPAND, 5); psizerActiveThemes->Add( new wxStaticText(this,-1,wxT("Daytime Theme")), 0, wxALL, 5); m_pctlDayTheme = new wxComboBox(this,idDayTheme,wxT(""),wxDefaultPosition,wxDefaultSize,0,NULL,wxCB_READONLY); psizerActiveThemes->Add( m_pctlDayTheme, 1, wxALL | wxEXPAND, 5); psizerActiveThemes->Add( new wxStaticText(this,-1,wxT("Aerial Photo Theme")), 0, wxALL, 5); m_pctlPhotoTheme = new wxComboBox(this,idPhotoTheme,wxT(""),wxDefaultPosition,wxDefaultSize,0,NULL,wxCB_READONLY); psizerActiveThemes->Add( m_pctlPhotoTheme, 1, wxALL | wxEXPAND, 5); wxString strChoices[] = {wxString(wxT("Swap at sunrise/sunset")),wxString(wxT("Nighttime Only")),wxString(wxT("Daytime Only"))}; m_pctlThemeUsage = new wxRadioBox(this,-1,wxT("Theme Usage"),wxDefaultPosition,wxDefaultSize,3,strChoices,1,wxRA_SPECIFY_COLS); psizerActiveThemes->Add( m_pctlThemeUsage, 0, wxALL, 5); psizerGrid->Add(psizerActiveThemes, 1, wxEXPAND, 0); ////////////////////////////////////////////////////////////////////////// // psizerWnd just adds a border to psizerGrid ////////////////////////////////////////////////////////////////////////// wxBoxSizer* psizerWnd = new wxBoxSizer(wxVERTICAL); psizerWnd->Add( psizerGrid, 0, wxALL | wxGROW, 10 ); ////////////////////////////////////////////////////////////////////////// // Set up the sizer ////////////////////////////////////////////////////////////////////////// m_pctlThemeList->SetFocus(); psizerWnd->Fit(this); SetSizer(psizerWnd); Layout(); psizerWnd->SetSizeHints(this); ////////////////////////////////////////////////////////////////////////// // Fill up the theme lists ////////////////////////////////////////////////////////////////////////// wxArrayString strThemes = m_ThemeManager.GetThemeNames(); #if wxCHECK_VERSION(2, 6, 0) m_pctlThemeList->Append(strThemes); m_pctlNightTheme->Append(strThemes); m_pctlDayTheme->Append(strThemes); m_pctlPhotoTheme->Append(strThemes);#else unsigned int i; for (i = 0; i < strThemes.Count(); i++) { m_pctlThemeList->Append(strThemes[i]); m_pctlNightTheme->Append(strThemes[i]); m_pctlDayTheme->Append(strThemes[i]); m_pctlPhotoTheme->Append(strThemes[i]); }#endif ////////////////////////////////////////////////////////////////////////// // Make the initialize selections ////////////////////////////////////////////////////////////////////////// m_pctlThemeList->SetSelection(0); m_pctlNightTheme->SetStringSelection( m_ThemeManager.GetNightThemeName() ); m_pctlDayTheme->SetStringSelection( m_ThemeManager.GetDayThemeName() ); m_pctlPhotoTheme->SetStringSelection( m_ThemeManager.GetPhotoThemeName() ); m_pctlThemeUsage->SetSelection( m_ThemeManager.GetThemeUsage() );}//////////////////////////////////////////////////////////////////////////////////// Ok was pressed .. save the settings/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnOk(wxCommandEvent& event){ m_ThemeManager.SetNightTheme( m_pctlNightTheme->GetStringSelection() ); m_ThemeManager.SetDayTheme( m_pctlDayTheme->GetStringSelection() ); m_ThemeManager.SetPhotoTheme( m_pctlPhotoTheme->GetStringSelection() ); m_ThemeManager.SetThemeUsage( (ThemeManager::ThemeUsage)m_pctlThemeUsage->GetSelection() ); MapApp& app = wxGetApp(); MapFrame* pFrame = (MapFrame*)app.GetTopWindow(); pFrame->SetThemeManager(m_ThemeManager);}//////////////////////////////////////////////////////////////////////////////////// Add was pressed .. create a new theme and edit it/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnAdd(wxCommandEvent& event){ // Don't store the theme in the theme manager until // after it has been edited. Give the user an opportunity // to change it's name. // // After edited, need to update combo boxes MapAppearanceSettings & default_theme = m_ThemeManager.GetTheme(wxT("Default-Day")); MapAppearanceSettings new_theme = default_theme; wxString strNewTheme = wxString::Format(wxT("Theme%d"),m_ThemeManager.GetThemeCount()+1); EditTheme(strNewTheme,new_theme); m_ThemeManager.AddTheme(strNewTheme,new_theme); int index = m_pctlThemeList->Append(strNewTheme); m_pctlThemeList->SetSelection(index); RefreshComboBoxes();}//////////////////////////////////////////////////////////////////////////////////// Edit was pressed .. edit the selected theme/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnEdit(wxCommandEvent& event){ wxString strOldThemeName = m_pctlThemeList->GetStringSelection(); wxString strNewThemeName = strOldThemeName; MapAppearanceSettings & theme = m_ThemeManager.GetTheme(strOldThemeName); EditTheme(strNewThemeName,theme); if ( strNewThemeName != strOldThemeName ) { // the theme was renamed m_ThemeManager.RenameTheme(strOldThemeName,strNewThemeName); RefreshComboBoxes(); }}//////////////////////////////////////////////////////////////////////////////////// Remove was pressed .. remove the selected theme/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::OnRemove(wxCommandEvent& event){ wxString strTheme = m_pctlThemeList->GetStringSelection(); wxString strMsg = wxString::Format(wxT("Are you sure you want to permanently delete %s"),strTheme.c_str()); if (wxMessageBox(strMsg, wxT("Confirm Deletion"), wxYES_NO | wxICON_QUESTION, this) == wxYES) { m_ThemeManager.RemoveTheme(strTheme); m_pctlThemeList->Delete( m_pctlThemeList->FindString(strTheme) ); RefreshComboBoxes(); }}//////////////////////////////////////////////////////////////////////////////////// Edit the theme/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::EditTheme(wxString& strTheme, MapAppearanceSettings & theme){ EditThemeDialog dlg(this, strTheme, theme, m_iDefaultDetailLevel); if (dlg.ShowModal() == wxID_OK) { theme = dlg.GetTheme(); strTheme = dlg.GetThemeName(); }}//////////////////////////////////////////////////////////////////////////////////// The list of theme names has changed... refresh all the combo boxes/////////////////////////////////////////////////////////////////////////////////void PreferencesPageThemes::RefreshComboBoxes(){ // Get current selection wxString strNightTheme = m_pctlNightTheme->GetStringSelection(); wxString strDayTheme = m_pctlDayTheme->GetStringSelection(); wxString strPhotoTheme = m_pctlPhotoTheme->GetStringSelection(); m_pctlNightTheme->Clear(); m_pctlDayTheme->Clear(); m_pctlPhotoTheme->Clear(); wxArrayString strThemes = m_ThemeManager.GetThemeNames();#if wxCHECK_VERSION(2, 6, 0) m_pctlThemeList->Append(strThemes); m_pctlNightTheme->Append(strThemes); m_pctlDayTheme->Append(strThemes); m_pctlPhotoTheme->Append(strThemes);#else unsigned int i; for (i = 0; i < strThemes.Count(); i++) { m_pctlThemeList->Append(strThemes[i]); m_pctlNightTheme->Append(strThemes[i]); m_pctlDayTheme->Append(strThemes[i]); m_pctlPhotoTheme->Append(strThemes[i]); }#endif m_pctlNightTheme->SetStringSelection(strNightTheme); m_pctlDayTheme->SetStringSelection(strDayTheme); m_pctlPhotoTheme->SetStringSelection(strPhotoTheme);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -