1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-16 19:31:02 +01:00

Make the album cover search results list scroll by pixel instead of item, and re-layout the items when any data changes

This commit is contained in:
David Sansome 2011-06-26 15:06:59 +00:00
parent a36d0706b5
commit dd98f8abc8
8 changed files with 90 additions and 20 deletions

View File

@ -270,6 +270,7 @@ set(SOURCES
widgets/fancytabwidget.cpp
widgets/fileview.cpp
widgets/fileviewlist.cpp
widgets/forcescrollperpixel.cpp
widgets/freespacebar.cpp
widgets/fullscreenhypnotoad.cpp
widgets/groupediconview.cpp

View File

@ -25,6 +25,7 @@
#include "library/libraryquery.h"
#include "library/sqlrow.h"
#include "playlist/songmimedata.h"
#include "widgets/forcescrollperpixel.h"
#include "widgets/maclineedit.h"
#include "ui/albumcoverchoicecontroller.h"
@ -39,7 +40,6 @@
#include <QMessageBox>
#include <QPainter>
#include <QProgressBar>
#include <QScrollBar>
#include <QSettings>
#include <QShortcut>
#include <QTimer>
@ -49,7 +49,6 @@ const char* AlbumCoverManager::kSettingsGroup = "CoverManager";
AlbumCoverManager::AlbumCoverManager(LibraryBackend* backend, QWidget* parent,
QNetworkAccessManager* network)
: QMainWindow(parent),
constructed_(false),
ui_(new Ui_CoverManager),
album_cover_choice_controller_(new AlbumCoverChoiceController(this)),
backend_(backend),
@ -188,7 +187,8 @@ void AlbumCoverManager::Init() {
cover_loader_->Start(true);
CoverLoaderInitialised();
cover_searcher_->Init(cover_fetcher_);
constructed_ = true;
new ForceScrollPerPixel(ui_->albums, this);
}
void AlbumCoverManager::CoverLoaderInitialised() {
@ -423,20 +423,6 @@ void AlbumCoverManager::UpdateStatusText() {
}
}
bool AlbumCoverManager::event(QEvent* e) {
if (constructed_) {
// I think KDE styles override these, and ScrollPerItem is really confusing
// when you have huge items.
// We seem to have to reset them to sensible values each time the contents
// of ui_->albums changes.
ui_->albums->setVerticalScrollMode(QListWidget::ScrollPerPixel);
ui_->albums->verticalScrollBar()->setSingleStep(20);
}
QMainWindow::event(e);
return false;
}
bool AlbumCoverManager::eventFilter(QObject *obj, QEvent *event) {
if (obj == ui_->albums && event->type() == QEvent::ContextMenu) {
context_menu_items_ = ui_->albums->selectedItems();

View File

@ -68,7 +68,6 @@ class AlbumCoverManager : public QMainWindow {
protected:
void showEvent(QShowEvent *);
void closeEvent(QCloseEvent *);
bool event(QEvent *);
// For the album view context menu events
bool eventFilter(QObject *obj, QEvent *event);
@ -139,8 +138,6 @@ class AlbumCoverManager : public QMainWindow {
void SaveAndSetCover(QListWidgetItem* item, const QImage& image);
private:
bool constructed_;
Ui_CoverManager* ui_;
AlbumCoverChoiceController* album_cover_choice_controller_;

View File

@ -20,6 +20,7 @@
#include "core/logging.h"
#include "covers/albumcoverfetcher.h"
#include "covers/albumcoverloader.h"
#include "widgets/forcescrollperpixel.h"
#include "widgets/groupediconview.h"
#include <QKeyEvent>
@ -52,6 +53,8 @@ AlbumCoverSearcher::AlbumCoverSearcher(const QIcon& no_cover_icon, QWidget* pare
connect(ui_->search, SIGNAL(clicked()), SLOT(Search()));
connect(ui_->covers, SIGNAL(doubleClicked(QModelIndex)), SLOT(CoverDoubleClicked(QModelIndex)));
new ForceScrollPerPixel(ui_->covers, this);
}
AlbumCoverSearcher::~AlbumCoverSearcher() {

View File

@ -0,0 +1,39 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "forcescrollperpixel.h"
#include <QAbstractItemView>
#include <QEvent>
#include <QScrollBar>
ForceScrollPerPixel::ForceScrollPerPixel(QAbstractItemView* item_view, QObject* parent)
: QObject(parent),
item_view_(item_view)
{
item_view_->installEventFilter(this);
}
bool ForceScrollPerPixel::eventFilter(QObject* object, QEvent* event) {
if (object == item_view_ && event->type() != QEvent::Destroy) {
item_view_->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
item_view_->verticalScrollBar()->setSingleStep(20);
}
return QObject::eventFilter(object, event);
}

View File

@ -0,0 +1,38 @@
/* This file is part of Clementine.
Copyright 2010, David Sansome <me@davidsansome.com>
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FORCESCROLLPERPIXEL_H
#define FORCESCROLLPERPIXEL_H
#include <QObject>
class QAbstractItemView;
// Some KDE styles override the ScrollMode property of QAbstractItemViews.
// This helper class forces the mode back to ScrollPerPixel.
class ForceScrollPerPixel : public QObject {
public:
ForceScrollPerPixel(QAbstractItemView* item_view, QObject* parent = 0);
protected:
bool eventFilter(QObject* object, QEvent* event);
private:
QAbstractItemView* item_view_;
};
#endif // FORCESCROLLPERPIXEL_H

View File

@ -98,6 +98,11 @@ void GroupedIconView::rowsInserted(const QModelIndex& parent, int start, int end
LayoutItems();
}
void GroupedIconView::dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight) {
QListView::dataChanged(topLeft, bottomRight);
LayoutItems();
}
void GroupedIconView::LayoutItems() {
if (!model())
return;

View File

@ -69,6 +69,7 @@ protected:
void resizeEvent(QResizeEvent* e);
// QAbstractItemView
void dataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);
QModelIndex indexAt(const QPoint& p) const;
void rowsInserted(const QModelIndex& parent, int start, int end);
void setSelection(const QRect& rect, QItemSelectionModel::SelectionFlags command);