Skip to content

Commit

Permalink
Merge pull request #3 from daschuer/libraryFocus
Browse files Browse the repository at this point in the history
Library focus
  • Loading branch information
jmigual authored Dec 1, 2016
2 parents 645cd28 + f02a996 commit 8d539cd
Show file tree
Hide file tree
Showing 12 changed files with 118 additions and 58 deletions.
Binary file added res/images/library/ic_library_lockpreselect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions res/mixxx.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
<file>skins/save_disabled.png</file>
<file>images/library/ic_library_preselect.png</file>
<file>images/library/ic_library_notpreselect.png</file>
<file>images/library/ic_library_lockpreselect.png</file>
<file>images/library/ic_library_pinned.png</file>
</qresource>
</RCC>
63 changes: 39 additions & 24 deletions res/skins/LateNight/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -1270,9 +1270,8 @@ QTableView:focus {

#LibrarySidebarButtons, QTableView, QTextBrowser, QTreeView {
border: 1px solid #585858;
/*font: 15px/18px;*/
color: #cfb32c;
background-color: #191919;
background-color: #0f0f0f;
alternate-background-color: #1a1a1a;

selection-color: #cfb32c;
Expand All @@ -1296,14 +1295,26 @@ WBaseLibrary QLabel {
border: 0px solid blue;
}

QTreeView::item:selected:active,
QTableView::item:selected:active {
color: #cfb32c;
background-color: #725309;
}

QTreeView::item:selected:!active,
QTableView::item:selected:!active {
color: #cfb32c;
background-color: #4c3b11;
}

QTableView:!focus {
selection-background-color: #4c3b11;
}

/* checkbox in library "Played" column */
QTableView::indicator { width: 12px; height: 12px;}
QTableView::indicator:checked { background: url(skin:/style/style_checkbox_checked.png);}
QTableView::indicator:unchecked { background: url(skin:/style/style_checkbox_unchecked.png);}
QTableView::item:selected {
color: #cfb32c;
background-color: #725309;
}

/* BPM lock icon in the library "BPM" column. */
#LibraryBPMButton::indicator:checked { image: url(:/images/library/ic_library_checked.png); }
Expand All @@ -1314,18 +1325,18 @@ QTableView::item:selected {
}

/* Button in library "Preview" column */
QPushButton#LibraryPreviewButton {

#LibraryPreviewButton {
width: 23px;
height: 12px;
background: transparent;
image: url(skin:/style/style_library_preview_play.png);
background-color: transparent;
border: 0px;
}
/*QPushButton#LibraryPreviewButton:focus {
background-color: #725309;
}*/

QPushButton#LibraryPreviewButton:!checked{ image: url(skin:/style/style_library_preview_play.png); }
QPushButton#LibraryPreviewButton:checked{ image: url(skin:/style/style_library_preview_pause.png); }
#LibraryPreviewButton:checked {
image: url(skin:/style/style_library_preview_pause.png);
}

QHeaderView {
font: 13px/15px;
Expand Down Expand Up @@ -1445,26 +1456,30 @@ WBaseLibrary QRadioButton#radioButtonRecentlyAdded { margin: 9px 3px 6px 12px; }
QTreeView { margin: 0px 0px 0px 0px; }

/* triangle for closed/opened branches in treeview */
QTreeView { show-decoration-selected: 0; background-color: #151515; } /* Suppresses that selected sidebar items branch indicator shows wrong color when out of focus ; lp:880588 */
QTreeView::branch,
QTreeView {
background-color: #0f0f0f; } /* Suppresses that selected sidebar items branch indicator shows wrong color when out of focus ; lp:880588 */
QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings { border-image: none; image: url(skin:/style/style_branch_closed.png);
QTreeView::branch:closed:has-children:has-siblings {
border-image: none;
image: url(skin:/style/style_branch_closed.png);
background-color:#0f0f0f;
}
QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings { border-image: none; image: url(skin:/style/style_branch_open.png);
QTreeView::branch:open:has-children:has-siblings {
border-image: none;
image: url(skin:/style/style_branch_open.png);
background-color:#0f0f0f;
}
QTreeView::branch:has-children:!has-siblings:closed:selected,
QTreeView::branch:closed:has-children:has-siblings:selected { border-image: none; image: url(skin:/style/style_branch_closed.png);
background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #585858, stop:1 #0f0f0f);
QTreeView::branch:closed:has-children:has-siblings:selected {
border-image: none;
image: url(skin:/style/style_branch_closed.png);
}
QTreeView::branch:open:has-children:!has-siblings:selected,
QTreeView::branch:open:has-children:has-siblings:selected { border-image: none; image: url(skin:/style/style_branch_open.png);
background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #585858, stop:1 #0f0f0f);
}
QTreeView::item:selected {
background-color:qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #585858, stop:1 #0f0f0f);
color: #cfb32c;
QTreeView::branch:open:has-children:has-siblings:selected {
border-image: none;
image: url(skin:/style/style_branch_open.png);
}

WLibrary[showFocus="0"] {
Expand Down
18 changes: 12 additions & 6 deletions src/library/coverartdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,18 @@ void CoverArtDelegate::slotCoverFound(const QObject* pRequestor,
}
}

void CoverArtDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const {
if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.highlight());
}
void CoverArtDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const {

QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index);

// Draw original item without text as background
opt.text = QString();
const QWidget *widget = opt.widget;
QStyle *style = widget ? widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);

CoverArtCache* pCache = CoverArtCache::instance();
if (pCache == NULL || m_iIdColumn == -1 || m_iCoverSourceColumn == -1 ||
Expand Down
7 changes: 6 additions & 1 deletion src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,16 +698,21 @@ void Library::handleFocus() {

void Library::handlePreselection() {
for (LibraryPaneManager* pPane : m_panes) {


pPane->setPreselected(false);
pPane->setPreviewed(false);



}
LibraryPaneManager* pSelectedPane = m_panes.value(m_preselectedPane);
if (pSelectedPane) {
pSelectedPane->setPreselected(true);
} else {
pSelectedPane = m_panes.value(m_previewPreselectedPane);
if (pSelectedPane) {
pSelectedPane->setPreselected(true);
pSelectedPane->setPreviewed(true);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/library/librarypanemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ void LibraryPaneManager::setPreviewed(bool value) {
}

void LibraryPaneManager::slotPanePreselected(bool value) {
// Preselect button clicked
setPreselected(value);
m_pLibrary->panePreselected(this, value);
}
Expand Down
25 changes: 16 additions & 9 deletions src/library/previewbuttondelegate.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <QPainter>
#include <QPushButton>
#include <QStylePainter>

#include "library/previewbuttondelegate.h"
#include "library/trackmodel.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ QWidget* PreviewButtonDelegate::createEditor(QWidget *parent,
QPushButton* btn = new QPushButton(parent);
btn->setObjectName("LibraryPreviewButton");
btn->setCheckable(true);
btn->setFocusPolicy(Qt::ClickFocus);
btn->setFocusPolicy(Qt::NoFocus);
bool playing = m_pPreviewDeckPlay->toBool();
// Check-state is whether the track is loaded (index.data()) and whether
// it's playing.
Expand All @@ -74,10 +75,20 @@ void PreviewButtonDelegate::setModelData(QWidget *editor,
Q_UNUSED(index);
}

void PreviewButtonDelegate::paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const {
// Let the editor paint in this case
void PreviewButtonDelegate::paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index) const {

QStyleOptionViewItemV4 opt = option;
initStyleOption(&opt, index);

// Draw original item without text as background
opt.text = QString();
const QWidget *widget = opt.widget;
QStyle *style = widget ? widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, widget);

// Let the editor paint the button in this case
if (index == m_currentEditedCellIndex) {
return;
}
Expand All @@ -92,10 +103,6 @@ void PreviewButtonDelegate::paint(QPainter *painter,
// it's playing.
m_pButton->setChecked(index.data().toBool() && playing);

if (option.state == QStyle::State_Selected) {
painter->fillRect(option.rect, option.palette.base());
}

painter->save();
// Render button at the desired position
painter->translate(option.rect.topLeft());
Expand Down
8 changes: 5 additions & 3 deletions src/widget/wlibrarybreadcrumb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ WLibraryBreadCrumb::WLibraryBreadCrumb(QWidget* parent)
layout->addWidget(m_pIcon);
layout->addWidget(m_pText);

QPixmap preOn(WPixmapStore::getLibraryPixmap(
QPixmap preHovered(WPixmapStore::getLibraryPixmap(
":/images/library/ic_library_preselect.png"));
QPixmap preOff(WPixmapStore::getLibraryPixmap(
":/images/library/ic_library_notpreselect.png"));
QPixmap preLock(WPixmapStore::getLibraryPixmap(
":/images/library/ic_library_lockpreselect.png"));

m_preselectIcon.addPixmap(preOn, QIcon::Normal, QIcon::On);
m_preselectIcon.addPixmap(preLock, QIcon::Normal, QIcon::On);
m_preselectIcon.addPixmap(preOff, QIcon::Normal, QIcon::Off);
m_preselectIcon.addPixmap(preOn, QIcon::Active, QIcon::Off);
m_preselectIcon.addPixmap(preHovered, QIcon::Active, QIcon::Off);
m_pPreselectButton->setIcon(m_preselectIcon);
m_pPreselectButton->setChecked(m_preselected);
m_pPreselectButton->setFocusPolicy(Qt::ClickFocus);
Expand Down
33 changes: 24 additions & 9 deletions src/widget/wlibrarysidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void WSidebarItemDelegate::paint(QPainter* painter,
painter->drawLine(option.rect.bottomLeft(), option.rect.bottomRight());
}


WLibrarySidebar::WLibrarySidebar(QWidget* parent)
: QTreeView(parent),
WBaseWidget(this) {
Expand Down Expand Up @@ -122,7 +121,7 @@ void WLibrarySidebar::dragMoveEvent(QDragMoveEvent * event) {
if (treeModel) {
accepted = false;
for (const QUrl& url : urls) {
QModelIndex destIndex = this->indexAt(event->pos());
QModelIndex destIndex = indexAt(event->pos());
if (treeModel->dragMoveAccept(destIndex, url)) {
accepted = true;
break;
Expand Down Expand Up @@ -165,7 +164,7 @@ void WLibrarySidebar::dropEvent(QDropEvent * event) {
event->ignore();
} else {
//Reset the selected items (if you had anything highlighted, it clears it)
//this->selectionModel()->clear();
//selectionModel()->clear();
//Drag-and-drop from an external application or the track table widget
//eg. dragging a track from Windows Explorer onto the sidebar
TreeItemModel* pTreeModel = dynamic_cast<TreeItemModel*>(model());
Expand All @@ -186,9 +185,8 @@ void WLibrarySidebar::dropEvent(QDropEvent * event) {
}
}


void WLibrarySidebar::toggleSelectedItem() {
QModelIndexList selectedIndices = this->selectionModel()->selectedRows();
QModelIndexList selectedIndices = selectionModel()->selectedRows();
if (selectedIndices.size() > 0) {
QModelIndex index = selectedIndices.at(0);
// Activate the item so its content shows in the main library.
Expand All @@ -198,6 +196,14 @@ void WLibrarySidebar::toggleSelectedItem() {
}
}

bool WLibrarySidebar::isDividerSelected() {
QModelIndex current = currentIndex();
if (current.isValid()) {
return current.data(AbstractRole::RoleDivider).toBool();
}
return false;
}

void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
qDebug() << "WLibrarySidebar::keyPressEvent" << event;
if (event == QKeySequence::Copy) {
Expand All @@ -213,8 +219,7 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
// or an undo feature
event->ignore();
} else if (event == QKeySequence::SelectAll) {
selectAll();
event->accept();
event->ignore();
} else if ((event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) &&
event->modifiers() == Qt::NoModifier) {
toggleSelectedItem();
Expand All @@ -223,15 +228,25 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
// TODO(XXX) allow delete by key but with a safety pop up
// or an undo feature
event->ignore();
} else if (event->key() == Qt::Key_Down &&
event->modifiers() == Qt::NoModifier) {
QTreeView::keyPressEvent(event);
if (isDividerSelected()) {
QTreeView::keyPressEvent(event);
}
} else if (event->key() == Qt::Key_Up &&
event->modifiers() == Qt::NoModifier) {
QTreeView::keyPressEvent(event);
if (isDividerSelected()) {
QTreeView::keyPressEvent(event);
}
} else {
// QTreeView::keyPressEvent(event) will consume all key events due to
// it's keyboardSearch feature.
// In Mixxx, we prefer that most keyboard mappings are working, so we
// pass only some basic keys to the base class
if (event->modifiers() == Qt::NoModifier) {
switch (event->key()) {
case Qt::Key_Down:
case Qt::Key_Up:
case Qt::Key_Left:
case Qt::Key_Right:
case Qt::Key_Home:
Expand Down
1 change: 1 addition & 0 deletions src/widget/wlibrarysidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class WLibrarySidebar : public QTreeView, public WBaseWidget {

private:
bool paste();
bool isDividerSelected();

QBasicTimer m_expandTimer;
QModelIndex m_hoverIndex;
Expand Down
1 change: 0 additions & 1 deletion src/widget/wtracktableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,6 @@ void WTrackTableView::loadTrackModel(QAbstractItemModel *model) {
setHorizontalHeader(header);
header->setMovable(true);
header->setClickable(true);
header->setHighlightSections(true);
header->setSortIndicatorShown(m_sorting);
header->setDefaultAlignment(Qt::AlignLeft);

Expand Down
Loading

0 comments on commit 8d539cd

Please sign in to comment.