10#include <QtWidgets/QMenu>
12#include <QtGui/QAction>
14#if defined(BROWSER_QTWEBKIT)
15# include <QWebHistory>
18using namespace Qt::StringLiterals;
22 Q_ASSERT(!m_instance != !parent);
28GlobalActions::GlobalActions(QObject *parent) : QObject(parent)
33 QString resourcePath =
":/qt-project.org/assistant/images/"_L1;
35 resourcePath.append(
"mac"_L1);
37 resourcePath.append(
"win"_L1);
41 m_backAction =
new QAction(tr(
"&Back"), parent);
42 m_backAction->setEnabled(
false);
43 m_backAction->setShortcuts(QKeySequence::Back);
44 m_backAction->setIcon(QIcon(resourcePath +
"/previous.png"_L1));
45 connect(m_backAction, &QAction::triggered, centralWidget, &CentralWidget::backward);
46 m_actionList << m_backAction;
48 m_nextAction =
new QAction(tr(
"&Forward"), parent);
49 m_nextAction->setPriority(QAction::LowPriority);
50 m_nextAction->setEnabled(
false);
51 m_nextAction->setShortcuts(QKeySequence::Forward);
52 m_nextAction->setIcon(QIcon(resourcePath +
"/next.png"_L1));
53 connect(m_nextAction, &QAction::triggered, centralWidget, &CentralWidget::forward);
54 m_actionList << m_nextAction;
56 setupNavigationMenus(m_backAction, m_nextAction, centralWidget);
58 m_homeAction =
new QAction(tr(
"&Home"), parent);
59 m_homeAction->setShortcut(tr(
"ALT+Home"));
60 m_homeAction->setIcon(QIcon(resourcePath +
"/home.png"_L1));
61 connect(m_homeAction, &QAction::triggered, centralWidget, &CentralWidget::home);
62 m_actionList << m_homeAction;
64 QAction *separator =
new QAction(parent);
65 separator->setSeparator(
true);
66 m_actionList << separator;
68 m_zoomInAction =
new QAction(tr(
"Zoom &in"), parent);
69 m_zoomInAction->setPriority(QAction::LowPriority);
70 m_zoomInAction->setIcon(QIcon(resourcePath +
"/zoomin.png"_L1));
71 m_zoomInAction->setShortcut(QKeySequence::ZoomIn);
72 connect(m_zoomInAction, &QAction::triggered, centralWidget, &CentralWidget::zoomIn);
73 m_actionList << m_zoomInAction;
75 m_zoomOutAction =
new QAction(tr(
"Zoom &out"), parent);
76 m_zoomOutAction->setPriority(QAction::LowPriority);
77 m_zoomOutAction->setIcon(QIcon(resourcePath +
"/zoomout.png"_L1));
78 m_zoomOutAction->setShortcut(QKeySequence::ZoomOut);
79 connect(m_zoomOutAction, &QAction::triggered, centralWidget, &CentralWidget::zoomOut);
80 m_actionList << m_zoomOutAction;
82 separator =
new QAction(parent);
83 separator->setSeparator(
true);
84 m_actionList << separator;
86#if QT_CONFIG(clipboard)
87 m_copyAction =
new QAction(tr(
"&Copy selected Text"), parent);
88 m_copyAction->setPriority(QAction::LowPriority);
89 m_copyAction->setIconText(
"&Copy");
90 m_copyAction->setIcon(QIcon(resourcePath +
"/editcopy.png"_L1));
91 m_copyAction->setShortcuts(QKeySequence::Copy);
92 m_copyAction->setEnabled(
false);
93 connect(m_copyAction, &QAction::triggered, centralWidget, &CentralWidget::copy);
94 m_actionList << m_copyAction;
97 m_printAction =
new QAction(tr(
"&Print..."), parent);
98 m_printAction->setPriority(QAction::LowPriority);
99 m_printAction->setIcon(QIcon(resourcePath +
"/print.png"_L1));
100 m_printAction->setShortcut(QKeySequence::Print);
101 connect(m_printAction, &QAction::triggered, centralWidget, &CentralWidget::print);
102 m_actionList << m_printAction;
104 m_findAction =
new QAction(tr(
"&Find in Text..."), parent);
105 m_findAction->setIconText(tr(
"&Find"));
106 m_findAction->setIcon(QIcon(resourcePath +
"/find.png"_L1));
107 m_findAction->setShortcuts(QKeySequence::Find);
108 connect(m_findAction, &QAction::triggered, centralWidget, &CentralWidget::showTextSearch);
109 m_actionList << m_findAction;
111#if defined (Q_OS_UNIX) && !defined(Q_OS_MAC)
112 m_backAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::GoPrevious,
113 m_backAction->icon()));
114 m_nextAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::GoNext,
115 m_nextAction->icon()));
116 m_zoomInAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::ZoomIn,
117 m_zoomInAction->icon()));
118 m_zoomOutAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::ZoomOut,
119 m_zoomOutAction->icon()));
120#if QT_CONFIG(clipboard)
121 m_copyAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::EditCopy,
122 m_copyAction->icon()));
124 m_findAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::EditFind,
125 m_findAction->icon()));
126 m_homeAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::GoHome,
127 m_homeAction->icon()));
128 m_printAction->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::DocumentPrint,
129 m_printAction->icon()));
137#if QT_CONFIG(clipboard)
138 m_copyAction->setEnabled(centralWidget->hasSelection());
144#if QT_CONFIG(clipboard)
145void GlobalActions::setCopyAvailable(
bool available)
148 m_copyAction->setEnabled(available);
152#if defined(BROWSER_QTWEBKIT)
154void GlobalActions::slotAboutToShowBackMenu()
158 if (QWebHistory *history = CentralWidget::instance()->currentHelpViewer()->history()) {
159 const int currentItemIndex = history->currentItemIndex();
160 QList<QWebHistoryItem> items = history->backItems(history->count());
161 for (
int i = items.count() - 1; i >= 0; --i) {
162 QAction *action =
new QAction(
this);
163 action->setText(items.at(i).title());
164 action->setData(-1 * (currentItemIndex - i));
165 m_backMenu->addAction(action);
170void GlobalActions::slotAboutToShowNextMenu()
174 if (QWebHistory *history = CentralWidget::instance()->currentHelpViewer()->history()) {
175 const int count = history->count();
176 QList<QWebHistoryItem> items = history->forwardItems(count);
177 for (
int i = 0; i < items.count(); ++i) {
178 QAction *action =
new QAction(
this);
179 action->setData(count - i);
180 action->setText(items.at(i).title());
181 m_nextMenu->addAction(action);
186void GlobalActions::slotOpenActionUrl(QAction *action)
189 if (HelpViewer* viewer = CentralWidget::instance()->currentHelpViewer()) {
190 const int offset = action->data().toInt();
191 QWebHistory *history = viewer->history();
193 history->goToItem(history->forwardItems(history->count()
194 - offset + 1).back());
195 }
else if (offset < 0) {
196 history->goToItem(history->backItems(-1 * offset).first());
203void GlobalActions::setupNavigationMenus(QAction *back, QAction *next,
206#if defined(BROWSER_QTWEBKIT)
207 m_backMenu =
new QMenu(parent);
208 connect(m_backMenu, &QMenu::aboutToShow,
209 this, &GlobalActions::slotAboutToShowBackMenu);
210 connect(m_backMenu, &QMenu::triggered,
211 this, &GlobalActions::slotOpenActionUrl);
212 back->setMenu(m_backMenu);
214 m_nextMenu =
new QMenu(parent);
215 connect(m_nextMenu, &QMenu::aboutToShow,
216 this, &GlobalActions::slotAboutToShowNextMenu);
217 connect(m_nextMenu, &QMenu::triggered,
218 this, &GlobalActions::slotOpenActionUrl);
219 next->setMenu(m_nextMenu);