~ubuntu-branches/ubuntu/raring/juffed/raring

« back to all changes in this revision

Viewing changes to src/gui/MultiPage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Maia Kozheva
  • Date: 2011-04-30 13:43:26 UTC
  • mfrom: (2.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430134326-0bnvvo5z2medbdxi
Tags: 0.9.1137-1
* New upstream release.
* Remove debian/juffed.1, added upstream (in debian.in).
* Remove debian/patches/static.patch: we can now bundle the .so after
  upstream has resolved soname issues.
* debian/control:
  - Bump Standards-Version to 0.9.2.
  - Update homepage.
  - Do not build-depend on chrpath, not needed anymore.
* debian/rules:
  - Remove chrpath rule, not needed anymore.
* Add juffed-dev and juffed-plugins packages.
* Do not install the libkeybindings.so plugin: causes a segfault on my
  amd64 machine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
JuffEd - An advanced text editor
3
 
Copyright 2007-2009 Mikhail Murzin
4
 
 
5
 
This program is free software; you can redistribute it and/or
6
 
modify it under the terms of the GNU General Public License 
7
 
version 2 as published by the Free Software Foundation.
8
 
 
9
 
This program is distributed in the hope that it will be useful,
10
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
GNU General Public License for more details.
13
 
 
14
 
You should have received a copy of the GNU General Public License
15
 
along with this program; if not, write to the Free Software
16
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17
 
*/
18
 
 
19
 
#include "MultiPage.h"
20
 
 
21
 
#include "Log.h"
22
 
 
23
 
//      Qt headers
24
 
#include <QtCore/QString>
25
 
#include <QtGui/QHBoxLayout>
26
 
#include <QtGui/QHeaderView>
27
 
#include <QtGui/QTreeWidget>
28
 
#include <QtGui/QTreeWidgetItem>
29
 
#include <QtCore/QMap>
30
 
 
31
 
class MultiPageInterior {
32
 
public:
33
 
        MultiPageInterior(QWidget* mp) {
34
 
                tree_ = new QTreeWidget();
35
 
                tree_->setFixedWidth(180);
36
 
                tree_->header()->hide();
37
 
                tree_->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
38
 
//              tree_->setRootIsDecorated(false);
39
 
                
40
 
                panel_ = new QWidget();
41
 
                panelLayout_ = new QHBoxLayout();
42
 
                panelLayout_->setMargin(0);
43
 
                panel_->setLayout(panelLayout_);
44
 
 
45
 
                QHBoxLayout* hbox = new QHBoxLayout();
46
 
                hbox->setMargin(0);
47
 
                hbox->addWidget(tree_);
48
 
                hbox->addWidget(panel_);
49
 
                mp->setLayout(hbox);
50
 
        }
51
 
        ~MultiPageInterior() {
52
 
                delete tree_;
53
 
                delete panel_;
54
 
        }
55
 
 
56
 
        QTreeWidget* tree_;
57
 
        QWidget* panel_;
58
 
        QHBoxLayout* panelLayout_;
59
 
 
60
 
        QMap<QTreeWidgetItem*, QWidget*> pages_;
61
 
};
62
 
 
63
 
 
64
 
MultiPage::MultiPage(QWidget* parent) : QWidget(parent) {
65
 
        JUFFENTRY2;
66
 
        mpInt_ = new MultiPageInterior(this);
67
 
        connect(mpInt_->tree_, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), SLOT(changeCurrentItem(QTreeWidgetItem*, QTreeWidgetItem*)));
68
 
}
69
 
 
70
 
MultiPage::~MultiPage() {
71
 
        delete mpInt_;
72
 
}
73
 
 
74
 
void MultiPage::addPage(const QString& title, QWidget* w) {
75
 
        JUFFENTRY2;
76
 
        QTreeWidgetItem* it = new QTreeWidgetItem(QStringList(title));
77
 
        mpInt_->tree_->addTopLevelItem(it);
78
 
        w->setParent(mpInt_->panel_);
79
 
        mpInt_->pages_[it] = w;
80
 
        w->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
81
 
        if ( pageCount() == 1 )
82
 
                selectPage(0);
83
 
        else
84
 
                selectPage(currentIndex());
85
 
}
86
 
 
87
 
void MultiPage::addChildPage(const QString& parentTitle, const QString& pageTitle, QWidget* w) {
88
 
        JUFFENTRY2;
89
 
        QList<QTreeWidgetItem*> items = mpInt_->tree_->findItems(parentTitle, Qt::MatchFixedString);
90
 
        if ( !items.isEmpty() ) {
91
 
                QTreeWidgetItem* p = items[0];
92
 
 
93
 
                QTreeWidgetItem* it = new QTreeWidgetItem(p, QStringList(pageTitle));
94
 
                w->setParent(mpInt_->panel_);
95
 
                mpInt_->pages_[it] = w;
96
 
                w->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
97
 
                if ( pageCount() == 1 )
98
 
                        selectPage(0);
99
 
                else
100
 
                        selectPage(currentIndex());
101
 
                p->setExpanded(true);
102
 
        }
103
 
}
104
 
 
105
 
int MultiPage::pageCount() const {
106
 
        return mpInt_->pages_.count();
107
 
}
108
 
 
109
 
QWidget* MultiPage::currentPage() const {
110
 
        return mpInt_->pages_[mpInt_->tree_->currentItem()];
111
 
}
112
 
 
113
 
QWidget* MultiPage::page(const QString& title) const {
114
 
        QList<QTreeWidgetItem*> items = mpInt_->tree_->findItems(title, Qt::MatchFixedString);
115
 
        if ( items.count() > 0 ) {
116
 
                QTreeWidgetItem* item = items[0];
117
 
                if ( mpInt_->pages_.contains(item) ) {
118
 
                        return mpInt_->pages_[item];
119
 
                }
120
 
        }
121
 
        return 0;
122
 
}
123
 
 
124
 
void MultiPage::selectPage(int page) {
125
 
        QTreeWidgetItem* it = mpInt_->tree_->topLevelItem(page);
126
 
        mpInt_->tree_->setCurrentItem(it);
127
 
        changeCurrentItem(it);
128
 
}
129
 
 
130
 
int MultiPage::currentIndex() const {
131
 
        QTreeWidgetItem* it = mpInt_->tree_->currentItem();
132
 
        return mpInt_->tree_->indexOfTopLevelItem(it);
133
 
}
134
 
 
135
 
void MultiPage::changeCurrentItem(QTreeWidgetItem* it, QTreeWidgetItem*) {
136
 
        if ( it ) {
137
 
                QWidget* page = mpInt_->pages_[it];
138
 
                if ( page )  {
139
 
                        foreach (QWidget* w, mpInt_->pages_.values()) {
140
 
                                w->hide();
141
 
                        }
142
 
                        while ( mpInt_->panelLayout_->count() > 0 ) {
143
 
                                mpInt_->panelLayout_->removeItem(mpInt_->panelLayout_->itemAt(0));
144
 
                        }
145
 
                        mpInt_->panelLayout_->addWidget(page);
146
 
                        page->show();
147
 
                }
148
 
        }
149
 
}
150
 
 
151
 
QStringList MultiPage::getChildrenTitles(const QString& parentTitle) {
152
 
        QStringList list;
153
 
        QList<QTreeWidgetItem*> items = mpInt_->tree_->findItems(parentTitle, Qt::MatchFixedString);
154
 
        if ( items.count() > 0 ) {
155
 
                QTreeWidgetItem* pluginsItem = items[0];
156
 
                int n = pluginsItem->childCount();
157
 
                for (int i = 0; i < n; ++i ) {
158
 
                        QTreeWidgetItem* it = pluginsItem->child(i);
159
 
                        if ( it ) {
160
 
                                list << it->text(0);
161
 
                        }
162
 
                }
163
 
        }
164
 
        return list;
165
 
}