Add new toolbar holding the quick annotations minibar action

This toolbar emulates the old version of the Okular annotation bar
remotes/origin/work/schwarzer/update_platform_name
Simone Gaiarin 5 years ago
parent 8837a1138f
commit 5d968d5112
  1. 5
      conf/okular.kcfg
  2. 52
      part/annotationactionhandler.cpp
  3. 5
      part/dlggeneral.cpp
  4. 5
      part/part.rc

@ -11,6 +11,7 @@
<signal name="colorModesChanged2" > <signal name="colorModesChanged2" >
<label>Same as colorModesChanged(), but kconfig_compiler does not allow to inherit signals, so appending a '2'.</label> <label>Same as colorModesChanged(), but kconfig_compiler does not allow to inherit signals, so appending a '2'.</label>
</signal> </signal>
<signal name="legacyAnnotationToolBarChanged" />
<group name="Dlg Performance" > <group name="Dlg Performance" >
<entry key="EnableCompositing" type="Bool" > <entry key="EnableCompositing" type="Bool" >
<default>true</default> <default>true</default>
@ -321,6 +322,10 @@
<default>true</default> <default>true</default>
<emit signal="viewContinuousChanged" /> <emit signal="viewContinuousChanged" />
</entry> </entry>
<entry key="LegacyAnnotationToolBar" type="Bool" >
<default>false</default>
<emit signal="legacyAnnotationToolBarChanged" />
</entry>
<entry key="ViewMode" type="Enum" > <entry key="ViewMode" type="Enum" >
<default>Single</default> <default>Single</default>
<choices> <choices>

@ -99,9 +99,10 @@ public:
void slotQuickToolSelected(int favToolId); void slotQuickToolSelected(int favToolId);
void slotSetColor(AnnotationColor colorType, const QColor &color = QColor()); void slotSetColor(AnnotationColor colorType, const QColor &color = QColor());
void slotSelectAnnotationFont(); void slotSelectAnnotationFont();
void slotToolBarVisibilityChanged(bool checked); void slotAnnotationToolBarVisibilityChanged(bool visible);
bool isQuickToolAction(QAction *aTool); bool isQuickToolAction(QAction *aTool);
bool isQuickToolStamp(int toolId); bool isQuickToolStamp(int toolId);
void assertToolBarExists(KParts::MainWindow *mw, const QString &toolBarName);
AnnotationActionHandler *q; AnnotationActionHandler *q;
@ -514,9 +515,10 @@ void AnnotationActionHandlerPrivate::slotSelectAnnotationFont()
} }
} }
void AnnotationActionHandlerPrivate::slotToolBarVisibilityChanged(bool checked) void AnnotationActionHandlerPrivate::slotAnnotationToolBarVisibilityChanged(bool visible)
{ {
if (!checked && !isQuickToolAction(agTools->checkedAction())) { aShowToolBar->setEnabled(!visible);
if (!visible && !isQuickToolAction(agTools->checkedAction())) {
q->deselectAllAnnotationActions(); q->deselectAllAnnotationActions();
} }
} }
@ -535,6 +537,13 @@ bool AnnotationActionHandlerPrivate::isQuickToolStamp(int toolId)
return annotType == QStringLiteral("stamp"); return annotType == QStringLiteral("stamp");
} }
void AnnotationActionHandlerPrivate::assertToolBarExists(KParts::MainWindow *mw, const QString &toolBarName)
{
QList<KToolBar *> toolbars = mw->toolBars();
auto itToolBar = std::find_if(toolbars.begin(), toolbars.end(), [&](const KToolBar *toolBar) { return toolBar->objectName() == toolBarName; });
Q_ASSERT(itToolBar != toolbars.end());
}
AnnotationActionHandler::AnnotationActionHandler(PageViewAnnotator *parent, KActionCollection *ac) AnnotationActionHandler::AnnotationActionHandler(PageViewAnnotator *parent, KActionCollection *ac)
: QObject(parent) : QObject(parent)
, d(new AnnotationActionHandlerPrivate(this)) , d(new AnnotationActionHandlerPrivate(this))
@ -544,10 +553,7 @@ AnnotationActionHandler::AnnotationActionHandler(PageViewAnnotator *parent, KAct
// toolbar visibility actions // toolbar visibility actions
d->aToolBarVisibility = new KToggleAction(QIcon::fromTheme(QStringLiteral("draw-freehand")), i18n("&Annotations"), this); d->aToolBarVisibility = new KToggleAction(QIcon::fromTheme(QStringLiteral("draw-freehand")), i18n("&Annotations"), this);
d->aHideToolBar = new QAction(QIcon::fromTheme(QStringLiteral("dialog-close")), i18nc("@action:intoolbar Hide the toolbar", "Hide"), this); d->aHideToolBar = new QAction(QIcon::fromTheme(QStringLiteral("dialog-close")), i18nc("@action:intoolbar Hide the toolbar", "Hide"), this);
connect(d->aHideToolBar, &QAction::triggered, this, [this]() { d->aToolBarVisibility->setChecked(false); });
d->aShowToolBar = new QAction(QIcon::fromTheme(QStringLiteral("draw-freehand")), i18nc("@action:intoolbar Show the builtin annotation toolbar", "Show more annotation tools"), this); d->aShowToolBar = new QAction(QIcon::fromTheme(QStringLiteral("draw-freehand")), i18nc("@action:intoolbar Show the builtin annotation toolbar", "Show more annotation tools"), this);
connect(d->aShowToolBar, &QAction::triggered, this, [this]() { d->aToolBarVisibility->setChecked(true); });
connect(d->aToolBarVisibility, &QAction::toggled, this, [this](bool checked) { d->aShowToolBar->setEnabled(!checked); });
// Text markup actions // Text markup actions
KToggleAction *aHighlighter = new KToggleAction(QIcon::fromTheme(QStringLiteral("draw-highlight")), i18nc("@action:intoolbar Annotation tool", "Highlighter"), this); KToggleAction *aHighlighter = new KToggleAction(QIcon::fromTheme(QStringLiteral("draw-highlight")), i18nc("@action:intoolbar Annotation tool", "Highlighter"), this);
@ -771,6 +777,8 @@ AnnotationActionHandler::AnnotationActionHandler(PageViewAnnotator *parent, KAct
ac->setDefaultShortcut(aRectangle, Qt::ALT + Qt::Key_0); ac->setDefaultShortcut(aRectangle, Qt::ALT + Qt::Key_0);
ac->setDefaultShortcut(d->aAddToQuickTools, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B)); ac->setDefaultShortcut(d->aAddToQuickTools, QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_B));
d->updateConfigActions(); d->updateConfigActions();
connect(Okular::Settings::self(), &Okular::Settings::legacyAnnotationToolBarChanged, this, &AnnotationActionHandler::setupAnnotationToolBarVisibilityAction);
} }
AnnotationActionHandler::~AnnotationActionHandler() AnnotationActionHandler::~AnnotationActionHandler()
@ -786,17 +794,29 @@ void AnnotationActionHandler::setupAnnotationToolBarVisibilityAction()
auto itMainWindow = std::find_if(widgets.begin(), widgets.end(), [](const QWidget *widget) { return qobject_cast<const KParts::MainWindow *>(widget) != nullptr; }); auto itMainWindow = std::find_if(widgets.begin(), widgets.end(), [](const QWidget *widget) { return qobject_cast<const KParts::MainWindow *>(widget) != nullptr; });
Q_ASSERT(itMainWindow != widgets.end()); Q_ASSERT(itMainWindow != widgets.end());
KParts::MainWindow *mw = qobject_cast<KParts::MainWindow *>(*itMainWindow); KParts::MainWindow *mw = qobject_cast<KParts::MainWindow *>(*itMainWindow);
// ensure that the annotation toolbar has been created and retrieve it
QList<KToolBar *> toolbars = mw->toolBars();
auto itToolBar = std::find_if(toolbars.begin(), toolbars.end(), [](const KToolBar *toolBar) { return toolBar->objectName() == QStringLiteral("annotationToolBar"); });
Q_ASSERT(itToolBar != toolbars.end());
KToolBar *annotationToolBar = mw->toolBar(QStringLiteral("annotationToolBar"));
d->aToolBarVisibility->setChecked(annotationToolBar->isVisible());
connect(annotationToolBar, &QToolBar::visibilityChanged, d->aToolBarVisibility, &QAction::setChecked, Qt::UniqueConnection);
connect(d->aToolBarVisibility, &QAction::toggled, annotationToolBar, &KToolBar::setVisible, Qt::UniqueConnection);
connect(d->aToolBarVisibility, &QAction::toggled, this, [this](bool checked) { d->slotToolBarVisibilityChanged(checked); });
d->aShowToolBar->setEnabled(!annotationToolBar->isVisible()); // ensure that the annotation toolbars have been created
d->assertToolBarExists(mw, QStringLiteral("annotationToolBar"));
d->assertToolBarExists(mw, QStringLiteral("quickAnnotationToolBar"));
KToolBar *annotationToolBar = mw->toolBar(QStringLiteral("annotationToolBar"));
connect(
annotationToolBar, &QToolBar::visibilityChanged, this, [this](bool visible) { d->slotAnnotationToolBarVisibilityChanged(visible); }, Qt::UniqueConnection);
// show action
connect(d->aShowToolBar, &QAction::triggered, annotationToolBar, &KToolBar::show, Qt::UniqueConnection);
// hide action
connect(d->aHideToolBar, &QAction::triggered, annotationToolBar, &KToolBar::hide, Qt::UniqueConnection);
KToolBar *defaultAnnotationToolBar = annotationToolBar;
if (Okular::Settings::legacyAnnotationToolBar()) {
defaultAnnotationToolBar = mw->toolBar(QStringLiteral("quickAnnotationToolBar"));
}
d->aToolBarVisibility->setChecked(false);
d->aToolBarVisibility->disconnect();
d->aToolBarVisibility->setChecked(defaultAnnotationToolBar->isVisible());
connect(defaultAnnotationToolBar, &QToolBar::visibilityChanged, d->aToolBarVisibility, &QAction::setChecked, Qt::UniqueConnection);
connect(d->aToolBarVisibility, &QAction::toggled, defaultAnnotationToolBar, &KToolBar::setVisible, Qt::UniqueConnection);
d->aShowToolBar->setEnabled(!defaultAnnotationToolBar->isVisible());
} }
void AnnotationActionHandler::reparseBuiltinToolsConfig() void AnnotationActionHandler::reparseBuiltinToolsConfig()

@ -165,6 +165,11 @@ DlgGeneral::DlgGeneral(QWidget *parent, Okular::EmbedMode embedMode)
openInContinuousModeByDefault->setText(i18nc("@option:check Config dialog, general page", "Open in continuous mode by default")); openInContinuousModeByDefault->setText(i18nc("@option:check Config dialog, general page", "Open in continuous mode by default"));
openInContinuousModeByDefault->setObjectName(QStringLiteral("kcfg_ViewContinuous")); openInContinuousModeByDefault->setObjectName(QStringLiteral("kcfg_ViewContinuous"));
layout->addRow(programFeaturesLabel(), openInContinuousModeByDefault); layout->addRow(programFeaturesLabel(), openInContinuousModeByDefault);
QCheckBox *useLegacyAnnotationToolBar = new QCheckBox(this);
useLegacyAnnotationToolBar->setText(i18nc("@option:check Config dialog, general page", "Use legacy annotation toolbar"));
useLegacyAnnotationToolBar->setObjectName(QStringLiteral("kcfg_LegacyAnnotationToolBar"));
layout->addRow(programFeaturesLabel(), useLegacyAnnotationToolBar);
// END Program features section // END Program features section
// If no Program features section, don’t add a second spacer: // If no Program features section, don’t add a second spacer:

@ -1,6 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<!DOCTYPE gui SYSTEM "kpartgui.dtd"> <!DOCTYPE gui SYSTEM "kpartgui.dtd">
<gui name="okular_part" version="49"> <gui name="okular_part" version="50">
<MenuBar> <MenuBar>
<Menu name="file"><text>&amp;File</text> <Menu name="file"><text>&amp;File</text>
<Action name="get_new_stuff" group="file_open"/> <Action name="get_new_stuff" group="file_open"/>
@ -137,4 +137,7 @@
<Spacer/> <Spacer/>
<Action name="hide_annotation_toolbar"/> <Action name="hide_annotation_toolbar"/>
</ToolBar> </ToolBar>
<ToolBar name="quickAnnotationToolBar" iconText="icononly" newline="true" hidden="true" position="right" iconSize="32"><text>Quick Annotation Toolbar</text>
<Action name="quick_annotation_action_bar"/>
</ToolBar>
</gui> </gui>

Loading…
Cancel
Save