Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions reader/sidebar/SideBarImageListview.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 - 2026 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "SideBarImageListview.h"
#include "DocSheet.h"
#include "SideBarImageViewModel.h"
#include "Application.h"

Check warning on line 9 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "Application.h" not found.

Check warning on line 9 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "Application.h" not found.
#include "MsgHeader.h"

Check warning on line 10 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "MsgHeader.h" not found.

Check warning on line 10 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "MsgHeader.h" not found.
#include "ThumbnailWidget.h"
#include "ddlog.h"

Check warning on line 12 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: "ddlog.h" not found.

Check warning on line 12 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "ddlog.h" not found.

#include <QScroller>

Check warning on line 14 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QScroller> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QScroller> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QScrollBar>

Check warning on line 15 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QScrollBar> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QScrollBar> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QSet>

Check warning on line 16 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QSet> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 16 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSet> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMouseEvent>

Check warning on line 17 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 17 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMouseEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QKeyEvent>

Check warning on line 18 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QKeyEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 18 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QKeyEvent> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QDebug>

Check warning on line 19 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 19 in reader/sidebar/SideBarImageListview.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.
SideBarImageListView::SideBarImageListView(DocSheet *sheet, QWidget *parent)
: DListView(parent)
, m_docSheet(sheet)
Expand All @@ -24,7 +26,8 @@
setAutoScroll(false);
setProperty("adaptScale", 1.0);
setSpacing(4);
setFocusPolicy(Qt::NoFocus);
setObjectName("sideBarImageListView");
setFocusPolicy(Qt::ClickFocus);
setFrameShape(QFrame::NoFrame);
setSelectionMode(QAbstractItemView::SingleSelection);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
Expand Down Expand Up @@ -212,6 +215,57 @@
// qCDebug(appLog) << "SideBarImageListView::mousePressEvent end";
}

void SideBarImageListView::keyPressEvent(QKeyEvent *event)
{
if (m_docSheet) {
switch (event->key()) {
case Qt::Key_Up:
m_docSheet->jumpToPrevPage();
event->accept();
return;
case Qt::Key_Down:
m_docSheet->jumpToNextPage();
event->accept();
return;
case Qt::Key_PageUp: {
ThumbnailWidget *tw = qobject_cast<ThumbnailWidget *>(parentWidget());
if (tw) tw->pageUp();
event->accept();
return;
}
case Qt::Key_PageDown: {
ThumbnailWidget *tw = qobject_cast<ThumbnailWidget *>(parentWidget());
if (tw) tw->pageDown();
event->accept();
return;
}
default:
break;
}
}
DListView::keyPressEvent(event);
}

bool SideBarImageListView::event(QEvent *event)
{
// 焦点在缩略图列表时,接受 ShortcutOverride 以抑制 Central 注册的窗口级
// 快捷键(Up/Down 文档滚动),使按键作为普通 KeyPress 交给 keyPressEvent 翻页
if (event->type() == QEvent::ShortcutOverride) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key()) {
case Qt::Key_Up:
case Qt::Key_Down:
case Qt::Key_PageUp:
case Qt::Key_PageDown:
event->accept();
return true;
default:
break;
}
}
return DListView::event(event);
}

void SideBarImageListView::showNoteMenu(const QPoint &point)
{
qCDebug(appLog) << "Showing note menu at:" << point;
Expand Down
20 changes: 18 additions & 2 deletions reader/sidebar/SideBarImageListview.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -17,6 +17,7 @@ class SideBarImageViewModel;
class BookMarkMenu;
class NoteMenu;
class QMouseEvent;
class QKeyEvent;

const int LEFTMINWIDTH = 266;
const int LEFTMAXWIDTH = 380;
Expand Down Expand Up @@ -166,6 +167,21 @@ private slots:
*/
void mousePressEvent(QMouseEvent *event);

/**
* @brief keyPressEvent
* 键盘事件,处理 Up/Down/PageUp/PageDown 导航
* @param event
*/
void keyPressEvent(QKeyEvent *event) override;

/**
* @brief event
* 拦截 ShortcutOverride,抑制 Central 的窗口级翻页快捷键,
* 使方向键/翻页键交由本控件 keyPressEvent 处理
* @param event
*/
bool event(QEvent *event) override;

private:
int m_listType;
DocSheet *m_docSheet;
Expand Down
33 changes: 31 additions & 2 deletions reader/widgets/PagingWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -7,9 +7,10 @@
#include "DocSheet.h"
#include "TMFunctionThread.h"
#include "ddlog.h"
#include <QDebug>

Check warning on line 10 in reader/widgets/PagingWidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in reader/widgets/PagingWidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QValidator>
#include <QKeyEvent>

#include <DGuiApplicationHelper>
#include <DApplication>
Expand All @@ -30,6 +31,33 @@
connect(m_tmFuncThread, &TMFunctionThread::finished, this, &PagingWidget::onFuncThreadFinished);
}

bool PagingWidget::eventFilter(QObject *obj, QEvent *event)
{
// 页数框获得焦点时,方向键/翻页键应翻页,且不能让事件穿透到 Central 的窗口级
// 快捷键(文档滚动)。必须同时处理 ShortcutOverride(抑制快捷键)和 KeyPress(执行翻页)。
if (m_pJumpPageLineEdit && obj == m_pJumpPageLineEdit->lineEdit()
&& (event->type() == QEvent::ShortcutOverride || event->type() == QEvent::KeyPress)) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
switch (keyEvent->key()) {
case Qt::Key_Up:
case Qt::Key_PageUp:
if (event->type() == QEvent::KeyPress && m_sheet)
m_sheet->jumpToPrevPage();
event->accept();
return true;
case Qt::Key_Down:
case Qt::Key_PageDown:
if (event->type() == QEvent::KeyPress && m_sheet)
m_sheet->jumpToNextPage();
event->accept();
return true;
default:
break;
}
}
return BaseWidget::eventFilter(obj, event);
}

PagingWidget::~PagingWidget()
{
qCDebug(appLog) << "PagingWidget destroyed";
Expand Down Expand Up @@ -59,6 +87,7 @@
m_pJumpPageLineEdit->setClearButtonEnabled(false);
connect(m_pJumpPageLineEdit, SIGNAL(returnPressed()), SLOT(SlotJumpPageLineEditReturnPressed()));
connect(m_pJumpPageLineEdit, SIGNAL(editingFinished()), SLOT(onEditFinished()));
m_pJumpPageLineEdit->lineEdit()->installEventFilter(this);

Dtk::Widget::DFontSizeManager::instance()->bind(m_pJumpPageLineEdit->lineEdit(), Dtk::Widget::DFontSizeManager::T6, true);

Expand Down
7 changes: 5 additions & 2 deletions reader/widgets/PagingWidget.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -51,6 +51,9 @@ class PagingWidget : public BaseWidget
*/
void setTabOrderWidget(QList<QWidget *> &tabWidgetlst);

protected:
bool eventFilter(QObject *obj, QEvent *event) override;

private slots:
/**
* @brief slotPrePageBtnClicked
Expand Down
29 changes: 27 additions & 2 deletions reader/widgets/ScaleWidget.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -9,6 +9,8 @@

#include <QHBoxLayout>
#include <QLineEdit>
#include <QKeyEvent>
#include <QEvent>
#include <DApplication>
#include <DFontSizeManager>

Expand Down Expand Up @@ -64,6 +66,7 @@ void ScaleWidget::initWidget()
connect(m_lineEdit, SIGNAL(returnPressed()), SLOT(onReturnPressed()));
connect(m_lineEdit, SIGNAL(editingFinished()), SLOT(onEditFinished()));
connect(m_arrowBtn, SIGNAL(clicked()), SLOT(onArrowBtnlicked()));
m_lineEdit->lineEdit()->installEventFilter(this);

DIconButton *pPreBtn = new DIconButton(DStyle::SP_DecreaseElement, this);
pPreBtn->setObjectName("SP_DecreaseElement");
Expand All @@ -84,6 +87,28 @@ void ScaleWidget::initWidget()
qCDebug(appLog) << "ScaleWidget::initWidget end";
}

bool ScaleWidget::eventFilter(QObject *obj, QEvent *event)
{
// 缩放框获得焦点时,Up/Down 调整缩放比,且不能让事件穿透到 Central 的窗口级
// 快捷键(文档滚动)。必须同时处理 ShortcutOverride(抑制快捷键)和 KeyPress(执行缩放)。
if (m_lineEdit && obj == m_lineEdit->lineEdit()
&& (event->type() == QEvent::ShortcutOverride || event->type() == QEvent::KeyPress)) {
QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
if (keyEvent->key() == Qt::Key_Up) {
if (event->type() == QEvent::KeyPress)
onNextScale(); // Up = 放大
event->accept();
return true;
} else if (keyEvent->key() == Qt::Key_Down) {
if (event->type() == QEvent::KeyPress)
onPrevScale(); // Down = 缩小
event->accept();
return true;
}
}
return DWidget::eventFilter(obj, event);
}

void ScaleWidget::onPrevScale()
{
qCDebug(appLog) << "Zoom out requested";
Expand Down
11 changes: 9 additions & 2 deletions reader/widgets/ScaleWidget.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright (C) 2019 ~ 2020 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
// Copyright (C) 2019 - 2026 Uniontech Software Technology Co.,Ltd.
// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -45,6 +45,13 @@ class ScaleWidget : public Dtk::Widget::DWidget
*/
void clear();

protected:
/**
* @brief eventFilter
* 缩放框获得焦点时拦截方向键,调整缩放比而非滚动文档
*/
bool eventFilter(QObject *obj, QEvent *event) override;

private:
/**
* @brief initWidget
Expand Down
Loading