Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/documentation/documentationview.cpp
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Line(s) | 77 | { | |||
---|---|---|---|---|---|
82 | addAction(mBack); | 82 | addAction(mBack); | ||
83 | 83 | | |||
84 | mForward = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), i18n("Forward"), this); | 84 | mForward = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), i18n("Forward"), this); | ||
85 | mForward->setEnabled(false); | 85 | mForward->setEnabled(false); | ||
86 | connect(mForward, &QAction::triggered, this, &DocumentationView::browseForward); | 86 | connect(mForward, &QAction::triggered, this, &DocumentationView::browseForward); | ||
87 | addAction(mForward); | 87 | addAction(mForward); | ||
88 | 88 | | |||
89 | mHomeAction = new QAction(QIcon::fromTheme(QStringLiteral("go-home")), i18n("Home"), this); | 89 | mHomeAction = new QAction(QIcon::fromTheme(QStringLiteral("go-home")), i18n("Home"), this); | ||
90 | mHomeAction->setEnabled(false); | ||||
90 | connect(mHomeAction, &QAction::triggered, this, &DocumentationView::showHome); | 91 | connect(mHomeAction, &QAction::triggered, this, &DocumentationView::showHome); | ||
91 | addAction(mHomeAction); | 92 | addAction(mHomeAction); | ||
92 | 93 | | |||
93 | mProviders = new QComboBox(this); | 94 | mProviders = new QComboBox(this); | ||
94 | auto providersAction = new QWidgetAction(this); | 95 | auto providersAction = new QWidgetAction(this); | ||
95 | providersAction->setDefaultWidget(mProviders); | 96 | providersAction->setDefaultWidget(mProviders); | ||
96 | addAction(providersAction); | 97 | addAction(providersAction); | ||
97 | 98 | | |||
98 | mIdentifiers = new QLineEdit(this); | 99 | mIdentifiers = new QLineEdit(this); | ||
100 | mIdentifiers->setEnabled(false); | ||||
99 | mIdentifiers->setClearButtonEnabled(true); | 101 | mIdentifiers->setClearButtonEnabled(true); | ||
100 | mIdentifiers->setPlaceholderText(i18n("Search...")); | 102 | mIdentifiers->setPlaceholderText(i18n("Search...")); | ||
101 | mIdentifiers->setCompleter(new QCompleter(mIdentifiers)); | 103 | mIdentifiers->setCompleter(new QCompleter(mIdentifiers)); | ||
102 | // mIdentifiers->completer()->setCompletionMode(QCompleter::UnfilteredPopupCompletion); | 104 | // mIdentifiers->completer()->setCompletionMode(QCompleter::UnfilteredPopupCompletion); | ||
103 | mIdentifiers->completer()->setCaseSensitivity(Qt::CaseInsensitive); | 105 | mIdentifiers->completer()->setCaseSensitivity(Qt::CaseInsensitive); | ||
104 | 106 | | |||
105 | /* vertical size policy should be left to the style. */ | 107 | /* vertical size policy should be left to the style. */ | ||
106 | mIdentifiers->setSizePolicy(QSizePolicy::Expanding, mIdentifiers->sizePolicy().verticalPolicy()); | 108 | mIdentifiers->setSizePolicy(QSizePolicy::Expanding, mIdentifiers->sizePolicy().verticalPolicy()); | ||
107 | connect(mIdentifiers->completer(), static_cast<void(QCompleter::*)(const QModelIndex&)>(&QCompleter::activated), | 109 | connect(mIdentifiers->completer(), static_cast<void(QCompleter::*)(const QModelIndex&)>(&QCompleter::activated), | ||
108 | this, &DocumentationView::changedSelection); | 110 | this, &DocumentationView::changedSelection); | ||
109 | connect(mIdentifiers, &QLineEdit::returnPressed, this, &DocumentationView::returnPressed); | 111 | connect(mIdentifiers, &QLineEdit::returnPressed, this, &DocumentationView::returnPressed); | ||
110 | auto identifiersAction = new QWidgetAction(this); | 112 | auto identifiersAction = new QWidgetAction(this); | ||
111 | identifiersAction->setDefaultWidget(mIdentifiers); | 113 | identifiersAction->setDefaultWidget(mIdentifiers); | ||
112 | addAction(identifiersAction); | 114 | addAction(identifiersAction); | ||
113 | 115 | | |||
114 | mSeparatorBeforeFind = new QAction(this); | 116 | mSeparatorBeforeFind = new QAction(this); | ||
115 | mSeparatorBeforeFind->setSeparator(true); | 117 | mSeparatorBeforeFind->setSeparator(true); | ||
116 | addAction(mSeparatorBeforeFind); | 118 | addAction(mSeparatorBeforeFind); | ||
117 | 119 | | |||
118 | mFind = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Find in Text..."), this); | 120 | mFind = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Find in Text..."), this); | ||
119 | mFind->setToolTip(i18n("Find in text of current documentation page.")); | 121 | mFind->setToolTip(i18n("Find in text of current documentation page.")); | ||
122 | mFind->setEnabled(false); | ||||
120 | connect(mFind, &QAction::triggered, mFindDoc, &DocumentationFindWidget::startSearch); | 123 | connect(mFind, &QAction::triggered, mFindDoc, &DocumentationFindWidget::startSearch); | ||
121 | addAction(mFind); | 124 | addAction(mFind); | ||
122 | 125 | | |||
123 | auto closeFindBarShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this); | 126 | auto closeFindBarShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this); | ||
124 | closeFindBarShortcut->setContext(Qt::WidgetWithChildrenShortcut); | 127 | closeFindBarShortcut->setContext(Qt::WidgetWithChildrenShortcut); | ||
125 | connect(closeFindBarShortcut, &QShortcut::activated, mFindDoc, &QWidget::hide); | 128 | connect(closeFindBarShortcut, &QShortcut::activated, mFindDoc, &QWidget::hide); | ||
126 | } | 129 | } | ||
127 | 130 | | |||
128 | void DocumentationView::initialize() | 131 | void DocumentationView::initialize() | ||
129 | { | 132 | { | ||
130 | mProviders->setModel(mProvidersModel); | 133 | mProviders->setModel(mProvidersModel); | ||
131 | connect(mProviders, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &DocumentationView::changedProvider); | 134 | connect(mProviders, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &DocumentationView::changedProvider); | ||
132 | foreach (IDocumentationProvider* p, mProvidersModel->providers()) { | 135 | foreach (IDocumentationProvider* p, mProvidersModel->providers()) { | ||
133 | // can't use new signal/slot syntax here, IDocumentation is not a QObject | 136 | // can't use new signal/slot syntax here, IDocumentation is not a QObject | ||
134 | connect(dynamic_cast<QObject*>(p), SIGNAL(addHistory(KDevelop::IDocumentation::Ptr)), | 137 | connect(dynamic_cast<QObject*>(p), SIGNAL(addHistory(KDevelop::IDocumentation::Ptr)), | ||
135 | this, SLOT(addHistory(KDevelop::IDocumentation::Ptr))); | 138 | this, SLOT(addHistory(KDevelop::IDocumentation::Ptr))); | ||
136 | } | 139 | } | ||
137 | connect(mProvidersModel, &ProvidersModel::providersChanged, this, &DocumentationView::emptyHistory); | 140 | connect(mProvidersModel, &ProvidersModel::providersChanged, this, &DocumentationView::emptyHistory); | ||
138 | 141 | | |||
139 | if (mProvidersModel->rowCount() > 0) { | 142 | const bool hasProviders = (mProviders->count() > 0); | ||
143 | mHomeAction->setEnabled(hasProviders); | ||||
144 | mIdentifiers->setEnabled(hasProviders); | ||||
145 | if (hasProviders) { | ||||
140 | changedProvider(0); | 146 | changedProvider(0); | ||
141 | } | 147 | } | ||
142 | } | 148 | } | ||
143 | 149 | | |||
144 | void DocumentationView::browseBack() | 150 | void DocumentationView::browseBack() | ||
145 | { | 151 | { | ||
146 | --mCurrent; | 152 | --mCurrent; | ||
147 | mBack->setEnabled(mCurrent != mHistory.begin()); | 153 | mBack->setEnabled(mCurrent != mHistory.begin()); | ||
▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Line(s) | |||||
233 | } | 239 | } | ||
234 | 240 | | |||
235 | void DocumentationView::emptyHistory() | 241 | void DocumentationView::emptyHistory() | ||
236 | { | 242 | { | ||
237 | mHistory.clear(); | 243 | mHistory.clear(); | ||
238 | mCurrent = mHistory.end(); | 244 | mCurrent = mHistory.end(); | ||
239 | mBack->setEnabled(false); | 245 | mBack->setEnabled(false); | ||
240 | mForward->setEnabled(false); | 246 | mForward->setEnabled(false); | ||
241 | if (mProviders->count() > 0) { | 247 | const bool hasProviders = (mProviders->count() > 0); | ||
248 | mHomeAction->setEnabled(hasProviders); | ||||
249 | mIdentifiers->setEnabled(hasProviders); | ||||
250 | if (hasProviders) { | ||||
242 | mProviders->setCurrentIndex(0); | 251 | mProviders->setCurrentIndex(0); | ||
243 | changedProvider(0); | 252 | changedProvider(0); | ||
253 | } else { | ||||
254 | updateView(); | ||||
244 | } | 255 | } | ||
245 | } | 256 | } | ||
246 | 257 | | |||
247 | void DocumentationView::updateView() | 258 | void DocumentationView::updateView() | ||
248 | { | 259 | { | ||
260 | if (mCurrent != mHistory.end()) { | ||||
249 | mProviders->setCurrentIndex(mProvidersModel->rowForProvider((*mCurrent)->provider())); | 261 | mProviders->setCurrentIndex(mProvidersModel->rowForProvider((*mCurrent)->provider())); | ||
250 | mIdentifiers->completer()->setModel((*mCurrent)->provider()->indexModel()); | 262 | mIdentifiers->completer()->setModel((*mCurrent)->provider()->indexModel()); | ||
251 | mIdentifiers->setText((*mCurrent)->name()); | 263 | mIdentifiers->setText((*mCurrent)->name()); | ||
252 | mIdentifiers->completer()->setCompletionPrefix((*mCurrent)->name()); | 264 | mIdentifiers->completer()->setCompletionPrefix((*mCurrent)->name()); | ||
265 | } else { | ||||
266 | mIdentifiers->clear(); | ||||
267 | } | ||||
253 | 268 | | |||
254 | QLayoutItem* lastview = layout()->takeAt(0); | 269 | QLayoutItem* lastview = layout()->takeAt(0); | ||
255 | Q_ASSERT(lastview); | 270 | Q_ASSERT(lastview); | ||
256 | 271 | | |||
257 | if (lastview->widget()->parent() == this) { | 272 | if (lastview->widget()->parent() == this) { | ||
258 | lastview->widget()->deleteLater(); | 273 | lastview->widget()->deleteLater(); | ||
259 | } | 274 | } | ||
260 | 275 | | |||
261 | delete lastview; | 276 | delete lastview; | ||
262 | 277 | | |||
263 | mFindDoc->setEnabled(false); | 278 | mFindDoc->setEnabled(false); | ||
264 | QWidget* w = (*mCurrent)->documentationWidget(mFindDoc, this); | 279 | QWidget* w; | ||
280 | if (mCurrent != mHistory.end()) { | ||||
281 | w = (*mCurrent)->documentationWidget(mFindDoc, this); | ||||
265 | Q_ASSERT(w); | 282 | Q_ASSERT(w); | ||
266 | QWidget::setTabOrder(mIdentifiers, w); | 283 | QWidget::setTabOrder(mIdentifiers, w); | ||
284 | } else { | ||||
285 | // placeholder widget at location of doc view | ||||
286 | w = new QWidget(this); | ||||
287 | } | ||||
267 | 288 | | |||
268 | mFind->setEnabled(mFindDoc->isEnabled()); | 289 | mFind->setEnabled(mFindDoc->isEnabled()); | ||
269 | if (!mFindDoc->isEnabled()) { | 290 | if (!mFindDoc->isEnabled()) { | ||
270 | mFindDoc->hide(); | 291 | mFindDoc->hide(); | ||
271 | } | 292 | } | ||
272 | 293 | | |||
273 | QLayoutItem* findWidget = layout()->takeAt(0); | 294 | QLayoutItem* findWidget = layout()->takeAt(0); | ||
274 | layout()->addWidget(w); | 295 | layout()->addWidget(w); | ||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |