[graphics/kuickshow] src: ImageWindow: Handle "go to first/last image" as viewer actions
Jonathan Marten <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 93338eb54b04fa33fb3f350d242f2893a6d65f92 by Jonathan Marten.
Committed on 06/08/2026 at 18:14.
Pushed by marten into branch 'master'.
ImageWindow: Handle "go to first/last image" as viewer actions
With the standard shortcuts and icons, instead of having to handle
the key presses specially in KuickShow::eventFilter().
M +17 -0 src/imagewindow.cpp
M +14 -30 src/kuickshow.cpp
https://invent.kde.org/graphics/kuickshow/-/commit/93338eb54b04fa33fb3f350d242f2893a6d65f92
diff --git a/src/imagewindow.cpp b/src/imagewindow.cpp
index 6ab0d6b..dfbdf99 100644
--- a/src/imagewindow.cpp
+++ b/src/imagewindow.cpp
@@ -131,6 +131,23 @@ void ImageWindow::setupActions()
act->setText( i18n("Show Previous Image") );
m_actions->addAction( "previous_image", act );
+ // Image navigation actions, not in context menu or toolbar
+ act = KStandardAction::firstPage(this, [this]() { Q_EMIT requestImage(this, INT_MIN); }, m_actions);
+ act->setText(i18n("Show First Image"));
+
+ auto cuts = act->shortcuts();
+ if (!cuts.contains(Qt::Key_Home)) cuts.prepend(Qt::Key_Home);
+ m_actions->addAction("first_image", act);
+ m_actions->setDefaultShortcuts(act, cuts);
+
+ act = KStandardAction::lastPage(this, [this]() { Q_EMIT requestImage(this, INT_MAX); }, m_actions);
+ act->setText(i18n("Show Last Image"));
+
+ cuts = act->shortcuts();
+ if (!cuts.contains(Qt::Key_End)) cuts.prepend(Qt::Key_End);
+ m_actions->addAction("last_image", act);
+ m_actions->setDefaultShortcuts(act, cuts);
+
act = m_actions->addAction( "duplicate_window", this, [this]() { Q_EMIT duplicateWindow(currentFile()->url()); });
act->setText( i18n("Duplicate Window") );
act->setIcon( QIcon::fromTheme("edit-duplicate") );
diff --git a/src/kuickshow.cpp b/src/kuickshow.cpp
index 4ebcce9..3362b69 100644
--- a/src/kuickshow.cpp
+++ b/src/kuickshow.cpp
@@ -796,12 +796,19 @@ void KuickShow::slotAdvanceImage( ImageWindow *view, int steps )
return;
}
- if ( steps > 0 ) {
+ if ( steps == INT_MIN ) {
+ item = fileWidget->gotoFirstImage();
+ item_next = fileWidget->getNext(false);
+ }
+ else if ( steps == INT_MAX ) {
+ item = fileWidget->gotoLastImage();
+ item_next = fileWidget->getPrevious(false);
+ }
+ else if ( steps > 0 ) {
for ( int i = 0; i < steps; i++ )
item = fileWidget->getNext( true );
item_next = fileWidget->getNext( false );
}
-
else if ( steps < 0 ) {
for ( int i = steps; i < 0; i++ )
item = fileWidget->getPrevious( true );
@@ -930,22 +937,8 @@ bool KuickShow::eventFilter( QObject *o, QEvent *e )
}
// we definitely have a fileWidget here!
- // TODO: check whether these keys can be implemented as actions
- // then this block handling key events is superfluous
-
- if ( key == Qt::Key_Home || KStandardShortcut::begin().contains( k->key() ) )
- {
- item = fileWidget->gotoFirstImage();
- item_next = fileWidget->getNext( false );
- }
- else if ( key == Qt::Key_End || KStandardShortcut::end().contains( k->key() ) )
- {
- item = fileWidget->gotoLastImage();
- item_next = fileWidget->getPrevious( false );
- }
-
- else if (fileWidget->action(KDirOperator::Delete)->shortcuts().contains( key ))
+ if (fileWidget->action(KDirOperator::Delete)->shortcuts().contains( key ))
{
performDeleteCurrentImage(fileWidget);
}
@@ -959,17 +952,6 @@ bool KuickShow::eventFilter( QObject *o, QEvent *e )
{
ret = false;
}
-
- if ( FileWidget::isImage( item ) ) {
- m_viewer->showNextImage( item.url() );
-
- if ( KuickConfig::get().preloadImage && !item_next.isNull() ) // preload next image
- if ( FileWidget::isImage( item_next ) )
- m_viewer->cacheImage( item_next.url() );
-
- ret = true; // don't pass keyEvent
- }
-
} // keyPressEvent on ImageWindow
@@ -997,6 +979,7 @@ bool KuickShow::eventFilter( QObject *o, QEvent *e )
return KXmlGuiWindow::eventFilter(o, e);
}
+
void KuickShow::configuration()
{
if ( !fileWidget ) {
@@ -1098,7 +1081,7 @@ void KuickShow::saveProperties( KConfigGroup& kc )
urls.append( url.toDisplayString() ); // ### check if writePathEntry( prettyUrl ) works!
}
- // TODO: can config read/write a list of URls directly?
+ // TODO: can config read/write a list of URLs directly?
kc.writePathEntry( "Images shown", urls );
}
@@ -1108,6 +1091,7 @@ void KuickShow::saveSettings()
{
KSharedConfig::Ptr kc = KSharedConfig::openConfig();
KConfigGroup sessGroup(kc, "SessionSettings");
+ // TODO: action may have been destroyed before we get here
if(auto oneWindowAction = kuickAction("kuick_one_window"))
sessGroup.writeEntry( "OpenImagesInActiveWindow", oneWindowAction->isChecked() );
@@ -1338,7 +1322,7 @@ void KuickShow::setupKuickActions()
act = fileWidget->action(KDirOperator::ShowPreview);
connect(act, &QAction::toggled, this, &KuickShow::slotToggleInlinePreview);
- // image actions
+ // Image actions
act = KStandardAction::open(this, &KuickShow::slotOpenURL, this);
ac->addAction("openURL", act);