2010-05-20 16:12:15 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-05-20 16:12:15 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-07-17 14:47:59 +02:00
|
|
|
#include "playlist.h"
|
|
|
|
#include "playlistmanager.h"
|
2010-05-20 16:12:15 +02:00
|
|
|
#include "playlisttabbar.h"
|
2011-04-02 16:46:56 +02:00
|
|
|
#include "playlistview.h"
|
2010-07-17 14:47:59 +02:00
|
|
|
#include "songmimedata.h"
|
2011-04-22 19:07:57 +02:00
|
|
|
#include "core/logging.h"
|
2014-12-18 23:35:21 +01:00
|
|
|
#include "internet/core/internetmimedata.h"
|
2010-05-20 16:12:15 +02:00
|
|
|
#include "ui/iconloader.h"
|
2011-04-02 16:46:56 +02:00
|
|
|
#include "widgets/renametablineedit.h"
|
2013-05-11 23:17:54 +02:00
|
|
|
#include "widgets/favoritewidget.h"
|
2010-05-20 16:12:15 +02:00
|
|
|
|
2013-08-10 20:18:29 +02:00
|
|
|
#include <QCheckBox>
|
2010-05-20 16:12:15 +02:00
|
|
|
#include <QContextMenuEvent>
|
2013-08-11 16:36:07 +02:00
|
|
|
#include <QDialogButtonBox>
|
|
|
|
#include <QGridLayout>
|
2013-05-11 23:17:54 +02:00
|
|
|
#include <QInputDialog>
|
2010-05-20 16:12:15 +02:00
|
|
|
#include <QMenu>
|
2011-06-19 10:44:10 +02:00
|
|
|
#include <QMessageBox>
|
2013-05-11 23:17:54 +02:00
|
|
|
#include <QPushButton>
|
2011-04-13 21:15:30 +02:00
|
|
|
#include <QToolTip>
|
2010-05-20 16:12:15 +02:00
|
|
|
|
2013-07-27 19:59:15 +02:00
|
|
|
const char* PlaylistTabBar::kSettingsGroup = "PlaylistTabBar";
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
PlaylistTabBar::PlaylistTabBar(QWidget* parent)
|
|
|
|
: QTabBar(parent),
|
|
|
|
manager_(nullptr),
|
|
|
|
menu_(new QMenu(this)),
|
|
|
|
menu_index_(-1),
|
|
|
|
suppress_current_changed_(false),
|
2014-12-07 05:36:27 +01:00
|
|
|
initialized_(false),
|
2014-02-07 16:34:20 +01:00
|
|
|
rename_editor_(new RenameTabLineEdit(this)) {
|
2010-07-17 14:47:59 +02:00
|
|
|
setAcceptDrops(true);
|
2011-04-02 16:46:56 +02:00
|
|
|
setElideMode(Qt::ElideRight);
|
2011-04-15 23:54:19 +02:00
|
|
|
setUsesScrollButtons(true);
|
2011-06-19 10:44:10 +02:00
|
|
|
setTabsClosable(true);
|
2010-07-17 14:47:59 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
close_ = menu_->addAction(IconLoader::Load("list-remove"),
|
|
|
|
tr("Close playlist"), this, SLOT(Close()));
|
|
|
|
rename_ = menu_->addAction(IconLoader::Load("edit-rename"),
|
|
|
|
tr("Rename playlist..."), this, SLOT(Rename()));
|
|
|
|
save_ = menu_->addAction(IconLoader::Load("document-save"),
|
|
|
|
tr("Save playlist..."), this, SLOT(Save()));
|
2010-05-20 16:12:15 +02:00
|
|
|
menu_->addSeparator();
|
2010-05-21 12:29:17 +02:00
|
|
|
|
2011-04-02 16:46:56 +02:00
|
|
|
rename_editor_->setVisible(false);
|
|
|
|
connect(rename_editor_, SIGNAL(editingFinished()), SLOT(RenameInline()));
|
|
|
|
connect(rename_editor_, SIGNAL(EditingCanceled()), SLOT(HideEditor()));
|
|
|
|
|
2011-06-19 10:44:10 +02:00
|
|
|
connect(this, SIGNAL(currentChanged(int)), SLOT(CurrentIndexChanged(int)));
|
2014-02-07 16:34:20 +01:00
|
|
|
connect(this, SIGNAL(tabMoved(int, int)), SLOT(TabMoved()));
|
2012-10-31 07:04:22 +01:00
|
|
|
// We can't just emit Close signal, we need to extract the playlist id first
|
|
|
|
connect(this, SIGNAL(tabCloseRequested(int)), SLOT(CloseFromTabIndex(int)));
|
2010-05-20 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::SetActions(QAction* new_playlist, QAction* load_playlist) {
|
2010-05-20 16:12:15 +02:00
|
|
|
menu_->insertAction(0, new_playlist);
|
|
|
|
menu_->insertAction(0, load_playlist);
|
2010-05-22 16:33:17 +02:00
|
|
|
|
|
|
|
new_ = new_playlist;
|
2010-05-20 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::SetManager(PlaylistManager* manager) {
|
2010-07-17 14:47:59 +02:00
|
|
|
manager_ = manager;
|
2013-05-11 23:17:54 +02:00
|
|
|
connect(manager_, SIGNAL(PlaylistFavorited(int, bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
SLOT(PlaylistFavoritedSlot(int, bool)));
|
2014-12-07 05:36:27 +01:00
|
|
|
connect(manager_, SIGNAL(PlaylistManagerInitialized()), this,
|
|
|
|
SLOT(PlaylistManagerInitialized()));
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistTabBar::PlaylistManagerInitialized() {
|
|
|
|
// Signal that we are done loading and thus further changes should be
|
|
|
|
// committed to the db.
|
|
|
|
initialized_ = true;
|
|
|
|
disconnect(manager_, SIGNAL(PlaylistManagerInitialized()), this,
|
|
|
|
SLOT(PlaylistManagerInitialized()));
|
2010-07-17 14:47:59 +02:00
|
|
|
}
|
|
|
|
|
2010-05-20 16:12:15 +02:00
|
|
|
void PlaylistTabBar::contextMenuEvent(QContextMenuEvent* e) {
|
2014-02-07 16:34:20 +01:00
|
|
|
// we need to finish the renaming action before showing context menu
|
2011-04-02 16:46:56 +02:00
|
|
|
if (rename_editor_->isVisible()) {
|
2014-02-07 16:34:20 +01:00
|
|
|
// discard any change
|
2011-04-02 16:46:56 +02:00
|
|
|
HideEditor();
|
|
|
|
}
|
|
|
|
|
2010-05-20 16:12:15 +02:00
|
|
|
menu_index_ = tabAt(e->pos());
|
|
|
|
rename_->setEnabled(menu_index_ != -1);
|
2012-10-31 07:04:22 +01:00
|
|
|
close_->setEnabled(menu_index_ != -1 && count() > 1);
|
2010-05-23 00:20:00 +02:00
|
|
|
save_->setEnabled(menu_index_ != -1);
|
2010-05-20 16:12:15 +02:00
|
|
|
|
|
|
|
menu_->popup(e->globalPos());
|
|
|
|
}
|
|
|
|
|
2010-05-22 16:33:17 +02:00
|
|
|
void PlaylistTabBar::mouseReleaseEvent(QMouseEvent* e) {
|
|
|
|
if (e->button() == Qt::MidButton) {
|
2011-06-19 10:44:10 +02:00
|
|
|
// Update menu index
|
|
|
|
menu_index_ = tabAt(e->pos());
|
2013-07-27 19:59:15 +02:00
|
|
|
Close();
|
2010-05-22 16:33:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QTabBar::mouseReleaseEvent(e);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::mouseDoubleClickEvent(QMouseEvent* e) {
|
2010-05-22 16:33:17 +02:00
|
|
|
int index = tabAt(e->pos());
|
2011-04-02 19:28:43 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// discard a double click with the middle button
|
2011-04-02 20:15:20 +02:00
|
|
|
if (e->button() != Qt::MidButton) {
|
2011-04-02 19:28:43 +02:00
|
|
|
if (index == -1) {
|
|
|
|
new_->activate(QAction::Trigger);
|
2014-02-07 16:34:20 +01:00
|
|
|
} else {
|
|
|
|
// update current tab
|
2011-04-02 19:28:43 +02:00
|
|
|
menu_index_ = index;
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// set position
|
2011-04-02 19:28:43 +02:00
|
|
|
rename_editor_->setGeometry(tabRect(index));
|
|
|
|
rename_editor_->setText(tabText(index));
|
|
|
|
rename_editor_->setVisible(true);
|
|
|
|
rename_editor_->setFocus();
|
|
|
|
}
|
2011-04-02 16:46:56 +02:00
|
|
|
}
|
2010-05-22 16:33:17 +02:00
|
|
|
|
|
|
|
QTabBar::mouseDoubleClickEvent(e);
|
|
|
|
}
|
|
|
|
|
2010-05-20 16:12:15 +02:00
|
|
|
void PlaylistTabBar::Rename() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (menu_index_ == -1) return;
|
2010-05-20 16:12:15 +02:00
|
|
|
|
|
|
|
QString name = tabText(menu_index_);
|
2014-02-07 16:34:20 +01:00
|
|
|
name = QInputDialog::getText(this, tr("Rename playlist"),
|
|
|
|
tr("Enter a new name for this playlist"),
|
|
|
|
QLineEdit::Normal, name);
|
2010-05-20 16:12:15 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
if (name.isNull()) return;
|
2010-05-20 16:12:15 +02:00
|
|
|
|
2010-05-21 12:44:26 +02:00
|
|
|
emit Rename(tabData(menu_index_).toInt(), name);
|
2010-05-20 16:12:15 +02:00
|
|
|
}
|
|
|
|
|
2011-04-02 16:46:56 +02:00
|
|
|
void PlaylistTabBar::RenameInline() {
|
|
|
|
emit Rename(tabData(menu_index_).toInt(), rename_editor_->text());
|
|
|
|
HideEditor();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistTabBar::HideEditor() {
|
2014-02-07 16:34:20 +01:00
|
|
|
// editingFinished() will be called twice due to Qt bug #40, so we reuse the
|
|
|
|
// same instance, don't delete it
|
2011-04-02 16:46:56 +02:00
|
|
|
rename_editor_->setVisible(false);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// hack to give back focus to playlist view
|
2011-04-02 16:46:56 +02:00
|
|
|
manager_->SetCurrentPlaylist(manager_->current()->id());
|
|
|
|
}
|
|
|
|
|
2013-07-27 19:59:15 +02:00
|
|
|
void PlaylistTabBar::Close() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (menu_index_ == -1) return;
|
2010-05-20 16:12:15 +02:00
|
|
|
|
2013-07-18 00:37:31 +02:00
|
|
|
const int playlist_id = tabData(menu_index_).toInt();
|
|
|
|
|
2013-07-27 19:59:15 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
2013-07-28 15:37:02 +02:00
|
|
|
const bool ask_for_delete = s.value("warn_close_playlist", true).toBool();
|
2013-07-27 19:59:15 +02:00
|
|
|
|
2013-08-28 21:38:17 +02:00
|
|
|
if (ask_for_delete && !manager_->IsPlaylistFavorite(playlist_id) &&
|
|
|
|
!manager_->playlist(playlist_id)->GetAllSongs().empty()) {
|
2013-08-10 20:18:29 +02:00
|
|
|
QMessageBox confirmation_box;
|
|
|
|
confirmation_box.setWindowIcon(QIcon(":/icon.png"));
|
|
|
|
confirmation_box.setWindowTitle(tr("Remove playlist"));
|
|
|
|
confirmation_box.setIcon(QMessageBox::Question);
|
|
|
|
confirmation_box.setText(
|
2014-02-07 16:34:20 +01:00
|
|
|
tr("You are about to remove a playlist which is not part of your "
|
|
|
|
"favorite playlists: "
|
2013-08-10 20:18:29 +02:00
|
|
|
"the playlist will be deleted (this action cannot be undone). \n"
|
|
|
|
"Are you sure you want to continue?"));
|
|
|
|
confirmation_box.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
QCheckBox dont_prompt_again(tr("Warn me when closing a playlist tab"),
|
|
|
|
&confirmation_box);
|
2013-08-10 20:18:29 +02:00
|
|
|
dont_prompt_again.setChecked(ask_for_delete);
|
|
|
|
dont_prompt_again.blockSignals(true);
|
|
|
|
dont_prompt_again.setToolTip(
|
|
|
|
tr("This option can be changed in the \"Behavior\" preferences"));
|
2013-08-11 16:36:07 +02:00
|
|
|
|
|
|
|
QGridLayout* grid = qobject_cast<QGridLayout*>(confirmation_box.layout());
|
|
|
|
QDialogButtonBox* buttons = confirmation_box.findChild<QDialogButtonBox*>();
|
|
|
|
if (grid && buttons) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const int index = grid->indexOf(buttons);
|
|
|
|
int row, column, row_span, column_span = 0;
|
|
|
|
grid->getItemPosition(index, &row, &column, &row_span, &column_span);
|
|
|
|
QLayoutItem* buttonsItem = grid->takeAt(index);
|
|
|
|
grid->addWidget(&dont_prompt_again, row, column, row_span, column_span,
|
|
|
|
Qt::AlignLeft | Qt::AlignTop);
|
|
|
|
grid->addItem(buttonsItem, ++row, column, row_span, column_span);
|
2013-08-11 16:36:07 +02:00
|
|
|
} else {
|
|
|
|
confirmation_box.addButton(&dont_prompt_again, QMessageBox::ActionRole);
|
|
|
|
}
|
2013-08-10 20:18:29 +02:00
|
|
|
|
|
|
|
if (confirmation_box.exec() != QMessageBox::Yes) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If user changed the pref, save the new one
|
|
|
|
if (dont_prompt_again.isChecked() != ask_for_delete) {
|
|
|
|
s.setValue("warn_close_playlist", dont_prompt_again.isChecked());
|
|
|
|
}
|
2013-07-18 00:37:31 +02:00
|
|
|
}
|
|
|
|
|
2013-08-11 16:36:07 +02:00
|
|
|
// Close the playlist. If the playlist is not a favorite playlist, it will be
|
|
|
|
// deleted, as it will not be visible after being closed. Otherwise, the tab
|
|
|
|
// is closed but the playlist still exists and can be resurrected from the
|
|
|
|
// "Playlists" tab.
|
2013-07-18 00:37:31 +02:00
|
|
|
emit Close(playlist_id);
|
2012-12-24 09:35:31 +01:00
|
|
|
|
|
|
|
// Select the nearest tab.
|
|
|
|
if (menu_index_ > 1) {
|
|
|
|
setCurrentIndex(menu_index_ - 1);
|
|
|
|
}
|
2013-01-16 23:23:08 +01:00
|
|
|
|
|
|
|
// Update playlist tab order/visibility
|
|
|
|
TabMoved();
|
2010-05-20 16:12:15 +02:00
|
|
|
}
|
2010-05-21 12:29:17 +02:00
|
|
|
|
2012-10-31 07:04:22 +01:00
|
|
|
void PlaylistTabBar::CloseFromTabIndex(int index) {
|
2011-06-19 10:44:10 +02:00
|
|
|
// Update the global index
|
|
|
|
menu_index_ = index;
|
2012-10-31 07:04:22 +01:00
|
|
|
Close();
|
2011-06-19 10:44:10 +02:00
|
|
|
}
|
|
|
|
|
2010-05-23 00:20:00 +02:00
|
|
|
void PlaylistTabBar::Save() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (menu_index_ == -1) return;
|
2010-05-23 00:20:00 +02:00
|
|
|
|
|
|
|
emit Save(tabData(menu_index_).toInt());
|
|
|
|
}
|
|
|
|
|
2010-05-21 12:29:17 +02:00
|
|
|
int PlaylistTabBar::current_id() const {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (currentIndex() == -1) return -1;
|
2010-05-21 12:29:17 +02:00
|
|
|
return tabData(currentIndex()).toInt();
|
|
|
|
}
|
|
|
|
|
|
|
|
int PlaylistTabBar::index_of(int id) const {
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < count(); ++i) {
|
2010-05-21 12:29:17 +02:00
|
|
|
if (tabData(i).toInt() == id) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::set_current_id(int id) { setCurrentIndex(index_of(id)); }
|
2010-05-21 12:29:17 +02:00
|
|
|
|
2011-04-19 22:11:24 +02:00
|
|
|
int PlaylistTabBar::id_of(int index) const {
|
2011-04-22 19:07:57 +02:00
|
|
|
if (index < 0 || index >= count()) {
|
|
|
|
qLog(Warning) << "Playlist tab index requested is out of bounds!";
|
2011-04-19 22:11:24 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return tabData(index).toInt();
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::set_icon_by_id(int id, const QIcon& icon) {
|
2010-05-21 12:29:17 +02:00
|
|
|
setTabIcon(index_of(id), icon);
|
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::RemoveTab(int id) { removeTab(index_of(id)); }
|
2010-05-21 12:29:17 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::set_text_by_id(int id, const QString& text) {
|
2010-05-21 12:29:17 +02:00
|
|
|
setTabText(index_of(id), text);
|
2011-04-11 18:29:36 +02:00
|
|
|
setTabToolTip(index_of(id), text);
|
2010-05-21 12:29:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistTabBar::CurrentIndexChanged(int index) {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!suppress_current_changed_) emit CurrentIdChanged(tabData(index).toInt());
|
2010-05-21 12:29:17 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
void PlaylistTabBar::InsertTab(int id, int index, const QString& text,
|
|
|
|
bool favorite) {
|
2010-05-21 12:29:17 +02:00
|
|
|
suppress_current_changed_ = true;
|
|
|
|
insertTab(index, text);
|
|
|
|
setTabData(index, id);
|
2011-04-11 18:29:36 +02:00
|
|
|
setTabToolTip(index, text);
|
2014-12-07 05:36:27 +01:00
|
|
|
|
2013-05-12 23:36:32 +02:00
|
|
|
FavoriteWidget* widget = new FavoriteWidget(id, favorite);
|
2014-02-07 16:34:20 +01:00
|
|
|
widget->setToolTip(
|
|
|
|
tr("Click here to favorite this playlist so it will be saved and remain "
|
|
|
|
"accessible "
|
|
|
|
"through the \"Playlists\" panel on the left side bar"));
|
2013-05-12 23:36:32 +02:00
|
|
|
connect(widget, SIGNAL(FavoriteStateChanged(int, bool)),
|
2014-02-07 16:34:20 +01:00
|
|
|
SIGNAL(PlaylistFavorited(int, bool)));
|
2013-05-11 23:17:54 +02:00
|
|
|
setTabButton(index, QTabBar::LeftSide, widget);
|
2010-05-21 12:29:17 +02:00
|
|
|
suppress_current_changed_ = false;
|
|
|
|
|
2014-12-07 05:36:27 +01:00
|
|
|
// If we are still starting up, we don't need to do this, as the
|
|
|
|
// tab ordering after startup will be the same as was already in the db.
|
|
|
|
if (initialized_) {
|
|
|
|
if (currentIndex() == index) emit CurrentIdChanged(id);
|
2013-01-16 23:23:08 +01:00
|
|
|
|
2014-12-07 05:36:27 +01:00
|
|
|
// Update playlist tab order/visibility
|
|
|
|
TabMoved();
|
|
|
|
}
|
2010-05-21 12:29:17 +02:00
|
|
|
}
|
2010-05-21 12:37:24 +02:00
|
|
|
|
|
|
|
void PlaylistTabBar::TabMoved() {
|
|
|
|
QList<int> ids;
|
2014-12-07 05:36:27 +01:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
for (int i = 0; i < count(); ++i) {
|
2010-05-21 12:37:24 +02:00
|
|
|
ids << tabData(i).toInt();
|
|
|
|
}
|
|
|
|
emit PlaylistOrderChanged(ids);
|
|
|
|
}
|
2010-07-17 14:47:59 +02:00
|
|
|
|
|
|
|
void PlaylistTabBar::dragEnterEvent(QDragEnterEvent* e) {
|
|
|
|
if (e->mimeData()->hasUrls() ||
|
|
|
|
e->mimeData()->hasFormat(Playlist::kRowsMimetype) ||
|
2011-02-09 19:48:31 +01:00
|
|
|
qobject_cast<const MimeData*>(e->mimeData())) {
|
2010-07-17 14:47:59 +02:00
|
|
|
e->acceptProposedAction();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistTabBar::dragMoveEvent(QDragMoveEvent* e) {
|
|
|
|
drag_hover_tab_ = tabAt(e->pos());
|
|
|
|
|
2011-02-09 19:48:31 +01:00
|
|
|
if (drag_hover_tab_ != -1) {
|
2010-07-17 14:47:59 +02:00
|
|
|
e->setDropAction(Qt::CopyAction);
|
|
|
|
e->accept(tabRect(drag_hover_tab_));
|
|
|
|
|
|
|
|
if (!drag_hover_timer_.isActive())
|
|
|
|
drag_hover_timer_.start(kDragHoverTimeout, this);
|
2011-02-09 19:48:31 +01:00
|
|
|
} else {
|
|
|
|
drag_hover_timer_.stop();
|
2010-07-17 14:47:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistTabBar::dragLeaveEvent(QDragLeaveEvent*) {
|
|
|
|
drag_hover_timer_.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistTabBar::timerEvent(QTimerEvent* e) {
|
|
|
|
QTabBar::timerEvent(e);
|
|
|
|
|
|
|
|
if (e->timerId() == drag_hover_timer_.timerId()) {
|
|
|
|
drag_hover_timer_.stop();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (drag_hover_tab_ != -1) setCurrentIndex(drag_hover_tab_);
|
2010-07-17 14:47:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PlaylistTabBar::dropEvent(QDropEvent* e) {
|
|
|
|
if (drag_hover_tab_ == -1) {
|
2014-02-07 16:34:20 +01:00
|
|
|
const MimeData* mime_data = qobject_cast<const MimeData*>(e->mimeData());
|
|
|
|
if (mime_data && !mime_data->name_for_new_playlist_.isEmpty()) {
|
2011-02-16 02:04:48 +01:00
|
|
|
manager_->New(mime_data->name_for_new_playlist_);
|
2011-02-15 00:06:36 +01:00
|
|
|
} else {
|
2011-02-16 02:04:48 +01:00
|
|
|
manager_->New(tr("Playlist"));
|
2011-02-15 00:06:36 +01:00
|
|
|
}
|
2011-02-14 18:44:15 +01:00
|
|
|
setCurrentIndex(count() - 1);
|
2011-02-09 19:48:31 +01:00
|
|
|
} else {
|
|
|
|
setCurrentIndex(drag_hover_tab_);
|
2010-07-17 14:47:59 +02:00
|
|
|
}
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
manager_->current()->dropMimeData(e->mimeData(), e->proposedAction(), -1, 0,
|
|
|
|
QModelIndex());
|
2010-07-17 14:47:59 +02:00
|
|
|
}
|
2011-04-13 21:15:30 +02:00
|
|
|
|
|
|
|
bool PlaylistTabBar::event(QEvent* e) {
|
2011-04-15 23:54:19 +02:00
|
|
|
switch (e->type()) {
|
2011-04-13 21:15:30 +02:00
|
|
|
case QEvent::ToolTip: {
|
2014-02-07 16:34:20 +01:00
|
|
|
QHelpEvent* he = static_cast<QHelpEvent*>(e);
|
2011-04-15 23:54:19 +02:00
|
|
|
|
2011-04-13 21:15:30 +02:00
|
|
|
QRect displayed_tab;
|
|
|
|
QSize real_tab;
|
|
|
|
bool is_elided = false;
|
|
|
|
|
|
|
|
real_tab = tabSizeHint(tabAt(he->pos()));
|
|
|
|
displayed_tab = tabRect(tabAt(he->pos()));
|
|
|
|
// Check whether the tab is elided or not
|
|
|
|
is_elided = displayed_tab.width() < real_tab.width();
|
2014-02-07 16:34:20 +01:00
|
|
|
if (!is_elided) {
|
2011-04-13 21:15:30 +02:00
|
|
|
// If it's not elided, don't show the tooltip
|
|
|
|
QToolTip::hideText();
|
|
|
|
} else {
|
|
|
|
QToolTip::showText(he->globalPos(), tabToolTip(tabAt(he->pos())));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return QTabBar::event(e);
|
|
|
|
}
|
|
|
|
}
|
2013-05-11 23:17:54 +02:00
|
|
|
|
|
|
|
void PlaylistTabBar::PlaylistFavoritedSlot(int id, bool favorite) {
|
|
|
|
const int index = index_of(id);
|
2014-02-07 16:34:20 +01:00
|
|
|
FavoriteWidget* favorite_widget =
|
|
|
|
qobject_cast<FavoriteWidget*>(tabButton(index, QTabBar::LeftSide));
|
2013-05-11 23:17:54 +02:00
|
|
|
if (favorite_widget) {
|
|
|
|
favorite_widget->SetFavorite(favorite);
|
|
|
|
}
|
|
|
|
}
|