19
19
#include "codeviewerdialog.h"
23
#include <qtabwidget.h>
24
#include <qcheckbox.h>
22
#include <QtCore/QString>
23
#include <QtGui/QTabWidget>
25
24
#include <kdebug.h>
26
25
#include <klocale.h>
29
#include "../codedocument.h"
30
#include "../classifiercodedocument.h"
29
#include "codedocument.h"
30
#include "classifiercodedocument.h"
31
31
#include "codeeditor.h"
33
33
CodeViewerDialog::CodeViewerDialog ( QWidget* parent, CodeDocument * doc,
34
34
Settings::CodeViewerState state,
35
const char* name, bool modal, WFlags fl )
36
: CodeViewerDialogBase ( parent, name, modal, fl )
35
const char* name, bool modal, Qt::WFlags fl )
36
: KDialog ( parent, fl ), m_state(state)
39
uDebug() << "setObjectName(" << name << ")";
41
setButtons(KDialog::Cancel);
42
setupUi(mainWidget());
43
setInitialSize(QSize(630, 730));
43
45
addCodeDocument(doc);
46
connect(this, SIGNAL(cancelClicked()), mainWidget(), SLOT(close()));
48
* Destroys the object and frees any allocated resources
50
49
CodeViewerDialog::~CodeViewerDialog()
52
51
// no need to delete child widgets, Qt does it all for us
55
void CodeViewerDialog::initGUI ( const char * name) {
58
setName( "CodeViewerDialog" );
54
void CodeViewerDialog::initGUI ( const char * name)
57
setObjectName( "CodeViewerDialog" );
60
60
setFont( getState().font );
62
// set some viewability parameters
63
int margin = fontMetrics().height();
64
int width = fontMetrics().maxWidth() * getState().width;
65
int height = fontMetrics().lineSpacing() * getState().height;
67
62
m_highlightCheckBox->setChecked( getState().blocksAreHighlighted );
68
63
m_showHiddenCodeCB->setChecked ( getState().showHiddenBlocks );
70
CodeViewerDialogBaseLayout->setMargin(margin);
72
resize( QSize(width, height).expandedTo(minimumSizeHint()) );
65
int margin = fontMetrics().height();
66
CodeViewerDialogBase::gridLayout->setMargin(margin);
77
* Adds a code document to the tabbed output
79
69
void CodeViewerDialog::addCodeDocument( CodeDocument * doc)
81
71
CodeEditor * page = new CodeEditor ( this, "_codedocumenteditor_", doc );
82
QString fname = doc->getFileName();
72
QString name = doc->getFileName();
83
73
QString ext = doc->getFileExtension();
84
m_tabWidget->insertTab(page, (fname + (ext.isEmpty()? "" : ext)));
74
uDebug() << "name=" << name << " / ext=" << ext;
75
m_tabWidget->addTab(page, (name + (ext.isEmpty() ? "" : ext)));
86
77
connect( m_highlightCheckBox, SIGNAL( stateChanged(int) ), page, SLOT( changeHighlighting(int) ) );
87
78
connect( m_showHiddenCodeCB, SIGNAL( stateChanged(int) ), page, SLOT( changeShowHidden(int) ) );
91
Settings::CodeViewerState CodeViewerDialog::getState() {
81
Settings::CodeViewerState CodeViewerDialog::getState()
95
bool CodeViewerDialog::close ( bool alsoDelete )
86
bool CodeViewerDialog::close()
98
88
// remember widget size for next time
99
89
m_state.height = height() / fontMetrics().lineSpacing();
100
90
m_state.width = width() / fontMetrics().maxWidth();
102
91
// remember block highlighting
103
92
m_state.blocksAreHighlighted = m_highlightCheckBox->isChecked();
105
93
// remember block show status
106
94
m_state.showHiddenBlocks = m_showHiddenCodeCB->isChecked();
108
95
// run superclass close now
109
return CodeViewerDialogBase::close(alsoDelete);
96
return KDialog::close();
114
* Sets the strings of the subwidgets using the current
117
99
void CodeViewerDialog::languageChange()
119
setCaption( tr2i18n( "Code Viewer" ) );
101
Uml::Programming_Language pl = UMLApp::app()->getActiveLanguage();
102
setWindowTitle( tr2i18n( "Code Viewer - " ) + pl );
122
105
#include "codeviewerdialog.moc"