summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/docwindow.cpp
blob: f4f3dd10c50d0ce1984e03cecdf2a34a08ae3660 (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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 *   copyright (C) 2002-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

// own header
#include "docwindow.h"

// qt/kde includes
#include <tqgroupbox.h>
#include <tqlayout.h>
#include <tqmultilineedit.h>
#include <tdelocale.h>

// local includes
#include "associationwidget.h"
#include "umldoc.h"
#include "umlobject.h"
#include "umlview.h"
#include "umlwidget.h"


DocWindow::DocWindow( UMLDoc * doc, TQWidget *parent, const char *name ) : TQWidget( parent, name ) {
    //setup visual display
    TQHBoxLayout * mainLayout = new TQHBoxLayout( this );

    m_pDocGB = new TQGroupBox( i18n( "Documentation" ), this );
    mainLayout -> addWidget( m_pDocGB );

    TQHBoxLayout * docLayout = new TQHBoxLayout( m_pDocGB );
    m_pDocMLE = new TQMultiLineEdit( m_pDocGB );
    m_pDocMLE -> setText( "" );
    docLayout -> setMargin( fontMetrics().height() );
    docLayout -> addWidget( m_pDocMLE);
    m_pDocMLE -> setWordWrap(TQMultiLineEdit::WidgetWidth);

    //setup the documentation variables
    //show projects documentation to start
    m_pUMLDoc = doc;
    m_Showing = st_Project;
    m_pUMLObject = 0;
    m_pUMLView = 0;
    m_pUMLWidget = 0;
    m_pAssocWidget = 0;
    updateDocumentation( true, true );
}

DocWindow::~DocWindow() {}

void DocWindow::showDocumentation( UMLObject * object, bool overwrite ) {
    if( object == m_pUMLObject && !overwrite )
        return;
    if( object != m_pUMLObject )
        updateDocumentation( true );

    m_Showing = st_UMLObject;
    if( !object ) {
        m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
        m_pUMLObject = 0;
        return;
    }
    m_pUMLObject = object;
    m_pDocMLE -> setText( m_pUMLObject -> getDoc() );
}

void DocWindow::updateDocumentation( bool clear, bool startup ) {

    bool mark_modified = false;
    if( m_pUMLObject )
    {
        // the file is marked modified, if the documentation differs
        // we don't do this on startup/load of a xmi file, because every time
        // modified is set, we get another undo/redo backup point
        if ( startup == false && m_pDocMLE -> text() != m_pUMLObject -> getDoc() )
        {
            mark_modified = true;
        }
        m_pUMLObject -> setDoc( m_pDocMLE -> text() );

    } else if( m_pUMLView ) {
        // the file is marked modified, if the documentation differs
        // we don't do this on startup/load of a xmi file, because every time
        // modified is set, we get another undo/redo backup point
        if ( startup == false && m_pDocMLE -> text() != m_pUMLView -> getDoc() )
        {
            mark_modified = true;
        }

        m_pUMLView -> setDoc( m_pDocMLE -> text() );
    } else if ( m_pUMLWidget ) {
        // the file is marked modified, if the documentation differs
        // we don't do this on startup/load of a xmi file, because every time
        // modified is set, we get another undo/redo backup point
        if ( startup == false && m_pDocMLE -> text() != m_pUMLWidget -> getDoc() )
        {
            mark_modified = true;
        }

        m_pUMLWidget -> setDoc( m_pDocMLE -> text() );
    } else if( m_pAssocWidget ) {
        // the file is marked modified, if the documentation differs
        // we don't do this on startup/load of a xmi file, because every time
        // modified is set, we get another undo/redo backup point
        if ( startup == false && m_pDocMLE -> text() != m_pAssocWidget -> getDoc() )
        {
            mark_modified = true;
        }

        m_pAssocWidget -> setDoc( m_pDocMLE -> text() );
    } else {
        // the file is marked modified, if the documentation differs
        // we don't do this on startup/load of a xmi file, because every time
        // modified is set, we get another undo/redo backup point
        if ( startup == false && m_pDocMLE -> text() != m_pUMLDoc->getDocumentation() )
        {
            mark_modified = true;
        }

        m_pUMLDoc->setDocumentation( m_pDocMLE->text() );
    }

    // now do the setModified call
    if (mark_modified == true)
        m_pUMLDoc -> setModified( true );

    // we should show the documentation of the whole project
    if( clear ) {
        m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
        m_pUMLObject = 0;
        m_pUMLView = 0;
        m_pUMLWidget = 0;
        m_pAssocWidget = 0;
        m_Showing = st_Project;
    }

    return;
}

void DocWindow::showDocumentation( UMLView * view, bool overwrite ) {
    if( view == m_pUMLView && !overwrite )
        return;
    if( view != m_pUMLView )
        updateDocumentation( true );
    m_Showing = st_UMLView;
    if( !view ) {
        m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
        m_pUMLView = 0;
        return;
    }
    m_pUMLView = view;
    m_pDocMLE -> setText( m_pUMLView -> getDoc() );
}

void DocWindow::showDocumentation( UMLWidget * widget, bool overwrite ) {
    if( widget == m_pUMLWidget && !overwrite )
        return;
    if( widget != m_pUMLWidget )
        updateDocumentation( true );
    m_Showing = st_UMLWidget;
    if( !widget ) {
        m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
        m_pUMLWidget = 0;
        return;
    }
    m_pUMLWidget = widget;
    m_pDocMLE -> setText( m_pUMLWidget -> getDoc() );
}

void DocWindow::showDocumentation( AssociationWidget * widget, bool overwrite ) {
    if( widget == m_pAssocWidget && !overwrite )
        return;
    if( widget != m_pAssocWidget )
        updateDocumentation( true );
    m_Showing = st_Association;
    if( !widget ) {
        m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
        m_pAssocWidget = 0;
        return;
    }
    m_pAssocWidget = widget;
    m_pDocMLE -> setText( m_pAssocWidget -> getDoc() );
}

void DocWindow::newDocumentation( ) {
    m_pUMLView = 0;
    m_pUMLObject = 0;
    m_pUMLWidget = 0;
    m_pAssocWidget = 0;
    m_Showing = st_Project;
    m_pDocMLE->setText( m_pUMLDoc->getDocumentation() );
}

bool DocWindow::isTyping()
{
    if (m_pDocMLE->hasFocus())
        return true;
    else
        return false;
}

void DocWindow::slotAssociationRemoved(AssociationWidget* association) {
    if (association == m_pAssocWidget || association->getUMLObject() == m_pUMLObject) {
        // In old code, the below line crashed (bugs.kde.org/89860)
        // A hotfix was made and detailed analysis was To Be Done:
        // newDocumentation()
        // However, it seems to have been fixed and the below line seems to work fine
        updateDocumentation(true);
    }
}

void DocWindow::slotWidgetRemoved(UMLWidget* widget) {
    if (widget == m_pUMLWidget || widget->getUMLObject() == m_pUMLObject) {
        updateDocumentation(true);
    }
}

#include "docwindow.moc"