Minor code cleanup and fixes

This commit is contained in:
Jonas Kvinge 2018-10-20 22:16:22 +02:00
parent 0c0a8d70f3
commit 5221f13498
4 changed files with 42 additions and 30 deletions

View File

@ -782,9 +782,9 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
if (!options.contains_play_options()) LoadPlaybackStatus();
qLog(Debug) << "Started";
RefreshStyleSheet();
qLog(Debug) << "Started";
initialised_ = true;
}
@ -824,7 +824,7 @@ void MainWindow::ReloadSettings() {
if (enable_tidal)
ui_->tabs->addTab(tidal_search_view_, IconLoader::Load("tidal"), "Tidal");
else
ui_->tabs->delTab("tidal");
ui_->tabs->delTab("Tidal");
#endif
#ifdef HAVE_STREAM_DEEZER
@ -834,11 +834,9 @@ void MainWindow::ReloadSettings() {
if (enable_deezer)
ui_->tabs->addTab(deezer_search_view_, IconLoader::Load("deezer"), "Deezer");
else
ui_->tabs->delTab("deezer");
ui_->tabs->delTab("Deezer");
#endif
ui_->tabs->loadSettings(kSettingsGroup);
}
void MainWindow::ReloadAllSettings() {
@ -864,6 +862,7 @@ void MainWindow::ReloadAllSettings() {
void MainWindow::RefreshStyleSheet() {
setStyleSheet(styleSheet());
}
void MainWindow::MediaStopped() {
setWindowTitle("Strawberry Music Player");
@ -1403,10 +1402,6 @@ void MainWindow::PlaylistRightClick(const QPoint &global_pos, const QModelIndex
#endif
playlist_open_in_browser_->setVisible(false);
//qLog(Debug) << "selected" << selected;
//qLog(Debug) << "in_queue" << in_queue << "not_in_queue" << not_in_queue;
//qLog(Debug) << "in_skipped" << in_skipped << "not_in_skipped" << not_in_skipped;
if (selected < 1) {
playlist_queue_->setVisible(false);
playlist_skip_->setVisible(false);
@ -1530,6 +1525,7 @@ void MainWindow::PlaylistStopAfter() {
}
void MainWindow::EditTracks() {
SongList songs;
PlaylistItemList items;
@ -1548,6 +1544,7 @@ void MainWindow::EditTracks() {
//EnsureEditTagDialogCreated();
edit_tag_dialog_->SetSongs(songs, items);
edit_tag_dialog_->show();
}
void MainWindow::EditTagDialogAccepted() {
@ -1605,6 +1602,7 @@ void MainWindow::SongSaveComplete(TagReaderReply *reply,const QPersistentModelIn
}
void MainWindow::SelectionSetValue() {
Playlist::Column column = (Playlist::Column)playlist_menu_index_.column();
QVariant column_value =app_->playlist_manager()->current()->data(playlist_menu_index_);
@ -1623,9 +1621,11 @@ void MainWindow::SelectionSetValue() {
NewClosure(reply, SIGNAL(Finished(bool)), this, SLOT(SongSaveComplete(TagReaderReply*, QPersistentModelIndex)),reply, QPersistentModelIndex(source_index));
}
}
}
void MainWindow::EditValue() {
QModelIndex current = ui_->playlist->view()->currentIndex();
if (!current.isValid()) return;
@ -1668,9 +1668,11 @@ void MainWindow::AddFile() {
MimeData *data = new MimeData;
data->setUrls(urls);
AddToPlaylist(data);
}
void MainWindow::AddFolder() {
// Last used directory
QString directory =settings_.value("add_folder_path", QDir::currentPath()).toString();
@ -1685,6 +1687,7 @@ void MainWindow::AddFolder() {
MimeData *data = new MimeData;
data->setUrls(QList<QUrl>() << QUrl::fromLocalFile(QFileInfo(directory).canonicalFilePath()));
AddToPlaylist(data);
}
void MainWindow::AddCDTracks() {

View File

@ -138,7 +138,7 @@ PlaylistView::PlaylistView(QWidget *parent)
setting_initial_header_layout_(false),
upgrading_from_qheaderview_(false),
read_only_settings_(true),
upgrading_from_version_(-1),
header_loaded_(false),
background_initialized_(false),
background_image_type_(Default),
blur_radius_(kDefaultBlurRadius),
@ -198,6 +198,11 @@ PlaylistView::PlaylistView(QWidget *parent)
}
PlaylistView::~PlaylistView() {
SaveGeometry();
delete style_;
}
void PlaylistView::SetApplication(Application *app) {
Q_ASSERT(app);
@ -248,7 +253,7 @@ void PlaylistView::SetPlaylist(Playlist *playlist) {
}
playlist_ = playlist;
LoadGeometry();
if (!header_loaded_) LoadGeometry();
ReloadSettings();
setFocus();
read_only_settings_ = false;
@ -265,7 +270,7 @@ void PlaylistView::setModel(QAbstractItemModel *m) {
if (model()) {
disconnect(model(), SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(InvalidateCachedCurrentPixmap()));
//disconnect(model(), SIGNAL(layoutAboutToBeChanged()), this, SLOT(RatingHoverOut()));
// When changing the model, always invalidate the current pixmap.
// If a remote client uses "stop after", without invaliding the stop mark would not appear.
InvalidateCachedCurrentPixmap();
@ -280,6 +285,7 @@ void PlaylistView::setModel(QAbstractItemModel *m) {
void PlaylistView::LoadGeometry() {
QSettings settings;
header_loaded_ = true;
settings.beginGroup(Playlist::kSettingsGroup);
QByteArray state(settings.value("state").toByteArray());

View File

@ -97,6 +97,7 @@ class PlaylistView : public QTreeView {
};
PlaylistView(QWidget *parent = nullptr);
~PlaylistView();
static const int kStateVersion;
// Constants for settings: are persistent, values should not be changed
@ -216,7 +217,7 @@ class PlaylistView : public QTreeView {
bool setting_initial_header_layout_;
bool upgrading_from_qheaderview_;
bool read_only_settings_;
int upgrading_from_version_;
bool header_loaded_;
bool background_initialized_;
BackgroundImageType background_image_type_;

View File

@ -124,14 +124,14 @@ class FancyTabBar: public QTabBar {
verticalTextTabs = true;
// if LargeSidebar, restore spacers
if (spacers.count() > 0 && tabWidget->mode() == FancyTabWidget::Mode_LargeSidebar) {
if (tabWidget->mode() == FancyTabWidget::Mode_LargeSidebar && spacers.count() > 0) {
for (int index : spacers.keys()) {
tabWidget->insertTab(index, spacers[index], QIcon(), QString());
tabWidget->setTabEnabled(index, false);
}
spacers.clear();
}
if (tabWidget->mode() != FancyTabWidget::Mode_LargeSidebar) {
else if (tabWidget->mode() != FancyTabWidget::Mode_LargeSidebar) {
// traverse in the opposite order to save indices of spacers
for (int i = count() - 1; i >= 0; --i) {
// spacers are disabled tabs
@ -285,7 +285,7 @@ class FancyTabBar: public QTabBar {
// Spacers are just disabled pages
void FancyTabWidget::addSpacer() {
QWidget *spacer = new QWidget();
QWidget *spacer = new QWidget(this);
const int index = addTab(spacer, QIcon(), QString());
setTabEnabled(index, false);
@ -323,6 +323,7 @@ FancyTabWidget::FancyTabWidget(QWidget* parent) : QTabWidget(parent),
{
FancyTabBar *tabBar = new FancyTabBar(this);
tabBar->setExpanding(0);
setTabBar(tabBar);
setTabPosition(QTabWidget::West);
@ -340,10 +341,9 @@ void FancyTabWidget::loadSettings(const char *kSettingsGroup) {
for (int i = 0 ; i < count() ; i++) {
QString k = "tab_" + tabBar()->tabData(i).toString().toLower();
int index = settings.value(k, i).toInt();
if (index >= 0)
if (index >= 0) {
tabBar()->moveTab(i, index);
else
removeTab(i); // Does not delete page
}
}
settings.endGroup();
@ -372,23 +372,23 @@ int FancyTabWidget::addTab(QWidget *widget, const QIcon &icon, const QString &la
return insertTab(count(), widget, icon, label);
}
int FancyTabWidget::insertTab(int index, QWidget *widget, const QIcon &icon, const QString &label) {
int FancyTabWidget::insertTab(int index, QWidget *widget_view, const QIcon &icon, const QString &label) {
QWidget *page(nullptr);
if (tabs_.contains(label)) page = tabs_.value(label);
else {
page = new QWidget();
page = new QWidget(this);
// In order to achieve the same effect as the "Bottom Widget" of the old Nokia based FancyTabWidget a VBoxLayout is used on each page
QVBoxLayout *layout = new QVBoxLayout();
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setSpacing(0);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(widget);
layout->addWidget(widget_view);
page->setLayout(layout);
tabs_.insert(label, page);
}
for (int i = 0 ; i < count() ; i++) {
QString l = tabBar()->tabData(i).toString().toLower();
QString l = tabBar()->tabData(i).toString();
if (l == label) return i;
}
@ -401,8 +401,11 @@ int FancyTabWidget::insertTab(int index, QWidget *widget, const QIcon &icon, con
void FancyTabWidget::delTab(const QString &label) {
for (int i = 0 ; i < count() ; i++) {
QString l = tabBar()->tabData(i).toString().toLower();
if (l == label) QTabWidget::removeTab(i);
QString l = tabBar()->tabData(i).toString();
if (l == label) {
removeTab(i);
break;
}
}
}
@ -491,7 +494,6 @@ void FancyTabWidget::addMenuItem(QSignalMapper* mapper, QActionGroup* group, con
}
void FancyTabWidget::contextMenuEvent(QContextMenuEvent* e) {
if (!menu_) {