Permalink
Browse files

Fix jumpy scrolling in Account Settings.

  • Loading branch information...
1 parent 3d94dc1 commit e7014caecbf37b99626d76633dc0d127d7570688 @teo teo committed Jan 17, 2013
View
@@ -61,6 +61,7 @@ SET( tomahawkSourcesGui ${tomahawkSourcesGui}
SocialWidget.cpp
widgets/ContainedMenuButton.cpp
+ widgets/AccountListView.cpp
widgets/AccountListWidget.cpp
widgets/AccountModelFactoryProxy.cpp
widgets/AccountWidget.cpp
View
@@ -55,7 +55,7 @@
</layout>
</item>
<item>
- <widget class="QListView" name="accountsView">
+ <widget class="AccountListView" name="accountsView">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
@@ -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/>
@@ -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
@@ -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 )
@@ -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
@@ -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 );
+}
@@ -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.