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 @@ -252,6 +252,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; @@ -68,7 +69,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 ); @@ -210,6 +211,13 @@ void createAnnotationsVideoWidgets(PageViewItem *item, const QLinkedList< Okular::Annotation * > &annotations); + /** + * Updates the default action and the checked states of the color mode menu. + * + * Call this when the color mode was changed or Change Colors was toggled. + */ + void updateColorModeMenu(); + // don't want to expose classes in here class PageViewPrivate * d; @@ -263,6 +271,14 @@ void slotPageSizes( int ); void slotTrimMarginsToggled( bool ); void slotTrimToSelectionToggled( bool ); + + /** + * Sets the color mode (render mode) to the one represented by @p action. + * + * If @p action represents the current mode, toggles the Change Colors feature. + */ + void slotColorModeActionTriggered(QAction * action); + void slotToggleForms(); void slotFormChanged( int pageNumber ); void slotRefreshPage(); 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,9 @@ KToggleAction * aZoomAutoFit; KActionMenu * aViewMode; KToggleAction * aViewContinuous; + ToggleActionMenu * aColorModeMenu; + QActionGroup * colorModeActions; + QAction * aColorModeNormal; QAction * aPrevAction; QAction * aToggleForms; QAction * aSpeakDoc; @@ -489,7 +493,7 @@ d->aZoomActual->setText(i18n("Zoom to 100%")); } -void PageView::setupViewerActions( KActionCollection * ac ) +void PageView::setupViewerActions( KActionCollection * ac, Okular::Part * part ) { d->actionCollection = ac; @@ -608,9 +612,59 @@ 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 ); + // Color Mode action menu + // The toolbar button will always show the last selected Change Colors mode, + // which is determined by Okular::SettingsCore::renderMode(). + d->aColorModeMenu = new ToggleActionMenu( QIcon::fromTheme( QStringLiteral("color-management") ), i18nc("@title:menu", "&Color Mode" ), this ); + d->aColorModeMenu->setDelayed( false ); + d->aColorModeMenu->setStickyMenu( false ); + ac->addAction( QStringLiteral( "color_mode_menu"), d->aColorModeMenu ); + d->colorModeActions = new QActionGroup( this ); + + // Add color mode Normal Colors action. + d->aColorModeNormal = new QAction( i18nc( "@item:inmenu color mode", "&Normal Colors" ), this ); + d->aColorModeNormal->setCheckable( true ); + ac->addAction( QStringLiteral( "color_mode_normal"), d->aColorModeNormal ); + d->aColorModeMenu->addAction( d->aColorModeNormal ); + d->colorModeActions->addAction( d->aColorModeNormal ); + + // Add other color mode actions. + auto addColorMode = [=] ( QAction * a, QString name, Okular::SettingsCore::EnumRenderMode::type id ) { + a->setCheckable( true ); + a->setData( int( id ) ); + d->aColorModeMenu->addAction( a ); + ac->addAction( name, a ); + d->colorModeActions->addAction( a ); + }; + QAction * tmpAction = new QAction( i18nc( "@item:inmenu color mode", "&Invert Colors" ), this ); + addColorMode( tmpAction, + "color_mode_inverted", Okular::SettingsCore::EnumRenderMode::Inverted ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_inverted triggered, now" << checked; } ); + tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Change &Paper Color" ), this ); + addColorMode( tmpAction, + "color_mode_paper", Okular::SettingsCore::EnumRenderMode::Paper ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_paper triggered, now" << checked; } ); + tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Change &Dark && Light Colors" ), this ); + addColorMode( tmpAction, + "color_mode_recolor", Okular::SettingsCore::EnumRenderMode::Recolor ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_recolor triggered, now" << checked; } ); + tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Convert to &Black && White" ), this ); + addColorMode( tmpAction, + "color_mode_black_white", Okular::SettingsCore::EnumRenderMode::BlackWhite ); + connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_black_white triggered, now" << checked; } ); + + connect( d->colorModeActions, &QActionGroup::triggered, + this, &PageView::slotColorModeActionTriggered ); + + // Add Configure Color Modes action. + d->aColorModeMenu->addSeparator(); + QAction * aConfigure = new QAction( QIcon::fromTheme( QStringLiteral("configure") ), + i18nc( "@item:inmenu color mode", "C&onfigure Color Modes..." ), + this ); + d->aColorModeMenu->addAction( aConfigure ); + connect( aConfigure, &QAction::triggered, part, &Okular::Part::slotAccessibilityPreferences ); + + updateColorModeMenu(); } // WARNING: 'setupViewerActions' must have been called before this method @@ -1195,6 +1249,9 @@ if ( d->aViewContinuous ) d->aViewContinuous->setEnabled( haspages ); + if ( d->aColorModeMenu ) + d->aColorModeMenu->setEnabled( haspages ); + if ( d->aZoomFitWidth ) d->aZoomFitWidth->setEnabled( haspages ); if ( d->aZoomFitPage ) @@ -5524,13 +5581,52 @@ Okular::SettingsCore::setChangeColors(active); Okular::Settings::self()->save(); viewport()->update(); + updateColorModeMenu(); } void PageView::slotToggleChangeColors() { slotSetChangeColors( !Okular::SettingsCore::changeColors() ); } +void PageView::slotColorModeActionTriggered( QAction * action ) +{ + const int newRenderMode = action->data().toInt(); + if ( Okular::SettingsCore::renderMode() == newRenderMode || action == d->aColorModeNormal ) + { + slotToggleChangeColors(); + } + else + { + Okular::SettingsCore::setRenderMode( newRenderMode ); + slotSetChangeColors( true ); + updateColorModeMenu(); + } +} + +void PageView::updateColorModeMenu() +{ + // Check the current color mode. + const int rm = Okular::SettingsCore::renderMode(); + for ( QAction * a : d->colorModeActions->actions() ) + { + if ( a == d->aColorModeNormal ) + { + continue; + } + + if ( a->data().toInt() == rm ) + { + a->setChecked( true ); + d->aColorModeMenu->setDefaultAction( a ); + break; + } + } + + // If Change Colors is disabled, check Normal Colors instead. + d->aColorModeNormal->setChecked( !Okular::SettingsCore::changeColors() ); +} + void PageView::slotFitWindowToPage() { const PageViewItem *currentPageItem = nullptr;