summaryrefslogtreecommitdiffstats
path: root/src/gui/microselectwidget.cpp
blob: 0abb83d9447d2981cd93baa27e535710f2f3dffd (plain)
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
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   david@bluehaze.org                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 ***************************************************************************/

#include "asminfo.h"
#include "microinfo.h"
#include "microlibrary.h"
#include "microselectwidget.h"

#include <kcombobox.h>
#include <tdelocale.h>
#include <tqgroupbox.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqtooltip.h>
#include <tqvariant.h>
#include <tqwhatsthis.h>

MicroSelectWidget::MicroSelectWidget( TQWidget* parent, const char* name, WFlags )
	: TQGroupBox( 4, Qt::Horizontal, i18n("Microprocessor"), parent, name )
{
	m_allowedAsmSet = AsmInfo::AsmSetAll;
	m_allowedGpsimSupport = m_allowedFlowCodeSupport = m_allowedMicrobeSupport = MicroInfo::AllSupport;
	
	if ( !name )
		setName( "MicroSelectWidget" );

	m_pMicroFamilyLabel = new TQLabel( this, "m_pMicroFamilyLabel" );
	m_pMicroFamilyLabel->setText( i18n("Family") );

	m_pMicroFamily = new KComboBox( FALSE, this, "m_pMicroFamily" );
	m_pMicroFamily->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Preferred );

	m_pMicroLabel = new TQLabel( this, "m_pMicroLabel" );
	m_pMicroLabel->setText( i18n("Micro") );

	m_pMicro = new KComboBox( FALSE, this, "m_pMicro" );
	m_pMicro->setSizePolicy( TQSizePolicy::MinimumExpanding, TQSizePolicy::Preferred );
	m_pMicro->setEditable( TRUE );
	m_pMicro->setAutoCompletion(true);
	updateFromAllowed();
	setMicro("P16F84");
	connect( m_pMicroFamily, TQT_SIGNAL(activated(const TQString & )), this, TQT_SLOT(microFamilyChanged(const TQString& )) );
}


MicroSelectWidget::~MicroSelectWidget()
{
}

void MicroSelectWidget::setAllowedAsmSet( unsigned allowed )
{
	m_allowedAsmSet = allowed;
	updateFromAllowed();
}
void MicroSelectWidget::setAllowedGpsimSupport( unsigned allowed )
{
	m_allowedGpsimSupport = allowed;
	updateFromAllowed();
}
void MicroSelectWidget::setAllowedFlowCodeSupport( unsigned allowed )
{
	m_allowedFlowCodeSupport = allowed;
	updateFromAllowed();
}	
void MicroSelectWidget::setAllowedMicrobeSupport( unsigned allowed )
{
	m_allowedMicrobeSupport = allowed;
	updateFromAllowed();
}


void MicroSelectWidget::updateFromAllowed()
{
	TQString oldFamily = m_pMicroFamily->currentText();
	
	m_pMicroFamily->clear();
	
#define CHECK_ADD(family) if ( (m_allowedAsmSet & AsmInfo::family) && !MicroLibrary::self()->microIDs( AsmInfo::family, m_allowedGpsimSupport, m_allowedFlowCodeSupport, m_allowedMicrobeSupport ).isEmpty() ) m_pMicroFamily->insertItem( AsmInfo::setToString(AsmInfo::family) );
	CHECK_ADD(PIC12)
	CHECK_ADD(PIC14)
	CHECK_ADD(PIC16);
#undef CHECK_ADD

	if ( m_pMicroFamily->contains(oldFamily) )
		m_pMicroFamily->setCurrentText(oldFamily);
	
	microFamilyChanged(oldFamily);
}


void MicroSelectWidget::setMicro( const TQString & id )
{
	MicroInfo * info = MicroLibrary::self()->microInfoWithID(id);
	if (!info)
		return;
	
	m_pMicro->clear();
	m_pMicro->insertStringList( MicroLibrary::self()->microIDs( info->instructionSet()->set() ) );
	m_pMicro->setCurrentText(id);
	
	m_pMicroFamily->setCurrentText( AsmInfo::setToString( info->instructionSet()->set() ) );
}


TQString MicroSelectWidget::micro() const
{
	return m_pMicro->currentText();
}


void MicroSelectWidget::microFamilyChanged( const TQString & family )
{
	TQString oldID = m_pMicro->currentText();
	
	m_pMicro->clear();
	m_pMicro->insertStringList( MicroLibrary::self()->microIDs( AsmInfo::stringToSet(family), m_allowedGpsimSupport, m_allowedFlowCodeSupport, m_allowedMicrobeSupport ) );
	
	if ( m_pMicro->contains(oldID) )
		m_pMicro->setCurrentText(oldID);
}

#include "microselectwidget.moc"