summaryrefslogtreecommitdiffstats
path: root/buildtools/qmake/choosesubprojectdlg.cpp
blob: 63da84f864af53d8ee97a2b2f59b519656341d0d (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
/***************************************************************************
 *   Copyright (C) 2003 by Alexander Dymo                                  *
 *   cloudtemple@mksat.net                                                 *
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/
#include <kpushbutton.h>

#include "trollprojectwidget.h"

#include "choosesubprojectdlg.h"
#include "scope.h"

ChooseSubprojectDlg::ChooseSubprojectDlg(TrollProjectWidget *widget, TQWidget* parent, const char* name, bool modal, WFlags fl)
    : ChooseSubprojectDlgBase(parent,name, modal,fl), m_widget(widget)
{
    connect(subprojects_view, TQT_SIGNAL(selectionChanged(TQListViewItem*)), this, TQT_SLOT(itemSelected(TQListViewItem *)));
    if( m_widget->m_rootSubproject)
    {
        ChooseItem *it = new ChooseItem(m_widget->m_rootSubproject, subprojects_view, m_widget->m_rootSubproject->text(0));
        it->setPixmap(0, *(m_widget->m_rootSubproject->pixmap(0)));
        it->setOpen(true);
        fillSubprojectsView(it);
        subprojects_view->setSelected(it, true);
    }
}

ChooseSubprojectDlg::~ChooseSubprojectDlg()
{
}

/*$SPECIALIZATION$*/
void ChooseSubprojectDlg::accept()
{
    if (!subprojects_view->currentItem())
        return;
    ChooseItem *item = dynamic_cast<ChooseItem*>(subprojects_view->currentItem());
    if (!item)
        return;
    if ( item->subproject()->scope->variableValues("TEMPLATE").findIndex("subdirs") != -1 )
        return;

    TQDialog::accept();
}

ChooseItem::ChooseItem( QMakeScopeItem * spitem, TQListViewItem * parent, TQString text )
    :KListViewItem(parent, text), m_spitem(spitem)
{
}

ChooseItem::ChooseItem( QMakeScopeItem * spitem, TQListView * parent, TQString text )
    :KListViewItem(parent, text), m_spitem(spitem)
{
}

QMakeScopeItem * ChooseItem::subproject( )
{
    return m_spitem;
}

void ChooseSubprojectDlg::fillSubprojectsView( ChooseItem *item )
{
    if (!item->subproject())
        return;

    TQListViewItem * sub_spitem = item->subproject()->firstChild();
    while( sub_spitem ) {
        QMakeScopeItem *spitem = dynamic_cast<QMakeScopeItem *>(sub_spitem);
        if ( spitem && spitem->scope->scopeType() == Scope::ProjectScope )
        {
            ChooseItem *child_item = new ChooseItem(spitem, item, spitem->text(0));
            child_item->setPixmap(0, *(spitem->pixmap(0)));
            child_item->setOpen(true);
            fillSubprojectsView(child_item);
        }

        sub_spitem = sub_spitem->nextSibling();
    }
}

void ChooseSubprojectDlg::itemSelected( TQListViewItem * it )
{
    if (!it)
        return;
    ChooseItem *item = dynamic_cast<ChooseItem*>(it);
    if (!item)
        return;
    if ( item->subproject()->scope->variableValues("TEMPLATE").findIndex("subdirs") != -1 )
        buttonOk->setEnabled(false);
    else
        buttonOk->setEnabled(true);
}

QMakeScopeItem * ChooseSubprojectDlg::selectedSubproject( )
{
    if (subprojects_view->currentItem())
    {
        ChooseItem *item = dynamic_cast<ChooseItem*>(subprojects_view->currentItem());
        if (item)
            return item->subproject();
    }

    return 0;
}


#include "choosesubprojectdlg.moc"

// kate: space-indent on; indent-width 4; tab-width 4; replace-tabs on