3 Copyright (c) 2012 Jakob Leben & Tim Blechmann
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "doc_list.hpp"
22 #include "../core/doc_manager.hpp"
24 #include <QApplication>
29 DocumentListWidget::DocumentListWidget(DocumentManager
*manager
, QWidget
* parent
):
31 mDocModifiedIcon( QApplication::style()->standardIcon(QStyle::SP_DialogSaveButton
) )
33 connect(manager
, SIGNAL(opened(Document
*, int, int)), this, SLOT(onOpen(Document
*, int, int)));
34 connect(manager
, SIGNAL(closed(Document
*)), this, SLOT(onClose(Document
*)));
35 connect(manager
, SIGNAL(saved(Document
*)), this, SLOT(onSaved(Document
*)));
36 connect(&mModificationMapper
, SIGNAL(mapped(QObject
*)),
37 this, SLOT(onModificationChanged(QObject
*)));
38 connect(this, SIGNAL(itemClicked(QListWidgetItem
*)),
39 this, SLOT(onItemClicked(QListWidgetItem
*)));
42 void DocumentListWidget::setCurrent( Document
*doc
)
47 Item
*itm
= itemFor(doc
);
53 void DocumentListWidget::onOpen( Document
*doc
, int, int )
58 void DocumentListWidget::onClose( Document
*doc
)
63 void DocumentListWidget::onSaved( Document
*doc
)
65 Item
*item
= itemFor(doc
);
67 item
->setText(doc
->title());
70 void DocumentListWidget::onModificationChanged( QObject
* obj
)
72 Document
*doc
= qobject_cast
<Document
*>(obj
);
73 Item
*item
= itemFor(doc
);
76 doc
->textDocument()->isModified() ?
77 mDocModifiedIcon
: QIcon()
81 void DocumentListWidget::onItemClicked(QListWidgetItem
* litem
)
83 Item
*item
= itemFor(litem
);
85 Q_EMIT( clicked(item
->mDoc
) );
88 DocumentListWidget::Item
* DocumentListWidget::addItemFor( Document
*doc
)
90 Item
*item
= new Item(doc
, this);
92 QTextDocument
*tdoc
= doc
->textDocument();
94 if(tdoc
->isModified())
95 item
->setIcon( mDocModifiedIcon
);
97 mModificationMapper
.setMapping(tdoc
, doc
);
98 connect(tdoc
, SIGNAL(modificationChanged(bool)),
99 &mModificationMapper
, SLOT(map()));
104 DocumentListWidget::Item
*DocumentListWidget::itemFor( Document
*doc
)
107 for(int i
= 0; i
< c
; ++i
)
109 Item
*itm
= itemFor( item(i
) );
110 if(itm
&& itm
->mDoc
== doc
) return itm
;
115 DocumentListWidget::Item
*DocumentListWidget::itemFor( QListWidgetItem
*litem
)
117 if(litem
->type() == QListWidgetItem::UserType
)
118 return static_cast<Item
*>(litem
);