/** Export one playlist at a time. */ void PlaylistDialog::exportSelectedPlaylist() { QString exportedPlaylistLocation; SettingsPrivate *settings = SettingsPrivate::instance(); if (settings->value("locationForExportedPlaylist").isNull()) { exportedPlaylistLocation = QStandardPaths::writableLocation(QStandardPaths::MusicLocation); } else { exportedPlaylistLocation = settings->value("locationForExportedPlaylist").toString(); } auto indexes = savedPlaylists->selectionModel()->selectedIndexes(); if (indexes.isEmpty()) { return; } QModelIndex index = indexes.first(); QStandardItem *item = _savedPlaylistModel->itemFromIndex(index); /// FIXME //QString pPath = item->data(PlaylistPath).toString(); QString pName = item->data(Qt::DisplayRole).toString(); // Open a file dialog and ask the user to choose a location QString newName = QFileDialog::getSaveFileName(this, tr("Export playlist"), exportedPlaylistLocation + QDir::separator() + pName, tr("Playlist (*.m3u8)")); if (QFile::exists(newName)) { QFile removePreviousOne(newName); if (!removePreviousOne.remove()) { qDebug() << Q_FUNC_INFO << "Cannot remove" << newName; } } if (newName.isEmpty()) { return; } }
void TabBar::paintEvent(QPaintEvent *) { SettingsPrivate *settings = SettingsPrivate::instance(); QStylePainter p(this); int dist = 0; if (settings->isRectTabs()) { paintRectTabs(p); } else { dist = settings->tabsOverlappingLength(); paintRoundedTabs(p, dist); } // Global bottom frame border int h = tabRect(0).height() - 1; p.setPen(QApplication::palette().mid().color()); if (count() > 1) { if (currentIndex() == 0) { p.drawLine(tabRect(0).right() + 1 + dist, h, rect().right(), h); } else { p.drawLine(rect().left(), h, tabRect(currentIndex()).left(), h); p.drawLine(tabRect(currentIndex()).right() + 1 + dist, h, rect().right(), h); } } else { if (isLeftToRight()) { p.drawLine(tabRect(0).width() + dist, h, rect().right(), h); } else { p.drawLine(rect().left(), h, tabRect(0).left(), h); } } }
CustomizeThemeDialog::CustomizeThemeDialog(MainWindow *parent) : QDialog(nullptr) , _mainWindow(parent) , _targetedColor(nullptr) , _animation(new QPropertyAnimation(this, "windowOpacity")) , _timer(new QTimer(this)) { setupUi(this); listWidget->setAttribute(Qt::WA_MacShowFocusRect, false); this->setWindowFlags(Qt::Tool); this->setAttribute(Qt::WA_DeleteOnClose); buttonsListBox->setVisible(false); spinBoxLibrary->setMouseTracking(true); // Animates this Dialog _timer->setInterval(3000); _timer->setSingleShot(true); _animation->setDuration(200); _animation->setTargetObject(this); this->setupActions(); SettingsPrivate *settings = SettingsPrivate::instance(); this->restoreGeometry(settings->value("customizeThemeDialogGeometry").toByteArray()); listWidget->setCurrentRow(settings->value("customizeThemeDialogCurrentTab").toInt()); this->loadTheme(); }
void CustomizeThemeDialog::toggleCustomColors(bool b) { SettingsPrivate *settings = SettingsPrivate::instance(); settings->setCustomColors(b); for (int i = 0; i < customColorsGridLayout->rowCount(); i++) { for (int j = 0; j < customColorsGridLayout->columnCount(); j++) { QLayoutItem *item = customColorsGridLayout->itemAtPosition(i, j); if (item->widget()) { item->widget()->setEnabled(b); } } } if (b) { bgPrimaryColorWidget->setColor(settings->customColors(QPalette::Base)); selectedItemColorWidget->setColor(settings->customColors(QPalette::Highlight)); } else { QColor base = style()->standardPalette().base().color(); QColor highlight = style()->standardPalette().highlight().color(); int gray = qGray(base.rgb()); bgPrimaryColorWidget->setColor(QColor(gray, gray, gray)); gray = qGray(highlight.rgb()); selectedItemColorWidget->setColor(QColor(gray, gray, gray)); QApplication::setPalette(style()->standardPalette()); } }
void CustomizeThemeDialog::openChooseIconDialog() { QPushButton *button = qobject_cast<QPushButton *>(sender()); SettingsPrivate *settings = SettingsPrivate::instance(); // It's always more convenient when the dialog re-open at the same location QString openPath; QVariant variantOpenPath = settings->value("customIcons/lastOpenPath"); if (variantOpenPath.isValid()) { openPath = variantOpenPath.toString(); } else { openPath = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first(); } QString path = QFileDialog::getOpenFileName(this, tr("Choose your custom icon"), openPath, tr("Pictures (*.jpg *.jpeg *.png)")); // Reset custom icon if path is empty (delete key in settings too) settings->setCustomIcon(button->objectName() + "Button", path); for (MediaButton *b : _mainWindow->findChildren<MediaButton*>(button->objectName() + "Button")) { if (b) { b->setIcon(QIcon(path)); } } MediaButton *b = _mainWindow->findChild<MediaButton*>(button->objectName() + "Button"); if (path.isEmpty()) { button->setIcon(QIcon(":/player/" + Settings::instance()->theme() + "/" + button->objectName())); b->setIcon(QIcon()); } else { settings->setValue("customIcons/lastOpenPath", QFileInfo(path).absolutePath()); button->setIcon(QIcon(path)); b->setIcon(QIcon(path)); } }
/** Reload icon when theme has changed or buttons size was changed in options by one. */ void PlaybackModeWidget::adjustIcon() { SettingsPrivate *settingsPrivate = SettingsPrivate::instance(); Settings *settings = Settings::instance(); button()->setIcon(QIcon(":/player/" + settings->theme() + "/" + _playbackMode)); button()->setIconSize(QSize(settingsPrivate->buttonsSize(), settingsPrivate->buttonsSize())); }
void PluginManager::init() { QDir appDirPath = QDir(qApp->applicationDirPath()); QString pluginPath; if (appDirPath.cd("plugins")) { pluginPath = appDirPath.absolutePath(); } if (!pluginPath.isEmpty()) { QDirIterator it(pluginPath); SettingsPrivate *settings = SettingsPrivate::instance(); QMap<QString, PluginInfo> plugins = settings->plugins(); QStringList failedPlugins; while (it.hasNext()) { if (QLibrary::isLibrary(it.next()) && !it.fileInfo().isSymLink()) { // If plugin was recognized by the App at least once if (plugins.contains(it.filePath())) { PluginInfo pluginInfo = plugins.value(it.filePath()); if (pluginInfo.isEnabled() && !this->loadPlugin(it.filePath())) { failedPlugins << it.fileName(); } } else if (!this->loadPlugin(it.filePath())) { failedPlugins << it.fileName(); } } } // If at least one plugin wasn't restored (API has changed for example) if (!failedPlugins.isEmpty()) { this->alertUser(failedPlugins); } } }
/** Redefined to display an editable area. */ void TabBar::mouseDoubleClickEvent(QMouseEvent *event) { int tabIndex = tabAt(event->pos()); int c = currentIndex(); if (-1 < tabIndex && tabIndex < count() && c == tabIndex) { QRect visualRect = tabRect(tabIndex); SettingsPrivate *settings = SettingsPrivate::instance(); if (settings->isRectTabs()) { visualRect.setLeft(visualRect.left() + 1); visualRect.setRight(visualRect.right() - 1); } else { visualRect.setLeft(visualRect.left() + 3 + settings->tabsOverlappingLength() * 1.25 + height() / 2); visualRect.setRight(visualRect.right() - settings->tabsOverlappingLength()); } visualRect.setTop(visualRect.top() + 1); // Disable close buttons in case of unfortunate click for (int t = 0; t < count(); t++) { QWidget *button = tabButton(t, QTabBar::RightSide); if (button && t != tabIndex) { button->setEnabled(false); } } // Feed the QLineEdit with current tab text lineEdit->setText(tabText(tabIndex)); lineEdit->selectAll(); lineEdit->setFocus(); lineEdit->setGeometry(visualRect); lineEdit->setVisible(true); lineEdit->grabMouse(); } QTabBar::mouseDoubleClickEvent(event); }
PlaylistHeaderView::PlaylistHeaderView(Playlist *parent) : QHeaderView(Qt::Horizontal, parent) { this->setHighlightSections(false); this->setFrameShape(QFrame::NoFrame); this->setMinimumSectionSize(this->height()); this->setMouseTracking(true); this->setSectionResizeMode(QHeaderView::Interactive); this->setSectionsMovable(true); this->setStretchLastSection(true); this->installEventFilter(this); // Context menu on header of columns _columns = new QMenu(this); connect(_columns, &QMenu::triggered, this, [=](const QAction *action) { int columnIndex = action->data().toInt(); this->setSectionHidden(columnIndex, !this->isSectionHidden(columnIndex)); parent->resizeColumnToContents(columnIndex); }); // Initialize font from settings SettingsPrivate *settings = SettingsPrivate::instance(); this->setFont(settings->font(SettingsPrivate::FF_Playlist)); connect(settings, &SettingsPrivate::fontHasChanged, this, [=](SettingsPrivate::FontFamily ff, const QFont &newFont) { if (ff == SettingsPrivate::FF_Playlist) { this->setFont(newFont); } }); }
/** Automatically centers the parent window when closing this dialog. */ void CustomizeThemeDialog::closeEvent(QCloseEvent *e) { SettingsPrivate *settings = SettingsPrivate::instance(); settings->setValue("customizeThemeDialogGeometry", saveGeometry()); settings->setValue("customizeThemeDialogCurrentTab", listWidget->currentRow()); QDialog::closeEvent(e); }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(player); qRegisterMetaType<GenericDAO>(); qRegisterMetaType<TrackDAO>(); qRegisterMetaTypeStreamOperators<TrackDAO>("TrackDAO"); qRegisterMetaType<QFileInfo>(); qRegisterMetaType<PluginInfo>(); qRegisterMetaTypeStreamOperators<PluginInfo>("PluginInfo"); #if defined(Q_OS_WIN) qInstallMessageHandler(debugOutput); #endif QtSingleApplication app(SOFT, argc, argv); app.setOrganizationName(COMPANY); app.setApplicationName(SOFT); app.setApplicationVersion(VERSION); app.setAttribute(Qt::AA_UseHighDpiPixmaps); if (app.isRunning()) { app.forwardArgsToServer(); return 0; } SettingsPrivate *settings = SettingsPrivate::instance(); app.installTranslator(&settings->playerTranslator); app.installTranslator(&settings->defaultQtTranslator); app.setStyle(new MiamStyle); MainWindow *window = new MainWindow; app.setActivationWindow(window); logBrowser = new LogBrowser; QObject::connect(window->actionShowDebug, &QAction::triggered, [=]() { logBrowser->show(); }); QObject::connect(&app, &QtSingleApplication::sendArgs, window, &MainWindow::processArgs); if (settings->isCustomColors()) { app.setPalette(settings->value("customPalette").value<QPalette>()); } window->init(); window->show(); window->loadPlugins(); window->activateLastView(); QStringList args; for (int i = 0; i < argc; i++) { args << argv[i]; } window->processArgs(args); int result = app.exec(); delete logBrowser; return result; }
int main(int argc, char *argv[]) { Q_INIT_RESOURCE(mp); qRegisterMetaType<GenericDAO>(); qRegisterMetaType<TrackDAO>(); qRegisterMetaTypeStreamOperators<TrackDAO>("TrackDAO"); qRegisterMetaType<QFileInfo>(); qRegisterMetaType<PluginInfo>(); qRegisterMetaTypeStreamOperators<PluginInfo>("PluginInfo"); qInstallMessageHandler(debugOutput); QtSingleApplication app(SOFT, argc, argv); if (app.isRunning()) { QString arg = QApplication::arguments().join(";"); app.sendMessage(arg); return 0; } app.setStyle(new MiamStyle); MainWindow *window = new MainWindow; logBrowser = new LogBrowser; QObject::connect(window->actionShowDebug, &QAction::triggered, [=]() { logBrowser->show(); }); QObject::connect(&app, &QtSingleApplication::sendArgs, window, &MainWindow::processArgs); app.setActivationWindow(window); SettingsPrivate *settings = SettingsPrivate::instance(); if (settings->isCustomColors()) { app.setPalette(settings->value("customPalette").value<QPalette>()); } app.setOrganizationName(COMPANY); app.setApplicationName(SOFT); app.setApplicationVersion(VERSION); window->init(); window->show(); window->loadPlugins(); window->activateLastView(); // It this application was started from a file (for example) if (argc > 1) { QStringList args; for (int i = 0; i < argc; i++) { args << argv[i]; } window->processArgs(args); } int result = app.exec(); delete logBrowser; return result; }
/** Redefined to always display the same height for albums, even for those without one. */ QSize LibraryItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { SettingsPrivate *settingsPrivate = SettingsPrivate::instance(); QStandardItem *item = _libraryModel->itemFromIndex(_proxy->mapToSource(index)); if (item->type() == Miam::IT_Album) { QFontMetrics fmf(settingsPrivate->font(SettingsPrivate::FF_Library)); return QSize(option.rect.width(), qMax(fmf.height(), Settings::instance()->coverSizeLibraryTree() + 2)); } else { QFontMetrics fmf(settingsPrivate->font(SettingsPrivate::FF_Library)); return QSize(option.rect.width(), fmf.height()); } }
/** Load an icon from a chosen theme in options. */ void MediaButton::setIconFromTheme(const QString &theme) { SettingsPrivate *settingsPrivate = SettingsPrivate::instance(); if (settingsPrivate->isButtonThemeCustomized() && settingsPrivate->hasCustomIcon(objectName())) { setIcon(QIcon(settingsPrivate->customIcon(objectName()))); } else { // The objectName in the UI file MUST match the alias in the QRC file! QString iconFile = ":/player/" + theme.toLower() + "/" + this->objectName().remove("Button"); QIcon icon(iconFile); if (!icon.isNull()) { QPushButton::setIcon(QIcon(iconFile)); } } }
/** Redefined to initialize favorites from settings. */ int CustomizeThemeDialog::exec() { // Change the label that talks about star delegates SettingsPrivate *settings = SettingsPrivate::instance(); bool starDelegateState = settings->isStarDelegates(); labelLibraryDelegates->setEnabled(starDelegateState); radioButtonShowNeverScoredTracks->setEnabled(starDelegateState); radioButtonHideNeverScoredTracks->setEnabled(starDelegateState); if (settings->value("customizeThemeDialogGeometry").isNull()) { int w = qApp->desktop()->screenGeometry().width() / 2; int h = qApp->desktop()->screenGeometry().height() / 2; this->move(w - frameGeometry().width() / 2, h - frameGeometry().height() / 2); } return QDialog::exec(); }
TabBar::TabBar(TabPlaylist *parent) : QTabBar(parent), lineEdit(new QLineEdit(this)), tabPlaylist(parent) { this->setAcceptDrops(true); this->setDocumentMode(true); this->setTabsClosable(true); this->setUsesScrollButtons(true); this->installEventFilter(this); lineEdit->setVisible(false); lineEdit->setAlignment(Qt::AlignCenter); lineEdit->setFrame(false); lineEdit->installEventFilter(this); lineEdit->setAttribute(Qt::WA_MacShowFocusRect, false); _timer = new QTimer(this); _timer->setInterval(300); _timer->setSingleShot(true); connect(lineEdit, &QLineEdit::returnPressed, this, &TabBar::renameTab); // Switch between tabs if the Drag & Drop isn't finished connect(_timer, &QTimer::timeout, [=]() { this->setCurrentIndex(tabAt(_targetRect.center())); _targetRect = tabRect(currentIndex()); }); SettingsPrivate *settings = SettingsPrivate::instance(); auto applyFont = [this, settings] (SettingsPrivate::FontFamily ff, const QFont &newFont) { if (ff == SettingsPrivate::FF_Playlist) { QFont font = newFont; font.setPointSizeF(font.pointSizeF() * 0.8); this->setFont(font); int h = fontMetrics().height() * 1.25; if (h >= 30) { this->setMinimumHeight(h); this->setMaximumHeight(h); } else { this->setMinimumHeight(30); this->setMaximumHeight(30); } } }; // Init font from settings applyFont(SettingsPrivate::FF_Playlist, settings->font(SettingsPrivate::FF_Playlist)); connect(settings, &SettingsPrivate::fontHasChanged, this, applyFont); }
CustomizeThemeDialog::CustomizeThemeDialog(QWidget *parent) : QDialog(parent) , _targetedColor(nullptr) , _animation(new QPropertyAnimation(this, "windowOpacity")) , _timer(new QTimer(this)) { setupUi(this); for (QSpinBox *spinBox : this->findChildren<QSpinBox*>()) { spinBox->setAttribute(Qt::WA_MacShowFocusRect, false); } listWidget->verticalScrollBar()->deleteLater(); listWidget->setVerticalScrollBar(new ScrollBar(Qt::Vertical, this)); listWidget->setAttribute(Qt::WA_MacShowFocusRect, false); this->setWindowFlags(Qt::Tool); this->setAttribute(Qt::WA_DeleteOnClose); buttonsListBox->setVisible(false); spinBoxLibrary->setMouseTracking(true); // Animates this Dialog _timer->setInterval(3000); _timer->setSingleShot(true); _animation->setDuration(200); _animation->setTargetObject(this); // Custom colors in the whole application auto settingsPrivate = SettingsPrivate::instance(); bool customColors = settingsPrivate->isCustomColors(); if (customColors) { enableCustomColorsRadioButton->setChecked(true); } // Override text color or not which is usually computed automatically if (settingsPrivate->isCustomTextColorOverriden()) { enableCustomTextColorsRadioButton->setChecked(true); } this->setupActions(); SettingsPrivate *settings = SettingsPrivate::instance(); this->restoreGeometry(settings->value("customizeThemeDialogGeometry").toByteArray()); listWidget->setCurrentRow(settings->value("customizeThemeDialogCurrentTab").toInt()); this->loadTheme(); }
void CustomizeThemeDialog::toggleCustomColorsReflector(Reflector *one, Reflector *two, bool enabled) { SettingsPrivate *settings = SettingsPrivate::instance(); QPalette palette = settings->customPalette(); QColor colorOne = palette.color(one->colorRole()); QColor colorTwo = palette.color(two->colorRole()); if (enabled) { one->setColor(colorOne); two->setColor(colorTwo); QApplication::setPalette(settings->customPalette()); } else { int gray = qGray(colorOne.rgb()); one->setColor(QColor(gray, gray, gray)); gray = qGray(colorTwo.rgb()); two->setColor(QColor(gray, gray, gray)); } }
QRect MiamStyle::subElementRect(SubElement element, const QStyleOption *option, const QWidget *widget) const { QRect r = QProxyStyle::subElementRect(element, option, widget); if (widget && widget->objectName() == "tabPlaylists") { const TabPlaylist *t = dynamic_cast<const TabPlaylist*>(widget); QRect minRect = QRect(0, 0, 0, 0); for (int i = 0; i < t->tabBar()->count(); i++) { minRect.setWidth(minRect.width() + t->tabBar()->tabRect(i).width()); } minRect.setHeight(t->tabBar()->tabRect(0).height()); switch (element) { case SE_TabWidgetRightCorner: r.setX(minRect.x() + minRect.width() + 1); r.setY(0); break; case SE_TabWidgetTabBar: { SettingsPrivate *settings = SettingsPrivate::instance(); if (!settings->isRectTabs()) { r = minRect.adjusted(0, 0, settings->tabsOverlappingLength(), 0); } else { r = minRect; } break; } default: break; } } else { if (widget && widget->objectName() == "tabBar") { const QStyleOptionTab *sot = qstyleoption_cast<const QStyleOptionTab*>(option); QStyleOptionTab tab = *sot; //qDebug() << Q_FUNC_INFO << element << r; if (element == SE_TabBarTabText) { //tab.rect.setX(tab.rect.x() + 20); //qDebug() << "SE_TabBarTabText" << sot->rect; return sot->rect; } else if (element == SE_CheckBoxContents) { //qDebug() << "SE_CheckBoxContents" << sot->rect; return sot->rect; } } } return r; }
/** Export one playlist at a time. */ void PlaylistDialog::exportSelectedPlaylist() { QString exportedPlaylistLocation; SettingsPrivate *settings = SettingsPrivate::instance(); if (settings->value("locationForExportedPlaylist").isNull()) { exportedPlaylistLocation = QStandardPaths::writableLocation(QStandardPaths::MusicLocation); } else { exportedPlaylistLocation = settings->value("locationForExportedPlaylist").toString(); } auto indexes = savedPlaylists->selectionModel()->selectedIndexes(); if (indexes.isEmpty()) { return; } QStandardItem *item = _savedPlaylistModel->itemFromIndex(indexes.first()); uint playlistId = item->data(PlaylistID).toUInt(); auto db = SqlDatabase::instance(); PlaylistDAO dao = db->selectPlaylist(playlistId); QString title = this->convertNameToValidFileName(dao.title()); // Open a file dialog and ask the user to choose a location QString newName = QFileDialog::getSaveFileName(this, tr("Export playlist"), exportedPlaylistLocation + QDir::separator() + title, tr("Playlist (*.m3u8)")); if (QFile::exists(newName)) { QFile removePreviousOne(newName); if (!removePreviousOne.remove()) { qDebug() << Q_FUNC_INFO << "Cannot remove" << newName; } } if (newName.isEmpty()) { return; } else { QFile f(newName); if (f.open(QIODevice::ReadWrite | QIODevice::Text)) { QTextStream stream(&f); QList<TrackDAO> tracks = db->selectPlaylistTracks(playlistId); for (TrackDAO t : tracks) { stream << t.uri(); endl(stream); } } f.close(); } }
/** Load a plugin by its location on the hard drive. */ bool PluginManager::loadPlugin(const QString &pluginAbsPath) { QPluginLoader pluginLoader(pluginAbsPath, this); QObject *plugin = pluginLoader.instance(); if (plugin) { BasicPlugin *basic = dynamic_cast<BasicPlugin*>(plugin); basic->setParent(this); SettingsPrivate *settings = SettingsPrivate::instance(); if (basic) { PluginInfo pluginInfo; pluginInfo.setAbsFilePath(pluginAbsPath); pluginInfo.setPluginName(basic->name()); pluginInfo.setVersion(basic->version()); pluginInfo.setConfigPage(basic->isConfigurable()); pluginInfo.setEnabled(true); settings->addPlugin(pluginInfo); if (basic->isConfigurable()) { QString pluginLang(":/translations/" + basic->name() + "_" + settings->language()); if (basic->translator.load(pluginLang)) { QApplication::installTranslator(&basic->translator); } } // Keep references of loaded plugins, to be able to unload them later _loadedPlugins.insert(pluginAbsPath, basic); } else { return false; } basic->init(); if (MediaPlayerPlugin *mediaPlayerPlugin = qobject_cast<MediaPlayerPlugin*>(plugin)) { this->loadMediaPlayerPlugin(mediaPlayerPlugin); } else if (ItemViewPlugin *itemViewPlugin = qobject_cast<ItemViewPlugin*>(plugin)) { this->loadItemViewPlugin(itemViewPlugin); } else if (RemoteMediaPlayerPlugin *remoteMediaPlayerPlugin = qobject_cast<RemoteMediaPlayerPlugin*>(plugin)) { this->loadRemoteMediaPlayerPlugin(remoteMediaPlayerPlugin); } else if (TagEditorPlugin *tagEditorPlugin = qobject_cast<TagEditorPlugin*>(plugin)) { this->loadTagEditorPlugin(tagEditorPlugin); } } return plugin != nullptr; }
/** Changes the current theme and updates this dialog too. */ void CustomizeThemeDialog::setThemeNameAndDialogButtons(QString newTheme) { SettingsPrivate *settings = SettingsPrivate::instance(); // Check for each button if there is a custom icon for (QPushButton *button : customizeButtonsScrollArea->findChildren<QPushButton*>()) { if (button) { // Keep the custom icon provided by one if (settings->hasCustomIcon(button->objectName())) { button->setIcon(QIcon(settings->customIcon(button->objectName()))); } else { button->setIcon(QIcon(":/player/" + newTheme.toLower() + "/" + button->objectName())); } } } Settings::instance()->setThemeName(newTheme); for (MediaButton *m : mainWindow->mediaButtons) { m->setIconFromTheme(newTheme); } }
/// FIXME: use Qt::Popup to avoir flicker effect when one clicks. The problem is to manage multiple popups on screen /// It seems difficult to handle more than one popup PlaybackModeWidget::PlaybackModeWidget(QMediaPlaylist::PlaybackMode mode, QPushButton *playbackModeButton) : QWidget(playbackModeButton, Qt::Tool | Qt::FramelessWindowHint), _mode(mode) { _animation = new QPropertyAnimation(this, "pos"); _animation->setDuration(200); QPushButton *button = new QPushButton(this); _playbackMode = PlaybackModeWidget::nameFromMode(mode); SettingsPrivate *settingsPrivate = SettingsPrivate::instance(); Settings *settings = Settings::instance(); button->setIcon(QIcon(":/player/" + settings->theme() + "/" + _playbackMode)); button->setIconSize(QSize(settingsPrivate->buttonsSize(), settingsPrivate->buttonsSize())); QVBoxLayout *vLayout = new QVBoxLayout(this); vLayout->setContentsMargins(0, 0, 0, 0); vLayout->addWidget(button); this->setLayout(vLayout); }
/** Changes the current theme and updates this dialog too. */ void CustomizeThemeDialog::setThemeNameAndDialogButtons(QString newTheme) { SettingsPrivate *settings = SettingsPrivate::instance(); // Check for each button if there is a custom icon for (QPushButton *button : customizeButtonsScrollArea->findChildren<QPushButton*>()) { if (button) { // Keep the custom icon provided by one if (settings->hasCustomIcon(button->objectName())) { button->setIcon(QIcon(settings->customIcon(button->objectName()))); } else { QIcon i(":/player/" + newTheme.replace(" ", "").toLower() + "/" + button->objectName()); if (!i.isNull()) { button->setIcon(i); } } } } Settings::instance()->setThemeName(newTheme); }
int MiamStyle::pixelMetric(QStyle::PixelMetric metric, const QStyleOption *opt, const QWidget *widget) const { int pm = QProxyStyle::pixelMetric(metric, opt, widget); #if defined(Q_OS_OSX) switch (metric) { case PM_TabCloseIndicatorWidth: { SettingsPrivate *settings = SettingsPrivate::instance(); if (settings->isRectTabs()) { return 13; } else { return 12 + SettingsPrivate::instance()->tabsOverlappingLength() / 1.5; } } default: return pm; } #endif return pm; }
/** Default constructor. */ ExtendedTabBar::ExtendedTabBar(QWidget *parent) : QTabBar(parent) { SettingsPrivate *settings = SettingsPrivate::instance(); QFont f = settings->font(SettingsPrivate::FF_Library); f.setPointSizeF(f.pointSizeF() * 0.8); this->setFont(f); this->setMouseTracking(true); connect(settings, &SettingsPrivate::fontHasChanged, this, [=](SettingsPrivate::FontFamily ff, const QFont &newFont) { if (ff == SettingsPrivate::FF_Library) { this->setMinimumHeight(fontMetrics().height() * 1.25); this->setMaximumHeight(fontMetrics().height() * 1.25); QFont font = newFont; font.setPointSizeF(font.pointSizeF() * 0.8); this->setFont(font); } }); }
/** Redefined: clean preview area, populate once again lists. */ void PlaylistDialog::open() { SettingsPrivate *settings = SettingsPrivate::instance(); if (settings->value("PlaylistDialogGeometry").isValid()) { this->restoreGeometry(settings->value("PlaylistDialogGeometry").toByteArray()); } this->clearPreview(false); for (int i = 0; i < _playlists.count(); i++) { Playlist *p = _playlists.at(i); if (p && p->id() == 0 && !p->mediaPlaylist()->isEmpty()) { QStandardItem *item = new QStandardItem(p->title()); _unsavedPlaylistModel->appendRow(item); _unsaved.insert(item, p); } } this->updatePlaylists(); QDialog::open(); this->activateWindow(); }
void LibraryOrderDialog::setVisible(bool b) { if (b) { QString track = tr("track"); // Artists \ Albums \ Tracks QStandardItemModel *artistModel = new QStandardItemModel(this); artistModel->setHorizontalHeaderItem(0, new QStandardItem(tr("Artists \\ Albums"))); artistModel->setHeaderData(0, Qt::Horizontal, SettingsPrivate::IP_Artists, Qt::UserRole); QStandardItem *artist = new QStandardItem(tr("Artist")); artistModel->appendRow(artist); for (int i = 1; i <= 1; i++) { QStandardItem *album = new QStandardItem(tr("Album")); artist->appendRow(album); for (int j = 1; j <= 2; j++) { album->appendRow(new QStandardItem("0" + QString::number(j) + ". " + track + " #" + QString::number(j))); } } auto m = artistTreeView->model(); artistTreeView->setModel(artistModel); delete m; bool disabled = false; // Albums \ Tracks QStandardItemModel *albumModel = new QStandardItemModel(this); albumModel->setHorizontalHeaderItem(0, new QStandardItem(tr("Albums"))); albumModel->setHeaderData(0, Qt::Horizontal, SettingsPrivate::IP_Albums, Qt::UserRole); QStandardItem *album = new QStandardItem(tr("Album")); albumModel->appendRow(album); for (int i = 1; i <= 2; i++) { album->appendRow(new QStandardItem("0" + QString::number(i) + ". " + track + " #" + QString::number(i))); } m = albumTreeView->model(); albumTreeView->setModel(albumModel); delete m; albumTreeView->setDisabled(disabled); // Artists - Albums \ Tracks QStandardItemModel *artistAlbumModel = new QStandardItemModel(this); artistAlbumModel->setHorizontalHeaderItem(0, new QStandardItem(tr("Artists – Albums"))); artistAlbumModel->setHeaderData(0, Qt::Horizontal, SettingsPrivate::IP_ArtistsAlbums, Qt::UserRole); QStandardItem *artistAlbum_1 = new QStandardItem(tr("Artist – Album")); artistAlbumModel->appendRow(artistAlbum_1); for (int i = 1; i <= 2; i++) { artistAlbum_1->appendRow(new QStandardItem("0" + QString::number(i) + ". " + track + " #" + QString::number(i))); } m = artistAlbumTreeView->model(); artistAlbumTreeView->setModel(artistAlbumModel); delete m; artistAlbumTreeView->setDisabled(disabled); // Year \ Artist - Album \ Tracks QStandardItemModel *yearModel = new QStandardItemModel(this); yearModel->setHorizontalHeaderItem(0, new QStandardItem(tr("Years"))); yearModel->setHeaderData(0, Qt::Horizontal, SettingsPrivate::IP_Years, Qt::UserRole); QStandardItem *year = new QStandardItem("2014"); yearModel->appendRow(year); QStandardItem *artistAlbum_2 = new QStandardItem(tr("Artist – Album")); year->appendRow(artistAlbum_2); for (int j = 1; j <= 2; j++) { artistAlbum_2->appendRow(new QStandardItem("0" + QString::number(j) + ". " + track + " #" + QString::number(j))); } m = yearTreeView->model(); yearTreeView->setModel(yearModel); delete m; yearTreeView->setDisabled(disabled); SettingsPrivate *settings = SettingsPrivate::instance(); for (QTreeView *treeView : findChildren<QTreeView*>()) { treeView->expandAll(); connect(treeView, &QTreeView::clicked, [=]() { for (QTreeView *treeView_2 : findChildren<QTreeView*>()) { if (treeView == treeView_2) { treeView_2->clearSelection(); int i = treeView_2->model()->headerData(0, Qt::Horizontal, Qt::UserRole).toInt(); SettingsPrivate::InsertPolicy insertPolicy = (SettingsPrivate::InsertPolicy) i; // Rebuild library only if the click was on another treeview if (insertPolicy != settings->insertPolicy()) { settings->setInsertPolicy(insertPolicy); emit accept(); } } } this->close(); }); } } QDialog::setVisible(b); }
void CustomizeThemeDialog::setupActions() { SettingsPrivate *settings = SettingsPrivate::instance(); for (MediaButton *b : _mainWindow->mediaButtons) { connect(sizeButtonsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), b, &MediaButton::setSize); } // Select button theme and size connect(themeComboBox, static_cast<void (QComboBox::*)(const QString &)>(&QComboBox::currentIndexChanged), this, &CustomizeThemeDialog::setThemeNameAndDialogButtons); connect(customizeThemeCheckBox, &QCheckBox::toggled, this, [=](bool b) { settings->setButtonThemeCustomized(b); if (!b) { // Restore all buttons when unchecked for (QCheckBox *button : customizeButtonsScrollArea->findChildren<QCheckBox*>()) { if (!button->isChecked()) { button->toggle(); } } // Restore default image for (MediaButton *b : _mainWindow->mediaButtons) { b->setIcon(QIcon()); } } }); connect(sizeButtonsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), settings, &SettingsPrivate::setButtonsSize); // Hide buttons or not for (MediaButton *b : _mainWindow->mediaButtons) { QCheckBox *checkBox = findChild<QCheckBox *>(b->objectName().replace("Button", "CheckBox")); if (checkBox) { connect(checkBox, &QCheckBox::toggled, [=] (bool visible) { b->setVisible(visible && !_mainWindow->tagEditor->isVisible()); settings->setMediaButtonVisible(b->objectName(), visible); }); } } // Connect a file dialog to every button if one wants to customize everything for (QPushButton *pushButton : customizeButtonsScrollArea->findChildren<QPushButton*>()) { connect(pushButton, &QPushButton::clicked, this, &CustomizeThemeDialog::openChooseIconDialog); } // Extended Search Area connect(radioButtonShowExtendedSearch, &QRadioButton::toggled, settings, &SettingsPrivate::setExtendedSearchVisible); // Volume bar connect(radioButtonShowVolume, &QRadioButton::toggled, this, [=](bool b) { settings->setVolumeBarTextAlwaysVisible(b); _mainWindow->volumeSlider->update(); }); connect(spinBoxHideVolumeLabel, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), settings, &SettingsPrivate::setVolumeBarHideAfter); // Fonts connect(fontComboBoxPlaylist, &QFontComboBox::currentFontChanged, [=](const QFont &font) { settings->setFont(SettingsPrivate::FF_Playlist, font); this->fade(); }); connect(fontComboBoxLibrary, &QFontComboBox::currentFontChanged, [=](const QFont &font) { settings->setFont(SettingsPrivate::FF_Library, font); this->fade(); _mainWindow->library->viewport()->update(); }); connect(fontComboBoxMenus, &QFontComboBox::currentFontChanged, [=](const QFont &font) { settings->setFont(SettingsPrivate::FF_Menu, font); this->fade(); _mainWindow->updateFonts(font); }); // And fonts size connect(spinBoxPlaylist, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int i) { settings->setFontPointSize(SettingsPrivate::FF_Playlist, i); this->fade(); }); connect(spinBoxLibrary, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int i) { settings->setFontPointSize(SettingsPrivate::FF_Library, i); _mainWindow->library->model()->layoutChanged(); QFont lowerFont = settings->font(SettingsPrivate::FF_Library); lowerFont.setPointSize(lowerFont.pointSizeF() * 0.7); _mainWindow->library->model()->setHeaderData(0, Qt::Horizontal, lowerFont, Qt::FontRole); this->fade(); }); connect(spinBoxMenus, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int i) { settings->setFontPointSize(SettingsPrivate::FF_Menu, i); _mainWindow->updateFonts(settings->font(SettingsPrivate::FF_Menu)); this->fade(); }); // Timer connect(_timer, &QTimer::timeout, [=]() { this->animate(0.5, 1.0); }); // Colors connect(enableCustomColorsRadioButton, &QCheckBox::toggled, this, &CustomizeThemeDialog::toggleCustomColors); connect(enableAlternateBGRadioButton, &QRadioButton::toggled, this, &CustomizeThemeDialog::toggleAlternativeBackgroundColor); for (QToolButton *b : groupBoxCustomColors->findChildren<QToolButton*>()) { connect(b, &QToolButton::clicked, this, &CustomizeThemeDialog::showColorDialog); } // Show covers in the Library connect(checkBoxDisplayCovers, &QCheckBox::toggled, [=](bool b) { settings->setCovers(b); if (_mainWindow->library->model()) { _mainWindow->library->model()->layoutChanged(); this->fade(); } }); // Change cover size QTimer *reloadCoverSizeTimer = new QTimer(this); reloadCoverSizeTimer->setSingleShot(true); connect(spinBoxCoverSize, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int cs) { settings->setCoverSize(cs); if (_mainWindow->library->model()) { _mainWindow->library->model()->layoutChanged(); this->fade(); } reloadCoverSizeTimer->start(1000); }); connect(reloadCoverSizeTimer, &QTimer::timeout, _mainWindow->library, &LibraryTreeView::aboutToUpdateCoverSize); // Change big cover opacity connect(radioButtonEnableBigCover, &QRadioButton::toggled, [=](bool b) { settings->setBigCovers(b); labelBigCoverOpacity->setEnabled(b); spinBoxBigCoverOpacity->setEnabled(b); this->fade(); _mainWindow->library->viewport()->repaint(); }); connect(spinBoxBigCoverOpacity, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int v) { settings->setBigCoverOpacity(v); this->fade(); _mainWindow->library->viewport()->repaint(); }); // Filter library connect(radioButtonEnableArticles, &QRadioButton::toggled, this, [=](bool b) { settings->setIsLibraryFilteredByArticles(b); // Don't reorder the library if one hasn't typed an article yet if (!settings->libraryFilteredByArticles().isEmpty()) { _mainWindow->library->model()->rebuildSeparators(); } }); connect(articlesLineEdit, &CustomizeThemeTagLineEdit::taglistHasChanged, this, [=](const QStringList &articles) { settings->setLibraryFilteredByArticles(articles); _mainWindow->library->model()->rebuildSeparators(); }); connect(radioButtonEnableReorderArtistsArticle, &QRadioButton::toggled, this, [=](bool b) { settings->setReorderArtistsArticle(b); this->fade(); _mainWindow->library->viewport()->repaint(); }); // Tabs connect(radioButtonTabsRect, &QRadioButton::toggled, [=](bool b) { settings->setTabsRect(b); this->fade(); _mainWindow->tabPlaylists->tabBar()->update(); _mainWindow->tabPlaylists->cornerWidget(Qt::TopRightCorner)->update(); }); connect(overlapTabsSpinBox, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [=](int v) { settings->setTabsOverlappingLength(v); this->fade(); _mainWindow->tabPlaylists->tabBar()->update(); }); // Star delegates connect(radioButtonEnableStarDelegate, &QRadioButton::toggled, this, [=](bool b) { settings->setDelegates(b); labelLibraryDelegates->setEnabled(b); radioButtonShowNeverScoredTracks->setEnabled(b); radioButtonHideNeverScoredTracks->setEnabled(b); }); connect(radioButtonShowNeverScoredTracks, &QRadioButton::toggled, settings, &SettingsPrivate::setShowNeverScored); }
/** Load theme at startup. */ void CustomizeThemeDialog::loadTheme() { SettingsPrivate *settings = SettingsPrivate::instance(); customizeThemeCheckBox->setChecked(settings->isButtonThemeCustomized()); sizeButtonsSpinBox->setValue(settings->buttonsSize()); // Select the right drop-down item according to the theme int i = 0; while (Settings::instance()->theme() != themeComboBox->itemText(i).toLower()) { i++; } themeComboBox->setCurrentIndex(i); // Buttons for (MediaButton *b : _mainWindow->mediaButtons) { // Check or uncheck checkboxes in this customize interface QCheckBox *checkBox = findChild<QCheckBox *>(b->objectName().replace("Button", "CheckBox")); if (checkBox) { checkBox->setChecked(settings->isMediaButtonVisible(b->objectName())); } // Display customs icons, if any QPushButton *pushButton = findChild<QPushButton *>(b->objectName().remove("Button")); if (pushButton) { pushButton->setIcon(b->icon()); } } // Extended Search Area settings->isExtendedSearchVisible() ? radioButtonShowExtendedSearch->setChecked(true) : radioButtonHideExtendedSearch->setChecked(true); // Volume bar radioButtonShowVolume->setChecked(settings->isVolumeBarTextAlwaysVisible()); spinBoxHideVolumeLabel->setValue(settings->volumeBarHideAfter()); // Fonts fontComboBoxPlaylist->setCurrentFont(settings->font(SettingsPrivate::FF_Playlist)); fontComboBoxLibrary->setCurrentFont(settings->font(SettingsPrivate::FF_Library)); fontComboBoxMenus->setCurrentFont(settings->font(SettingsPrivate::FF_Menu)); spinBoxPlaylist->setValue(settings->fontSize(SettingsPrivate::FF_Playlist)); spinBoxLibrary->blockSignals(true); spinBoxLibrary->setValue(settings->fontSize(SettingsPrivate::FF_Library)); spinBoxLibrary->blockSignals(false); spinBoxMenus->setValue(settings->fontSize(SettingsPrivate::FF_Menu)); // Library checkBoxDisplayCovers->setChecked(settings->isCoversEnabled()); spinBoxCoverSize->blockSignals(true); spinBoxCoverSize->setValue(settings->coverSize()); spinBoxCoverSize->blockSignals(false); // Colors settings->colorsAlternateBG() ? enableAlternateBGRadioButton->setChecked(true) : disableAlternateBGRadioButton->setChecked(true); settings->isCustomColors() ? enableCustomColorsRadioButton->setChecked(true) : disableCustomColorsRadioButton->setChecked(true); this->toggleCustomColors(settings->isCustomColors()); // Covers radioButtonEnableBigCover->setChecked(settings->isBigCoverEnabled()); spinBoxBigCoverOpacity->setValue(settings->bigCoverOpacity() * 100); // Tabs radioButtonTabsRect->setChecked(settings->isRectTabs()); overlapTabsSpinBox->setValue(settings->tabsOverlappingLength()); // Articles radioButtonEnableArticles->blockSignals(true); bool isFiltered = settings->isLibraryFilteredByArticles(); radioButtonEnableArticles->setChecked(isFiltered); std::list<QWidget*> enabled = { articlesLineEdit, labelReorderArtistsArticle, labelReorderArtistsArticleExample, radioButtonEnableReorderArtistsArticle, radioButtonDisableReorderArtistsArticle }; for (QWidget *w : enabled) { w->setEnabled(isFiltered); } radioButtonEnableReorderArtistsArticle->setChecked(settings->isReorderArtistsArticle()); radioButtonEnableArticles->blockSignals(false); // Star delegate if (settings->isStarDelegates()) { radioButtonEnableStarDelegate->setChecked(true); } else { radioButtonDisableStarDelegate->setChecked(true); } if (settings->isShowNeverScored()) { radioButtonShowNeverScoredTracks->setChecked(true); } else { radioButtonHideNeverScoredTracks->setChecked(true); } }