Skip to content

Commit

Permalink
Fix jumpy scrolling in Account Settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
teo committed Jan 17, 2013
1 parent 3d94dc1 commit e7014ca
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -61,6 +61,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
SocialWidget.cpp

widgets/ContainedMenuButton.cpp
widgets/AccountListView.cpp
widgets/AccountListWidget.cpp
widgets/AccountModelFactoryProxy.cpp
widgets/AccountWidget.cpp
Expand Down
7 changes: 6 additions & 1 deletion src/Settings_Accounts.ui
Expand Up @@ -55,7 +55,7 @@
</layout>
</item>
<item>
<widget class="QListView" name="accountsView">
<widget class="AccountListView" name="accountsView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
Expand All @@ -76,6 +76,11 @@
<header>thirdparty/Qocoa/qbutton.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>AccountListView</class>
<extends>QListView</extends>
<header>widgets/AccountListView.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
8 changes: 1 addition & 7 deletions src/libtomahawk/accounts/AccountDelegate.cpp
Expand Up @@ -39,12 +39,6 @@
#define PADDING_BETWEEN_STARS 2
#define STAR_SIZE 12

#ifdef Q_OS_MAC
#define ROW_HEIGHT_MULTIPLIER 4.9
#else
#define ROW_HEIGHT_MULTIPLIER 5.7
#endif

#define ICONSIZE 40
#define WRENCH_SIZE 24
#define SMALL_WRENCH_SIZE 16
Expand Down Expand Up @@ -72,7 +66,7 @@ AccountDelegate::sizeHint( const QStyleOptionViewItem& option, const QModelIndex
// Haven't calculated normal item height yet, do it once and save it
QStyleOptionViewItemV4 opt( option );
initStyleOption( &opt, index );
m_accountRowHeight = ROW_HEIGHT_MULTIPLIER * opt.fontMetrics.height();
m_accountRowHeight = ACCOUNT_DELEGATE_ROW_HEIGHT_MULTIPLIER * opt.fontMetrics.height();
}

if ( rowType == AccountModel::TopLevelAccount || rowType == AccountModel::UniqueFactory || rowType == AccountModel::CustomAccount )
Expand Down
8 changes: 8 additions & 0 deletions src/libtomahawk/accounts/AccountDelegate.h
Expand Up @@ -23,6 +23,14 @@
#include <QStyledItemDelegate>
#include "accounts/AccountModel.h"


#ifdef Q_OS_MAC
#define ACCOUNT_DELEGATE_ROW_HEIGHT_MULTIPLIER 4.9
#else
#define ACCOUNT_DELEGATE_ROW_HEIGHT_MULTIPLIER 5.7
#endif


class AnimatedSpinner;

namespace Tomahawk
Expand Down
38 changes: 38 additions & 0 deletions src/widgets/AccountListView.cpp
@@ -0,0 +1,38 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk 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.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/

#include "AccountListView.h"
#include "accounts/AccountDelegate.h"

#include <QScrollBar>

AccountListView::AccountListView( QWidget* parent )
: QListView( parent )
{}

void
AccountListView::wheelEvent( QWheelEvent* e )
{
//HACK: Workaround for QTBUG-7232: Smooth scrolling (scroll per pixel) in ItemViews
// does not work as expected.
#ifdef Q_WS_X11
verticalScrollBar()->setSingleStep( ACCOUNT_DELEGATE_ROW_HEIGHT_MULTIPLIER * fontMetrics().height() / 8 );
// ^ scroll step is 1/8 of the estimated row height
#endif
QListView::wheelEvent( e );
}
38 changes: 38 additions & 0 deletions src/widgets/AccountListView.h
@@ -0,0 +1,38 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* Copyright 2013, Teo Mrnjavac <teo@kde.org>
*
* Tomahawk 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.
*
* Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ACCOUNTLISTVIEW_H
#define ACCOUNTLISTVIEW_H

#include <QListView>

/**
* @brief The AccountListView class does not add functionality, it just implements a
* much needed workaround that fixes a scrolling issue with large delegates.
*/
class AccountListView : public QListView
{
Q_OBJECT
public:
explicit AccountListView( QWidget* parent = 0 );

protected:
void wheelEvent( QWheelEvent* );
};

#endif // ACCOUNTLISTVIEW_H

0 comments on commit e7014ca

Please sign in to comment.