Changeset View
Standalone View
ui/pageview.cpp
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | |||||
58 | #include <krun.h> | 58 | #include <krun.h> | ||
59 | 59 | | |||
60 | // system includes | 60 | // system includes | ||
61 | #include <math.h> | 61 | #include <math.h> | ||
62 | #include <stdlib.h> | 62 | #include <stdlib.h> | ||
63 | 63 | | |||
64 | // local includes | 64 | // local includes | ||
65 | #include "debug_ui.h" | 65 | #include "debug_ui.h" | ||
66 | #include "part.h" | ||||
66 | #include "formwidgets.h" | 67 | #include "formwidgets.h" | ||
67 | #include "pageviewutils.h" | 68 | #include "pageviewutils.h" | ||
68 | #include "pagepainter.h" | 69 | #include "pagepainter.h" | ||
69 | #include "core/annotations.h" | 70 | #include "core/annotations.h" | ||
70 | #include "annotwindow.h" | 71 | #include "annotwindow.h" | ||
71 | #include "guiutils.h" | 72 | #include "guiutils.h" | ||
72 | #include "annotationpopup.h" | 73 | #include "annotationpopup.h" | ||
73 | #include "pageviewannotator.h" | 74 | #include "pageviewannotator.h" | ||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Line(s) | 192 | #endif | |||
224 | QAction * aZoomIn; | 225 | QAction * aZoomIn; | ||
225 | QAction * aZoomOut; | 226 | QAction * aZoomOut; | ||
226 | QAction * aZoomActual; | 227 | QAction * aZoomActual; | ||
227 | KToggleAction * aZoomFitWidth; | 228 | KToggleAction * aZoomFitWidth; | ||
228 | KToggleAction * aZoomFitPage; | 229 | KToggleAction * aZoomFitPage; | ||
229 | KToggleAction * aZoomAutoFit; | 230 | KToggleAction * aZoomAutoFit; | ||
230 | KActionMenu * aViewMode; | 231 | KActionMenu * aViewMode; | ||
231 | KToggleAction * aViewContinuous; | 232 | KToggleAction * aViewContinuous; | ||
233 | ToggleActionMenu * aColorModeMenu; | ||||
234 | QActionGroup * colorModeActions; | ||||
235 | QAction * aColorModeNormal; | ||||
232 | QAction * aPrevAction; | 236 | QAction * aPrevAction; | ||
233 | QAction * aToggleForms; | 237 | QAction * aToggleForms; | ||
234 | QAction * aSpeakDoc; | 238 | QAction * aSpeakDoc; | ||
235 | QAction * aSpeakPage; | 239 | QAction * aSpeakPage; | ||
236 | QAction * aSpeakStop; | 240 | QAction * aSpeakStop; | ||
237 | KActionCollection * actionCollection; | 241 | KActionCollection * actionCollection; | ||
238 | QActionGroup * mouseModeActionGroup; | 242 | QActionGroup * mouseModeActionGroup; | ||
239 | QAction * aFitWindowToPage; | 243 | QAction * aFitWindowToPage; | ||
▲ Show 20 Lines • Show All 243 Lines • ▼ Show 20 Line(s) | 476 | { | |||
483 | d->aZoomIn = KStandardAction::zoomIn( this, SLOT(slotZoomIn()), ac ); | 487 | d->aZoomIn = KStandardAction::zoomIn( this, SLOT(slotZoomIn()), ac ); | ||
484 | 488 | | |||
485 | d->aZoomOut = KStandardAction::zoomOut( this, SLOT(slotZoomOut()), ac ); | 489 | d->aZoomOut = KStandardAction::zoomOut( this, SLOT(slotZoomOut()), ac ); | ||
486 | 490 | | |||
487 | d->aZoomActual = KStandardAction::actualSize( this, &PageView::slotZoomActual, ac ); | 491 | d->aZoomActual = KStandardAction::actualSize( this, &PageView::slotZoomActual, ac ); | ||
488 | d->aZoomActual->setText(i18n("Zoom to 100%")); | 492 | d->aZoomActual->setText(i18n("Zoom to 100%")); | ||
489 | } | 493 | } | ||
490 | 494 | | |||
491 | void PageView::setupViewerActions( KActionCollection * ac ) | 495 | void PageView::setupViewerActions( KActionCollection * ac, Okular::Part * part ) | ||
492 | { | 496 | { | ||
493 | d->actionCollection = ac; | 497 | d->actionCollection = ac; | ||
494 | 498 | | |||
495 | ac->setDefaultShortcut(d->aZoomIn, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Plus)); | 499 | ac->setDefaultShortcut(d->aZoomIn, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Plus)); | ||
496 | ac->setDefaultShortcut(d->aZoomOut, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Minus)); | 500 | ac->setDefaultShortcut(d->aZoomOut, QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_Minus)); | ||
497 | 501 | | |||
498 | // orientation menu actions | 502 | // orientation menu actions | ||
499 | d->aRotateClockwise = new QAction( QIcon::fromTheme( QStringLiteral("object-rotate-right") ), i18n( "Rotate &Right" ), this ); | 503 | d->aRotateClockwise = new QAction( QIcon::fromTheme( QStringLiteral("object-rotate-right") ), i18n( "Rotate &Right" ), this ); | ||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Line(s) | 588 | #undef ADD_VIEWMODE_ACTION | |||
602 | QAction * mz = new QAction(QIcon::fromTheme( QStringLiteral("page-zoom") ), i18n("&Zoom"), this); | 606 | QAction * mz = new QAction(QIcon::fromTheme( QStringLiteral("page-zoom") ), i18n("&Zoom"), this); | ||
603 | ac->addAction(QStringLiteral("mouse_zoom"), mz ); | 607 | ac->addAction(QStringLiteral("mouse_zoom"), mz ); | ||
604 | connect( mz, &QAction::triggered, this, &PageView::slotSetMouseZoom ); | 608 | connect( mz, &QAction::triggered, this, &PageView::slotSetMouseZoom ); | ||
605 | mz->setCheckable( true ); | 609 | mz->setCheckable( true ); | ||
606 | ac->setDefaultShortcut(mz, QKeySequence(Qt::CTRL + Qt::Key_2)); | 610 | ac->setDefaultShortcut(mz, QKeySequence(Qt::CTRL + Qt::Key_2)); | ||
607 | mz->setActionGroup( d->mouseModeActionGroup ); | 611 | mz->setActionGroup( d->mouseModeActionGroup ); | ||
608 | mz->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Zoom ); | 612 | mz->setChecked( Okular::Settings::mouseMode() == Okular::Settings::EnumMouseMode::Zoom ); | ||
609 | 613 | | |||
610 | QAction * aToggleChangeColors = new QAction(i18n("&Toggle Change Colors"), this); | 614 | // Color Mode action menu | ||
611 | ac->addAction(QStringLiteral("toggle_change_colors"), aToggleChangeColors ); | 615 | // The toolbar button will always show the last selected Change Colors mode, | ||
davidhurka: Which would be a good accelerator for “Change Colors”? | |||||
612 | connect( aToggleChangeColors, &QAction::triggered, this, &PageView::slotToggleChangeColors ); | 616 | // which is determined by Okular::SettingsCore::renderMode(). | ||
617 | d->aColorModeMenu = new ToggleActionMenu( QIcon::fromTheme( QStringLiteral("color-management") ), i18nc("@title:menu", "&Color Mode" ), this ); | ||||
618 | // Add the menu to the action collection, so it can be plugged into the tool bar. | ||||
619 | // It will not confuse the Configure Shortcuts dialog, because KActionMenu does not accept a shortcut. | ||||
620 | ac->addAction( QStringLiteral( "color_mode_menu"), d->aColorModeMenu ); | ||||
621 | d->colorModeActions = new QActionGroup( this ); | ||||
622 | | ||||
623 | // Add color mode Normal Colors action. | ||||
624 | d->aColorModeNormal = new QAction( i18nc( "@item:inmenu color mode", "&Normal Colors" ), this ); | ||||
625 | d->aColorModeNormal->setCheckable( true ); | ||||
626 | ac->addAction( QStringLiteral( "color_mode_normal"), d->aColorModeNormal ); | ||||
627 | d->aColorModeMenu->addAction( d->aColorModeNormal ); | ||||
628 | d->colorModeActions->addAction( d->aColorModeNormal ); | ||||
629 | | ||||
630 | // Add other color mode actions. | ||||
631 | auto addColorMode = [=] ( QAction * a, QString name, Okular::SettingsCore::EnumRenderMode::type id ) { | ||||
632 | a->setCheckable( true ); | ||||
633 | a->setData( int( id ) ); | ||||
634 | d->aColorModeMenu->addAction( a ); | ||||
Can I use Okular::SettingsCore::EnumRenderMode::type somehow for the action data, without casting it to int? davidhurka: Can I use Okular::SettingsCore::EnumRenderMode::type somehow for the action data, without… | |||||
635 | ac->addAction( name, a ); | ||||
636 | d->colorModeActions->addAction( a ); | ||||
I want to avoid function-like macros. Can I just add a private method instead? davidhurka: I want to avoid function-like macros. Can I just add a private method instead? | |||||
davidre: You could use a lambda instead | |||||
That is, I assign a lambda function to a locale auto variable, and “call” the variable? (I’m new to lambda, so I will try that.) davidhurka: That is, I assign a lambda function to a locale `auto` variable, and “call” the variable? (I’m… | |||||
davidre: Exactly! | |||||
637 | }; | ||||
638 | QAction * tmpAction = new QAction( i18nc( "@item:inmenu color mode", "&Invert Colors" ), this ); | ||||
639 | addColorMode( tmpAction, | ||||
640 | "color_mode_inverted", Okular::SettingsCore::EnumRenderMode::Inverted ); | ||||
641 | connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_inverted triggered, now" << checked; } ); | ||||
642 | tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Change &Paper Color" ), this ); | ||||
643 | addColorMode( tmpAction, | ||||
644 | "color_mode_paper", Okular::SettingsCore::EnumRenderMode::Paper ); | ||||
645 | connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_paper triggered, now" << checked; } ); | ||||
646 | tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Change &Dark && Light Colors" ), this ); | ||||
647 | addColorMode( tmpAction, | ||||
648 | "color_mode_recolor", Okular::SettingsCore::EnumRenderMode::Recolor ); | ||||
649 | connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_recolor triggered, now" << checked; } ); | ||||
650 | tmpAction = new QAction( i18nc( "@item:inmenu color mode", "Convert to &Black && White" ), this ); | ||||
651 | addColorMode( tmpAction, | ||||
652 | "color_mode_black_white", Okular::SettingsCore::EnumRenderMode::BlackWhite ); | ||||
653 | connect( tmpAction, &QAction::triggered, [=] (bool checked) { qDebug() << "color_mode_black_white triggered, now" << checked; } ); | ||||
654 | | ||||
655 | connect( d->colorModeActions, &QActionGroup::triggered, | ||||
656 | this, &PageView::slotColorModeActionTriggered ); | ||||
657 | | ||||
658 | // Add Configure Color Modes action. | ||||
659 | d->aColorModeMenu->addSeparator(); | ||||
660 | QAction * aConfigure = new QAction( QIcon::fromTheme( QStringLiteral("configure") ), | ||||
661 | i18nc( "@item:inmenu color mode", "C&onfigure Color Modes..." ), | ||||
662 | this ); | ||||
663 | d->aColorModeMenu->addAction( aConfigure ); | ||||
664 | connect( aConfigure, &QAction::triggered, part, &Okular::Part::slotAccessibilityPreferences ); | ||||
665 | | ||||
666 | updateColorModeMenu(); | ||||
613 | } | 667 | } | ||
614 | 668 | | |||
615 | // WARNING: 'setupViewerActions' must have been called before this method | 669 | // WARNING: 'setupViewerActions' must have been called before this method | ||
616 | void PageView::setupActions( KActionCollection * ac ) | 670 | void PageView::setupActions( KActionCollection * ac ) | ||
617 | { | 671 | { | ||
davidhurka: Unicode ellipsis … instead of periods ... ? | |||||
GB_2: No, we always use three dots.
This item should have the `configure` icon BTW. | |||||
davidhurka: Ok I’ll add that. | |||||
618 | d->actionCollection = ac; | 672 | d->actionCollection = ac; | ||
619 | 673 | | |||
620 | ac->setDefaultShortcuts(d->aZoomIn, KStandardShortcut::zoomIn()); | 674 | ac->setDefaultShortcuts(d->aZoomIn, KStandardShortcut::zoomIn()); | ||
621 | ac->setDefaultShortcuts(d->aZoomOut, KStandardShortcut::zoomOut()); | 675 | ac->setDefaultShortcuts(d->aZoomOut, KStandardShortcut::zoomOut()); | ||
622 | 676 | | |||
623 | // Mouse-Mode actions | 677 | // Mouse-Mode actions | ||
624 | d->aMouseSelect = new QAction(QIcon::fromTheme( QStringLiteral("select-rectangular") ), i18n("Area &Selection"), this); | 678 | d->aMouseSelect = new QAction(QIcon::fromTheme( QStringLiteral("select-rectangular") ), i18n("Area &Selection"), this); | ||
625 | ac->addAction(QStringLiteral("mouse_select"), d->aMouseSelect ); | 679 | ac->addAction(QStringLiteral("mouse_select"), d->aMouseSelect ); | ||
▲ Show 20 Lines • Show All 561 Lines • ▼ Show 20 Line(s) | 1240 | if ( d->aTrimToSelection ) | |||
1187 | d->aTrimToSelection->setEnabled( haspages ); | 1241 | d->aTrimToSelection->setEnabled( haspages ); | ||
1188 | 1242 | | |||
1189 | if ( d->aViewMode ) | 1243 | if ( d->aViewMode ) | ||
1190 | d->aViewMode->setEnabled( haspages ); | 1244 | d->aViewMode->setEnabled( haspages ); | ||
1191 | 1245 | | |||
1192 | if ( d->aViewContinuous ) | 1246 | if ( d->aViewContinuous ) | ||
1193 | d->aViewContinuous->setEnabled( haspages ); | 1247 | d->aViewContinuous->setEnabled( haspages ); | ||
1194 | 1248 | | |||
1249 | if ( d->aColorModeMenu ) | ||||
1250 | d->aColorModeMenu->setEnabled( haspages ); | ||||
1251 | | ||||
1195 | if ( d->aZoomFitWidth ) | 1252 | if ( d->aZoomFitWidth ) | ||
1196 | d->aZoomFitWidth->setEnabled( haspages ); | 1253 | d->aZoomFitWidth->setEnabled( haspages ); | ||
1197 | if ( d->aZoomFitPage ) | 1254 | if ( d->aZoomFitPage ) | ||
1198 | d->aZoomFitPage->setEnabled( haspages ); | 1255 | d->aZoomFitPage->setEnabled( haspages ); | ||
1199 | if ( d->aZoomAutoFit ) | 1256 | if ( d->aZoomAutoFit ) | ||
1200 | d->aZoomAutoFit->setEnabled( haspages ); | 1257 | d->aZoomAutoFit->setEnabled( haspages ); | ||
1201 | 1258 | | |||
1202 | if ( d->aZoom ) | 1259 | if ( d->aZoom ) | ||
▲ Show 20 Lines • Show All 4311 Lines • ▼ Show 20 Line(s) | 5534 | { | |||
5514 | }; | 5571 | }; | ||
5515 | } | 5572 | } | ||
5516 | 5573 | | |||
5517 | void PageView::slotSetChangeColors(bool active) | 5574 | void PageView::slotSetChangeColors(bool active) | ||
5518 | { | 5575 | { | ||
5519 | Okular::SettingsCore::setChangeColors(active); | 5576 | Okular::SettingsCore::setChangeColors(active); | ||
5520 | Okular::Settings::self()->save(); | 5577 | Okular::Settings::self()->save(); | ||
5521 | viewport()->update(); | 5578 | viewport()->update(); | ||
5579 | updateColorModeMenu(); | ||||
5522 | } | 5580 | } | ||
5523 | 5581 | | |||
5524 | void PageView::slotToggleChangeColors() | 5582 | void PageView::slotToggleChangeColors() | ||
5525 | { | 5583 | { | ||
5526 | slotSetChangeColors( !Okular::SettingsCore::changeColors() ); | 5584 | slotSetChangeColors( !Okular::SettingsCore::changeColors() ); | ||
5527 | } | 5585 | } | ||
5528 | 5586 | | |||
5587 | void PageView::slotColorModeActionTriggered( QAction * action ) | ||||
Just discovered that the existing slots (slotToggleChangeColors(), slotSetChangeColors(bool)) are exposed to D-Bus through Okular::Part. Probably, there should be another slot slotSetChangeColorsMode(QString or similar) to set the color mode from D-Bus. Exposing this slot to D-Bus makes little sense, because of the QAction* parameter. davidhurka: Just discovered that the existing slots (slotToggleChangeColors(), slotSetChangeColors(bool))… | |||||
5588 | { | ||||
5589 | const int newRenderMode = action->data().toInt(); | ||||
5590 | if ( Okular::SettingsCore::renderMode() == newRenderMode || action == d->aColorModeNormal ) | ||||
5591 | { | ||||
5592 | slotToggleChangeColors(); | ||||
5593 | } | ||||
This toggles Change Colors on and off, if the same shortcut e. g. for Invert Colors is triggered twice. But it also toggles if an already selected mode is clicked in the menu. Is that OK? davidhurka: This toggles Change Colors on and off, if the same shortcut e. g. for Invert Colors is… | |||||
5594 | else | ||||
5595 | { | ||||
5596 | Okular::SettingsCore::setRenderMode( newRenderMode ); | ||||
5597 | slotSetChangeColors( true ); | ||||
5598 | updateColorModeMenu(); | ||||
5599 | } | ||||
5600 | } | ||||
5601 | | ||||
5602 | void PageView::updateColorModeMenu() | ||||
5603 | { | ||||
5604 | // Check the current color mode. | ||||
5605 | const int rm = Okular::SettingsCore::renderMode(); | ||||
5606 | for ( QAction * a : d->colorModeActions->actions() ) | ||||
5607 | { | ||||
5608 | if ( a == d->aColorModeNormal ) | ||||
5609 | { | ||||
5610 | continue; | ||||
5611 | } | ||||
5612 | | ||||
5613 | if ( a->data().toInt() == rm ) | ||||
5614 | { | ||||
5615 | a->setChecked( true ); | ||||
5616 | d->aColorModeMenu->setDefaultAction( a ); | ||||
5617 | break; | ||||
5618 | } | ||||
5619 | } | ||||
5620 | | ||||
5621 | // If Change Colors is disabled, check Normal Colors instead. | ||||
5622 | d->aColorModeNormal->setChecked( !Okular::SettingsCore::changeColors() ); | ||||
5623 | } | ||||
5624 | | ||||
5529 | void PageView::slotFitWindowToPage() | 5625 | void PageView::slotFitWindowToPage() | ||
5530 | { | 5626 | { | ||
5531 | const PageViewItem *currentPageItem = nullptr; | 5627 | const PageViewItem *currentPageItem = nullptr; | ||
5532 | QSize viewportSize = viewport()->size(); | 5628 | QSize viewportSize = viewport()->size(); | ||
5533 | foreach ( const PageViewItem * pageItem, d->items ) | 5629 | foreach ( const PageViewItem * pageItem, d->items ) | ||
5534 | { | 5630 | { | ||
5535 | if ( pageItem->isVisible() ) | 5631 | if ( pageItem->isVisible() ) | ||
5536 | { | 5632 | { | ||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |
Which would be a good accelerator for “Change Colors”?