umbrello API Documentation

codeviewerdialog.cpp

00001 /***************************************************************************
00002     begin                : Fri Aug 1 2003
00003     copyright            : (C) 2003 by Brian Thomas
00004     email                : brian.thomas@gsfc.nasa.gov
00005  ***************************************************************************/
00006 
00007 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  *   copyright (C) 2004-2007                                               *
00015  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00016  ***************************************************************************/
00017 
00018 // own header
00019 #include "codeviewerdialog.h"
00020 
00021 // qt/kde includes
00022 #include <qlayout.h>
00023 #include <qtabwidget.h>
00024 #include <qcheckbox.h>
00025 #include <kdebug.h>
00026 #include <klocale.h>
00027 
00028 // local includes
00029 #include "../codedocument.h"
00030 #include "../classifiercodedocument.h"
00031 #include "codeeditor.h"
00032 
00033 CodeViewerDialog::CodeViewerDialog ( QWidget* parent, CodeDocument * doc,
00034                                      Settings::CodeViewerState state,
00035                                      const char* name, bool modal, WFlags fl )
00036         : CodeViewerDialogBase ( parent, name, modal, fl )
00037 
00038 {
00039     m_state = state;
00040 
00041     initGUI(name);
00042 
00043     addCodeDocument(doc);
00044 
00045 }
00046 
00047 /*
00048  *  Destroys the object and frees any allocated resources
00049  */
00050 CodeViewerDialog::~CodeViewerDialog()
00051 {
00052     // no need to delete child widgets, Qt does it all for us
00053 }
00054 
00055 void CodeViewerDialog::initGUI ( const char * name) {
00056 
00057     if ( !name )
00058         setName( "CodeViewerDialog" );
00059 
00060     setFont( getState().font );
00061 
00062     // set some viewability parameters
00063     int margin = fontMetrics().height();
00064     int width = fontMetrics().maxWidth() * getState().width;
00065     int height = fontMetrics().lineSpacing() * getState().height;
00066 
00067     m_highlightCheckBox->setChecked( getState().blocksAreHighlighted );
00068     m_showHiddenCodeCB->setChecked ( getState().showHiddenBlocks );
00069 
00070     CodeViewerDialogBaseLayout->setMargin(margin);
00071 
00072     resize( QSize(width, height).expandedTo(minimumSizeHint()) );
00073 
00074 }
00075 
00076 /*
00077  *  Adds a code document to the tabbed output
00078  */
00079 void CodeViewerDialog::addCodeDocument( CodeDocument * doc)
00080 {
00081     CodeEditor * page = new CodeEditor ( this, "_codedocumenteditor_", doc );
00082     QString fname = doc->getFileName();
00083     QString ext = doc->getFileExtension();
00084     m_tabWidget->insertTab(page, (fname + (ext.isEmpty()? "" : ext)));
00085 
00086     connect( m_highlightCheckBox, SIGNAL( stateChanged(int) ), page, SLOT( changeHighlighting(int) ) );
00087     connect( m_showHiddenCodeCB, SIGNAL( stateChanged(int) ), page, SLOT( changeShowHidden(int) ) );
00088 
00089 }
00090 
00091 Settings::CodeViewerState CodeViewerDialog::getState() {
00092     return m_state;
00093 }
00094 
00095 bool CodeViewerDialog::close ( bool alsoDelete )
00096 {
00097 
00098     // remember widget size for next time
00099     m_state.height = height() / fontMetrics().lineSpacing();
00100     m_state.width = width() / fontMetrics().maxWidth();
00101 
00102     // remember block highlighting
00103     m_state.blocksAreHighlighted = m_highlightCheckBox->isChecked();
00104 
00105     // remember block show status
00106     m_state.showHiddenBlocks = m_showHiddenCodeCB->isChecked();
00107 
00108     // run superclass close now
00109     return CodeViewerDialogBase::close(alsoDelete);
00110 
00111 }
00112 
00113 /*
00114  *  Sets the strings of the subwidgets using the current
00115  *  language.
00116  */
00117 void CodeViewerDialog::languageChange()
00118 {
00119     setCaption( tr2i18n( "Code Viewer" ) );
00120 }
00121 
00122 #include "codeviewerdialog.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:55 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003