/src/gui/WelcomeScreen.cpp

https://github.com/fronin/lmms · C++ · 187 lines · 102 code · 55 blank · 30 comment · 2 complexity · 5ddef24405c8185e896ab3f8a5161410 MD5 · raw file

  1. /*
  2. * WelcomeScreen.cpp - implementation of WelcomeScreen
  3. *
  4. * Copyright (c) 2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #include <QtGui/QDesktopServices>
  25. #include "WelcomeScreen.h"
  26. #include "RecentResourceListModel.h"
  27. #include "MainWindow.h"
  28. #include "ResourceAction.h"
  29. #include "engine.h"
  30. #include "embed.h"
  31. #include "ui_WelcomeScreen.h"
  32. WelcomeScreen::WelcomeScreen( QWidget * _parent ) :
  33. QWidget( _parent ),
  34. ui( new Ui::WelcomeScreen )
  35. {
  36. ui->setupUi( this );
  37. // polish UI
  38. foreach( QPushButton * btn,
  39. ui->WelcomeFrame->findChildren<QPushButton *>() )
  40. {
  41. btn->setText( " " + btn->text() + " " );
  42. }
  43. ui->iconLabel->setPixmap( embed::getIconPixmap( "icon" ) );
  44. ui->newProjectButton->setIcon(
  45. embed::getIconPixmap( "project_new_from_template" ) );
  46. ui->importProjectButton->setIcon(
  47. embed::getIconPixmap( "project_import" ) );
  48. ui->openTutorialButton->setIcon(
  49. embed::getIconPixmap( "help" ) );
  50. ui->instantMidiActionButton->setIcon(
  51. embed::getIconPixmap( "instrument_track" ) );
  52. // connect signals of buttons
  53. connect( ui->newProjectButton, SIGNAL( clicked() ),
  54. this, SLOT( createNewProject() ) );
  55. connect( ui->importProjectButton, SIGNAL( clicked() ),
  56. this, SLOT( importProject() ) );
  57. connect( ui->openTutorialButton, SIGNAL( clicked() ),
  58. this, SLOT( openTutorial() ) );
  59. connect( ui->instantMidiActionButton, SIGNAL( clicked() ),
  60. this, SLOT( instantMidiAction() ) );
  61. // setup recent projects list view
  62. m_recentProjectsModel =
  63. new RecentResourceListModel( engine::workingDirResourceDB(), -1, this );
  64. m_recentProjectsModel->resourceListModel()->
  65. setTypeFilter( ResourceItem::TypeProject );
  66. ui->recentProjectsListView->setModel( m_recentProjectsModel );
  67. connect( ui->recentProjectsListView,
  68. SIGNAL( clicked( const QModelIndex & ) ),
  69. this, SLOT( openRecentProject( const QModelIndex & ) ) );
  70. // setup recent community resources list view
  71. m_communityResourcesModel =
  72. new RecentResourceListModel( engine::webResourceDB(), 100, this );
  73. ui->communityResourcesListView->setModel( m_communityResourcesModel );
  74. connect( ui->communityResourcesListView,
  75. SIGNAL( clicked( const QModelIndex & ) ),
  76. this, SLOT( openCommunityResource( const QModelIndex & ) ) );
  77. // setup online resources list widget
  78. for( int i = 0; i < ui->onlineResourcesListWidget->count(); ++i )
  79. {
  80. ui->onlineResourcesListWidget->item( i )->setIcon(
  81. embed::getIconPixmap( "ListArrow" ) );
  82. }
  83. connect( ui->onlineResourcesListWidget,
  84. SIGNAL( itemClicked( QListWidgetItem * ) ),
  85. this, SLOT( openOnlineResource( QListWidgetItem * ) ) );
  86. }
  87. WelcomeScreen::~WelcomeScreen()
  88. {
  89. }
  90. void WelcomeScreen::createNewProject()
  91. {
  92. hideWelcomeScreen();
  93. }
  94. void WelcomeScreen::importProject()
  95. {
  96. }
  97. void WelcomeScreen::openTutorial()
  98. {
  99. }
  100. void WelcomeScreen::instantMidiAction()
  101. {
  102. }
  103. void WelcomeScreen::openRecentProject( const QModelIndex & _idx )
  104. {
  105. hideWelcomeScreen();
  106. ResourceAction( m_recentProjectsModel->item( _idx ) ).loadProject();
  107. }
  108. void WelcomeScreen::openCommunityResource( const QModelIndex & _idx )
  109. {
  110. ResourceItem * item = m_communityResourcesModel->item( _idx );
  111. ResourceAction action( item );
  112. switch( item->type() )
  113. {
  114. case ResourceItem::TypeProject:
  115. hideWelcomeScreen();
  116. action.loadProject();
  117. break;
  118. default:
  119. break;
  120. }
  121. }
  122. void WelcomeScreen::openOnlineResource( QListWidgetItem * _item )
  123. {
  124. // the URL to be opened is encoded in status tip (no other
  125. // possibility to store such information in Qt Designer)
  126. QDesktopServices::openUrl( _item->statusTip() );
  127. }
  128. void WelcomeScreen::hideWelcomeScreen()
  129. {
  130. engine::mainWindow()->showWelcomeScreen( false );
  131. }
  132. #include "moc_WelcomeScreen.cxx"