[d9bbba]: src / plugins / ktlgui / newfiledlg.cpp Maximize Restore History

Download this file

newfiledlg.cpp    163 lines (127 with data), 5.5 kB

  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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/***************************************************************************
* Copyright (C) 2005 by David Saxton <david@bluehaze.org> *
* Copyright (C) 2008 Julian B채ume <julian@svg4all.de> *
* *
* 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 "config.h"
//#include "document.h"
//#include "microinfo.h"
#include "newfiledlg.h"
#include "ui_newfilewidget.h"
//#include "microlibrary.h"
//#include "microselectwidget.h"
//#include "projectmanager.h"
//#include "textdocument.h"
#include <KComboBox>
#include <KDebug>
#include <KLineEdit>
#include <KLocale>
#include <KIconLoader>
#include <QListWidgetItem>
#include <QCheckBox>
#include <QDir>
#include <QFile>
#include <QLabel>
#include <QStyle>
using namespace KTechLab;
NewFileDlg::NewFileDlg( QWidget *parent )
: KDialog( parent )
{
m_pMainParent = parent;
m_bAccepted = false;
setObjectName( "newfiledlg" );
setWindowTitle( "New File" );
m_pNewFileWidget = new Ui::NewFileWidget();
m_pNewFileWidget->setupUi( mainWidget() );
KIconLoader *loader = KIconLoader::global();
QList<QListWidgetItem *> items;
//BEGIN insert icons
QString text = QString("%1 (.asm)").arg( i18n("Assembly Code") );
items << new QListWidgetItem( loader->loadIcon( "source", KIconLoader::NoGroup, KIconLoader::SizeHuge ), text, m_pNewFileWidget->typeIconView );
text = "C (.c)";
items << new QListWidgetItem( loader->loadIcon( "source_c", KIconLoader::NoGroup, KIconLoader::SizeHuge ), text, m_pNewFileWidget->typeIconView );
text = QString("%1 (.circuit)").arg( i18n("Circuit") );
items << new QListWidgetItem( loader->loadIcon( "ktechlab_circuit", KIconLoader::NoGroup, KIconLoader::SizeHuge ), text, m_pNewFileWidget->typeIconView );
text = QString("%1 (.flowcode)").arg( i18n("FlowCode") );
items << new QListWidgetItem( loader->loadIcon( "ktechlab_flowcode", KIconLoader::NoGroup, KIconLoader::SizeHuge ), text, m_pNewFileWidget->typeIconView );
#ifdef MECHANICS
text = QString("%1 (.mechanics)").arg( i18n("Mechanics") );
items << new QListWidgetItem( loader->loadIcon( "exec", KIconLoader::NoGroup, KIconLoader::SizeHuge ), text , m_pNewFileWidget->typeIconView );
#endif
text = QString("%1 (.microbe)").arg( i18n("Microbe") );
items << new QListWidgetItem( loader->loadIcon( "ktechlab_microbe", KIconLoader::NoGroup, KIconLoader::SizeHuge ), text, m_pNewFileWidget->typeIconView );
//END insert icons
const QList<QListWidgetItem *>::iterator end = items.end();
for ( QList<QListWidgetItem *>::iterator it = items.begin(); it != end; ++it )
{
QFlags<Qt::ItemFlag> flags = (*it)->flags();
(*it)->setFlags( flags & ~( Qt::ItemIsDropEnabled | Qt::ItemIsDragEnabled ) );
}
m_pNewFileWidget->typeIconView->setCurrentItem(items[3]);
// microSelectWidget()->setAllowedFlowCodeSupport( MicroInfo::FullSupport | MicroInfo::PartialSupport );
// Our behaviour is to have single click selects and double click accepts the dialog
connect( m_pNewFileWidget->typeIconView, SIGNAL( itemSelectionChanged() ), this, SLOT( fileTypeChanged() ) );
connect( m_pNewFileWidget->typeIconView, SIGNAL( executed( QListWidgetItem* ) ), this, SLOT( accept() ) );
setAcceptDrops(true);
m_pNewFileWidget->typeIconView->adjustSize();
adjustSize();
}
void NewFileDlg::accept()
{
hide();
printf("new file dialog accepted\n");
m_bAccepted = true;
const QString fileText = m_pNewFileWidget->typeIconView->currentItem()->text();
m_bAddToProject = m_pNewFileWidget->addToProjectCheck->isChecked();
// m_microID = m_pNewFileWidget->m_pMicroSelect->micro();
// check which signal to emit
qDebug() << "selection: " << m_pNewFileWidget->typeIconView->currentIndex();
qDebug() << "selection count: " << m_pNewFileWidget->typeIconView->currentIndex().row();
switch(m_pNewFileWidget->typeIconView->currentIndex().row()){
case 0:
// assembly
emit signalFileNewAssembly();
break;
case 1:
// C
emit signalFileNewC();
break;
case 2:
// circuit
emit signalFileNewCircuit();
break;
case 3:
// flowcode
emit signalFileNewFlowCode();
break;
case 4:
// microbe
emit signalFileNewMicrobe();
break;
default:
qCritical("unexpected item selected in new file widget!\n");
printf("item number: %d\n",
m_pNewFileWidget->typeIconView->currentIndex().row());
}
}
void NewFileDlg::reject()
{
hide();
m_bAccepted = false;
}
void NewFileDlg::fileTypeChanged()
{
QListWidgetItem *item = m_pNewFileWidget->typeIconView->currentItem();
m_pNewFileWidget->microSelect->setEnabled(
item->text().contains(".flowcode") );
}
MicroSelectWidget * NewFileDlg::microSelectWidget() const
{
// return m_pNewFileWidget->m_pMicroSelect;
return 0;
}
#include "newfiledlg.moc"