mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Nicer solution to the activate on click problem
This commit is contained in:
parent
ec0d2d7c17
commit
11d7dac241
@ -6,6 +6,7 @@
|
||||
#include <QStyle>
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QProxyStyle>
|
||||
|
||||
QProgressIndicator::QProgressIndicator(QWidget* parent, int size)
|
||||
: QWidget(parent),
|
||||
@ -159,3 +160,15 @@ bool do_notify(QObject *receiver, QEvent *event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
class NoActivateStyle: public QProxyStyle {
|
||||
public:
|
||||
int styleHint(StyleHint hint, const QStyleOption *option = 0, const QWidget *widget = 0, QStyleHintReturn *returnData = 0) const {
|
||||
if (hint == QStyle::SH_ItemView_ActivateItemOnSingleClick) return 0;
|
||||
return QProxyStyle::styleHint(hint, option, widget, returnData);
|
||||
}
|
||||
};
|
||||
|
||||
void set_no_activate_on_click(QWidget *widget) {
|
||||
widget->setStyle(new NoActivateStyle);
|
||||
}
|
||||
|
||||
|
@ -102,3 +102,4 @@ int load_style(QString &path, QString &name);
|
||||
|
||||
bool do_notify(QObject *receiver, QEvent *event);
|
||||
|
||||
void set_no_activate_on_click(QWidget *widget);
|
||||
|
@ -9,6 +9,7 @@
|
||||
%ModuleHeaderCode
|
||||
int load_style(QString &path, QString &name);
|
||||
bool do_notify(QObject *receiver, QEvent *event);
|
||||
void set_no_activate_on_click(QWidget *widget);
|
||||
%End
|
||||
|
||||
class QProgressIndicator : QWidget {
|
||||
@ -60,3 +61,4 @@ int load_style(QString &path, QString &name);
|
||||
|
||||
bool do_notify(QObject *receiver, QEvent *event);
|
||||
|
||||
void set_no_activate_on_click(QWidget *widget);
|
||||
|
@ -9,8 +9,9 @@ __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
from PyQt4.Qt import (
|
||||
QDialog, pyqtSignal, QIcon, QVBoxLayout, QDialogButtonBox, QStackedWidget,
|
||||
QAction, QMenu, QTreeWidget, QTreeWidgetItem, QGridLayout, QWidget, Qt,
|
||||
QSize, QStyledItemDelegate, QTimer)
|
||||
QSize, QStyledItemDelegate)
|
||||
|
||||
from calibre.constants import plugins
|
||||
from calibre.ebooks.oeb.polish.toc import commit_toc, get_toc
|
||||
from calibre.gui2 import gprefs, error_dialog
|
||||
from calibre.gui2.toc.main import TOCView, ItemEdit
|
||||
@ -125,12 +126,14 @@ class TOCViewer(QWidget):
|
||||
self.view.setContextMenuPolicy(Qt.CustomContextMenu)
|
||||
self.view.customContextMenuRequested.connect(self.show_context_menu, type=Qt.QueuedConnection)
|
||||
self.view.itemActivated.connect(self.emit_navigate)
|
||||
self.view.itemClicked.connect(self.emit_navigate)
|
||||
pi = plugins['progress_indicator'][0]
|
||||
if hasattr(pi, 'set_no_activate_on_click'):
|
||||
pi.set_no_activate_on_click(self.view)
|
||||
self.view.itemDoubleClicked.connect(self.emit_navigate)
|
||||
l.addWidget(self.view)
|
||||
|
||||
self.refresh_action = QAction(QIcon(I('view-refresh.png')), _('&Refresh'), self)
|
||||
self.refresh_action.triggered.connect(self.build)
|
||||
self._last_nav_request = None
|
||||
|
||||
def show_context_menu(self, pos):
|
||||
menu = QMenu(self)
|
||||
@ -156,15 +159,7 @@ class TOCViewer(QWidget):
|
||||
frag = unicode(item.data(0, FRAG_ROLE).toString())
|
||||
if not frag:
|
||||
frag = TOP
|
||||
# Debounce as on some platforms clicking causes both itemActivated
|
||||
# and itemClicked to be emitted
|
||||
self._last_nav_request = (dest, frag)
|
||||
QTimer.singleShot(0, self._emit_navigate)
|
||||
|
||||
def _emit_navigate(self):
|
||||
if self._last_nav_request is not None:
|
||||
self.navigate_requested.emit(*self._last_nav_request)
|
||||
self._last_nav_request = None
|
||||
self.navigate_requested.emit(dest, frag)
|
||||
|
||||
def build(self):
|
||||
c = current_container()
|
||||
|
Loading…
x
Reference in New Issue
Block a user