editthemedialog.cpp

来自「roadnav 内含一个基于wxWindows库的车载导航系统。编译后」· C++ 代码 · 共 489 行

CPP
489
字号
/* *  Roadnav *  EditThemeDialog.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 colors 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 "EditThemeDialog.h"#include "libroadnav/MapSupport.h"#include "Frame.h"using namespace std;//////////////////////////////////////////////////////////////////////////////////// IDs for EditThemeDialog.cpp/////////////////////////////////////////////////////////////////////////////////enum{	idName,	idDetailLevel,	idRecordType,	idColor};//////////////////////////////////////////////////////////////////////////////////// EditThemeDialog event table/////////////////////////////////////////////////////////////////////////////////BEGIN_EVENT_TABLE(EditThemeDialog, wxDialog)	EVT_TEXT(idDetailLevel, EditThemeDialog::OnDetailLevelChange)	EVT_TEXT(idRecordType, EditThemeDialog::OnRecordTypeChange)	EVT_BUTTON(wxID_OK, EditThemeDialog::OnOk)END_EVENT_TABLE()//////////////////////////////////////////////////////////////////////////////////// \brief EditThemeDialog constructor - create and initialize controls/////////////////////////////////////////////////////////////////////////////////EditThemeDialog::EditThemeDialog(										wxWindow *parent,										const wxString & strTheme,										const MapAppearanceSettings & theme,										int iDefaultDetailLevel)											: wxDialog(														parent, 														-1, 														wxT("Edit Theme"), 														wxDefaultPosition, 														wxDefaultSize),m_Theme(theme), m_strTheme(strTheme){	wxBoxSizer * psizerWnd;	wxFlexGridSizer * psizerGrid;	wxString strSel;	int iDetailLevel;		//////////////////////////////////////////////////////////////////////////	// Box sizer for entire window	//////////////////////////////////////////////////////////////////////////	psizerWnd = new wxBoxSizer(wxVERTICAL);	//////////////////////////////////////////////////////////////////////////	// Sizer for top half	//////////////////////////////////////////////////////////////////////////	psizerGrid = new wxFlexGridSizer(2, 4, 10);	psizerWnd->Add(		psizerGrid,		0,		wxALL | wxGROW,		10	);		//////////////////////////////////////////////////////////////////////////	// Theme Name	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, idName, wxT("Theme Name")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		m_pctlThemeName = new wxTextCtrl(this, idName, m_strTheme);	psizerGrid->Add ( m_pctlThemeName, 1, wxGROW, 0 );		//////////////////////////////////////////////////////////////////////////	// Feature type text	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("Feature Type")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Feature type combo box	//////////////////////////////////////////////////////////////////////////	m_pctlRecordType = new wxComboBox(this, idRecordType, wxT(""), wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_READONLY);	wxArrayString strRecordTypes = GetRecordTypeNames();	m_pctlRecordType->Append(strRecordTypes);		m_pctlRecordType->SetSelection(0);		// add to the sizer	psizerGrid->Add(m_pctlRecordType,				1,				wxGROW,				0	);	//////////////////////////////////////////////////////////////////////////	// Detail level text	//////////////////////////////////////////////////////////////////////////	psizerGrid->Add(		new wxStaticText(this, -1, wxT("Detail Level")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Detail level combo box	//////////////////////////////////////////////////////////////////////////	m_pctlDetailLevel = new wxComboBox(this, idRecordType, wxT(""), wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_READONLY);		for (iDetailLevel = 0; iDetailLevel < theme.GetDetailLevelCount(); iDetailLevel++)		m_pctlDetailLevel->Append(wxString::Format(wxT("%d"), iDetailLevel));				m_pctlDetailLevel->SetSelection(iDefaultDetailLevel);		// add to the sizer	psizerGrid->Add(m_pctlDetailLevel,				1,				wxGROW,				0	);		wxStaticBoxSizer * psizerDetailSpecific = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Detail Level Settings"));	// add to the sizer	psizerWnd->Add(psizerDetailSpecific,				1,				wxGROW | wxALL,				10	);	wxFlexGridSizer * psizerDetailSpecificGrid = new wxFlexGridSizer(2, 4, 10);	// add to the sizer	psizerDetailSpecific->Add(psizerDetailSpecificGrid,				1,				wxGROW,				0	);		//////////////////////////////////////////////////////////////////////////	// Color text	//////////////////////////////////////////////////////////////////////////	psizerDetailSpecificGrid->Add(		new wxStaticText(this, -1, wxT("Color")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Color RecordType control	//////////////////////////////////////////////////////////////////////////	m_pctlColor = new ColorPickerControl(this, idColor, wxDefaultPosition, wxSize(40, 30));		m_pctlColor->SetColor(m_Theme.GetMiscColor((EMiscColor) 0));		// add to the sizer	psizerDetailSpecificGrid->Add(m_pctlColor,				1,				wxFIXED_MINSIZE,				0	);	//////////////////////////////////////////////////////////////////////////	// Label Visible text	//////////////////////////////////////////////////////////////////////////	psizerDetailSpecificGrid->Add(		new wxStaticText(this, -1, wxT("Label Visible")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Label Visible checkbox	//////////////////////////////////////////////////////////////////////////	m_pctlLabelVisible = new wxCheckBox(this, -1, wxT(""));		// add to the sizer	psizerDetailSpecificGrid->Add(m_pctlLabelVisible,				1,				wxGROW,				0	);	//////////////////////////////////////////////////////////////////////////	// Label Font Size text	//////////////////////////////////////////////////////////////////////////	psizerDetailSpecificGrid->Add(		new wxStaticText(this, -1, wxT("Label Font Size")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Label Font Size text control	//////////////////////////////////////////////////////////////////////////	m_pctlLabelFontSize = new wxTextCtrl(this, -1, wxT(""));		// add to the sizer	psizerDetailSpecificGrid->Add(m_pctlLabelFontSize,				1,				wxGROW,				0	);	//////////////////////////////////////////////////////////////////////////	// Line Visible text	//////////////////////////////////////////////////////////////////////////	psizerDetailSpecificGrid->Add(		new wxStaticText(this, -1, wxT("Line Visible")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Line Visible checkbox	//////////////////////////////////////////////////////////////////////////	m_pctlLineVisible = new wxCheckBox(this, -1, wxT(""));		// add to the sizer	psizerDetailSpecificGrid->Add(m_pctlLineVisible,				1,				wxGROW,				0	);	//////////////////////////////////////////////////////////////////////////	// Line Width text	//////////////////////////////////////////////////////////////////////////	psizerDetailSpecificGrid->Add(		new wxStaticText(this, -1, wxT("Line Width")),		1,		wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT,		0	);		//////////////////////////////////////////////////////////////////////////	// Line Width text control	//////////////////////////////////////////////////////////////////////////	m_pctlLineWidth = new wxTextCtrl(this, -1, wxT(""));		// add to the sizer	psizerDetailSpecificGrid->Add(m_pctlLineWidth,				1,				wxGROW,				0	);	//////////////////////////////////////////////////////////////////////////	// ok and cancel button	//////////////////////////////////////////////////////////////////////////	wxStdDialogButtonSizer* psizerButton = CreateStdDialogButtonSizer(wxOK | wxCANCEL);	psizerWnd->Add(psizerButton, 0, wxALL | wxALIGN_CENTER, 5);		//////////////////////////////////////////////////////////////////////////	// Set up the sizer	//////////////////////////////////////////////////////////////////////////	m_pctlRecordType->SetFocus();	psizerWnd->Fit(this);	SetSizer(psizerWnd);	Layout();	psizerWnd->SetSizeHints(this);		RecordSettings();		wxCommandEvent ev;	OnRecordTypeChange(ev);}//////////////////////////////////////////////////////////////////////////////////// \brief Ok button pressed - save settings/////////////////////////////////////////////////////////////////////////////////void EditThemeDialog::OnOk(wxCommandEvent& event){	RecordSettings();	wxDialog::OnOK(event);}//////////////////////////////////////////////////////////////////////////////////// \brief Save the active settings to m_Theme/////////////////////////////////////////////////////////////////////////////////void EditThemeDialog::RecordSettings(){	m_strTheme = m_pctlThemeName->GetValue();	if (m_iLastRecordType < 0)		return;	if (m_iLastRecordType <= LAST_MISCCOLOR )		m_Theme.SetMiscColor((EMiscColor) m_iLastRecordType, m_pctlColor->GetColor());	else	{		long lTmp;		ERecordType eRecordType = (ERecordType) (m_iLastRecordType - LAST_MISCCOLOR - 1);			m_Theme.SetColor(eRecordType, m_pctlColor->GetColor());		if (m_iLastDetailLevel < 0)			return;				m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_bTextVisible = m_pctlLabelVisible->GetValue();				m_pctlLabelFontSize->GetValue().ToLong(&lTmp);		m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_iFontSize = lTmp;				m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_bLineVisible = m_pctlLineVisible->GetValue();				m_pctlLineWidth->GetValue().ToLong(&lTmp);		m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_iWidth = lTmp;	}	}//////////////////////////////////////////////////////////////////////////////////// \brief User changed feature types/////////////////////////////////////////////////////////////////////////////////void EditThemeDialog::OnRecordTypeChange(wxCommandEvent & event){	RecordSettings();		m_iLastRecordType = m_pctlRecordType->GetSelection();	m_iLastDetailLevel = m_pctlDetailLevel->GetSelection();		if (m_iLastRecordType < 0)		return;	if ( m_iLastRecordType <= LAST_MISCCOLOR)	{		m_pctlDetailLevel->Enable(false);		m_pctlLabelVisible->Enable(false);		m_pctlLabelFontSize->Enable(false);		m_pctlLineVisible->Enable(false);		m_pctlLineWidth->Enable(false);		m_pctlColor->SetColor(m_Theme.GetMiscColor((EMiscColor) m_iLastRecordType));	}	else	{		m_pctlDetailLevel->Enable(true);		if (m_iLastRecordType < 0)			return;					ERecordType eRecordType = (ERecordType) (m_iLastRecordType - LAST_MISCCOLOR - 1);				m_pctlLabelVisible->Enable(true);		m_pctlLabelVisible->SetValue(m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_bTextVisible);		m_pctlLabelFontSize->Enable(true);		m_pctlLabelFontSize->SetValue(wxString::Format(wxT("%d"), m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_iFontSize));		m_pctlLineVisible->Enable(true);		m_pctlLineVisible->SetValue(m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_bLineVisible);		m_pctlLineWidth->Enable(true);		m_pctlLineWidth->SetValue(wxString::Format(wxT("%d"), m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_iWidth));		m_pctlColor->SetColor(m_Theme.GetDetailSettings(m_iLastDetailLevel, eRecordType).m_clrLine);	}}//////////////////////////////////////////////////////////////////////////////////// \brief User changed detail level/////////////////////////////////////////////////////////////////////////////////void EditThemeDialog::OnDetailLevelChange(wxCommandEvent & event){	OnRecordTypeChange(event);}//////////////////////////////////////////////////////////////////////////////////// \brief Creates a wxArrayString of record type names/////////////////////////////////////////////////////////////////////////////////wxArrayString EditThemeDialog::GetRecordTypeNames(){	wxArrayString strNames;	MapApp& app = wxGetApp();	MapFrame* pFrame = (MapFrame*)app.GetTopWindow();	IMapControlData& mapControlData = pFrame->GetMapControlData();	strNames.Add(wxT("Background"));	strNames.Add(wxT("Foreground"));	strNames.Add(wxT("Marker Background"));	strNames.Add(wxT("Marker Foreground"));		wxInt16 nRecordTypes = mapControlData.GetNumRecordTypes();	for ( wxInt16 iRecordType = 0; iRecordType < nRecordTypes; iRecordType++ )	{		strNames.Add( mapControlData.GetRecordTypeDisplayName(iRecordType) );	}		return strNames;}//////////////////////////////////////////////////////////////////////////////////// \brief Returns the theme object/////////////////////////////////////////////////////////////////////////////////MapAppearanceSettings EditThemeDialog::GetTheme(){	return m_Theme;}//////////////////////////////////////////////////////////////////////////////////// \brief Returns the theme name/////////////////////////////////////////////////////////////////////////////////wxString EditThemeDialog::GetThemeName(){   return m_strTheme;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?