Changeset View
Changeset View
Standalone View
Standalone View
documentation/documentationview.cpp
Show All 13 Lines | 1 | /* | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License | ||
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to | ||
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | Boston, MA 02110-1301, USA. | 17 | Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "documentationview.h" | 20 | #include "documentationview.h" | ||
21 | 21 | | |||
22 | #include <QWidgetAction> | ||||
22 | #include <QAction> | 23 | #include <QAction> | ||
23 | #include <QIcon> | 24 | #include <QIcon> | ||
24 | #include <QVBoxLayout> | 25 | #include <QVBoxLayout> | ||
25 | #include <QComboBox> | 26 | #include <QComboBox> | ||
26 | #include <QCompleter> | 27 | #include <QCompleter> | ||
27 | #include <QLayout> | | |||
28 | #include <QAbstractItemView> | 28 | #include <QAbstractItemView> | ||
29 | #include <QLineEdit> | 29 | #include <QLineEdit> | ||
30 | #include <QShortcut> | ||||
30 | 31 | | |||
31 | #include <KToolBar> | | |||
32 | #include <KLocalizedString> | 32 | #include <KLocalizedString> | ||
33 | 33 | | |||
34 | #include <interfaces/icore.h> | 34 | #include <interfaces/icore.h> | ||
35 | #include <interfaces/idocumentationprovider.h> | 35 | #include <interfaces/idocumentationprovider.h> | ||
36 | #include <interfaces/idocumentationproviderprovider.h> | 36 | #include <interfaces/idocumentationproviderprovider.h> | ||
37 | #include <interfaces/idocumentationcontroller.h> | 37 | #include <interfaces/idocumentationcontroller.h> | ||
38 | #include <interfaces/iplugincontroller.h> | 38 | #include <interfaces/iplugincontroller.h> | ||
39 | #include "documentationfindwidget.h" | 39 | #include "documentationfindwidget.h" | ||
40 | #include "debug.h" | 40 | #include "debug.h" | ||
41 | 41 | | |||
42 | using namespace KDevelop; | 42 | using namespace KDevelop; | ||
43 | 43 | | |||
44 | DocumentationView::DocumentationView(QWidget* parent, ProvidersModel* model) | 44 | DocumentationView::DocumentationView(QWidget* parent, ProvidersModel* model) | ||
45 | : QWidget(parent), mProvidersModel(model) | 45 | : QWidget(parent), mProvidersModel(model) | ||
46 | { | 46 | { | ||
47 | setWindowIcon(QIcon::fromTheme(QStringLiteral("documentation"), windowIcon())); | 47 | setWindowIcon(QIcon::fromTheme(QStringLiteral("documentation"), windowIcon())); | ||
48 | setWindowTitle(i18n("Documentation")); | 48 | setWindowTitle(i18n("Documentation")); | ||
49 | 49 | | |||
50 | setLayout(new QVBoxLayout(this)); | 50 | setLayout(new QVBoxLayout(this)); | ||
51 | layout()->setMargin(0); | 51 | layout()->setMargin(0); | ||
52 | layout()->setSpacing(0); | 52 | layout()->setSpacing(0); | ||
53 | 53 | | |||
54 | //TODO: clean this up, simply use addAction as that will create a toolbar automatically | 54 | mFindDoc = new DocumentationFindWidget; | ||
55 | mFindDoc->hide(); | ||||
56 | | ||||
57 | // insert placeholder widget at location of doc view | ||||
58 | layout()->addWidget(new QWidget(this)); | ||||
59 | layout()->addWidget(mFindDoc); | ||||
60 | | ||||
61 | setupActions(); | ||||
62 | | ||||
63 | mCurrent = mHistory.end(); | ||||
64 | | ||||
65 | setFocusProxy(mIdentifiers); | ||||
66 | | ||||
67 | QMetaObject::invokeMethod(this, "initialize", Qt::QueuedConnection); | ||||
68 | } | ||||
69 | | ||||
70 | void DocumentationView::setupActions() | ||||
71 | { | ||||
kossebau: Ah, forgot to separate the solving of this TODO in another diff.
Would do when pushing, unless… | |||||
55 | // use custom QAction's with createWidget for mProviders and mIdentifiers | 72 | // use custom QAction's with createWidget for mProviders and mIdentifiers | ||
56 | mActions = new KToolBar(this); | | |||
57 | // set window title so the QAction from QToolBar::toggleViewAction gets a proper name set | 73 | // set window title so the QAction from QToolBar::toggleViewAction gets a proper name set | ||
58 | mActions->setWindowTitle(i18n("Documentation Tool Bar")); | 74 | mBack = new QAction(QIcon::fromTheme(QStringLiteral("go-previous")), i18n("Back"), this); | ||
59 | mActions->setToolButtonStyle(Qt::ToolButtonIconOnly); | 75 | mBack->setEnabled(false); | ||
60 | int iconSize = style()->pixelMetric(QStyle::PM_SmallIconSize); | 76 | connect(mBack, &QAction::triggered, this, &DocumentationView::browseBack); | ||
61 | mActions->setIconSize(QSize(iconSize, iconSize)); | 77 | addAction(mBack); | ||
62 | 78 | | |||
63 | mFindDoc = new DocumentationFindWidget; | 79 | mForward = new QAction(QIcon::fromTheme(QStringLiteral("go-next")), i18n("Forward"), this); | ||
64 | mFindDoc->hide(); | 80 | mForward->setEnabled(false); | ||
81 | connect(mForward, &QAction::triggered, this, &DocumentationView::browseForward); | ||||
82 | addAction(mForward); | ||||
65 | 83 | | |||
66 | mBack = mActions->addAction(QIcon::fromTheme(QStringLiteral("go-previous")), i18n("Back")); | 84 | mFind = new QAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Find"), this); | ||
67 | mForward = mActions->addAction(QIcon::fromTheme(QStringLiteral("go-next")), i18n("Forward")); | 85 | connect(mFind, &QAction::triggered, mFindDoc, &DocumentationFindWidget::startSearch); | ||
68 | mFind = mActions->addAction(QIcon::fromTheme(QStringLiteral("edit-find")), i18n("Find"), mFindDoc, SLOT(startSearch())); | 86 | addAction(mFind); | ||
69 | mActions->addSeparator(); | 87 | | ||
70 | mActions->addAction(QIcon::fromTheme(QStringLiteral("go-home")), i18n("Home"), this, SLOT(showHome())); | 88 | QAction* separator = new QAction(this); | ||
71 | mProviders = new QComboBox(mActions); | 89 | separator->setSeparator(true); | ||
90 | addAction(separator); | ||||
91 | | ||||
92 | mHomeAction = new QAction(QIcon::fromTheme(QStringLiteral("go-home")), i18n("Home"), this); | ||||
93 | connect(mHomeAction, &QAction::triggered, this, &DocumentationView::showHome); | ||||
94 | addAction(mHomeAction); | ||||
95 | | ||||
96 | mProviders = new QComboBox(this); | ||||
97 | auto provicersAction = new QWidgetAction(this); | ||||
98 | provicersAction->setDefaultWidget(mProviders); | ||||
99 | addAction(provicersAction); | ||||
72 | 100 | | |||
73 | mIdentifiers = new QLineEdit(mActions); | 101 | mIdentifiers = new QLineEdit(this); | ||
74 | mIdentifiers->setClearButtonEnabled(true); | 102 | mIdentifiers->setClearButtonEnabled(true); | ||
75 | mIdentifiers->setPlaceholderText(i18n("Search...")); | 103 | mIdentifiers->setPlaceholderText(i18n("Search...")); | ||
76 | mIdentifiers->setCompleter(new QCompleter(mIdentifiers)); | 104 | mIdentifiers->setCompleter(new QCompleter(mIdentifiers)); | ||
77 | // mIdentifiers->completer()->setCompletionMode(QCompleter::UnfilteredPopupCompletion); | 105 | // mIdentifiers->completer()->setCompletionMode(QCompleter::UnfilteredPopupCompletion); | ||
78 | mIdentifiers->completer()->setCaseSensitivity(Qt::CaseInsensitive); | 106 | mIdentifiers->completer()->setCaseSensitivity(Qt::CaseInsensitive); | ||
79 | 107 | | |||
80 | /* vertical size policy should be left to the style. */ | 108 | /* vertical size policy should be left to the style. */ | ||
81 | mIdentifiers->setSizePolicy(QSizePolicy::Expanding, mIdentifiers->sizePolicy().verticalPolicy()); | 109 | mIdentifiers->setSizePolicy(QSizePolicy::Expanding, mIdentifiers->sizePolicy().verticalPolicy()); | ||
82 | connect(mIdentifiers->completer(), static_cast<void(QCompleter::*)(const QModelIndex&)>(&QCompleter::activated), | 110 | connect(mIdentifiers->completer(), static_cast<void(QCompleter::*)(const QModelIndex&)>(&QCompleter::activated), | ||
83 | this, &DocumentationView::changedSelection); | 111 | this, &DocumentationView::changedSelection); | ||
84 | connect(mIdentifiers, &QLineEdit::returnPressed, this, &DocumentationView::returnPressed); | 112 | connect(mIdentifiers, &QLineEdit::returnPressed, this, &DocumentationView::returnPressed); | ||
113 | auto identifiersAction = new QWidgetAction(this); | ||||
114 | identifiersAction->setDefaultWidget(mIdentifiers); | ||||
115 | addAction(identifiersAction); | ||||
85 | 116 | | |||
86 | QWidget::setTabOrder(mProviders, mIdentifiers); | 117 | auto closeFindBarShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this); | ||
87 | mActions->addWidget(mProviders); | 118 | closeFindBarShortcut->setContext(Qt::WidgetWithChildrenShortcut); | ||
88 | mActions->addWidget(mIdentifiers); | 119 | connect(closeFindBarShortcut, &QShortcut::activated, mFindDoc, &QWidget::hide); | ||
89 | 120 | } | |||
90 | mBack->setEnabled(false); | | |||
91 | mForward->setEnabled(false); | | |||
92 | connect(mBack, &QAction::triggered, this, &DocumentationView::browseBack); | | |||
93 | connect(mForward, &QAction::triggered, this, &DocumentationView::browseForward); | | |||
94 | mCurrent = mHistory.end(); | | |||
95 | | ||||
96 | layout()->addWidget(mActions); | | |||
97 | layout()->addWidget(new QWidget(this)); | | |||
98 | layout()->addWidget(mFindDoc); | | |||
99 | | ||||
100 | setFocusProxy(mIdentifiers); | | |||
101 | 121 | | |||
102 | QMetaObject::invokeMethod(this, "initialize", Qt::QueuedConnection); | 122 | QList<QAction*> DocumentationView::contextMenuActions() const | ||
123 | { | ||||
124 | return {mBack, mForward, mFind, mHomeAction}; // TODO: also show providers | ||||
103 | } | 125 | } | ||
104 | 126 | | |||
105 | void DocumentationView::initialize() | 127 | void DocumentationView::initialize() | ||
106 | { | 128 | { | ||
107 | mProviders->setModel(mProvidersModel); | 129 | mProviders->setModel(mProvidersModel); | ||
108 | connect(mProviders, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &DocumentationView::changedProvider); | 130 | connect(mProviders, static_cast<void (QComboBox::*)(int)>(&QComboBox::activated), this, &DocumentationView::changedProvider); | ||
109 | foreach (IDocumentationProvider* p, mProvidersModel->providers()) { | 131 | foreach (IDocumentationProvider* p, mProvidersModel->providers()) { | ||
110 | // can't use new signal/slot syntax here, IDocumentation is not a QObject | 132 | // can't use new signal/slot syntax here, IDocumentation is not a QObject | ||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Line(s) | |||||
223 | 245 | | |||
224 | void DocumentationView::updateView() | 246 | void DocumentationView::updateView() | ||
225 | { | 247 | { | ||
226 | mProviders->setCurrentIndex(mProvidersModel->rowForProvider((*mCurrent)->provider())); | 248 | mProviders->setCurrentIndex(mProvidersModel->rowForProvider((*mCurrent)->provider())); | ||
227 | mIdentifiers->completer()->setModel((*mCurrent)->provider()->indexModel()); | 249 | mIdentifiers->completer()->setModel((*mCurrent)->provider()->indexModel()); | ||
228 | mIdentifiers->setText((*mCurrent)->name()); | 250 | mIdentifiers->setText((*mCurrent)->name()); | ||
229 | mIdentifiers->completer()->setCompletionPrefix((*mCurrent)->name()); | 251 | mIdentifiers->completer()->setCompletionPrefix((*mCurrent)->name()); | ||
230 | 252 | | |||
231 | QLayoutItem* lastview = layout()->takeAt(1); | 253 | QLayoutItem* lastview = layout()->takeAt(0); | ||
232 | Q_ASSERT(lastview); | 254 | Q_ASSERT(lastview); | ||
233 | 255 | | |||
234 | if (lastview->widget()->parent() == this) { | 256 | if (lastview->widget()->parent() == this) { | ||
235 | lastview->widget()->deleteLater(); | 257 | lastview->widget()->deleteLater(); | ||
236 | } | 258 | } | ||
237 | 259 | | |||
238 | delete lastview; | 260 | delete lastview; | ||
239 | 261 | | |||
240 | mFindDoc->setEnabled(false); | 262 | mFindDoc->setEnabled(false); | ||
241 | QWidget* w = (*mCurrent)->documentationWidget(mFindDoc, this); | 263 | QWidget* w = (*mCurrent)->documentationWidget(mFindDoc, this); | ||
242 | Q_ASSERT(w); | 264 | Q_ASSERT(w); | ||
243 | QWidget::setTabOrder(mIdentifiers, w); | 265 | QWidget::setTabOrder(mIdentifiers, w); | ||
244 | 266 | | |||
245 | mFind->setEnabled(mFindDoc->isEnabled()); | 267 | mFind->setEnabled(mFindDoc->isEnabled()); | ||
246 | if (!mFindDoc->isEnabled()) { | 268 | if (!mFindDoc->isEnabled()) { | ||
247 | mFindDoc->hide(); | 269 | mFindDoc->hide(); | ||
248 | } | 270 | } | ||
249 | 271 | | |||
250 | QLayoutItem* findWidget = layout()->takeAt(1); | 272 | QLayoutItem* findWidget = layout()->takeAt(0); | ||
251 | layout()->addWidget(w); | 273 | layout()->addWidget(w); | ||
252 | layout()->addItem(findWidget); | 274 | layout()->addItem(findWidget); | ||
253 | } | 275 | } | ||
254 | 276 | | |||
255 | void DocumentationView::changedProvider(int row) | 277 | void DocumentationView::changedProvider(int row) | ||
256 | { | 278 | { | ||
257 | mIdentifiers->completer()->setModel(mProvidersModel->provider(row)->indexModel()); | 279 | mIdentifiers->completer()->setModel(mProvidersModel->provider(row)->indexModel()); | ||
258 | mIdentifiers->clear(); | 280 | mIdentifiers->clear(); | ||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |
Ah, forgot to separate the solving of this TODO in another diff.
Would do when pushing, unless you want that also separated for review.