Formatting
This commit is contained in:
@@ -503,8 +503,9 @@ int Playlist::NextVirtualIndex(int i, const bool ignore_repeat_track) const {
|
||||
|
||||
// This one's easy - if we have to repeat the current track then just return i
|
||||
if (repeat_mode == PlaylistSequence::Repeat_Track && !ignore_repeat_track) {
|
||||
if (!FilterContainsVirtualIndex(i))
|
||||
if (!FilterContainsVirtualIndex(i)) {
|
||||
return virtual_items_.count(); // It's not in the filter any more
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -782,10 +783,12 @@ bool Playlist::dropMimeData(const QMimeData *data, Qt::DropAction action, int ro
|
||||
if (const SongMimeData *song_data = qobject_cast<const SongMimeData*>(data)) {
|
||||
// Dragged from a collection
|
||||
// We want to check if these songs are from the actual local file backend, if they are we treat them differently.
|
||||
if (song_data->backend && song_data->backend->songs_table() == SCollection::kSongsTable)
|
||||
if (song_data->backend && song_data->backend->songs_table() == SCollection::kSongsTable) {
|
||||
InsertSongItems<CollectionPlaylistItem>(song_data->songs, row, play_now, enqueue_now, enqueue_next_now);
|
||||
else
|
||||
}
|
||||
else {
|
||||
InsertSongItems<SongPlaylistItem>(song_data->songs, row, play_now, enqueue_now, enqueue_next_now);
|
||||
}
|
||||
}
|
||||
else if (const PlaylistItemMimeData *item_data = qobject_cast<const PlaylistItemMimeData*>(data)) {
|
||||
InsertItems(item_data->items_, row, play_now, enqueue_now, enqueue_next_now);
|
||||
@@ -1184,7 +1187,7 @@ void Playlist::UpdateItems(SongList songs) {
|
||||
// then we remove song from our list because we will not need to check it again.
|
||||
// And we also update undo actions.
|
||||
|
||||
for (int i = 0; i < items_.size() ; i++) {
|
||||
for (int i = 0; i < items_.size(); i++) {
|
||||
// Update current items list
|
||||
QMutableListIterator<Song> it(songs);
|
||||
while (it.hasNext()) {
|
||||
@@ -1203,7 +1206,7 @@ void Playlist::UpdateItems(SongList songs) {
|
||||
items_[i] = new_item;
|
||||
emit dataChanged(index(i, 0), index(i, ColumnCount - 1));
|
||||
// Also update undo actions
|
||||
for (int y = 0 ; y < undo_stack_->count() ; y++) {
|
||||
for (int y = 0; y < undo_stack_->count(); y++) {
|
||||
QUndoCommand *undo_action = const_cast<QUndoCommand*>(undo_stack_->command(i));
|
||||
PlaylistUndoCommands::InsertItems *undo_action_insert = dynamic_cast<PlaylistUndoCommands::InsertItems*>(undo_action);
|
||||
if (undo_action_insert) {
|
||||
@@ -1883,13 +1886,15 @@ void Playlist::Shuffle() {
|
||||
|
||||
int begin = 0;
|
||||
if (current_item_index_.isValid()) {
|
||||
if (new_items[0] != new_items[current_item_index_.row()])
|
||||
if (new_items[0] != new_items[current_item_index_.row()]) {
|
||||
std::swap(new_items[0], new_items[current_item_index_.row()]);
|
||||
}
|
||||
begin = 1;
|
||||
}
|
||||
|
||||
if (dynamic_playlist_ && current_item_index_.isValid())
|
||||
if (dynamic_playlist_ && current_item_index_.isValid()) {
|
||||
begin += current_item_index_.row() + 1;
|
||||
}
|
||||
|
||||
const int count = items_.count();
|
||||
for (int i = begin; i < count; ++i) {
|
||||
@@ -1925,16 +1930,18 @@ void Playlist::ReshuffleIndices() {
|
||||
if (playlist_sequence_->shuffle_mode() == PlaylistSequence::Shuffle_Off) {
|
||||
// No shuffling - sort the virtual item list normally.
|
||||
std::sort(virtual_items_.begin(), virtual_items_.end());
|
||||
if (current_row() != -1)
|
||||
if (current_row() != -1) {
|
||||
current_virtual_index_ = virtual_items_.indexOf(current_row());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// If the user is already playing a song, advance the begin iterator to only shuffle items that haven't been played yet.
|
||||
QList<int>::iterator begin = virtual_items_.begin();
|
||||
QList<int>::iterator end = virtual_items_.end();
|
||||
if (current_virtual_index_ != -1)
|
||||
if (current_virtual_index_ != -1) {
|
||||
std::advance(begin, current_virtual_index_ + 1);
|
||||
}
|
||||
|
||||
std::random_device rd;
|
||||
std::mt19937 g(rd());
|
||||
|
||||
@@ -217,8 +217,9 @@ void PlaylistContainer::SetViewModel(Playlist *playlist, const int scroll_positi
|
||||
UpdateNoMatchesLabel();
|
||||
|
||||
// Ensure that tab is current
|
||||
if (ui_->tab_bar->current_id() != manager_->current_id())
|
||||
if (ui_->tab_bar->current_id() != manager_->current_id()) {
|
||||
ui_->tab_bar->set_current_id(manager_->current_id());
|
||||
}
|
||||
|
||||
// Sort out the undo/redo actions
|
||||
delete undo_;
|
||||
|
||||
@@ -235,8 +235,9 @@ QStyleOptionViewItem PlaylistDelegateBase::Adjusted(const QStyleOptionViewItem &
|
||||
|
||||
QPoint top_left(-view_->horizontalScrollBar()->value(), -view_->verticalScrollBar()->value());
|
||||
|
||||
if (view_->header()->logicalIndexAt(top_left) != idx.column())
|
||||
if (view_->header()->logicalIndexAt(top_left) != idx.column()) {
|
||||
return option;
|
||||
}
|
||||
|
||||
QStyleOptionViewItem ret(option);
|
||||
|
||||
@@ -327,8 +328,9 @@ QString DateItemDelegate::displayText(const QVariant &value, const QLocale &loca
|
||||
bool ok = false;
|
||||
qint64 time = value.toLongLong(&ok);
|
||||
|
||||
if (!ok || time == -1)
|
||||
if (!ok || time == -1) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
return QDateTime::fromSecsSinceEpoch(time).toString(QLocale::system().dateTimeFormat(QLocale::ShortFormat));
|
||||
|
||||
@@ -339,8 +341,9 @@ QString LastPlayedItemDelegate::displayText(const QVariant &value, const QLocale
|
||||
bool ok = false;
|
||||
const qint64 time = value.toLongLong(&ok);
|
||||
|
||||
if (!ok || time == -1)
|
||||
if (!ok || time == -1) {
|
||||
return tr("Never");
|
||||
}
|
||||
|
||||
return Utilities::Ago(time, locale);
|
||||
|
||||
|
||||
@@ -165,10 +165,12 @@ class DropTailComparatorDecorator : public SearchTermComparator {
|
||||
explicit DropTailComparatorDecorator(SearchTermComparator *cmp) : cmp_(cmp) {}
|
||||
|
||||
bool Matches(const QString &element) const override {
|
||||
if (element.length() > 9)
|
||||
if (element.length() > 9) {
|
||||
return cmp_->Matches(element.left(element.length() - 9));
|
||||
else
|
||||
}
|
||||
else {
|
||||
return cmp_->Matches(element);
|
||||
}
|
||||
}
|
||||
private:
|
||||
QScopedPointer<SearchTermComparator> cmp_;
|
||||
@@ -406,10 +408,12 @@ FilterTree *FilterParser::parseSearchTerm() {
|
||||
bool inQuotes = false;
|
||||
for (; iter_ != end_; ++iter_) {
|
||||
if (inQuotes) {
|
||||
if (*iter_ == '"')
|
||||
if (*iter_ == '"') {
|
||||
inQuotes = false;
|
||||
else
|
||||
}
|
||||
else {
|
||||
buf_ += *iter_;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (*iter_ == '"') {
|
||||
|
||||
@@ -92,8 +92,9 @@ void PlaylistHeader::contextMenuEvent(QContextMenuEvent *e) {
|
||||
|
||||
menu_section_ = logicalIndexAt(e->pos());
|
||||
|
||||
if (menu_section_ == -1 || (menu_section_ == logicalIndex(0) && logicalIndex(1) == -1))
|
||||
if (menu_section_ == -1 || (menu_section_ == logicalIndex(0) && logicalIndex(1) == -1)) {
|
||||
action_hide_->setVisible(false);
|
||||
}
|
||||
else {
|
||||
action_hide_->setVisible(true);
|
||||
|
||||
@@ -112,7 +113,7 @@ void PlaylistHeader::contextMenuEvent(QContextMenuEvent *e) {
|
||||
|
||||
qDeleteAll(show_actions_);
|
||||
show_actions_.clear();
|
||||
for (int i = 0 ; i < count() ; ++i) {
|
||||
for (int i = 0; i < count(); ++i) {
|
||||
AddColumnAction(i);
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,9 @@ void PlaylistItem::RemoveBackgroundColor(short priority) {
|
||||
}
|
||||
QColor PlaylistItem::GetCurrentBackgroundColor() const {
|
||||
|
||||
if (background_colors_.isEmpty()) return QColor();
|
||||
if (background_colors_.isEmpty()) {
|
||||
return QColor();
|
||||
}
|
||||
else {
|
||||
QList<short> background_colors_keys = background_colors_.keys();
|
||||
return background_colors_[background_colors_keys.last()];
|
||||
|
||||
@@ -461,10 +461,11 @@ void PlaylistManager::UpdateSummaryText() {
|
||||
if (!range.isValid()) continue;
|
||||
|
||||
selected += range.bottom() - range.top() + 1;
|
||||
for (int i = range.top() ; i <= range.bottom() ; ++i) {
|
||||
for (int i = range.top(); i <= range.bottom(); ++i) {
|
||||
qint64 length = range.model()->index(i, Playlist::Column_Length).data().toLongLong();
|
||||
if (length > 0)
|
||||
if (length > 0) {
|
||||
nanoseconds += length;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -377,12 +377,14 @@ void PlaylistTabBar::dragMoveEvent(QDragMoveEvent *e) {
|
||||
e->setDropAction(Qt::CopyAction);
|
||||
e->accept(tabRect(drag_hover_tab_));
|
||||
|
||||
if (!drag_hover_timer_.isActive())
|
||||
if (!drag_hover_timer_.isActive()) {
|
||||
drag_hover_timer_.start(kDragHoverTimeout, this);
|
||||
}
|
||||
}
|
||||
else {
|
||||
drag_hover_timer_.stop();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlaylistTabBar::dragLeaveEvent(QDragLeaveEvent*) {
|
||||
|
||||
@@ -75,16 +75,23 @@ RemoveItems::RemoveItems(Playlist *playlist, int pos, int count) : Base(playlist
|
||||
}
|
||||
|
||||
void RemoveItems::redo() {
|
||||
for (int i = 0; i < ranges_.count(); ++i)
|
||||
|
||||
for (int i = 0; i < ranges_.count(); ++i) {
|
||||
ranges_[i].items_ = playlist_->RemoveItemsWithoutUndo(ranges_[i].pos_, ranges_[i].count_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RemoveItems::undo() {
|
||||
for (int i = static_cast<int>(ranges_.count() - 1); i >= 0; --i)
|
||||
|
||||
for (int i = static_cast<int>(ranges_.count() - 1); i >= 0; --i) {
|
||||
playlist_->InsertItemsWithoutUndo(ranges_[i].items_, ranges_[i].pos_);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool RemoveItems::mergeWith(const QUndoCommand *other) {
|
||||
|
||||
const RemoveItems *remove_command = static_cast<const RemoveItems*>(other);
|
||||
ranges_.append(remove_command->ranges_);
|
||||
|
||||
@@ -93,6 +100,7 @@ bool RemoveItems::mergeWith(const QUndoCommand *other) {
|
||||
setText(tr("remove %n songs", "", sum));
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -505,8 +505,9 @@ void PlaylistView::drawRow(QPainter *painter, const QStyleOptionViewItem &option
|
||||
const_cast<PlaylistView*>(this)->last_glow_rect_ = opt.rect;
|
||||
|
||||
int step = glow_intensity_step_;
|
||||
if (step >= kGlowIntensitySteps)
|
||||
if (step >= kGlowIntensitySteps) {
|
||||
step = 2 * (kGlowIntensitySteps - 1) - step + 1;
|
||||
}
|
||||
|
||||
int row_height = opt.rect.height();
|
||||
if (row_height != row_height_) {
|
||||
@@ -607,8 +608,9 @@ void PlaylistView::StopGlowing() {
|
||||
void PlaylistView::StartGlowing() {
|
||||
|
||||
currently_glowing_ = true;
|
||||
if (isVisible() && glow_enabled_)
|
||||
if (isVisible() && glow_enabled_) {
|
||||
glow_timer_.start(1500 / kGlowIntensitySteps, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -619,8 +621,9 @@ void PlaylistView::hideEvent(QHideEvent *e) {
|
||||
|
||||
void PlaylistView::showEvent(QShowEvent *e) {
|
||||
|
||||
if (currently_glowing_ && glow_enabled_)
|
||||
if (currently_glowing_ && glow_enabled_) {
|
||||
glow_timer_.start(1500 / kGlowIntensitySteps, this);
|
||||
}
|
||||
|
||||
MaybeAutoscroll(Playlist::AutoScroll_Maybe);
|
||||
|
||||
@@ -710,8 +713,9 @@ void PlaylistView::RemoveSelected() {
|
||||
// Select the new current item, we want always the item after the last selected
|
||||
if (new_idx.isValid()) {
|
||||
// Workaround to update keyboard selected row, if it's not the first row (this also triggers selection)
|
||||
if (new_row != 0)
|
||||
if (new_row != 0) {
|
||||
keyPressEvent(new QKeyEvent(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier));
|
||||
}
|
||||
// Update visual selection with the entire row
|
||||
selectionModel()->select(new_idx, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows);
|
||||
}
|
||||
@@ -742,8 +746,9 @@ QModelIndex PlaylistView::NextEditableIndex(const QModelIndex ¤t) {
|
||||
QHeaderView *h = header();
|
||||
int idx = columns.indexOf(h->visualIndex(current.column()));
|
||||
|
||||
if (idx + 1 >= columns.size())
|
||||
if (idx + 1 >= columns.size()) {
|
||||
return model()->index(current.row() + 1, h->logicalIndex(columns.first()));
|
||||
}
|
||||
|
||||
return model()->index(current.row(), h->logicalIndex(columns[idx + 1]));
|
||||
|
||||
@@ -755,8 +760,9 @@ QModelIndex PlaylistView::PrevEditableIndex(const QModelIndex ¤t) {
|
||||
QHeaderView *h = header();
|
||||
int idx = columns.indexOf(h->visualIndex(current.column()));
|
||||
|
||||
if (idx - 1 < 0)
|
||||
if (idx - 1 < 0) {
|
||||
return model()->index(current.row() - 1, h->logicalIndex(columns.last()));
|
||||
}
|
||||
|
||||
return model()->index(current.row(), h->logicalIndex(columns[idx - 1]));
|
||||
|
||||
@@ -780,19 +786,21 @@ void PlaylistView::closeEditor(QWidget *editor, QAbstractItemDelegate::EndEditHi
|
||||
else if (hint == QAbstractItemDelegate::EditNextItem || hint == QAbstractItemDelegate::EditPreviousItem) {
|
||||
|
||||
QModelIndex idx;
|
||||
if (hint == QAbstractItemDelegate::EditNextItem)
|
||||
if (hint == QAbstractItemDelegate::EditNextItem) {
|
||||
idx = NextEditableIndex(currentIndex());
|
||||
else
|
||||
idx = PrevEditableIndex(currentIndex());
|
||||
|
||||
if (!idx.isValid()) {
|
||||
QTreeView::closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
|
||||
}
|
||||
else {
|
||||
idx = PrevEditableIndex(currentIndex());
|
||||
}
|
||||
|
||||
if (idx.isValid()) {
|
||||
QTreeView::closeEditor(editor, QAbstractItemDelegate::NoHint);
|
||||
setCurrentIndex(idx);
|
||||
QAbstractItemView::edit(idx);
|
||||
}
|
||||
else {
|
||||
QTreeView::closeEditor(editor, QAbstractItemDelegate::SubmitModelCache);
|
||||
}
|
||||
}
|
||||
else {
|
||||
QTreeView::closeEditor(editor, hint);
|
||||
@@ -905,7 +913,11 @@ void PlaylistView::InhibitAutoscrollTimeout() {
|
||||
}
|
||||
|
||||
void PlaylistView::MaybeAutoscroll(const Playlist::AutoScroll autoscroll) {
|
||||
if (autoscroll == Playlist::AutoScroll_Always || (autoscroll == Playlist::AutoScroll_Maybe && !inhibit_autoscroll_)) JumpToCurrentlyPlayingTrack();
|
||||
|
||||
if (autoscroll == Playlist::AutoScroll_Always || (autoscroll == Playlist::AutoScroll_Maybe && !inhibit_autoscroll_)) {
|
||||
JumpToCurrentlyPlayingTrack();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void PlaylistView::JumpToCurrentlyPlayingTrack() {
|
||||
@@ -1077,10 +1089,12 @@ void PlaylistView::paintEvent(QPaintEvent *event) {
|
||||
break;
|
||||
|
||||
case QAbstractItemView::OnViewport:
|
||||
if (model()->rowCount() == 0)
|
||||
if (model()->rowCount() == 0) {
|
||||
drop_pos = 1;
|
||||
else
|
||||
}
|
||||
else {
|
||||
drop_pos = 1 + visualRect(model()->index(model()->rowCount() - 1, first_column)).bottom();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1123,23 +1137,29 @@ void PlaylistView::dragMoveEvent(QDragMoveEvent *event) {
|
||||
}
|
||||
|
||||
void PlaylistView::dragEnterEvent(QDragEnterEvent *event) {
|
||||
|
||||
QTreeView::dragEnterEvent(event);
|
||||
cached_tree_ = QPixmap();
|
||||
drag_over_ = true;
|
||||
|
||||
}
|
||||
|
||||
void PlaylistView::dragLeaveEvent(QDragLeaveEvent *event) {
|
||||
|
||||
QTreeView::dragLeaveEvent(event);
|
||||
cached_tree_ = QPixmap();
|
||||
drag_over_ = false;
|
||||
drop_indicator_row_ = -1;
|
||||
|
||||
}
|
||||
|
||||
void PlaylistView::dropEvent(QDropEvent *event) {
|
||||
|
||||
QTreeView::dropEvent(event);
|
||||
cached_tree_ = QPixmap();
|
||||
drop_indicator_row_ = -1;
|
||||
drag_over_ = false;
|
||||
|
||||
}
|
||||
|
||||
void PlaylistView::PlaylistDestroyed() {
|
||||
@@ -1438,7 +1458,7 @@ void PlaylistView::set_background_image(const QImage &image) {
|
||||
if (!background_image_.isNull()) {
|
||||
// Apply opacity filter
|
||||
uchar *bits = background_image_.bits();
|
||||
for (int i = 0 ; i < background_image_.height() * background_image_.bytesPerLine() ; i += 4) {
|
||||
for (int i = 0; i < background_image_.height() * background_image_.bytesPerLine(); i += 4) {
|
||||
bits[i + 3] = (opacity_level_ / 100.0) * 255;
|
||||
}
|
||||
|
||||
|
||||
@@ -143,10 +143,12 @@ void SongLoaderInserter::AudioCDTagsLoaded(const bool success) {
|
||||
SongLoader *loader = qobject_cast<SongLoader*>(sender());
|
||||
if (!loader || !destination_) return;
|
||||
|
||||
if (success)
|
||||
if (success) {
|
||||
destination_->UpdateItems(loader->songs());
|
||||
else
|
||||
}
|
||||
else {
|
||||
qLog(Error) << "Error while getting audio CD metadata from MusicBrainz";
|
||||
}
|
||||
|
||||
deleteLater();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user