1
/***************************************************************************
2
* Copyright (C) 2009 by Kai Dombrowe <just89@gmx.de> *
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. *
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. *
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
***************************************************************************/
22
#include "timelinetopicsdialog.h"
23
#include "topicwidget.h"
25
#include "topictreeitem.h"
29
#include <klocalizedstring.h>
30
#include <kicondialog.h>
34
#include <QtGui/QTimeEdit>
37
TimelineTopicsDialog::TimelineTopicsDialog(QWidget *parent, TopicWidget *topicWidget)
38
: KDialog(parent), m_topicWidget(topicWidget)
41
setAttribute(Qt::WA_DeleteOnClose);
42
setWindowTitle(i18n("Topics"));
44
QWidget *widget = new QWidget(this);
46
setMainWidget(widget);
48
addButton->setIcon(KIcon("list-add"));
49
removeButton->setIcon(KIcon("list-remove"));
50
upButton->setIcon(KIcon("go-up"));
51
downButton->setIcon(KIcon("go-down"));
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()));
60
treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
63
QList<Topic*> topics = m_topicWidget->topics();
64
for (int i = 0; i < topics.size(); i++) {
65
addTopic(); // create widgets
68
for (int i = 0; i < topics.size(); i++) {
69
TopicTreeItem *item = static_cast<TopicTreeItem*>(treeWidget->invisibleRootItem()->child(i));
70
item->setTopic(topics[i]);
76
TimelineTopicsDialog::~TimelineTopicsDialog()
83
void TimelineTopicsDialog::addTopic()
86
TopicTreeItem *item = new TopicTreeItem(treeWidget);
87
connect(item, SIGNAL(durationChanged()), this, SLOT(updateTotalDuration()));
92
void TimelineTopicsDialog::removeTopic()
95
QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
96
foreach (QTreeWidgetItem *child, items) {
97
treeWidget->invisibleRootItem()->removeChild(child);
99
updateTotalDuration();
104
void TimelineTopicsDialog::updateTopicWidget(const int &ret)
107
if (ret != KDialog::Accepted) {
111
m_topicWidget->clear();
113
for (int i = 0; i < treeWidget->invisibleRootItem()->childCount(); i++) {
114
QTreeWidgetItem *item = treeWidget->invisibleRootItem()->child(i);
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();
120
m_topicWidget->addTopic(dTime, title, icon);
126
void TimelineTopicsDialog::upClicked()
129
QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
130
if (items.isEmpty() || items.size() > 1) {
133
TopicTreeItem *item = static_cast<TopicTreeItem*>(items[0]);
135
const int index = treeWidget->indexOfTopLevelItem(item)-1;
141
TopicTreeItem *copy = new TopicTreeItem(treeWidget, item, index);
142
connect(copy, SIGNAL(durationChanged()), this, SLOT(updateTotalDuration()));
144
treeWidget->invisibleRootItem()->removeChild(item);
145
treeWidget->setCurrentItem(copy);
150
void TimelineTopicsDialog::downClicked()
153
QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
154
if (items.isEmpty() || items.size() > 1) {
157
TopicTreeItem *item = static_cast<TopicTreeItem*>(items[0]);
159
const int index = treeWidget->indexOfTopLevelItem(item)+2;
161
if (index > treeWidget->topLevelItemCount()) {
165
TopicTreeItem *copy = new TopicTreeItem(treeWidget, item, index);
166
connect(copy, SIGNAL(durationChanged()), this, SLOT(updateTotalDuration()));
168
treeWidget->invisibleRootItem()->removeChild(item);
169
treeWidget->setCurrentItem(copy);
174
void TimelineTopicsDialog::itemSelectionChanged()
177
if(treeWidget->selectedItems().isEmpty() || treeWidget->selectedItems().size() > 1) {
178
upButton->setEnabled(false);
179
downButton->setEnabled(false);
180
removeButton->setEnabled(false);
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);
191
void TimelineTopicsDialog::updateTotalDuration()
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();
199
totalDurationEdit->setTime(Topic::secondsToTime(duration));
204
#include "timelinetopicsdialog.moc"