~ubuntu-branches/ubuntu/intrepid/kdesdk/intrepid-updates

« back to all changes in this revision

Viewing changes to umbrello/umbrello/dialogs/codeviewerdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2008-05-28 10:11:43 UTC
  • mto: This revision was merged to the branch mainline in revision 37.
  • Revision ID: james.westby@ubuntu.com-20080528101143-gzc3styjz1b70zxu
Tags: upstream-4.0.80
ImportĀ upstreamĀ versionĀ 4.0.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 *   the Free Software Foundation; either version 2 of the License, or     *
12
12
 *   (at your option) any later version.                                   *
13
13
 *                                                                         *
14
 
 *   copyright (C) 2004-2007                                               *
 
14
 *   copyright (C) 2004-2008                                               *
15
15
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
16
16
 ***************************************************************************/
17
17
 
19
19
#include "codeviewerdialog.h"
20
20
 
21
21
// qt/kde includes
22
 
#include <qlayout.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>
27
26
 
28
27
// local includes
29
 
#include "../codedocument.h"
30
 
#include "../classifiercodedocument.h"
 
28
#include "uml.h"
 
29
#include "codedocument.h"
 
30
#include "classifiercodedocument.h"
31
31
#include "codeeditor.h"
32
32
 
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 )
37
 
 
 
35
                                     const char* name, bool modal, Qt::WFlags fl )
 
36
        : KDialog ( parent, fl ), m_state(state)
38
37
{
39
 
    m_state = state;
40
 
 
 
38
    setObjectName(name);
 
39
    uDebug() << "setObjectName(" << name << ")";
 
40
    setModal(modal);
 
41
    setButtons(KDialog::Cancel);
 
42
    setupUi(mainWidget());
 
43
    setInitialSize(QSize(630, 730));
41
44
    initGUI(name);
42
 
 
43
45
    addCodeDocument(doc);
44
 
 
 
46
    connect(this, SIGNAL(cancelClicked()), mainWidget(), SLOT(close()));
45
47
}
46
48
 
47
 
/*
48
 
 *  Destroys the object and frees any allocated resources
49
 
 */
50
49
CodeViewerDialog::~CodeViewerDialog()
51
50
{
52
51
    // no need to delete child widgets, Qt does it all for us
53
52
}
54
53
 
55
 
void CodeViewerDialog::initGUI ( const char * name) {
56
 
 
57
 
    if ( !name )
58
 
        setName( "CodeViewerDialog" );
 
54
void CodeViewerDialog::initGUI ( const char * name)
 
55
{
 
56
    if ( !name ) {
 
57
        setObjectName( "CodeViewerDialog" );
 
58
    }
59
59
 
60
60
    setFont( getState().font );
61
61
 
62
 
    // set some viewability parameters
63
 
    int margin = fontMetrics().height();
64
 
    int width = fontMetrics().maxWidth() * getState().width;
65
 
    int height = fontMetrics().lineSpacing() * getState().height;
66
 
 
67
62
    m_highlightCheckBox->setChecked( getState().blocksAreHighlighted );
68
63
    m_showHiddenCodeCB->setChecked ( getState().showHiddenBlocks );
69
64
 
70
 
    CodeViewerDialogBaseLayout->setMargin(margin);
71
 
 
72
 
    resize( QSize(width, height).expandedTo(minimumSizeHint()) );
73
 
 
 
65
    int margin = fontMetrics().height();
 
66
    CodeViewerDialogBase::gridLayout->setMargin(margin);
74
67
}
75
68
 
76
 
/*
77
 
 *  Adds a code document to the tabbed output
78
 
 */
79
69
void CodeViewerDialog::addCodeDocument( CodeDocument * doc)
80
70
{
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)));
85
76
 
86
77
    connect( m_highlightCheckBox, SIGNAL( stateChanged(int) ), page, SLOT( changeHighlighting(int) ) );
87
78
    connect( m_showHiddenCodeCB, SIGNAL( stateChanged(int) ), page, SLOT( changeShowHidden(int) ) );
88
 
 
89
79
}
90
80
 
91
 
Settings::CodeViewerState CodeViewerDialog::getState() {
 
81
Settings::CodeViewerState CodeViewerDialog::getState()
 
82
{
92
83
    return m_state;
93
84
}
94
85
 
95
 
bool CodeViewerDialog::close ( bool alsoDelete )
 
86
bool CodeViewerDialog::close()
96
87
{
97
 
 
98
88
    // remember widget size for next time
99
89
    m_state.height = height() / fontMetrics().lineSpacing();
100
90
    m_state.width = width() / fontMetrics().maxWidth();
101
 
 
102
91
    // remember block highlighting
103
92
    m_state.blocksAreHighlighted = m_highlightCheckBox->isChecked();
104
 
 
105
93
    // remember block show status
106
94
    m_state.showHiddenBlocks = m_showHiddenCodeCB->isChecked();
107
 
 
108
95
    // run superclass close now
109
 
    return CodeViewerDialogBase::close(alsoDelete);
110
 
 
 
96
    return KDialog::close();
111
97
}
112
98
 
113
 
/*
114
 
 *  Sets the strings of the subwidgets using the current
115
 
 *  language.
116
 
 */
117
99
void CodeViewerDialog::languageChange()
118
100
{
119
 
    setCaption( tr2i18n( "Code Viewer" ) );
 
101
    Uml::Programming_Language pl = UMLApp::app()->getActiveLanguage();
 
102
    setWindowTitle( tr2i18n( "Code Viewer - " ) + pl );
120
103
}
121
104
 
122
105
#include "codeviewerdialog.moc"