File indexing completed on 2024-05-05 04:47:27
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2009 Mark Kretschmann <kretschmann@kde.org> * 0004 * * 0005 * This program is free software; you can redistribute it and/or modify it under * 0006 * the terms of the GNU General Public License as published by the Free Software * 0007 * Foundation; either version 2 of the License, or (at your option) any later * 0008 * version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0011 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0012 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License along with * 0015 * this program. If not, see <http://www.gnu.org/licenses/>. * 0016 ****************************************************************************************/ 0017 0018 #include "BrowserDock.h" 0019 0020 #include "core/logger/Logger.h" 0021 #include "core/support/Amarok.h" 0022 #include "core/support/Components.h" 0023 #include "core/support/Debug.h" 0024 #include "PaletteHandler.h" 0025 #include "widgets/BoxWidget.h" 0026 #include "widgets/HorizontalDivider.h" 0027 0028 #include <QAction> 0029 #include <QIcon> 0030 0031 #include <KLocalizedString> 0032 0033 BrowserDock::BrowserDock( QWidget *parent ) 0034 : AmarokDockWidget( i18n( "&Media Sources" ), parent ) 0035 { 0036 setObjectName( QStringLiteral("Media Sources dock") ); 0037 setAllowedAreas( Qt::AllDockWidgetAreas ); 0038 0039 //we have to create this here as it is used when setting up the 0040 //categories (unless of course we move that to polish as well...) 0041 m_mainWidget = new BoxWidget( true, this ); 0042 setWidget( m_mainWidget ); 0043 m_mainWidget->setContentsMargins( 0, 0, 0, 0 ); 0044 m_mainWidget->setFrameShape( QFrame::NoFrame ); 0045 m_mainWidget->setMinimumWidth( 200 ); 0046 m_mainWidget->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Ignored ); 0047 m_mainWidget->setFocus( Qt::ActiveWindowFocusReason ); 0048 0049 m_breadcrumbWidget = new BrowserBreadcrumbWidget( m_mainWidget ); 0050 new HorizontalDivider( m_mainWidget ); 0051 m_categoryList = new BrowserCategoryList( QStringLiteral("root list"), m_mainWidget ); 0052 m_breadcrumbWidget->setRootList( m_categoryList.data() ); 0053 0054 m_messageArea = new BrowserMessageArea( m_mainWidget ); 0055 m_messageArea->setAutoFillBackground( true ); 0056 //TODO: set dynamic height for hidpi displays 0057 m_messageArea->setFixedHeight( 36 ); 0058 0059 ensurePolish(); 0060 } 0061 0062 BrowserDock::~BrowserDock() 0063 {} 0064 0065 void BrowserDock::polish() 0066 { 0067 m_categoryList->setIcon( QIcon::fromTheme( QStringLiteral("user-home") ) ); 0068 0069 m_categoryList->setMinimumSize( 100, 300 ); 0070 0071 connect( m_breadcrumbWidget, &BrowserBreadcrumbWidget::toHome, this, &BrowserDock::home ); 0072 0073 // Keyboard shortcut for going back one level 0074 QAction *action = new QAction( QIcon::fromTheme( QStringLiteral("go-up") ), i18n( "Go Up in Media Sources Pane" ), 0075 m_mainWidget ); 0076 Amarok::actionCollection()->addAction( QStringLiteral("browser_previous"), action ); 0077 connect( action, &QAction::triggered, m_categoryList.data(), &BrowserCategoryList::back ); 0078 // action->setShortcut( QKeySequence( Qt::Key_Backspace ) ); 0079 action->setShortcut( Qt::Key_Backspace ); 0080 0081 paletteChanged( palette() ); 0082 0083 connect( The::paletteHandler(), &PaletteHandler::newPalette, this, &BrowserDock::paletteChanged ); 0084 } 0085 0086 BrowserCategoryList *BrowserDock::list() const 0087 { 0088 return m_categoryList.data(); 0089 } 0090 0091 void 0092 BrowserDock::navigate( const QString &target ) 0093 { 0094 m_categoryList->navigate( target ); 0095 } 0096 0097 void 0098 BrowserDock::home() 0099 { 0100 m_categoryList->home(); 0101 } 0102 0103 void 0104 BrowserDock::paletteChanged( const QPalette &palette ) 0105 { 0106 m_messageArea->setStyleSheet( 0107 QString( "QFrame#BrowserMessageArea { border: 1px ridge %1; " \ 0108 "background-color: %2; color: %3; border-radius: 3px; }" \ 0109 "QLabel { color: %3; }" ) 0110 .arg( palette.color( QPalette::Active, QPalette::Window ).name(), 0111 palette.color( QPalette::Active, QPalette::Mid ).name(), 0112 palette.color( QPalette::Active, QPalette::HighlightedText ).name() ) 0113 ); 0114 } 0115