diff --git a/conf/preferencesdialog.h b/conf/preferencesdialog.h --- a/conf/preferencesdialog.h +++ b/conf/preferencesdialog.h @@ -32,6 +32,7 @@ public: PreferencesDialog( QWidget * parent, KConfigSkeleton * config, Okular::EmbedMode embedMode ); + void switchToAccessibilityPage(); void switchToAnnotationsPage(); protected: @@ -52,6 +53,7 @@ DlgDebug * m_debug; #endif + KPageWidgetItem * m_accessibilityPage; KPageWidgetItem * m_annotationsPage; }; diff --git a/conf/preferencesdialog.cpp b/conf/preferencesdialog.cpp --- a/conf/preferencesdialog.cpp +++ b/conf/preferencesdialog.cpp @@ -29,6 +29,7 @@ m_general = new DlgGeneral( this, embedMode ); m_performance = new DlgPerformance( this ); m_accessibility = new DlgAccessibility( this ); + m_accessibilityPage = nullptr; m_presentation = nullptr; m_annotations = nullptr; m_annotationsPage = nullptr; @@ -38,7 +39,7 @@ #endif addPage( m_general, i18n("General"), QStringLiteral("okular"), i18n("General Options") ); - addPage( m_accessibility, i18n("Accessibility"), QStringLiteral("preferences-desktop-accessibility"), i18n("Accessibility Reading Aids") ); + m_accessibilityPage = addPage( m_accessibility, i18n("Accessibility"), QStringLiteral("preferences-desktop-accessibility"), i18n("Accessibility Reading Aids") ); addPage( m_performance, i18n("Performance"), QStringLiteral("preferences-system-performance"), i18n("Performance Tuning") ); if( embedMode == Okular::ViewerWidgetMode ) { @@ -61,6 +62,12 @@ setHelp(QStringLiteral("configure"), QStringLiteral("okular")); } +void PreferencesDialog::switchToAccessibilityPage() +{ + if ( m_accessibilityPage ) + setCurrentPage( m_accessibilityPage ); +} + void PreferencesDialog::switchToAnnotationsPage() { if ( m_annotationsPage ) diff --git a/part.h b/part.h --- a/part.h +++ b/part.h @@ -255,6 +255,8 @@ void moveSplitter( const int sideWidgetSize ); + void slotAccessibilityPreferences(); + private: bool aboutToShowContextMenu(QMenu *menu, QAction *action, QMenu *contextMenu); void showMenu(const Okular::Page *page, const QPoint &point, const QString &bookmarkTitle = QString(), const Okular::DocumentViewport &vp = DocumentViewport(), bool showTOCActions = false); diff --git a/part.cpp b/part.cpp --- a/part.cpp +++ b/part.cpp @@ -623,7 +623,7 @@ if ( m_embedMode != PrintPreviewMode ) { // now set up actions that are required for all remaining modes - m_pageView->setupViewerActions( actionCollection() ); + m_pageView->setupViewerActions( actionCollection(), this ); // and if we are not in viewer mode, we want the full GUI if ( m_embedMode != ViewerWidgetMode ) { @@ -2945,6 +2945,17 @@ m_pageView->slotSetChangeColors(active); } +void Part::slotAccessibilityPreferences() +{ + // Create dialog + PreferencesDialog * dialog = new PreferencesDialog( m_pageView, Okular::Settings::self(), m_embedMode ); + dialog->setAttribute( Qt::WA_DeleteOnClose ); + + // Show it + dialog->switchToAccessibilityPage(); + dialog->show(); +} + void Part::slotAnnotationPreferences() { // Create dialog diff --git a/ui/pageview.h b/ui/pageview.h --- a/ui/pageview.h +++ b/ui/pageview.h @@ -34,6 +34,7 @@ namespace Okular { class Action; +class Part; class Document; class DocumentViewport; class FormFieldSignature; @@ -71,7 +72,7 @@ // create actions that interact with this widget void setupBaseActions( KActionCollection * collection ); - void setupViewerActions( KActionCollection * collection ); + void setupViewerActions( KActionCollection * collection, Okular::Part * part ); void setupActions( KActionCollection * collection ); void updateActionState( bool docHasPages, bool docChanged, bool docHasFormWidgets ); @@ -129,6 +130,11 @@ void slotToggleChangeColors(); void slotSetChangeColors(bool active); + + /** + * Sets the color mode (render mode) to the one represented by @param action. + */ + void slotSetChangeColorsMode(QAction * action); void slotSelectPage(); diff --git a/ui/pageview.cpp b/ui/pageview.cpp --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -63,6 +63,7 @@ // local includes #include "debug_ui.h" +#include "part.h" #include "formwidgets.h" #include "pageviewutils.h" #include "pagepainter.h" @@ -229,6 +230,8 @@ KToggleAction * aZoomAutoFit; KActionMenu * aViewMode; KToggleAction * aViewContinuous; + KActionMenu * aChangeColorsMenu; + QAction * aChangeColors; QAction * aPrevAction; QAction * aToggleForms; QAction * aSpeakDoc; @@ -488,7 +491,7 @@ d->aZoomActual->setText(i18n("Zoom to 100%")); } -void PageView::setupViewerActions( KActionCollection * ac ) +void PageView::setupViewerActions( KActionCollection * ac, Okular::Part * part ) { d->actionCollection = ac; @@ -609,9 +612,66 @@ mz->setActionGroup( d->mouseModeActionGroup ); mz->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Zoom ); - QAction * aToggleChangeColors = new QAction(i18n("&Toggle Change Colors"), this); - ac->addAction(QStringLiteral("toggle_change_colors"), aToggleChangeColors ); - connect( aToggleChangeColors, &QAction::triggered, this, &PageView::slotToggleChangeColors ); + // Change Colors action menu + d->aChangeColorsMenu = new KActionMenu( QIcon::fromTheme( QStringLiteral("color-management") ), i18n( "Change Colors" ), this ); + d->aChangeColorsMenu->setDelayed( false ); + d->aChangeColorsMenu->setStickyMenu( false ); + d->aChangeColorsMenu->setCheckable( true ); + d->aChangeColorsMenu->setChecked( Okular::SettingsCore::changeColors() ); + connect( d->aChangeColorsMenu, &QAction::triggered, this, &PageView::slotSetChangeColors ); + // Add the menu to the action collection, so it can be plugged into the tool bar. + // It will not confuse the Configure Shortcuts dialog, because KActionMenu does not accept a shortcut. + ac->addAction( QStringLiteral( "change_colors_menu"), d->aChangeColorsMenu ); + + d->aChangeColors = new QAction( i18nc( "@item:inmenu color mode", "&Change Colors" ), this ); + d->aChangeColors->setCheckable( true ); + d->aChangeColors->setChecked( Okular::SettingsCore::changeColors() ); + connect( d->aChangeColors, &QAction::triggered, this, &PageView::slotSetChangeColors ); + ac->addAction( QStringLiteral( "change_colors"), d->aChangeColors ); + d->aChangeColorsMenu->addAction( d->aChangeColors ); + connect( d->aChangeColors, &QAction::triggered, [=] (bool checked) { qDebug() << "change_colors triggered, now" << checked; } ); + connect( d->aChangeColorsMenu, &QAction::triggered, [=] (bool checked) { qDebug() << "change_colors_menu triggered, now" << checked; } ); + + d->aChangeColorsMenu->addSeparator(); + QActionGroup * cmGroup = new QActionGroup( this ); +#define ADD_COLORMODE_ACTION( action, name, id ) \ +do { \ + action->setCheckable( true ); \ + action->setData( qVariantFromValue( id ) ); \ + d->aChangeColorsMenu->addAction( action ); \ + ac->addAction( QStringLiteral(name), action ); \ + cmGroup->addAction( action ); \ +} while( 0 ) + QAction *tmpAction = new QAction( i18nc( "@item:inmenu color mode", "&Invert Colors" ), this ); + ADD_COLORMODE_ACTION( tmpAction, "change_colors_inverted", (int)Okular::SettingsCore::EnumRenderMode::Inverted ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "change_colors_inverted triggered, now" << checked; } ); + tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Change &Paper Color" ), this ); + ADD_COLORMODE_ACTION( tmpAction, "change_colors_paper", (int)Okular::SettingsCore::EnumRenderMode::Paper ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "change_colors_paper triggered, now" << checked; } ); + tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Change &Dark && Light Colors" ), this ); + ADD_COLORMODE_ACTION( tmpAction, "change_colors_recolor", (int)Okular::SettingsCore::EnumRenderMode::Recolor ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "change_colors_recolor triggered, now" << checked; } ); + tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Convert to &Black && White" ), this ); + ADD_COLORMODE_ACTION( tmpAction, "change_colors_black_white", (int)Okular::SettingsCore::EnumRenderMode::BlackWhite ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "change_colors_black_white triggered, now" << checked; } ); +#undef ADD_COLORMODE_ACTION + + const int rm = Okular::SettingsCore::renderMode(); + for ( QAction * a : cmGroup->actions() ) + { + if ( a->data().toInt() == rm ) + { + a->setChecked( true ); + break; + } + } + + connect( cmGroup, &QActionGroup::triggered, this, &PageView::slotSetChangeColorsMode ); + + d->aChangeColorsMenu->addSeparator(); + QAction * aConfigure = new QAction( i18nc( "@item:inmenu color mode", "C&onfigure..." ), this ); + d->aChangeColorsMenu->addAction( aConfigure ); + connect( aConfigure, &QAction::triggered, part, &Okular::Part::slotAccessibilityPreferences ); } // WARNING: 'setupViewerActions' must have been called before this method @@ -5507,13 +5567,30 @@ Okular::SettingsCore::setChangeColors(active); Okular::Settings::self()->save(); viewport()->update(); + d->aChangeColors->setChecked( active ); + d->aChangeColorsMenu->setChecked( active ); } void PageView::slotToggleChangeColors() { slotSetChangeColors( !Okular::SettingsCore::changeColors() ); } +void PageView::slotSetChangeColorsMode( QAction * action ) +{ + const int rm = action->data().toInt(); + if ( Okular::SettingsCore::renderMode() == rm ) + { + // Assigning a shortcut to a color mode only makes sense if it can toggle the feature on and off. + slotToggleChangeColors(); + } + else + { + Okular::SettingsCore::setRenderMode( rm ); + slotSetChangeColors( true ); + } +} + void PageView::slotFitWindowToPage() { const PageViewItem *currentPageItem = nullptr;