~ubuntu-branches/ubuntu/natty/recorditnow/natty

« back to all changes in this revision

Viewing changes to src/timeline/timelinetopicsdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2009-12-27 00:45:15 UTC
  • Revision ID: james.westby@ubuntu.com-20091227004515-8gndndfv8iqleqf1
Tags: 0.7-0ubuntu1
* New upstream release.
* Using source format 3.0
* Using DH 7 rules now
* Dropped cdbs. Specified debhelper and pkg-kde-tools minimum versions
* Added libxext-dev and libxcursor-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2009 by Kai Dombrowe <just89@gmx.de>                    *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
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                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
18
 ***************************************************************************/
 
19
 
 
20
 
 
21
// own
 
22
#include "timelinetopicsdialog.h"
 
23
#include "topicwidget.h"
 
24
#include "topic.h"
 
25
#include "topictreeitem.h"
 
26
 
 
27
// KDE
 
28
#include <kicon.h>
 
29
#include <klocalizedstring.h>
 
30
#include <kicondialog.h>
 
31
#include <kdebug.h>
 
32
 
 
33
// Qt
 
34
#include <QtGui/QTimeEdit>
 
35
 
 
36
 
 
37
TimelineTopicsDialog::TimelineTopicsDialog(QWidget *parent, TopicWidget *topicWidget)
 
38
    : KDialog(parent), m_topicWidget(topicWidget)
 
39
{
 
40
 
 
41
    setAttribute(Qt::WA_DeleteOnClose);
 
42
    setWindowTitle(i18n("Topics"));
 
43
 
 
44
    QWidget *widget = new QWidget(this);
 
45
    setupUi(widget);    
 
46
    setMainWidget(widget);
 
47
 
 
48
    addButton->setIcon(KIcon("list-add"));
 
49
    removeButton->setIcon(KIcon("list-remove"));
 
50
    upButton->setIcon(KIcon("go-up"));
 
51
    downButton->setIcon(KIcon("go-down"));
 
52
 
 
53
    connect(addButton, SIGNAL(clicked()), this, SLOT(addTopic()));
 
54
    connect(removeButton, SIGNAL(clicked()), this, SLOT(removeTopic()));
 
55
    connect(this, SIGNAL(finished(int)), this, SLOT(updateTopicWidget(int)));
 
56
    connect(upButton, SIGNAL(clicked()), this, SLOT(upClicked()));
 
57
    connect(downButton, SIGNAL(clicked()), this, SLOT(downClicked()));
 
58
    connect(treeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
 
59
 
 
60
    treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
 
61
 
 
62
    // load
 
63
    QList<Topic*> topics = m_topicWidget->topics();
 
64
    for (int i = 0; i < topics.size(); i++) {
 
65
        addTopic(); // create widgets
 
66
    }
 
67
 
 
68
    for (int i = 0; i < topics.size(); i++) {
 
69
        TopicTreeItem *item = static_cast<TopicTreeItem*>(treeWidget->invisibleRootItem()->child(i));
 
70
        item->setTopic(topics[i]);
 
71
    }
 
72
 
 
73
}
 
74
 
 
75
 
 
76
TimelineTopicsDialog::~TimelineTopicsDialog()
 
77
{
 
78
 
 
79
 
 
80
}
 
81
 
 
82
 
 
83
void TimelineTopicsDialog::addTopic()
 
84
{
 
85
 
 
86
    TopicTreeItem *item = new TopicTreeItem(treeWidget);
 
87
    connect(item, SIGNAL(durationChanged()), this, SLOT(updateTotalDuration()));
 
88
 
 
89
}
 
90
 
 
91
 
 
92
void TimelineTopicsDialog::removeTopic()
 
93
{
 
94
 
 
95
    QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
 
96
    foreach (QTreeWidgetItem *child, items) {
 
97
        treeWidget->invisibleRootItem()->removeChild(child);
 
98
    }
 
99
    updateTotalDuration();
 
100
 
 
101
}
 
102
 
 
103
 
 
104
void TimelineTopicsDialog::updateTopicWidget(const int &ret)
 
105
{
 
106
 
 
107
    if (ret != KDialog::Accepted) {
 
108
        return;
 
109
    }
 
110
 
 
111
    m_topicWidget->clear();
 
112
 
 
113
    for (int i = 0; i < treeWidget->invisibleRootItem()->childCount(); i++) {
 
114
        QTreeWidgetItem *item = treeWidget->invisibleRootItem()->child(i);
 
115
 
 
116
        QString title = item->text(0);
 
117
        QString icon = static_cast<KIconButton*>(treeWidget->itemWidget(item, 1))->icon();
 
118
        QTime dTime = static_cast<QTimeEdit*>(treeWidget->itemWidget(item, 2))->time();
 
119
 
 
120
        m_topicWidget->addTopic(dTime, title, icon);
 
121
    }
 
122
 
 
123
}
 
124
 
 
125
 
 
126
void TimelineTopicsDialog::upClicked()
 
127
{
 
128
 
 
129
    QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
 
130
    if (items.isEmpty() || items.size() > 1) {
 
131
        return;
 
132
    }
 
133
    TopicTreeItem *item = static_cast<TopicTreeItem*>(items[0]);
 
134
 
 
135
    const int index = treeWidget->indexOfTopLevelItem(item)-1;
 
136
 
 
137
    if (index < 0) {
 
138
        return;
 
139
    }
 
140
 
 
141
    TopicTreeItem *copy = new TopicTreeItem(treeWidget, item, index);
 
142
    connect(copy, SIGNAL(durationChanged()), this, SLOT(updateTotalDuration()));
 
143
 
 
144
    treeWidget->invisibleRootItem()->removeChild(item);
 
145
    treeWidget->setCurrentItem(copy);
 
146
 
 
147
}
 
148
 
 
149
 
 
150
void TimelineTopicsDialog::downClicked()
 
151
{
 
152
 
 
153
    QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
 
154
    if (items.isEmpty() || items.size() > 1) {
 
155
        return;
 
156
    }
 
157
    TopicTreeItem *item = static_cast<TopicTreeItem*>(items[0]);
 
158
 
 
159
    const int index = treeWidget->indexOfTopLevelItem(item)+2;
 
160
 
 
161
    if (index > treeWidget->topLevelItemCount()) {
 
162
        return;
 
163
    }
 
164
 
 
165
    TopicTreeItem *copy = new TopicTreeItem(treeWidget, item, index);
 
166
    connect(copy, SIGNAL(durationChanged()), this, SLOT(updateTotalDuration()));
 
167
 
 
168
    treeWidget->invisibleRootItem()->removeChild(item);
 
169
    treeWidget->setCurrentItem(copy);
 
170
 
 
171
}
 
172
 
 
173
 
 
174
void TimelineTopicsDialog::itemSelectionChanged()
 
175
{
 
176
 
 
177
    if(treeWidget->selectedItems().isEmpty() || treeWidget->selectedItems().size() > 1) {
 
178
        upButton->setEnabled(false);
 
179
        downButton->setEnabled(false);
 
180
        removeButton->setEnabled(false);
 
181
    } else {
 
182
        const int index = treeWidget->indexOfTopLevelItem(treeWidget->selectedItems().first());
 
183
        upButton->setEnabled(index != 0);
 
184
        downButton->setEnabled(index != treeWidget->topLevelItemCount()-1);
 
185
        removeButton->setEnabled(true);
 
186
    }
 
187
 
 
188
}
 
189
 
 
190
 
 
191
void TimelineTopicsDialog::updateTotalDuration()
 
192
{
 
193
 
 
194
    unsigned long duration = 0;
 
195
    for (int i = 0; i < treeWidget->invisibleRootItem()->childCount(); i++) {
 
196
        TopicTreeItem *item = static_cast<TopicTreeItem*>(treeWidget->invisibleRootItem()->child(i));
 
197
        duration += item->duration();
 
198
    }
 
199
    totalDurationEdit->setTime(Topic::secondsToTime(duration));
 
200
 
 
201
}
 
202
 
 
203
 
 
204
#include "timelinetopicsdialog.moc"
 
205