summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/dialogs/diagramprintpage.cpp
blob: c6e34b15a0258a19efa53a87b7e5ae48c2503ab5 (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
224
225
/***************************************************************************
 *                                                                         *
 *   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 "diagramprintpage.h"

// qt/kde includes
#include <tqlayout.h>
#include <tqptrlist.h>
#include <tqlistbox.h>
#include <tqradiobutton.h>
#include <tqcombobox.h>
#include <tqbuttongroup.h>
#include <tqgroupbox.h>
#include <tdelocale.h>

// local includes
#include "../uml.h"
#include "../umldoc.h"
#include "../umlview.h"
#include "../umlviewlist.h"
#include "../umlnamespace.h"


DiagramPrintPage::DiagramPrintPage(TQWidget * parent, UMLDoc * m_pDoc) : KPrintDialogPage(parent), m_pDoc(m_pDoc) {
    int margin = fontMetrics().height();
    setTitle(i18n("&Diagrams"));
    TQHBoxLayout * mainLayout = new TQHBoxLayout(this);
    mainLayout -> setSpacing(10);
    mainLayout -> setMargin(margin);

    m_pFilterBG = new TQButtonGroup(i18n("Filter"), this);
    mainLayout -> addWidget(m_pFilterBG);
    m_pFilterBG -> setExclusive(true);

    TQVBoxLayout * filter = new TQVBoxLayout(m_pFilterBG);
    filter -> setSpacing(10);
    filter-> setMargin(margin);

    m_pCurrentRB = new TQRadioButton(i18n("&Current diagram"), m_pFilterBG);
    filter -> addWidget(m_pCurrentRB);
    m_pCurrentRB -> setChecked(true);
    m_pFilterBG -> insert(m_pCurrentRB, Current);

    m_pAllRB = new TQRadioButton(i18n("&All diagrams"), m_pFilterBG);
    filter -> addWidget(m_pAllRB);
    m_pFilterBG -> insert(m_pAllRB, All);

    m_pSelectRB = new TQRadioButton(i18n("&Select diagrams"), m_pFilterBG);
    filter -> addWidget(m_pSelectRB);
    m_pFilterBG -> insert(m_pSelectRB, Select);

    m_pTypeRB = new TQRadioButton(i18n("&Type of diagram"), m_pFilterBG);
    filter -> addWidget(m_pTypeRB);
    m_pFilterBG -> insert(m_pTypeRB, Type);

    m_pSelectGB = new TQGroupBox(i18n("Selection"), this);
    mainLayout -> addWidget(m_pSelectGB);

    TQVBoxLayout * select = new TQVBoxLayout(m_pSelectGB);
    select -> setSpacing(10);
    select-> setMargin(margin);

    m_pTypeCB = new TQComboBox(m_pSelectGB);
    select -> addWidget(m_pTypeCB);
    m_pTypeCB -> setEnabled(false);

    m_pSelectLB = new TQListBox(m_pSelectGB);
    select -> addWidget(m_pSelectLB);
    m_pSelectLB -> setEnabled(false);
    m_pSelectLB -> setSelectionMode(TQListBox::Multi);
    m_pSelectLB -> insertItem(UMLApp::app()->getCurrentView()->getName());
    m_pSelectLB -> setSelected(0, true);
    m_nIdList.clear();
    m_nIdList.append(UMLApp::app()->getCurrentView()->getID());



    m_ViewType = Uml::dt_Class;
    connect(m_pFilterBG, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(slotClicked(int)));
    connect(m_pTypeCB, TQT_SIGNAL(activated(const TQString&)), this, TQT_SLOT(slotActivated(const TQString&)));

    m_pTypeCB -> insertItem(i18n("Class"));
    m_pTypeCB -> insertItem(i18n("Use Case"));
    m_pTypeCB -> insertItem(i18n("Collaboration"));
    m_pTypeCB -> insertItem(i18n("Sequence"));
    m_pTypeCB -> insertItem(i18n("State"));
    m_pTypeCB -> insertItem(i18n("Activity"));
    m_pTypeCB -> insertItem(i18n("Component"));
    m_pTypeCB -> insertItem(i18n("Deployment"));
}

DiagramPrintPage::~DiagramPrintPage()
{
    disconnect(m_pFilterBG, TQT_SIGNAL(clicked(int)), this, TQT_SLOT(slotClicked(int)));
    disconnect(m_pTypeCB, TQT_SIGNAL(activated(const TQString&)), this, TQT_SLOT(slotActivated(const TQString&)));
}

void DiagramPrintPage::getOptions( TQMap<TQString,TQString>& opts, bool /*incldef = false*/ ) {
    int listCount = m_pSelectLB -> count();
    int count = 0;

    TQString diagram(i18n("kde-uml-Diagram"));
    for(int     i=0;i<listCount;i++) {
        if(m_pSelectLB -> isSelected(i)) {
            UMLView *view = (UMLView *)m_pDoc -> findView(m_nIdList[i]);
            TQString sCount = TQString("%1").arg(count);
            TQString sID = TQString("%1").arg(ID2STR(view -> getID()));
            opts.insert(diagram + sCount, sID);
            count++;
        }
    }
    opts.insert("kde-uml-count", TQString("%1").arg(count));
}

void DiagramPrintPage::setOptions( const TQMap<TQString,TQString>& /*opts*/ ) {}

bool DiagramPrintPage::isValid( TQString& msg ) {
    int listCount = m_pSelectLB -> count();
    bool sel = false;
    for(int i =0;i<listCount;i++) {
        if(m_pSelectLB -> isSelected(i)) {
            sel = true;
            i = listCount;
        }
    }
    msg = i18n("No diagrams selected.");
    return sel;
}

void DiagramPrintPage::slotClicked(int id) {
    UMLViewList list = m_pDoc -> getViewIterator();
    UMLView * view = 0;
    TQString type;

    // clear list with diagrams to print
    m_nIdList.clear();

    switch(id) {
    case Current:
        m_pTypeCB -> setEnabled(false);
        m_pSelectLB -> setEnabled(false);
        m_pSelectLB -> clear();
        m_pSelectLB -> insertItem(UMLApp::app()->getCurrentView()->getName());
        m_pSelectLB -> setSelected(0, true);
        m_nIdList.append(UMLApp::app()->getCurrentView()->getID());
        break;

    case All:

        m_pTypeCB -> setEnabled(false);
        m_pSelectLB -> setEnabled(false);
        m_pSelectLB -> clear();
        for(view = list.first(); view; view = list.next()) {
            m_pSelectLB -> insertItem(view -> getName());
            m_nIdList.append(view -> getID());
        }
        m_pSelectLB -> selectAll(true);
        break;

    case Select:
        m_pTypeCB -> setEnabled(false);
        m_pSelectLB -> setEnabled(true);
        m_pSelectLB -> clear();
        for(view = list.first(); view; view = list.next()) {
            m_pSelectLB -> insertItem(view -> getName());
            m_nIdList.append(view -> getID());
        }
        break;

    case Type:
        m_pTypeCB -> setEnabled(true);
        m_pSelectLB -> setEnabled(true);
        m_pSelectLB -> clear();
        for(view = list.first(); view; view = list.next()) {
            if(view -> getType() == m_ViewType) {
                m_pSelectLB -> insertItem(view -> getName());
                m_nIdList.append(view -> getID());
            }
        }
        m_pSelectLB -> selectAll(true);
        break;
    }
}

void DiagramPrintPage::slotActivated(const TQString & text) {
    UMLViewList list = m_pDoc -> getViewIterator();
    UMLView * view = 0;

    if(text == i18n("Class"))
        m_ViewType = Uml::dt_Class;
    else if(text == i18n("Sequence"))
        m_ViewType = Uml::dt_Sequence;
    else if(text == i18n("Use Case"))
        m_ViewType = Uml::dt_UseCase;
    else if(text == i18n("Collaboration"))
        m_ViewType = Uml::dt_Collaboration;
    else if(text == i18n("State"))
        m_ViewType = Uml::dt_State;
    else if(text == i18n("Activity"))
        m_ViewType = Uml::dt_Activity;
    else if(text == i18n("Component"))
        m_ViewType = Uml::dt_Component;
    else if(text == i18n("Deployment"))
        m_ViewType = Uml::dt_Deployment;
    m_pSelectLB -> clear();
    m_nIdList.clear();
    for(view = list.first(); view; view = list.next()) {
        if(view -> getType() == m_ViewType) {
            m_pSelectLB -> insertItem(view -> getName());
            m_nIdList.append(view -> getID());
        }
    }
    m_pSelectLB -> selectAll(true);
}

#include "diagramprintpage.moc"