1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 #include "kworshipview.h"
23 #include "prefsDisplay.h"
24 #include "prefsSongDB.h"
25 #include "KwDatabaseSetup.h"
26 #include "KwDocument.h"
28 #include "KwPlaylistNode.h"
29 #include "KwPlaylistList.h"
30 #include "KwPlaylistNote.h"
31 #include "KwPlaylistText.h"
32 #include "KwPlaylistImage.h"
33 #include "KwPlaylistVideo.h"
34 #include "KwPlaylistModel.h"
36 #include "KwCssStyleSheet.h"
37 #include "KwCssStyleRule.h"
39 #include "KwDisplayManager.h"
40 #include "KwLocalDisplay.h"
41 #include "KwLocalDisplayPreview.h"
43 #include "KwMediaManager.h"
44 #include "KwMediaControlWidget.h"
47 #include "KwSongdbModel.h"
48 #include "KwSongdbFilterNode.h"
49 #include "KwSongdbTree.h"
50 #include "KwSongdbSong.h"
51 #include "KwSongdbSongEditDialog.h"
52 #include "KwSongdbSongBooksEditWidget.h"
54 #include "UpManager.h"
55 #include "UpPresentationsModel.h"
56 #include "UpPresentation.h"
57 #include "UpPresentationNode.h"
59 #include "UpKpr1Backend.h"
60 #include "UpKpr2Backend.h"
61 #include "UpOoBackend.h"
63 #include <kconfigdialog.h>
64 #include <kstatusbar.h>
66 #include <kactionmenu.h>
68 #include <ktoggleaction.h>
69 #include <kactioncollection.h>
70 #include <kstandardaction.h>
71 #include <KDE/KLocale>
72 #include <KFileDialog>
73 #include <KMessageBox>
75 #include <phonon/audiooutput.h>
77 #include <QtGui/QDropEvent>
78 #include <QtGui/QPainter>
80 #include <QDesktopWidget>
82 #include <QToolButton>
84 #include <QSqlDatabase>
85 #include <QHeaderView>
90 , m_view(new kworshipView(this))
93 , m_presentationManager(new UpManager(this))
94 , m_currentPresentation(0)
97 m_playlistModel
= new KwPlaylistModel
;
100 // set up presentation backends
101 m_presentationManager
->registerBackend
<UpOoBackend
>();
102 m_presentationManager
->registerBackend
<UpKpr2Backend
>();
103 m_presentationManager
->registerBackend
<UpKpr1Backend
>();
106 m_previewDisplay
= 0;
109 setAcceptDrops(true);
111 // tell the KXmlGuiWindow that this is indeed the main widget
112 setCentralWidget(m_view
);
114 // then, setup our actions
120 // a call to KXmlGuiWindow::setupGUI() populates the GUI
121 // with actions, using KXMLGUI.
122 // It also applies the saved mainwindow settings, if any, and ask the
123 // mainwindow to automatically save settings if changed: window size,
124 // toolbar position, icon size, etc.
128 addDockWidget(Qt::LeftDockWidgetArea
, m_view
->dockPresentation
);
129 tabifyDockWidget(m_view
->dockPresentation
, m_view
->dockSongs
);
130 addDockWidget(Qt::RightDockWidgetArea
, m_view
->dockPreview
);
131 addDockWidget(Qt::RightDockWidgetArea
, m_view
->dockLyrics
);
132 addDockWidget(Qt::BottomDockWidgetArea
, m_view
->dockThemes
);
133 addDockWidget(Qt::BottomDockWidgetArea
, m_view
->dockNowPlaying
);
135 // Setup some stuff in the tree
137 #define TREE_ITEM(name, string, parent) QTreeWidgetItem* name = new QTreeWidgetItem(parent); name->setText(0, tr(string));
139 TREE_ITEM(song1
, "Our God is a great big God", m_view
->treeWidget
);
140 TREE_ITEM(song1_style
, "(style)", song1
);
141 TREE_ITEM(song1_style_1
, "Mode", song1_style
);
142 TREE_ITEM(song1_v1
, "Our God is a great big God,\nOur God is a great big God,\nOur God is a great big God,\nAnd He holds us in his hands.", song1
);
143 TREE_ITEM(song1_v2
, "He's higher than a skyscraper\nAnd he's deeper than a submarine.", song1
);
144 TREE_ITEM(song1_v3
, "He's wider than the universe\nAnd beyond my wildest dreams.", song1
);
151 KwDatabaseSetup dbSetup
;
152 bool databaseOk
= dbSetup
.initialiseFromConfig();
155 new KwSongdb(dbSetup
.database());
159 m_document
->playlist()->addClass("beachy");
161 KwCssStyleSheet
* styleRules
= new KwCssStyleSheet
;
163 KwCssStyleRule beachyTheme
;
164 beachyTheme
.setCriteriaClasses(QSet
<QString
>() << "beachy");
165 beachyTheme
.setStyle
<QBrush
>("background.brush", Qt::black
);
166 beachyTheme
.setStyle
<QPixmap
>("background.image.pixmap", QPixmap("/home/james/media/images/projector/misc/love-god-light.jpg"));
167 styleRules
->addRule(beachyTheme
);
169 m_document
->playlist()->addStyleSheet(styleRules
);
171 m_view
->treePlaylist
->setModel(m_playlistModel
);
172 m_view
->treePlaylist
->setExpandsOnDoubleClick(false);
173 m_view
->treePlaylist
->setAcceptDrops(true);
175 connect(m_view
->treePlaylist
, SIGNAL(doubleClicked(QModelIndex
)), this, SLOT(playlist_doubleClicked(QModelIndex
)));
177 m_mediaManager
= new KwMediaManager();
178 m_mediaManager
->linkAudio(new Phonon::AudioOutput(Phonon::MusicCategory
));
179 m_displayManager
= new KwDisplayManager(&m_displayController
, m_mediaManager
);
181 m_previewDisplay
= new KwLocalDisplayPreview
;
182 m_view
->layoutPreview
->addWidget(m_previewDisplay
);
183 m_displayController
.attachChild(m_previewDisplay
);
185 KwMediaControlWidget
* mediaWidget
= new KwMediaControlWidget(m_mediaManager
, m_view
->dockNowPlaying
);
186 m_view
->layoutNowPlaying
->addWidget(mediaWidget
);
188 // Small toolbar for group by action
189 QToolBar
* songTextToolBar
= new QToolBar("Songs");
190 songTextToolBar
->setToolButtonStyle(Qt::ToolButtonTextBesideIcon
);
191 songTextToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
192 m_view
->layoutSongsToolbar
->layout()->addWidget(songTextToolBar
);
194 songTextToolBar
->addAction(m_groupSongsByAction
);
196 // Rest of the toolbar
197 QToolBar
* songToolBar
= new QToolBar("Songs");
198 songToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
199 m_view
->layoutSongsToolbar
->layout()->addWidget(songToolBar
);
201 songToolBar
->addAction(m_addSongAction
);
202 songToolBar
->addAction(m_editSongAction
);
203 songToolBar
->addAction(m_editSongBooksAction
);
204 KAction
* insertIntoPlaylistAction
= new KAction(KIcon("player_playlist"), i18n("Insert Into Playlist"), songToolBar
);
205 songToolBar
->addAction(insertIntoPlaylistAction
);
207 KMenu
* groupByMenu
= new KMenu(songToolBar
);
208 m_groupSongsByAction
->setMenu(groupByMenu
);
212 m_songDbTree
= new KwSongdbTree(m_view
);
213 m_view
->layoutSongsTree
->addWidget(m_songDbTree
);
214 groupByMenu
->addActions(m_songDbTree
->groupByActions()->actions());
222 // Drop down list of presentations
223 QComboBox
* selectPresCombo
= m_view
->comboPresentations
;
224 m_selectPresTree
= new QTreeView(this);
225 m_selectPresTree
->header()->hide();
226 selectPresCombo
->setModel(m_presentationManager
->presentationsModel());
227 selectPresCombo
->setView(m_selectPresTree
);
228 presentationComboReset();
229 connect(m_presentationManager
->presentationsModel(), SIGNAL(modelReset()), this, SLOT(presentationComboReset()));
230 connect(selectPresCombo
, SIGNAL(currentIndexChanged(int)), this, SLOT(presentationSelected(int)));
232 // Custom slideshow selector
233 m_view
->slideshows
->setVisible(false);
234 connect(m_view
->comboSlideshows
, SIGNAL(currentIndexChanged(const QString
&)), this, SLOT(changeSlideshowCombo(QString
)));
236 QToolBar
* customSlideshowsToolBar
= new QToolBar(i18n("Custom Slideshows"));
237 customSlideshowsToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Fixed
, QSizePolicy::Fixed
));
238 m_view
->slideshows
->layout()->addWidget(customSlideshowsToolBar
);
239 // Add slideshow to playlist
240 KActionMenu
* addSlideshowToPlaylistAction
= new KActionMenu(KIcon("list-add"), i18n("Add Slideshow to Playlist"), customSlideshowsToolBar
);
241 addSlideshowToPlaylistAction
->setDelayed(false);
242 customSlideshowsToolBar
->addAction(addSlideshowToPlaylistAction
);
244 KAction
* asLinkAction
= new KAction(KIcon("insert-link"), i18n("Add Link to Slideshow into Playlist"), customSlideshowsToolBar
);
245 connect(asLinkAction
, SIGNAL(triggered(bool)), this, SLOT(addSlideshowLinkToPlaylist()));
246 addSlideshowToPlaylistAction
->addAction(asLinkAction
);
249 KAction
* asCopyAction
= new KAction(KIcon("edit-copy"), i18n("Save Copy of Slideshow into Playlist"), customSlideshowsToolBar
);
250 connect(asCopyAction
, SIGNAL(triggered(bool)), this, SLOT(addSlideshowCopyToPlaylist()));
251 addSlideshowToPlaylistAction
->addAction(asCopyAction
);
254 // Presentations toolbar
255 QToolBar
* presToolBar
= new QToolBar("Presentations");
256 m_view
->layoutPresentationsToolbar
->layout()->addWidget(presToolBar
);
258 KActionMenu
* openPresAction
= new KActionMenu(KIcon("document-open"), "Open Presentation", presToolBar
);
259 openPresAction
->setDelayed(true);
260 presToolBar
->addAction(openPresAction
);
262 KAction
* refreshPresAction
= new KAction(KIcon("view-refresh"), "Refresh Presentation List", presToolBar
);
263 presToolBar
->addAction(refreshPresAction
);
265 KAction
* closePresAction
= new KAction(KIcon("fileclose"), "Close Presentation", presToolBar
);
266 presToolBar
->addAction(closePresAction
);
268 KToggleAction
* fullscreenPresAction
= new KToggleAction(KIcon("view-fullscreen"), "Fullscreen Presentation Mode", presToolBar
);
269 presToolBar
->addAction(fullscreenPresAction
);
272 connect(m_view
->listSlides
, SIGNAL(doubleClicked(QModelIndex
)), this, SLOT(slide_doubleClicked(QModelIndex
)));
275 QToolBar
* slidesToolBar
= new QToolBar("Slides");
276 slidesToolBar
->setSizePolicy(QSizePolicy(QSizePolicy::Minimum
, QSizePolicy::Minimum
));
277 slidesToolBar
->setIconSize(QSize(32,32));
278 m_view
->layoutSlidesToolbar
->layout()->addWidget(slidesToolBar
);
280 m_slideshowPrevSlideAction
= new KAction(KIcon("media-skip-backward"), i18n("Previous Slide"), slidesToolBar
);
281 connect(m_slideshowPrevSlideAction
, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousSlide()));
282 slidesToolBar
->addAction(m_slideshowPrevSlideAction
);
284 m_slideshowPrevStepAction
= new KAction(KIcon("media-seek-backward"), i18n("Previous Step"), slidesToolBar
);
285 connect(m_slideshowPrevStepAction
, SIGNAL(triggered(bool)), this, SLOT(presentationPreviousStep()));
286 slidesToolBar
->addAction(m_slideshowPrevStepAction
);
288 m_slideshowNextStepAction
= new KAction(KIcon("media-seek-forward"), i18n("Next Step"), slidesToolBar
);
289 connect(m_slideshowNextStepAction
, SIGNAL(triggered(bool)), this, SLOT(presentationNextStep()));
290 slidesToolBar
->addAction(m_slideshowNextStepAction
);
292 m_slideshowNextSlideAction
= new KAction(KIcon("media-skip-forward"), i18n("Next Slide"), slidesToolBar
);
293 connect(m_slideshowNextSlideAction
, SIGNAL(triggered(bool)), this, SLOT(presentationNextSlide()));
294 slidesToolBar
->addAction(m_slideshowNextSlideAction
);
296 m_slideshowAction
= new KToggleAction(KIcon("view-presentation"), i18n("Start/Stop Slideshow"), slidesToolBar
);
297 connect(m_slideshowAction
, SIGNAL(toggled(bool)), this, SLOT(presentationToggled(bool)));
298 slidesToolBar
->addAction(m_slideshowAction
);
301 m_slideNotes
= new QTextEdit();
302 m_slideNotes
->setReadOnly(true);
303 m_slideNotes
->setWindowTitle(i18n("Slide Notes"));
304 m_slideNotes
->show();
306 // Ensure the controls are as when slideshow is stopped
307 m_slideshowAction
->setEnabled(false);
314 // Show the display on startup?
315 if (Settings::displayShowStartup())
317 // If there's only one screen, don't bother showing display.
318 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
319 assert(0 != desktop
);
320 if (desktop
->numScreens() > 1)
322 toggleMainDisplay(true);
323 m_mainDisplayAction
->setChecked(true);
328 kworship::~kworship()
330 delete KwSongdb::self();
338 /// Load a specified playlist.
339 void kworship::loadPlaylist(const KUrl
& url
)
342 m_document
->reload();
349 /// Get the main display manager.
350 KwDisplayManager
* kworship::displayManager()
352 return m_displayManager
;
355 /// Get the current document.
356 KwDocument
* kworship::document()
361 /// Get the playlist model.
362 KwPlaylistModel
* kworship::playlistModel()
364 return m_playlistModel
;
367 void kworship::setupActions()
370 KStandardAction::quit(qApp
, SLOT(quit()), actionCollection());
371 KStandardAction::preferences(this, SLOT(optionsPreferences()), actionCollection());
374 KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
375 KStandardAction::open(this, SLOT(fileOpen()), actionCollection());
376 KStandardAction::save(this, SLOT(fileSave()), actionCollection());
377 KStandardAction::saveAs(this, SLOT(fileSaveAs()), actionCollection());
380 KStandardAction::fullScreen(this, SLOT(toggleFullscreen(bool)), this, actionCollection());
382 m_mainDisplayAction
= new KToggleAction(KIcon("video-projector"), i18n("Show Main Display"), this);
383 actionCollection()->addAction( QLatin1String("show_main_display"), m_mainDisplayAction
);
384 connect(m_mainDisplayAction
, SIGNAL(triggered(bool)), this, SLOT(toggleMainDisplay(bool)));
386 KAction
* clearDisplayAction
= new KAction(KIcon("clear"), i18n("Clear display"), this);
387 actionCollection()->addAction( QLatin1String("display_clear"), clearDisplayAction
);
388 connect(clearDisplayAction
, SIGNAL(triggered()), this, SLOT(displayClear()));
391 m_unlockSongDbAction
= new KAction(KIcon("document-decrypt"), i18n("Unlock Song Database"), this);
392 actionCollection()->addAction( QLatin1String("unlock_song_database"), m_unlockSongDbAction
);
393 connect(m_unlockSongDbAction
, SIGNAL(triggered(bool)), this, SLOT(songdbUnlock()));
395 m_lockSongDbAction
= new KAction(KIcon("document-encrypt"), i18n("Lock Song Database"), this);
396 m_lockSongDbAction
->setVisible(false);
397 actionCollection()->addAction( QLatin1String("lock_song_database"), m_lockSongDbAction
);
398 connect(m_lockSongDbAction
, SIGNAL(triggered(bool)), this, SLOT(songdbLock()));
400 m_groupSongsByAction
= new KActionMenu(KIcon("view-filter"), i18n("Group By"), this);
401 m_groupSongsByAction
->setDelayed(false);
402 actionCollection()->addAction( QLatin1String("group_songs_by"), m_groupSongsByAction
);
404 m_addSongAction
= new KAction(KIcon("list-add"), i18n("Add Song"), this);
405 actionCollection()->addAction( QLatin1String("add_song"), m_addSongAction
);
406 connect(m_addSongAction
, SIGNAL(triggered(bool)), this, SLOT(songdbAdd()));
408 m_editSongAction
= new KAction(KIcon("view-media-lyrics"), i18n("Edit Song"), this);
409 actionCollection()->addAction( QLatin1String("edit_song"), m_editSongAction
);
410 connect(m_editSongAction
, SIGNAL(triggered(bool)), this, SLOT(songdbEdit()));
412 m_editSongBooksAction
= new KAction(KIcon("format-list-ordered"), i18n("Edit Song Books"), this);
413 actionCollection()->addAction( QLatin1String("edit_song_books"), m_editSongBooksAction
);
414 connect(m_editSongBooksAction
, SIGNAL(triggered(bool)), this, SLOT(songdbEditSongBooks()));
417 void kworship::settingsChanged()
419 // If the main display is on and screen has changed, move it now
420 if (0 != m_mainDisplay
&& getCorrectDisplayScreen() != getCurrentDisplayScreen())
422 toggleMainDisplay(false);
423 toggleMainDisplay(true);
424 m_mainDisplayAction
->setChecked(true);
428 int kworship::getCorrectDisplayScreen()
430 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
431 assert(0 != desktop
);
433 int screens
= desktop
->numScreens();
434 int displayScreen
= -1;
435 if (Settings::displayScreenChoose())
437 displayScreen
= Settings::displayScreen();
439 if (-1 == displayScreen
)
442 if (m_view
->isVisible())
444 currentScreen
= desktop
->screenNumber(m_view
);
448 currentScreen
= desktop
->primaryScreen();
451 if (displayScreen
== currentScreen
&& displayScreen
< screens
-1)
457 return displayScreen
;
460 int kworship::getCurrentDisplayScreen()
462 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
463 assert(0 != desktop
);
465 int previousScreen
= desktop
->screenNumber(m_mainDisplay
);
467 return previousScreen
;
470 void kworship::toggleMainDisplay(bool checked
)
474 // Ensure the display exists
475 if (0 == m_mainDisplay
)
477 m_mainDisplay
= new KwLocalDisplay
;
478 m_mainDisplay
->setPrimary(true);
479 m_mainDisplay
->setWindowTitle("kworship display");
480 m_displayController
.attachChild(m_mainDisplay
);
481 connect(m_mainDisplay
, SIGNAL(closed()), this, SLOT(mainDisplayClosed()));
484 QDesktopWidget
* desktop
= qobject_cast
<QApplication
*>(QCoreApplication::instance())->desktop();
485 assert(0 != desktop
);
487 int screens
= desktop
->numScreens();
488 int displayScreen
= getCorrectDisplayScreen();
490 if (displayScreen
>= 0 && displayScreen
< screens
)
492 m_mainDisplay
->move(desktop
->screenGeometry(displayScreen
).topLeft());
495 if (!m_slideshowAction
->isChecked())
497 m_mainDisplay
->showFullScreen();
502 if (0 != m_mainDisplay
)
504 m_mainDisplay
->close();
509 void kworship::mainDisplayClosed()
511 m_mainDisplay
->deleteLater();
513 m_mainDisplayAction
->setChecked(false);
516 void kworship::displayClear()
518 m_displayManager
->background
.clear();
519 m_displayManager
->text
.clear();
522 void kworship::toggleFullscreen(bool checked
)
534 bool kworship::askToSave()
536 if (m_document
->isModified())
538 switch (KMessageBox::questionYesNoCancel(this,
539 i18n("The current playlist has been modified. "
540 "These modifications will be lost if you continue without saving. "
541 "Would you like to save now?"),
542 i18n("Playlist is modified")))
544 case KMessageBox::Yes
:
547 // If the document is still modified, save must have been cancelled
548 if (m_document
->isModified())
554 case KMessageBox::No
:
556 case KMessageBox::Cancel
:
567 void kworship::fileNew()
575 void kworship::fileOpen()
579 // Do the open operation
580 QString filter
= "*.kwz *.kw|" + i18n("All KWorship playlists");
581 KUrl
defaultUrl("kfiledialog:///playlist");
582 if (m_document
->isSaved())
584 defaultUrl
= m_document
->url();
586 KUrl url
= KFileDialog::getOpenUrl(defaultUrl
, filter
, this);
594 void kworship::fileSave()
596 if (m_document
->isSaved())
606 void kworship::fileSaveAs()
608 QString filter
= "*.kwz|" + i18n("KWorship playlists") + "\n"
609 "*.kw|" + i18n("KWorship uncompressed playlists");
610 KUrl
defaultUrl("kfiledialog:///playlist");
611 if (m_document
->isSaved())
613 defaultUrl
= m_document
->url();
615 KUrl url
= KFileDialog::getSaveUrl(defaultUrl
, filter
, this);
618 m_document
->saveAs(url
);
622 void kworship::optionsPreferences()
624 //avoid to have 2 dialogs shown
625 if ( KConfigDialog::showDialog( "settings" ) ) {
628 KConfigDialog
*dialog
= new KConfigDialog(this, "settings", Settings::self());
630 QWidget
*generalSettingsDlg
= new QWidget(dialog
);
631 ui_prefs_base
.setupUi(generalSettingsDlg
);
632 dialog
->addPage(generalSettingsDlg
, i18n("General"), "preferences-other", i18n("General"));
634 prefsDisplay
*displaySettingsDlg
= new prefsDisplay(dialog
);
635 dialog
->addPage(displaySettingsDlg
, i18n("Display"), "video-projector", i18n("Display and Screen"));
637 prefsSongDB
*songdbSettingsDlg
= new prefsSongDB(dialog
);
638 dialog
->addPage(songdbSettingsDlg
, i18n("Song DB"), "applications-multimedia", i18n("Song Database"));
640 QWidget
*presentationSettingsDlg
= new QWidget(dialog
);
641 ui_prefsPresentations_base
.setupUi(presentationSettingsDlg
);
642 dialog
->addPage(presentationSettingsDlg
, i18n("Presentations"), "view-presentation", i18n("Presentations and Slideshows"));
644 connect(dialog
, SIGNAL(settingsChanged(QString
)), m_view
, SLOT(settingsChanged()));
645 connect(dialog
, SIGNAL(settingsChanged(QString
)), this, SLOT(settingsChanged()));
646 dialog
->setAttribute( Qt::WA_DeleteOnClose
);
650 void kworship::playlist_doubleClicked(QModelIndex index
)
652 KwPlaylistNode
* node
= m_playlistModel
->itemFromIndex(index
);
653 node
->activate(m_displayManager
);
656 void kworship::playlistReset()
658 // Connect up the new document
659 m_playlistModel
->setRootNode(m_document
->playlist()->getNode(0));
663 /// Add the new docker to the interface.
664 void kworship::newDocker(QDockWidget
* docker
)
666 std::cout
<< docker
<< std::endl
;
667 addDockWidget(Qt::LeftDockWidgetArea
, docker
);
670 void kworship::presentationDelete()
672 setPresentation(0, true);
673 presentationSelected(0);
676 void kworship::presentationSelected(int)
678 // Find the treeviews current index
679 QModelIndex index
= m_selectPresTree
->currentIndex();
680 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
681 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
684 m_view
->listSlides
->setModel(model
);
685 m_view
->listSlides
->setRootIndex(index
);
686 setPresentation(presNode
->getItem());
690 m_view
->listSlides
->setModel(0);
695 void kworship::presentationToggled(bool checked
)
697 // Find the treeviews current index
698 QModelIndex index
= m_selectPresTree
->currentIndex();
699 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
700 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
705 presNode
->getItem()->startSlideshow();
709 presNode
->getItem()->stopSlideshow();
714 void kworship::presentationPreviousSlide()
716 // Find the treeviews current index
717 QModelIndex index
= m_selectPresTree
->currentIndex();
718 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
719 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
722 presNode
->getItem()->previousSlide();
726 void kworship::presentationNextSlide()
728 // Find the treeviews current index
729 QModelIndex index
= m_selectPresTree
->currentIndex();
730 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
731 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
734 presNode
->getItem()->nextSlide();
738 void kworship::presentationPreviousStep()
740 // Find the treeviews current index
741 QModelIndex index
= m_selectPresTree
->currentIndex();
742 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
743 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
746 presNode
->getItem()->previousStep();
750 void kworship::presentationNextStep()
752 // Find the treeviews current index
753 QModelIndex index
= m_selectPresTree
->currentIndex();
754 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
755 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(index
));
758 presNode
->getItem()->nextStep();
762 void kworship::slide_doubleClicked(QModelIndex index
)
764 // Find the listviews current index
765 UpPresentationsModel
* model
= m_presentationManager
->presentationsModel();
766 QModelIndex parentIndex
= model
->parent(index
);
767 UpPresentationNode
* presNode
= dynamic_cast<UpPresentationNode
*>(model
->itemFromIndex(parentIndex
));
770 presNode
->getItem()->goToSlide(index
.row());
775 void kworship::setDocument(KUrl url
)
778 m_document
= new KwDocument(url
, this);
780 // Playlist will have changed
784 connect(m_document
, SIGNAL(playlistReset()), this, SLOT(playlistReset()));
788 void kworship::setPresentation(UpPresentation
* presentation
, bool alreadyDestroyed
)
790 if (0 != m_currentPresentation
)
792 // Stop the slideshow if its running
793 m_view
->slideshows
->setVisible(false);
794 if (!alreadyDestroyed
)
796 m_currentPresentation
->stopSlideshow();
797 disconnect(m_currentPresentation
, SIGNAL(currentSlideshowChanged(QString
)), this, SLOT(changeSlideshowExternal(QString
)));
798 disconnect(m_currentPresentation
, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
799 disconnect(m_currentPresentation
, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
800 disconnect(m_currentPresentation
, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
801 disconnect(m_currentPresentation
, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
802 disconnect(m_currentPresentation
, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
803 disconnect(m_currentPresentation
, SIGNAL(destroyed(QObject
*)), this, SLOT(presentationDelete()));
807 m_currentPresentation
= presentation
;
808 if (0 != m_currentPresentation
)
810 connect(m_currentPresentation
, SIGNAL(currentSlideshowChanged(QString
)), this, SLOT(changeSlideshowExternal(QString
)));
811 connect(m_currentPresentation
, SIGNAL(customSlideshowsModified()), this, SLOT(refreshSlideshows()));
812 connect(m_currentPresentation
, SIGNAL(slideshowStarted(int)), this, SLOT(slideshowStarted(int)));
813 connect(m_currentPresentation
, SIGNAL(slideshowStopped()), this, SLOT(slideshowStopped()));
814 connect(m_currentPresentation
, SIGNAL(slideshowSlideChanged(int, int)), this, SLOT(slideshowSlideChanged(int, int)));
815 connect(m_currentPresentation
, SIGNAL(slideshowStepChanged(int)), this, SLOT(slideshowStepChanged(int)));
816 connect(m_currentPresentation
, SIGNAL(destroyed(QObject
*)), this, SLOT(presentationDelete()));
817 // update slideshows list
819 m_view
->slideshows
->setVisible(true);
821 if (m_currentPresentation
->isSlideshowRunning())
823 slideshowStarted(m_currentPresentation
->numSlidesInSlideshow());
824 slideshowSlideChanged(m_currentPresentation
->currentSlideshowSlide(), m_currentPresentation
->stepsInCurrentSlideshowSlide());
825 slideshowStepChanged(m_currentPresentation
->currentSlideshowStep());
828 m_slideshowAction
->setEnabled(0 != m_currentPresentation
);
833 void kworship::presentationComboReset()
835 m_selectPresTree
->expandToDepth(0);
836 m_selectPresTree
->setItemsExpandable(false);
839 void kworship::changeSlideshowCombo(QString name
)
841 Q_ASSERT(0 != m_currentPresentation
);
842 m_currentPresentation
->setSlideshow(name
);
846 void kworship::changeSlideshowExternal(QString name
)
848 if (m_view
->comboSlideshows
->currentText() != name
)
850 m_view
->comboSlideshows
->setCurrentIndex(m_view
->comboSlideshows
->findText(name
));
855 void kworship::refreshSlideshows()
857 Q_ASSERT(0 != m_currentPresentation
);
858 m_view
->comboSlideshows
->clear();
859 m_view
->comboSlideshows
->insertItems(0, m_currentPresentation
->slideshows());
860 m_view
->comboSlideshows
->setCurrentIndex(m_view
->comboSlideshows
->findText(m_currentPresentation
->currentSlideshow()));
863 void kworship::refreshSlides()
866 QModelIndex root
= m_view
->listSlides
->rootIndex();
867 DefaultModelNode
* node
= m_presentationManager
->presentationsModel()->itemFromIndex(root
);
869 node
->clearChildCache();
872 m_view
->listSlides
->setRootIndex(root
);
875 void kworship::addSlideshowLinkToPlaylist()
877 Q_ASSERT(0 != m_currentPresentation
);
878 QUrl url
= m_currentPresentation
->url();
879 QString slideshow
= m_currentPresentation
->currentSlideshow();
880 /// @todo Implement me
882 void kworship::addSlideshowCopyToPlaylist()
884 Q_ASSERT(0 != m_currentPresentation
);
885 QString slideshow
= m_currentPresentation
->currentSlideshow();
886 /// @todo Implement me
889 // From current presentation
891 void kworship::slideshowStarted(int numSlides
)
894 if (0 != m_mainDisplay
)
896 m_mainDisplay
->hide();
900 m_displayManager
->background
.clear();
901 m_displayManager
->text
.clear();
903 m_view
->slideshows
->setEnabled(false);
904 m_view
->progressPresSlides
->setMaximum(numSlides
);
905 m_view
->progressPresSlides
->setVisible(true);
906 m_slideshowAction
->setChecked(true);
909 void kworship::slideshowStopped()
911 m_view
->slideshows
->setEnabled(true);
912 m_view
->progressPresSlides
->setVisible(false);
913 m_view
->progressPresSteps
->setVisible(false);
914 m_slideshowAction
->setChecked(false);
915 m_slideshowPrevSlideAction
->setEnabled(false);
916 m_slideshowPrevStepAction
->setEnabled(false);
917 m_slideshowNextStepAction
->setEnabled(false);
918 m_slideshowNextSlideAction
->setEnabled(false);
920 // Clear any preview left from the slideshow
921 m_displayManager
->background
.clear();
923 m_slideNotes
->document()->clear();
925 // Show the screen again
926 if (0 != m_mainDisplay
)
928 m_mainDisplay
->showFullScreen();
932 void kworship::slideshowSlideChanged(int slide
, int numSteps
)
934 m_view
->progressPresSlides
->setValue(slide
+ 1);
935 m_view
->progressPresSteps
->setMaximum(numSteps
);
936 m_view
->progressPresSteps
->setVisible(numSteps
> 1);
938 m_slideshowPrevSlideAction
->setEnabled(slide
> 0);
939 m_slideshowNextSlideAction
->setEnabled(slide
< m_view
->progressPresSlides
->maximum()-1);
941 // live preview and notes
942 m_slideNotes
->document()->clear();
943 assert(0 != m_currentPresentation
);
944 UpSlide
* currentSlide
= m_currentPresentation
->slide(slide
);
945 if (0 != currentSlide
)
948 if (Settings::presLivePreview())
950 m_displayManager
->background
.setImage(currentSlide
->preview());
953 currentSlide
->writeNotes(m_slideNotes
->document());
957 void kworship::slideshowStepChanged(int step
)
959 m_view
->progressPresSteps
->setValue(step
+ 1);
961 bool firstSlide
= (m_view
->progressPresSlides
->value() <= 1);
962 bool lastSlide
= (m_view
->progressPresSlides
->value() >= m_view
->progressPresSlides
->maximum());
963 bool firstStep
= firstSlide
&& (step
<= 0);
964 bool lastStep
= lastSlide
&& (step
>= m_view
->progressPresSteps
->maximum() - 1);
965 m_slideshowPrevStepAction
->setEnabled(!firstStep
);
966 m_slideshowNextStepAction
->setEnabled(!lastStep
);
971 void kworship::songdbUnlock()
973 m_unlockSongDbAction
->setVisible(false);
974 m_lockSongDbAction
->setVisible(true);
977 void kworship::songdbLock()
979 m_unlockSongDbAction
->setVisible(true);
980 m_lockSongDbAction
->setVisible(false);
983 void kworship::songdbAdd()
985 KwSongdbSongEditDialog
* dialog
= new KwSongdbSongEditDialog(0);
986 dialog
->setCaption(i18n("Add Song"));
987 dialog
->setAttribute(Qt::WA_DeleteOnClose
, true);
991 void kworship::songdbEdit()
993 /// @todo Ensure the same song isn't open twice
994 KwSongdbSong
* song
= m_songDbTree
->currentSong();
997 KwSongdbVersion
* version
= m_songDbTree
->currentSongVersion();
999 KwSongdbSongEditDialog
* dialog
= new KwSongdbSongEditDialog(song
, version
);
1000 dialog
->setCaption(i18n("Edit Song - %1", song
->name()));
1001 dialog
->setAttribute(Qt::WA_DeleteOnClose
, true);
1006 KMessageBox::information(this, i18n("Please select a song."));
1010 void kworship::songdbEditSongBooks()
1012 KwSongdbSongBooksEditWidget::showDialog();
1015 #include "kworship.moc"